var yourzoomContainerHeight;
var yzCanShowBigger = true;

function initYourZoom(){
	
    jQuery( ".altImage" ).mouseover(
    	function() 	{
    		updateLargeImage(jQuery,jQuery(this));
    	}
    );
 
    jQuery('.swatchImage').mouseover(
    	function()  {
    		updateLargeImage(jQuery,jQuery(this));
    	}
    );
    
    if (jQuery("#largeImage").length) {
		/* if flash not enabled */
		jQuery('#yourzoom').show();	
		if(jQuery('div#altImages').length){		    	
			jQuery('#yourzoomcontainer').css({'top' : 65});
			jQuery('#yzWrapper').height(jQuery('div#altImages').height() + 362);
			jQuery('#yourzoom').height(jQuery('div#altImages').height() + 362);
		}
      //return;
    }	
    
    if (!MM_FlashCanPlay) {
    	// flash not supported
    	return;
    }
	var path = null;
  
	if(jQuery("#largeImage")!=null) {
		if(jQuery("#largeImage").attr('src')!=null)
         path = jQuery("#largeImage").attr('src').replace("detail.jpg", "");
	}
	if(document.getElementById("yourzoomcontainer")!=null){
    document.getElementById("yourzoomcontainer").innerHTML = flashEmbed(
		'zoomimg',
		'http://yz.totes-isotoner.com/to/assets/fullscreen.swf',
		'100%', 
		'100%',
		'imageName='+path+'&downloadThreads=4&baseDomain=yourzoom.com&downloadHost=cdn&dataHost=yzos.s3.amazonaws.com&fullScreenEnabled=false&initialImageName=detail.jpg&initialImageFitWidth=350&initialImageFitHeight=350'
    );
	}
    jQuery("object").append(
    	    jQuery("<param/>").attr({
    	        'name': 'wmode',
    	        'value': 'transparent'
    	    })
    	).find("embed").attr('wmode', 'transparent');
     
    if(jQuery.browser.msie && jQuery("#360Panel").length > 0){    	
    	
    	jQuery('#yourzoomcontainer').append('<iframe class=ieOverlay />');
    	jQuery('.ieOverlay').css({'position': 'absolute', 'top' : 0, 'left' : 0, 'width' : jQuery("#360Panel").width(), 'height' : jQuery("#360Panel").height()})
    	
    	if(jQuery.browser.version.slice(0,1) == "9"){    		
    		jQuery('.ieOverlay').css({'width' : jQuery('.ieOverlay').width() - 3, 'height' : jQuery('.ieOverlay').height() - 3});
    	}
    	
    }
    
    if(jQuery('div#altImages').length > 0){		    	
		jQuery('#yourzoomcontainer').css({'top' : 65});
		jQuery('#yzWrapper').height(jQuery('div#altImages').height() + 362);
		jQuery('#yourzoom').height(jQuery('div#altImages').height() + 362);		    			
	}
	
	if(jQuery('div#360Panel').length > 0){						
		jQuery('#yzBigger').css('margin-top', 0);
	}
    
    jQuery('div.dragToRotate').click(
    	function(){
    		return false;
    	}
    );
    
    jQuery('#yourzoom').fadeIn(500);
	
    if (yzCanShowBigger) jQuery("#yzBigger").show();	
  
    jQuery("#yzBigger").click( 
    	function(){
    		yourzoomContainerHeight = jQuery("#yourzoomcontainer").height();
    		yourzoomContainerWidth = jQuery("#yourzoomcontainer").width();
    		
			jQuery("#yourzoom").width(jQuery(window).width() - 100);
			jQuery("#yourzoom").height(jQuery(window).height() - 100);
			jQuery("#yourzoom").offset({top:50+jQuery(window).scrollTop(),left:50});			
			
			jQuery("#yourzoomcontainer").height(jQuery("#yourzoom").height() - 120).width(jQuery("#yourzoom").width() - 120);
			jQuery('#360Panel').height(jQuery("#yourzoom").height() - 120).width(jQuery("#yourzoom").width() - 120);
			jQuery('#image360-reel').height(jQuery("#yourzoom").height() - 120).width(jQuery("#yourzoom").width() - 120);
			jQuery('#image360').height(jQuery("#yourzoom").height() - 120).css({'margin' : '0 auto', 'width' : 'auto'});
			jQuery('.jquery-reel-interface').height(jQuery("#yourzoom").height() - 120).width(jQuery("#yourzoom").width() - 120);
			jQuery('.jquery-reel-indicator').hide();			
			jQuery('#yzSmaller > div.dragToRotate').css('left', (((jQuery('#yzSmaller > div.dragToRotate').width() + jQuery("#yourzoomcontainer").width()) / 2) * -1));
			jQuery('.ieOverlay').height(jQuery("#yourzoom").height() - 120).width(jQuery("#yourzoom").width() - 120);
			
			if(jQuery.browser.version.slice(0,1) == "9"){    		
	    		jQuery('.ieOverlay').css({'width' : jQuery('.ieOverlay').width() - 3, 'height' : jQuery('.ieOverlay').height() - 3});
	    	}
			
			var leftOffSet = jQuery("#yourzoom").width() - jQuery("#yourzoomcontainer").width();
			leftOffSet = leftOffSet / 2;
			
			jQuery('#yourzoomcontainer').css({'left' : leftOffSet});
			jQuery('#360Panel').css({'left' : leftOffSet});
			
			jQuery("#yzBigger").hide();
			jQuery("#yzSmaller").show();
	
			/* Make a background div */
			var shadeDiv = jQuery('<div />');
			shadeDiv.addClass("yzShade");
			jQuery(document.body).append(shadeDiv);
			jQuery(".yzShade").height(jQuery(document.body).height());
			
			// ie7 z-index bug workaround - JMY 10/03/2011
			if(jQuery.browser.msie && jQuery.browser.version.slice(0,1) == "7"){				
				// set zindex of .yzWrapper to z-index of #yourzoomcontainer			
				jQuery('#yzWrapper').css('z-index', 1000);			
				
				// add relative div called .yzShadeWrapper around .yzshade
				// set css attributes of .yzShadeWrapper: 
				// position: relative; z-index: 999; height: 0 
				// and a value for top value that is calculated via widow height x 2			
				var yzShadeWrapperTop = jQuery(window).height() * -2.5;			
				
				jQuery('div.yzShade').wrap('<div class="yzShadeWrapper" />');
				jQuery('div.yzShadeWrapper').css({'position' : 'relative', 'z-index' : 999, 'top' : yzShadeWrapperTop, 'height' : 0});
				
				// set height of .yzShade to a value  
				// that is calculated via widow height x 2
				var yzShadeNewHeight = jQuery(window).height() + jQuery('div.yzShade').height();
				jQuery('div.yzShade').css('height', yzShadeNewHeight);
				
			}						
		}
    );

    jQuery("#yzSmaller").click(
    	function() 	{
			jQuery("#yourzoom").width(jQuery("#yourzoom").parent().width());
			jQuery("#yourzoom").height(jQuery("#yourzoom").parent().height());
			jQuery("#yourzoom").css({'top': 0, 'left' : 0});
			if(jQuery('div#altImages').length > 0){	
				jQuery('#yourzoomcontainer').height(yourzoomContainerHeight).width(yourzoomContainerWidth).css({'top': 65, 'left' : 0});
			} else {
				jQuery('#yourzoomcontainer').height(yourzoomContainerHeight).width(yourzoomContainerWidth).css({'top': 0, 'left' : 0});				
			}
			jQuery('#360Panel').height(yourzoomContainerHeight).width(yourzoomContainerWidth).css({'top': 0, 'left' : 0});
			jQuery('#image360-reel').height(yourzoomContainerHeight).width(yourzoomContainerWidth);
			jQuery('#image360').height(yourzoomContainerHeight).width(yourzoomContainerWidth);
			jQuery('.jquery-reel-interface').height(yourzoomContainerHeight).width(yourzoomContainerWidth);
			jQuery('.jquery-reel-indicator').show();
			jQuery('.ieOverlay').height(yourzoomContainerHeight).width(yourzoomContainerWidth);
			
			if(jQuery.browser.version.slice(0,1) == "9"){    		
	    		jQuery('.ieOverlay').css({'width' : jQuery('.ieOverlay').width() - 3, 'height' : jQuery('.ieOverlay').height() - 3});
	    	}
			
			jQuery("#yzBigger").show();
			jQuery("#yzSmaller").hide();
			jQuery(".yzShade").remove();
		}
    );
};

