/***********************************************
***  BUTTON ROLLOVER & PRELOAD  ****************
************************************************/

$(function(){
	// button rollover
	if ($('.imgBtn') != null) {
		$('.imgBtn').hover(function(){
				if(!$(this).is('.disabled'))
					$(this).attr("src", $(this).attr("src").replace(/^(.*?)(?:-hover)?(\..*?)$/i,'$1-hover$2'));
			},
			function(){
					if(!$(this).is('.disabled'))
						$(this).attr("src", $(this).attr("src").replace(/^(.*)-hover(\..*?)$/i, '$1$2'));
				});
	}
	// preload image rollovers
	if ($("img.imgBtn, img[src^='images/buttons/btn'], input[src^='images/buttons/btn']") != null) {
	    $("img.imgBtn, img[src^='images/buttons/btn'], input[src^='images/buttons/btn']").each(function(){
			    $("<img>").attr("src", $(this).attr("src").replace(/(btn-.*)(\..*?)/i, '$1-hover$2'));
		    });
	}
});

/***********************************************
***  TEXT SIZING  ******************************
************************************************/

var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
var startSz = 3;
function TextResize( trgt,inc ) {
	if (!$) return;
	var sz = startSz;
	
	sz += inc;
	if ( sz < 0 ) sz = 0;
	if ( sz > 6 ) sz = 6;
	startSz = sz;

	$(trgt).css("font-size", szs[sz]);
}

$(function(){
	$('.headerControls #textSizeUp').click(function(){
			TextResize('#main',1);
		});
	$('.headerControls #textSizeDown').click(function(){
			TextResize('#main',-1);
		});
});

/***********************************************
***  EXTERNAL LINKS  ***************************
************************************************/

$(document).ready(function() {
	$("a[rel=external]").each(function() {
		$(this).addClass('external');
		$(this).attr({
			title: "Open this page in a new window",
			target: "_blank"
		});
	})
	
	$('.shareBox').hide();
	$('.shareBtn').hover(function(){
		$(this).find('.shareBox').show();
	}, function(){
		$(this).find('.shareBox').hide();
	});
});

/***********************************************
***  CUSTOM SELECT BOX  ************************
************************************************/

$('html').addClass('jsEnabled');

$(function(){
	$('.selectReplace').selectbox();
});

/***********************************************
***  CUFON  ************************************
************************************************/

$(function() {
	Cufon.replace('h1');
	Cufon.replace('.freeTrialLink');
	Cufon.replace('.storeDetailsNote a');
	Cufon.replace('.macContainer span');
    	Cufon.now();
});

/***********************************************
***  EQUAL COLS  *******************************
************************************************/

function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
		    tallest = thisHeight;
		}
	});
	if ($.browser.msie && $.browser.version.substring(0,1) === '6'){
		group.css('height',tallest);
	}
	else {
		group.css('min-height',tallest);
	}
}

/***********************************************
***  RESULT LISTING BORDERS  *******************
************************************************/

$(function(){
		if($(".resultsList li").size() % 2 === 1){
			$(".resultsList li:last").addClass("bottom");
		}
		else
			$(".resultsList li:last").addClass("bottom").prev().addClass("bottom");
	});
