jQuery.noConflict();

var imgChange = false;

var imgSizes = {
	normal : {
		width : 314,
		height : 370
	},
	big : {
		width : 1256,
		height : 1480
	},
	veryBig : {
		width : 1697,
		height : 2000
	}
}

jQuery.noConflict();

function fnImgSrc() { // capture image src and repurpose for use with jqzoom
	var imgSrc = jQuery("#productImage > img").attr("src");
	
	var sizeRegexp = new RegExp(imgSizes.normal.width + ',' + imgSizes.normal.height, 'gi');
	var imgSrcBig = imgSrc.replace(sizeRegexp, imgSizes.big.width + ',' + imgSizes.big.height);

	var widRegexp = new RegExp('wid=' +imgSizes.normal.width, 'gi');
	var imgSrcBig = imgSrcBig.replace(widRegexp, 'wid=' + imgSizes.big.width);

	var heiRegexp = new RegExp('hei=' + imgSizes.normal.height, 'gi');
	var imgSrcBig = imgSrcBig.replace(heiRegexp, 'hei=' + imgSizes.big.height);

	var itsRegexp = new RegExp('sw=' + imgSizes.normal.width + '&sh=' + imgSizes.normal.height, 'gi');
	var imgSrcBig = imgSrcBig.replace(itsRegexp, 'sw=' + imgSizes.big.width + '&sh=' + imgSizes.big.height);		
	
	jQuery("#productImage > img").attr("jqimg", imgSrcBig);
	jQuery("#productImage > img").attr("jqimgBig", imgSrcBig);
}

jQuery(document).ready(function() {

	// USC-1214: Using both browser and object detection gives us quite reliabale results
	if(jQuery.browser.safari && window.devicePixelRatio){
		jQuery('div.tabControl ul.tabNavigation li a').css('font-size', '0.9em');
		jQuery('div.tabControl ul.tabNavigation li a').css('width', '120px');
	}
	// END USC-1214
	
	if (jQuery("#productFeatures iframe").length > 0 ){ //iframe shim for IE6
		jQuery("#productImage").mouseover(function(){
				jQuery("#productFeatures iframe").show();
		 });
		jQuery("#productImage").mouseout(function(){
				jQuery("#productFeatures iframe").hide();
		 });
	};
	
	jQuery.preloadImages = function() { // jQuery preloader
	  for(var i = 0; i<arguments.length; i++) {
	    jQuery("<img>").attr("src", arguments[i]);
	    //alert(arguments[i]);
	  }
	}
	jQuery("#imageNavigator > ul > li > a").each(function () { // preload each full size product image
		var imgToload = jQuery(this).attr("href");
	
		var sizeRegexp = new RegExp(imgSizes.normal.width + ',' + imgSizes.normal.width, 'gi');
		var imgToloadbig = imgToload.replace(sizeRegexp, imgSizes.big.width + ',' + imgSizes.big.width);
		
		var widRegexp = new RegExp('wid=' +imgSizes.normal.width, 'gi');
		var imgToloadbig = imgToloadbig.replace(widRegexp, 'wid=' + imgSizes.big.width);
	
		var heiRegexp = new RegExp('hei=' + imgSizes.normal.height, 'gi');
		var imgToloadbig = imgToloadbig.replace(heiRegexp, 'hei=' + imgSizes.big.height);

		var itsRegexp = new RegExp('sw=' + imgSizes.normal.width + '&sh=' + imgSizes.normal.height, 'gi');
		var imgToloadbig = imgToloadbig.replace(itsRegexp, 'sw=' + imgSizes.big.width + '&sh=' + imgSizes.big.height);		
		
		var imgToloadVerybig = imgToload.replace(imgSizes.normal.width + ',' + imgSizes.normal.width, imgSizes.veryBig.width + ',' + imgSizes.veryBig.width);
		var imgToloadVerybig = imgToloadVerybig.replace('wid=' +imgSizes.normal.width, 'wid=' + imgSizes.veryBig.width);
		var imgToloadVerybig = imgToloadVerybig.replace('hei=' + imgSizes.normal.height, 'hei=' + imgSizes.veryBig.height);
		
		jQuery.preloadImages(imgToload,imgToloadbig,imgToloadVerybig);
    });
	
	jQuery("#imageNavigator > ul > li > a").click(function () { // change product image on click
       var altImage = jQuery(this).attr("href");
       jQuery("#productImage > img").attr("src", altImage);
       fnImgSrc();
       return false;
    });
	
	fnImgSrc();
	
	jQuery(".jqzoom").jqueryzoom({
		xzoom: 605, //zooming div default width(default width value is 200)
		yzoom: 440, //zooming div default height(default height value is 200)
		offset: 100, //zooming div default offset(default offset value is 10)
		position: "right", //zooming div position(default position value is "right")
		preload: 1 , // preload of images :1 by default
		lens:1 // lens over the image 1 by default
	});
	
	jQuery("#productBadge").mouseover(function (event) {
		jQuery("#productImage > img").trigger(event);
	});
	
});