function updateLargeImage(jQuery,thumbImage){
  
	if(thumbImage.attr('id')=='alt360Image'){
		jQuery('div#360Panel').css('z-index', 1000);
		if(jQuery("#largeImage").length){
			jQuery('img#largeImage').hide();	
		}else{
			yzHideZoom();			
		}	  
	}else{
		var path = thumbImage.attr('src').replace("detail.jpg", "");  
		/* if using zoom */

		jQuery('div#360Panel').css('z-index', 999);
		if (jQuery("#largeImage").length) {
			/* if flash not enabled */
			jQuery('img#largeImage').show();
			jQuery("#largeImage").attr('src',thumbImage.attr('src'));
		}else{
			yzShowZoom();			
			window.document.zoomimg.loadImage(path, null, null, 'detail.jpg', 350, 350);	
		}
	}
}

function yzHideZoom() {
  
	jQuery('#yourzoomcontainer').css('z-index', 999);
 
  	// IE7 added this element above
	// if it exists, show it and put 
	// the zoom button back where it was
	if(jQuery('div.dragToRotate').length){
		jQuery('div.dragToRotate').show();
		jQuery('#yzBigger').css('background-position', 'right center');
	}
	
	// all Versions of IE add this element
	// show it to hide YZ
	if(jQuery.browser.msie){
		jQuery('.ieOverlay').show();	
	}
}
function yzShowZoom() {
	
	jQuery('#yourzoomcontainer').css('z-index', 1000);
  
  	// IE7 added this element above
	// if it exists, hide it and put 
	// the zoom button back where we had it
	if(jQuery('div.dragToRotate').length){
		jQuery('div.dragToRotate').hide();
		jQuery('#yzBigger').css('background-position', 'center center');
	}
	
	// all Versions of IE add this element
	// hide it show YZ
	if(jQuery.browser.msie){
		jQuery('.ieOverlay').hide();	
	}
}

