function clearValue(clearInput, defaultValue)
{
  if (clearInput.value == defaultValue) clearInput.value = '';
}
function showHide (showOrHide, elementToChange) {
  if (showOrHide == 'show')
  {
    $('#'+elementToChange).show();
  }
  else
  {
    $('#'+elementToChange).hide();
  }
}

function openUrl(url)
{
  window.open(url, '_self');
}
function openUrlFromSelect(select)
{
  var url = select.options[select.options.selectedIndex].value;
  openUrl(url);
}
function submitOnChange(idForm)
{
  $('#' + idForm).submit();
}


function ccTypeSelectShowHide(selectOrValue)
{
  if (typeof(selectOrValue) == 'string') {
    var val = selectOrValue;
  } else if (selectOrValue != undefined) {
    var val = selectOrValue.options[selectOrValue.options.selectedIndex].value;
  } else {
    var val = 'rubbish';
  }

  if (
  val == 'Solo'
  || val == 'Switch'
  || val == 'American Express'
  ) {
    $('#ecom_cc_extra').show();
    if (val != 'American Express') {
      $('#ecom_cc_extra_issue').show();
    } else {
      $('#ecom_cc_extra_issue').hide();
    }
  } else {
    $('#ecom_cc_extra_issue').hide();
    $('#ecom_cc_extra').hide();
  }
}



$(document).ready(function() {
  maxHeight = 0;
  els = new Array;
  i=0;
  $('.full-centre-editorial').find('.max-height .grey-box').each(function() {
    i=i+1;
    if ($.browser.msie && $.browser.version=='6.0') {
	    h5width = $(this).find('H5').width();
    }
	thisHeight = $(this).height();
    if (thisHeight > maxHeight) maxHeight = thisHeight;
    els.push(this);

    
    
    $(els).height(maxHeight);
    if ($.browser.msie && $.browser.version=='6.0') {
	    $(els).each(function () { 
	    	$(this).find('H5').width(h5width);
	    }); 
    }
    if (i==3) {
      i=0;
      maxHeight = 0;
      els = new Array;
    }

  });
  // $('.full-centre-editorial').find('.max-height .grey-box').css('height', maxHeight + 'px');


});

function collapsible_hide(clicked) {
  el = $(clicked).parents('.collapse');
  if (!el.hasClass('open')) {
	$(el).find('ul').slideUp();
	$(el).find('.grey-box').css('padding-bottom', '0');
	$(el).find('.grey-box h5').css('background-image', "url('/media/image/design/icons/grey-icon-list-closed.gif')");
    $(clicked).unbind('click');
    $(clicked).bind('click', function (event) {  if (!$(event.target).is('a')) { collapsible_show(clicked); } });
  } else {
    el.removeClass('open');
    $(el).find('.grey-box h5').css('background-image', "url('/media/image/design/icons/grey-icon-list-open.gif')");
    $(clicked).unbind('click');
    $(clicked).bind('click', function (event) { if (!$(event.target).is('a')) { collapsible_hide(clicked); } });
  }
}

function collapsible_show(clicked) {
  el = $(clicked).parents('.collapse');
  $(el).find('.grey-box').css('padding-bottom', '18px');
  $(el).find('.grey-box h5').css('background-image', "url('/media/image/design/icons/grey-icon-list-open.gif')");
  $(el).find('ul').slideDown();
  $(clicked).unbind('click');
  $(clicked).bind('click', function (event) { if (!$(event.target).is('a')) { collapsible_hide(clicked); } });
}


$(document).ready(function() {
  $('.collapse').find('h5').each( function () { collapsible_hide(this) });
  $('.open').find('h5').each( function () { collapsible_show(this) });

//  $('.collapse').find('.grey-box').css('padding-bottom', '0');
//  $('.collapse').find('h5').bind('click', function () { collapsible_show(this); });
});


function switch_gallery_image(clicked) {
  $('.slideshow-thumbs').find('a').bind('click', function () {
    switch_gallery_image(this);
  });
  $(clicked).unbind('click');
  $('#main-image').fadeTo('slow', 0, function() {
    $('#main-image').attr('src', $(clicked).attr('rel')).load(function () { $(this).fadeTo('slow', 1)});;
  });
}

$(document).ready(function () {
  /* preloading images */
  $('.slideshow-thumbs').each(function(){

      $(this).find('a:not(a.site_link)').each(function(){

          $("<img>").attr("src", jQuery(this).attr('href'));

          $(this).bind('click', function () {
            switch_gallery_image(this);
          }).attr('href', 'javascript:void(0)');

      });

  });
});

(function ($) {
    $.fn.vAlignImg = function(container) {
        return this.each(function(i){
      	   var paddingPx = 0; //change this value as you need (It is the extra height for the parent element)
      	   var el = $(this).find("img");
      	   var elh = $(el).height(); //new element height
      	   var ph = $(this).height(); //parent height
      	   if(elh > ph) { //if new element height is larger apply this to parent
      	       $(this).height(elh + paddingPx);
      	       ph = elh + paddingPx;
      	   }
      	   var nh = (ph - elh) / 2; //new margin to apply
      	   $(el).css('margin-top', nh);

        });
     };
})(jQuery);

$(document).ready(function () {
		$('ul.image-list li').vAlignImg();
	}
);

$(document).ready(function () {
  if(!document.getElementsByTagName) return;
  var links=document.getElementsByTagName("a");
  for(var i=0;i<links.length;i++) {
    var link=links[i];
    if(link.getAttribute("rel")=="external")link.target="_blank";
  }
});

$(document).ready(function() {
	$("a.fancy").fancybox({
	'frameHeight': 500,
	'frameWidth': 680,
	'zoomSpeedIn': 300,
	'zoomSpeedOut': 300,
	'overlayShow': false,
	'centerOnScroll': true,
	'hideOnContentClick': false
	});
	
	$('#fancy_close_link').click(function () {
		parent.top.$('#fancy_close').trigger('click'); 
		return false;
	});

});