function flashEmbed(id, movie, width, height, flashVars) {
  return '<OBJECT  classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" WIDTH="' + width + '" HEIGHT="' + height + '" id="' + id + '" ALIGN="">'
  + '   <PARAM NAME="movie" VALUE="' + movie + '">' 
  + '   <PARAM NAME="quality" VALUE="high">' 
  + '   <PARAM NAME="allowScriptAccess" VALUE="always">' 
  + '   <PARAM NAME="FlashVars" VALUE="' + flashVars + '">' 
  + '   <PARAM NAME="bgcolor" VALUE="#FFFFFF">' 
  + '   <embed src="' + movie + '" FlashVars="' + flashVars + '" quality="high" bgcolor="#FFFFFF" width="' + width + '" height="' + height +'" name="' + id + '" id="x' + id + '" allowScriptAccess="always" align="" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">' 
  + '</OBJECT>' ;
}

var MM_FlashCanPlay;
var MM_contentVersion = 6;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
		var words = navigator.plugins["Shockwave Flash"].description.split(" ");
  	    for (var i = 0; i < words.length; ++i)
	    {
		if (isNaN(parseInt(words[i])))
		continue;
		var MM_PluginVersion = words[i]; 
	    }
	var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
     && (navigator.appVersion.indexOf("Win") != -1)) {
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
	document.write('on error resume next \n');
	document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
	document.write('</SCR' + 'IPT\> \n');
}



function initYourZoomQV(){

    if (jQuery("#largeImage").length <= 0) {
      // this page doesn't have zoom
      return;
    }	
    
    jQuery( ".altImage" ).mouseover(
    	function() 	{
    		updateLargeImageQV(jQuery,jQuery(this));
    	}
    );
 
    jQuery('.swatchImage').mouseover(
    	function()  {
    		updateLargeImageQV(jQuery,jQuery(this));
    	}
    );

    if (!MM_FlashCanPlay) {
    	// flash not supported
    	return;
    }

    var path = jQuery("#largeImage").attr('src').replace("detail.jpg", "");
    
    document.getElementById("yourzoomcontainer").innerHTML = flashEmbed(
		'zoomimgQV',
		'http://yz.totes-isotoner.com/to/assets/fullscreen.swf',
		'100%', 
		'100%',
		'imageName='+path+'&downloadThreads=4&baseDomain=yourzoom.com&downloadHost=cdn&dataHost=yzos.s3.amazonaws.com&fullScreenEnabled=false&initialImageName=detail.jpg&initialImageFitWidth=350&initialImageFitHeight=350'
    );
   
    jQuery("object").append(
    	    jQuery("<param/>").attr({
    	        'name': 'wmode',
    	        'value': 'transparent'
    	    })
    	).find("embed").attr('wmode', 'transparent');
     
    if(jQuery.browser.msie && jQuery("#360Panel").length > 0){    	
    	
    	jQuery('#yourzoomcontainer').append('<iframe class=ieOverlay />');
    	jQuery('.ieOverlay').css({'position': 'absolute', 'top' : 0, 'left' : 0, 'width' : jQuery("#360Panel").width(), 'height' : jQuery("#360Panel").height()})
    	
    	if(jQuery.browser.version.slice(0,1) == "9"){    		
    		jQuery('.ieOverlay').css({'width' : jQuery('.ieOverlay').width() - 3, 'height' : jQuery('.ieOverlay').height() - 3});
    	}
    	
    }
    
    if(jQuery('div#altImages').length > 0){		    	
		jQuery('#yourzoomcontainer').css({'top' : 65});
		jQuery('#yzWrapper').height(jQuery('div#altImages').height() + 362);
		jQuery('#yourzoom').height(jQuery('div#altImages').height() + 362);		    			
	}
	
	if(jQuery('div#360Panel').length > 0){						
		jQuery('#yzBigger').css('margin-top', 0);
	}
    
    jQuery('div.dragToRotate').click(
    	function(){
    		return false;
    	}
    );
    
    jQuery('#yourzoom').fadeIn(500);
	
    if (yzCanShowBigger) jQuery("#yzBigger").show();	
  
    jQuery("#yzBigger").click( 
    	function(){
    		yourzoomContainerHeight = jQuery("#yourzoomcontainer").height();
    		yourzoomContainerWidth = jQuery("#yourzoomcontainer").width();
    		
			jQuery("#yourzoom").width(jQuery(window).width() - 100);
			jQuery("#yourzoom").height(jQuery(window).height() - 100);
			jQuery("#yourzoom").offset({top:50+jQuery(window).scrollTop(),left:50});			
			
			jQuery("#yourzoomcontainer").height(jQuery("#yourzoom").height() - 120).width(jQuery("#yourzoom").width() - 120);
			jQuery('#360Panel').height(jQuery("#yourzoom").height() - 120).width(jQuery("#yourzoom").width() - 120);
			jQuery('#image360-reel').height(jQuery("#yourzoom").height() - 120).width(jQuery("#yourzoom").width() - 120);
			jQuery('#image360').height(jQuery("#yourzoom").height() - 120).css({'margin' : '0 auto', 'width' : 'auto'});
			jQuery('.jquery-reel-interface').height(jQuery("#yourzoom").height() - 120).width(jQuery("#yourzoom").width() - 120);
			jQuery('.jquery-reel-indicator').hide();			
			jQuery('#yzSmaller > div.dragToRotate').css('left', (((jQuery('#yzSmaller > div.dragToRotate').width() + jQuery("#yourzoomcontainer").width()) / 2) * -1));
			jQuery('.ieOverlay').height(jQuery("#yourzoom").height() - 120).width(jQuery("#yourzoom").width() - 120);
			
			if(jQuery.browser.version.slice(0,1) == "9"){    		
	    		jQuery('.ieOverlay').css({'width' : jQuery('.ieOverlay').width() - 3, 'height' : jQuery('.ieOverlay').height() - 3});
	    	}
			
			var leftOffSet = jQuery("#yourzoom").width() - jQuery("#yourzoomcontainer").width();
			leftOffSet = leftOffSet / 2;
			
			jQuery('#yourzoomcontainer').css({'left' : leftOffSet});
			jQuery('#360Panel').css({'left' : leftOffSet});
			
			jQuery("#yzBigger").hide();
			jQuery("#yzSmaller").show();
	
			/* Make a background div */
			var shadeDiv = jQuery('<div />');
			shadeDiv.addClass("yzShade");
			jQuery(document.body).append(shadeDiv);
			jQuery(".yzShade").height(jQuery(document.body).height());
			
			// ie7 z-index bug workaround - JMY 10/03/2011
			if(jQuery.browser.msie && jQuery.browser.version.slice(0,1) == "7"){				
				// set zindex of .yzWrapper to z-index of #yourzoomcontainer			
				jQuery('#yzWrapper').css('z-index', 1000);			
				
				// add relative div called .yzShadeWrapper around .yzshade
				// set css attributes of .yzShadeWrapper: 
				// position: relative; z-index: 999; height: 0 
				// and a value for top value that is calculated via widow height x 2			
				var yzShadeWrapperTop = jQuery(window).height() * -2.5;			
				
				jQuery('div.yzShade').wrap('<div class="yzShadeWrapper" />');
				jQuery('div.yzShadeWrapper').css({'position' : 'relative', 'z-index' : 999, 'top' : yzShadeWrapperTop, 'height' : 0});
				
				// set height of .yzShade to a value  
				// that is calculated via widow height x 2
				var yzShadeNewHeight = jQuery(window).height() + jQuery('div.yzShade').height();
				jQuery('div.yzShade').css('height', yzShadeNewHeight);
				
			}						
		}
    );

    jQuery("#yzSmaller").click(
    	function() 	{
			jQuery("#yourzoom").width(jQuery("#yourzoom").parent().width());
			jQuery("#yourzoom").height(jQuery("#yourzoom").parent().height());
			jQuery("#yourzoom").css({'top': 0, 'left' : 0});
			if(jQuery('div#altImages').length > 0){	
				jQuery('#yourzoomcontainer').height(yourzoomContainerHeight).width(yourzoomContainerWidth).css({'top': 65, 'left' : 0});
			} else {
				jQuery('#yourzoomcontainer').height(yourzoomContainerHeight).width(yourzoomContainerWidth).css({'top': 0, 'left' : 0});				
			}
			jQuery('#360Panel').height(yourzoomContainerHeight).width(yourzoomContainerWidth).css({'top': 0, 'left' : 0});
			jQuery('#image360-reel').height(yourzoomContainerHeight).width(yourzoomContainerWidth);
			jQuery('#image360').height(yourzoomContainerHeight).width(yourzoomContainerWidth);
			jQuery('.jquery-reel-interface').height(yourzoomContainerHeight).width(yourzoomContainerWidth);
			jQuery('.jquery-reel-indicator').show();
			jQuery('.ieOverlay').height(yourzoomContainerHeight).width(yourzoomContainerWidth);
			
			if(jQuery.browser.version.slice(0,1) == "9"){    		
	    		jQuery('.ieOverlay').css({'width' : jQuery('.ieOverlay').width() - 3, 'height' : jQuery('.ieOverlay').height() - 3});
	    	}
			
			jQuery("#yzBigger").show();
			jQuery("#yzSmaller").hide();
			jQuery(".yzShade").remove();
		}
    );
};

function updateLargeImageQV(jQuery,thumbImage){
	  
	if(thumbImage.attr('id')=='alt360Image'){
		jQuery('div#360Panel').css('z-index', 1000);
		if(jQuery("#largeImage").length){
			jQuery('img#largeImage').hide();	
		}else{
			yzHideZoom();
			
		}	  
	}else{
		var path = thumbImage.attr('src').replace("detail.jpg", "");  
		/* if using zoom */

		jQuery('div#360Panel').css('z-index', 999);
		if (jQuery("#largeImage").length) {
			/* if flash not enabled */
			jQuery('img#largeImage').show();
			jQuery("#largeImage").attr('src',thumbImage.attr('src'));
		}else{
			yzShowZoom();			
			window.document.zoomimgQV.loadImage(path, null, null, 'detail.jpg', 350, 350);	
		}
	}
}



