$(document).ready(function(){
  

  imgToPreload = new Array();
	currentColor = 0;
	currentView = 0;
	currentSize = 0;
	arrayPos = 0;
	order = true;
	currentColorId = "";
	currentColorName = "";
	currentSizeName = "";
	currentTheme = "";
	titleProduct = "";
	
	init();
	minWidth();
	utils.addResizeEvent(minWidth);
	tabs2();
	
	return false;
});

var config = {
	pathPictures : "",
	pathColors : "",
	imgSize2Width : 304,
	imgSize2Height : 276,
	imgSize3Width : 1000,
	imgSize3Height : 941,
	showLinkSizes : false,
	showLinkWishList : false,
	showLinkSendFriend : false,
	timeOutShowPictures : 1000
};

var init = function(){
	if(utils.isDefined("productArray")){
		currentImg = productArray[1][0][1];
		currentTheme = productArray[1][0][1].split("/")[0].substr(0,5);
		
		var currentChoice = $.cookie('ptt_choice');
		if (currentChoice != null && currentChoice != ""){
		    if (currentTheme == currentChoice.split("_")[0]){
		        currentColorId = currentChoice.split("_")[1];
		        currentSizeName = currentChoice.split("_")[2];
		    }
		    else{
		        currentColorId = "";
		        currentSizeName = "";
	        }
		}
		else {
	    currentColorId = $("#hiddenColorId").val();
      currentSizeName = $("#hiddenSize").val();
    }
    
    var currentColorUrl = utils.getUrlParam("Couleur");
    if (currentColorUrl != null && currentColorUrl != "") { currentColorId = currentColorUrl; }

		preloading();
		zoomProduct();
		
		jQuery(".productsList").jcarousel({
			itemVisible: 1,
			itemScroll: 1,
			scrollAnimation : 800,
			wrap : true,
			wrapPrev : true
		});
		jcarouselItemOn();

		colors = new extract.colors(productArray);
		build.colors();
		
		sizes = new extract.sizes(productArray[1][0][3]);
		build.sizes();
		
		price = new extract.price(productArray[1][currentColor][3][currentSize]);
		build.price();
		
		build.views();	
		
		showLinkSizesFunc();
		showLinkWishListFunc();
		showLinkSendFriendFunc();
		$(".tabContent").jScrollPane({showArrows:false, scrollbarWidth:9, scrollbarMargin:0, dragMinHeight:26, dragMaxHeight:26});
		tabs();
	}
	
	topMenu();
	
	/*page shops */
  jQuery(".ShopsList").jcarousel({
    autoScroll: 4,
    wrap: true,
    wrapPrev : true,
		itemVisible: 1,
		itemScroll: 1,
		scrollAnimation : 800,
		noButtons : true
	});
	
  /* page gifts */
	heightBlockMax = 0;
	$(".gifts .right li").each(function(){ if( $(this).height() > heightBlockMax ) heightBlockMax = $(this).height(); }); // get max height
	$(".gifts .right li").each(function(){ $(this).css("height",heightBlockMax); }); // assign max height
	
	/* page discount */
	heightBlockMax = 0;
	$(".discount .right li").each(function(){ if( $(this).height() > heightBlockMax ) heightBlockMax = $(this).height(); }); // get max height
	$(".discount .right li").each(function(){ $(this).css("height",heightBlockMax); }); // assign max height
	
	/* page search */
	heightBlockMax = 0;
	$("#wrapSearch .scroller .right li").each(function(){ if( $(this).height() > heightBlockMax ) heightBlockMax = $(this).height(); }); // get max height
	$("#wrapSearch .scroller .right li").each(function(){ $(this).css("height",heightBlockMax); }); // assign max height
	
	if( $("#wrapSearch .scroller").is("div") )
		$("#wrapSearch .scroller").jScrollPane({showArrows:false, scrollbarWidth:17, scrollbarHeight:401, scrollbarMargin:0, dragMinHeight:57, dragMaxHeight:57});
	
	/* page login */
	if( $("#compte01 .scroller").is("div") )
		$("#compte01 .scroller").jScrollPane({showArrows:false, scrollbarWidth:17, scrollbarHeight:394, scrollbarMargin:0, dragMinHeight:57, dragMaxHeight:57});
		
	/* page user infos */
	if( $("#compte10 .scroller").is("div") )
		$("#compte10 .scroller").jScrollPane({showArrows:false, scrollbarWidth:17, scrollbarHeight:394, scrollbarMargin:0, dragMinHeight:57, dragMaxHeight:57});
	
	/* page favorite */
	if( $("#favorite04 .scroller").is("div") )
		$("#favorite04 .scroller").jScrollPane({showArrows:false, scrollbarWidth:17, scrollbarHeight:380, scrollbarMargin:0, dragMinHeight:57, dragMaxHeight:57});
		
	/* page newsletter */
    if( $("#corpo02 .scroller").is("div") )
		$("#corpo02 .scroller").jScrollPane({showArrows:false, scrollbarWidth:17, scrollbarHeight:360, scrollbarMargin:0, dragMinHeight:57, dragMaxHeight:57});
	
	/* page collection */
	($(".collection").size() == 2) ? $(".collections").css("width",664) : $(".collections").css("width",326);
	
	/* page fits */
	if( $("#fitList1").is("div") ){
		$("#fitList1 ul li a").each(function(i){
			this.setAttribute("rel", $("#"+this.href.split("#")[1]).offset().top );
			
			$(this).bind("click",function(){
				$(".fitsContainer #tab1 .scroller").get(0).scrollTo( parseInt( this.getAttribute("rel") ) - parseInt( $(".fitsContainer #tab1 .scroller").offset().top ) );
				return false;
			});
		});
	}
	
	if( $("#fitList2").is("div") ){
		$("#fitList2 ul li a").each(function(i){
			this.setAttribute("rel", $("#"+this.href.split("#")[1]).offset().top );
			
			$(this).bind("click",function(){
				$(".fitsContainer #tab2 .scroller").get(0).scrollTo( parseInt( this.getAttribute("rel") ) - parseInt( $(".fitsContainer #tab2 .scroller").offset().top ) );
				return false;
			});
		});
	}
	
	if( $(".fitsContainer .scroller").is("div") )
		$(".fitsContainer .scroller").jScrollPane({showArrows:false, scrollbarWidth:15, scrollbarHeight:366, scrollbarMargin:0, dragMinHeight:57, dragMaxHeight:57});
	
	/* page cleaning */
	if( $(".cleaningContainer .scroller").is("div") )
		$(".cleaningContainer .scroller").jScrollPane({showArrows:false, scrollbarWidth:15, scrollbarHeight:366, scrollbarMargin:0, dragMinHeight:57, dragMaxHeight:57});
		    
};

var jcarouselItemOn = function(){
	// from url : #list2_2
	if(document.location.href.indexOf("#list") > -1) {
		temp = document.location.href.substring( document.location.href.indexOf("#list") ).split("#")[1].split("_");
		$("ul li:eq(" + (temp[1]-1) + ")","."+temp[0]).addClass("on");
	}
};

var tabs = function(){
	$("#productDescription .item1").addClass("tabs-selected");
	$(".jScrollPaneContainer").hide();
	$("#tab1").parent(".jScrollPaneContainer").show();
	
	$("#productDescription ul li a").click(function(){
		$("#productDescription ul li").removeClass("tabs-selected");
		$("#tab2").removeClass("tabContent2");
		$(this).parent("li").addClass("tabs-selected");
		$(".jScrollPaneContainer").hide();
		$("#" + this.href.split("#")[1]).parent(".jScrollPaneContainer").show();
		$(".tabContent").jScrollPane({showArrows:false, scrollbarWidth:9, scrollbarMargin:0, dragMinHeight:26, dragMaxHeight:26});
		return false;
	});	
};

var tabs2 = function(){
	if( $(".advicesContainer").is("div") ){
		$(".advicesContainer .navTabs li:eq(0)").addClass("tabs-selected");
		$(".advicesContainer .tabContent").hide();
		$(".advicesContainer #tab1").show();
		
		$(".advicesContainer .navTabs li a").click(function(){
			$(".advicesContainer .navTabs li").removeClass("tabs-selected");
			$(this).parent("li").addClass("tabs-selected");
			$(".advicesContainer .tabContent").hide();
			$("#" + this.href.split("#")[1]).show();
			return false;
		});
	}
};

var showLinkSizesFunc = function(){
	if(config.showLinkSizes)
		$("#productSizes").after("<a href=\"sizes.html?TB_iframe=true&amp;width=422&amp;height=530\" class=\"thickbox\">Table des tailles</a>");
};

var showLinkWishListFunc = function(){
	if(config.showLinkWishList)
		$(".blockBottom .block3 .blockContent .col1 p").append("<a href=\"wishlist.html?TB_iframe=true&amp;width=422&amp;height=530\" class=\"addWishList thickbox\">ajouter à votre wishlist</a>");
};

var showLinkSendFriendFunc = function(){
	if(config.showLinkSendFriend)
		$(".blockBottom .block3 .blockContent .col1 p").append("<a href=\"send_to_friend.html?TB_iframe=true&amp;width=422&amp;height=530\" class=\"send thickbox\">Envoyer à une amie</a>");
};

function menuTamTam(targetListClass) {

  $("." + targetListClass + " > li").each(function(i){
    if($(this).is(".navLiLevelOne")){
      if (!$(this).attr("widthlevelone")) {
        $(this).attr("minwidth",$(this).get(0).offsetWidth - 25); // - margin
      }
      $(this).hover(
        function() {
          widthLevelOne = parseInt($(this).attr("minwidth"));
          $("> a",this).addClass("on");
          ulChild = $("ul",this);
          if (!$(ulChild).attr("minwidth")) {
            $(ulChild).attr("minwidth",$(this).get(0).offsetWidth);
          }
          $(ulChild).each(
            function() {
                $(this).css("left", (i  > 0) ? (-1 * Math.round( (parseInt($(this).attr("minwidth"))-widthLevelOne) / 2 )) + "px" :  "-1px");
                
                if ((targetListClass == "menu2") && (widthLevelOne > 0) && (($.browser.msie) && ($.browser.version.substr(0,3)=="6.0")))
                {
                  var form = $(this).parents('form:first');
                  var input =  $('select#ctl00_MainContent_DropDownItemsParPage', form);
                  input.css("visibility","hidden");
                }
            }
          );
        },
        function() {
          $("." + targetListClass + " > li > a").removeClass("on");
          $("ul",this).each(
            function(){
              $(this).css("left","-9999px");
              
              if ((targetListClass == "menu2") && (widthLevelOne > 0)  && (($.browser.msie)  && ($.browser.version.substr(0,3)=="6.0")))
                {
                  var form = $(this).parents('form:first');
                  var input =  $('select#ctl00_MainContent_DropDownItemsParPage', form);
                  input.css("visibility","visible");
                }
            }
          );          
        }
      );
    }
  });
}

var topMenu = function() {

  var menuClasses = new Array("menu1","menu2");

  $(menuClasses).each(
    function(i) {
      if ($("." + menuClasses[i]).size() > 0) {
        menuTamTam(menuClasses[i]);
      }
    }
  );
}

var preloading = function(){
	arrayPos++;
	imgToPreload[arrayPos] = new Image();
	imgToPreload[arrayPos].src = config.pathPictures + currentImg + "_view1_size2.jpg";
	
	arrayPos++;
	imgToPreload[arrayPos] = new Image();
	imgToPreload[arrayPos].src = config.pathPictures + currentImg + "_view1_size3.jpg";
	
	for(i=0; i<productArray[1].length; i++) {
		arrayPos++;
		imgToPreload[arrayPos] = new Image();
		imgToPreload[arrayPos].src = config.pathPictures + productArray[1][i][1] + "_view1_size2.jpg";
		
		arrayPos++;
		imgToPreload[arrayPos] = new Image();
		imgToPreload[arrayPos].src = config.pathPictures + productArray[1][i][1] + "_view2_size2.jpg";
		
		arrayPos++;
		imgToPreload[arrayPos] = new Image();
		imgToPreload[arrayPos].src = config.pathPictures + productArray[1][i][1] + "_view3_size2.jpg";
	}
};

var zoomProduct = function(){

	zoomBrowser = document.createElement("div");
	zoomBrowser.setAttribute("id","zoomBrowser");
	zoomBrowserImg = document.createElement("img");
	zoomBrowser.appendChild(zoomBrowserImg);
	
	zoomBrowserWrap = document.createElement("div");
	zoomBrowserWrap.setAttribute("id","zoomBrowserWrap");
	
	zoomView = document.createElement("div");
	zoomView.setAttribute("id","zoomView");
	zoomViewImg = document.createElement("img");
	zoomView.appendChild(zoomViewImg);
	
	zoomHover = document.createElement("div");
	zoomHover.setAttribute("id","zoomHover");
	
	zoomMouse = document.createElement("div");
	zoomMouse.setAttribute("id", "zoomMouse");
	zoomMouse.innerHTML = zoomActivateLabel;
	
	$(".pictureContainer").empty();
	$(".pictureContainer").append(zoomBrowser);
	$(".pictureContainer").append(zoomBrowserWrap);
	$(".pictureContainer").append(zoomView);
	$(".pictureContainer").append(zoomHover);
	$(".pictureContainer").append(zoomMouse);
	
	build.setPictureZoom(currentImg,currentView);
	
	scaley = Math.round( config.imgSize3Height / config.imgSize2Height );
	scalex = Math.round( config.imgSize3Width / config.imgSize2Width );
	
	zoomHoverH = (config.imgSize2Height / scaley)/1.2;
	zoomHoverW = (config.imgSize2Width / scalex)/1.2;
	$(zoomHover).css("height",zoomHoverH + "px");
	$(zoomHover).css("width",zoomHoverW + "px");
	
	zoomProductActivate();
	
};

var zoomProductActivate = function() {
	$(zoomBrowserWrap).unbind();
	$("#zoomBrowserWrap").css("cursor","pointer");
	
	$(zoomBrowserWrap).bind("mouseover",function(){
		$(document.body).get(0).browser = this;
		
		timerZoomView = setTimeout(function(){
			$(".blockTop > .block3 > .blockContent").hide(); // bug IE > position relative
			$(zoomView).show();
		},config.timeOutShowPictures);
		
		$(document.body).mousemove(function(e){
			mouse = new utils.MouseEvent(e);
			pos = new utils.findPos(this.browser);
			
			scrolly = mouse.y - pos.y;
			$(zoomView).get(0).scrollTop = (scrolly * scaley) - (30 * scaley);
			
			scrollx = mouse.x - pos.x;
			$(zoomView).get(0).scrollLeft = (scrollx * scalex) - (40 * scalex);
		});
	});
	
	$(zoomBrowserWrap).bind("mouseout",function(){
		$(".blockTop > .block3 > .blockContent").show();
		$(document.body).unbind("mousemove");
		$(zoomView).hide();
		clearTimeout(timerZoomView);
	});
}

var extract = {
	colors : function(array){
		this.name = new Array();
		this.productImg = new Array();
		this.colorImg = new Array();
		this.txt = new Array();
		this.id = new Array();
		
		for(i=0; i<array[1].length; i++){
			this.name[i] = productArray[1][i][0];
			this.productImg[i] = productArray[1][i][1];
			this.colorImg[i] = productArray[1][i][2];
			this.txt[i] = productArray[1][i][4];
			this.id[i] = productArray[1][i][1].split("_")[1];
		}
	},
	
	sizes : function(array){
		this.size = new Array();
		this.price = new Array();
		this.available = new Array();
		
		for(i=0; i<array.length; i++){
			this.size[i] = array[i][0];
			this.price[i] = array[i][1];
			this.available[i] = array[i][2];
		}
	},
	
	price : function(array){
		this.price = array[1];
		this.savePrice = array[2];
		this.discount = array[4];
	},
	
	available : function(array){
		this.available = array[3];
	}
};

var build = {
	colors : function(){
	    colorExist = false;
	    sizeExist = false;
	    sizeAvailable = false;
	    colorIndex = 0;
	    sizeIndex = 0;
	    for(i=0; i<colors.id.length; i++){
	        if (currentColorId != null && currentColorId != ""){
	            if (colors.id[i] == currentColorId){
			        colorExist = true;
			        colorIndex = i;
			        if (currentSizeName != null && currentSizeName != ""){
			            for(j=0; j<(productArray[1][i][3]).length; j++){
		                    if(productArray[1][i][3][j][0] == currentSizeName){
		                        sizeExist = true;
		                        sizeIndex = j;
		                        if (productArray[1][i][3][j][3] != 0){
		                            sizeAvailable = true;
		                            colorIndex = i;
	                            }
		                        break;
		                    }
		                }
		            }
		            break;
		        }
		    }
	    }
	    if (sizeExist && !sizeAvailable){
		    for(i=0; i<colors.name.length; i++){
                if(productArray[1][i][3][sizeIndex][3] != 0){
                    colorIndex = i;
                    break;
                }
	        }             
        }
	    
	  $(".productColors").empty();
	  
    for(i=0; i<colors.name.length; i++){
			container = document.createElement("div");
			container.className = "itemColor clearfix";
			
			colorLink = document.createElement("a");
			colorLink.setAttribute("href","#");
			colorLink.style.backgroundImage = "url("+ config.pathColors + colors.colorImg[i] +")";
			
			colorBackground = document.createElement("span");
			colorBackground.className = "legend";
			colorBackground.appendChild( document.createTextNode(colors.name[i]) );
			
			fading = document.createElement("div");
			fading.className = "fadeOn";
			
			container.appendChild(fading);
			container.appendChild(colorLink);
			container.appendChild(colorBackground);
			
			colorLink.current = i;
			
			if(i == 0 && !colorExist) {
				currentColorName = colors.name[0];
				currentColorId = colors.id[0];
				fading.style.display = "block";
				$("#hiddenColor").val(colors.name[0]);
				$("#hiddenColorId").val(colors.id[0]);
			}
			
			else if (colorExist){
			    if (i == colorIndex){
			        currentColor = i;
			        currentImg = colors.productImg[i];
			        currentColorName = colors.name[i];
				    fading.style.display = "block";
				    $("#hiddenColor").val(colors.name[i]);
				    $("#hiddenColorId").val(colors.id[i]);
				    build.setPictureZoom(currentImg,currentView);
			    }
			}
			
			colorLink.onmouseover = function(){
				imgHref = this.getAttribute("href").split("#");
				timerColor = setTimeout("build.setPictureZoom('"+colors.productImg[this.current]+"',"+currentView+")",config.timeOutShowPictures);
			};
			
			colorLink.onmouseout = function(){
				build.setPictureZoom(currentImg,currentView);
				clearTimeout(timerColor);
			};
			
			colorLink.onclick = function(){
				currentColor = this.current;
				currentColorName = colors.name[this.current];
				currentColorId = colors.id[this.current];
				currentImg = colors.productImg[this.current];
				
				titleProduct = titleName.replace('{colorName}',currentColorName);
				document.title=(titleProduct);
				
				$(".productColors .fadeOn:visible").hide().slideUp();
				$(this).prev().slideDown().show();
				
				sizes = new extract.sizes(productArray[1][this.current][3]);
				build.sizes();
				
				$.cookie('ptt_choice', currentTheme + "_" + currentColorId + "_" + currentSizeName, {path: '/'});
				$("#hiddenColor").val(currentColorName);
				$("#hiddenColorId").val(currentColorId);
			   buildURL();
				$("#tab1").html(colors.txt[this.current]);
				$(".tabContent").jScrollPane({showArrows:false, scrollbarWidth:9, scrollbarMargin:0, dragMinHeight:26, dragMaxHeight:26});
				
				return false;
			};
			
			titleProduct = titleName.replace('{colorName}',currentColorName);
			document.title=(titleProduct);
			
			$(".productColors").append(container);
		}
	},
	
	sizes : function(){
		selectSizes = $(".productSizes select").get(0);
		
		selectSizes.onchange = function(){
			currentSize = this.selectedIndex;
			currentSizeName = sizes.size[currentSize];
			$.cookie('ptt_choice', currentTheme + "_" + currentColorId + "_" + currentSizeName, {path: '/'});
			price = new extract.price( productArray[1][currentColor][3][this.selectedIndex] );
			build.price();
			
			available = new extract.available( productArray[1][currentColor][3][this.selectedIndex] );
			build.available();
			
			$("#hiddenSize").val( selectSizes.options[currentSize].text );
			buildURL();
		};
		
		if (productArray[1][currentColor][3][currentSize][3] == 0){
		    for(i=0; i<(productArray[1][currentColor][3]).length; i++){
		        if(productArray[1][currentColor][3][i][3] != 0){
		            currentSize = i;
		            break;
		        }
		    }
		}
		else{
		    for(i=0; i<sizes.size.length; i++){
		        if(sizes.size[i] == currentSizeName){
		            currentSize = i;
		            break;
		        }
		    }
		}
		
		selectSizes.selectedIndex = currentSize;
		currentSizeName = sizes.size[currentSize];
		$.cookie('ptt_choice', currentTheme + "_" + currentColorId + "_" + currentSizeName, {path: '/'});
		
		$("#hiddenSize").val( selectSizes.options[currentSize].text );
		
		price = new extract.price( productArray[1][currentColor][3][currentSize] );
		build.price();
		
		available = new extract.available( productArray[1][currentColor][3][currentSize] );
		build.available();
	},
	
	views : function(){
		for(i=0; i<3; i++){
		  container = document.createElement("div");
		  container.className = "itemView clearfix";
		  
			if (utils.isImageExists(config.pathPictures + currentImg.split("_")[0] + "_view" + (i+1) + "_size1.jpg")) 
			{
			    viewLink = document.createElement("a");
			    viewLink.setAttribute("href","#");
          viewLink.style.backgroundImage = "url("+ config.pathPictures + currentImg.split("_")[0] + "_view" + (i+1) + "_size1.jpg)";
                        			
			    viewLink.current = i;
			    
			    fading = document.createElement("div");
          fading.className = "fadeOn";
						
      		if (i == currentView)
          {
            $(viewLink).addClass('on');
			      fading.style.display = "block";
			    }
			    
			    container.appendChild(fading);
			    container.appendChild(viewLink);
    			
			    viewLink.onmouseover = function(){
				    timerView = setTimeout("build.setPictureZoom('"+currentImg+"',"+this.current+")",config.timeOutShowPictures);
			    };
    			
			    viewLink.onmouseout = function(){
				    build.setPictureZoom(currentImg,currentView);
				    clearTimeout(timerView);
			    };
    			
			    viewLink.onclick = function(){
				    currentView = this.current;
				    
				    $("#menuViews .fadeOn:visible").hide().slideUp();
				    $(this).prev().slideDown().show();
    				
				    $("#menuViews a").each(function(){ $(this).removeClass('on'); });
				    $(this).addClass('on');
    				
				    return false;
			    };
			    
			    $("#menuViews").append(container);
			}
		}
	},
	
	price : function(){
		if ((price.savePrice == 0) && (price.discount == "0")) {
			$(".productPrice").html(price.price + " &euro;").removeClass("savePriceContainer");
			$("#hiddenPrice").val(price.price);
		} else if ((price.savePrice > 0) && (price.discount == "1")) {
			$(".productPrice").html(price.savePrice + " &euro;<span class=\"savePrice\">" + lngInsteadOf + "<br /><span class=\"barred\">" + price.price + "</span> &euro;<br /><strong>" + prixSpecial + "</strong></span>").addClass("savePriceContainer");
			$("#hiddenPrice").val(price.savePrice);
		} else if ((price.savePrice > 0) && (price.discount == "0")) {
			$(".productPrice").html(price.savePrice + " &euro;<span class=\"savePrice\">" + lngInsteadOf + "<br /><span class=\"barred\">" + price.price + "</span> &euro;</span>").addClass("savePriceContainer");
			$("#hiddenPrice").val(price.savePrice);
		} else if (price.discount == "1") {
			$(".productPrice").html(price.price + " &euro;<span class=\"savePrice\"><strong>" + prixSpecial + "</strong></span>").addClass("savePriceContainer");
			$("#hiddenPrice").val(price.savePrice);
		}
		buildURL();
	},
	
	available : function(){
		$("#productAvailable").css("display","block");
    if(available.available == 0) {
			$(".qty").hide();
			$(".productPrice").hide();
			$("#productAvailable").show();
			$("#linkOrder").hide();
			$("#linkDispo").show();
			order = false;
		} else {
			$(".qty").show();
			$(".productPrice").show();
			$("#productAvailable").hide();
			$("#linkOrder").show();
			$("#linkDispo").hide();
			order = true;
		}
	},
	setPictureZoom : function(currentImg,currentView){
		arrayPos++;
		imgToPreload[arrayPos] = new Image();
		imgToPreload[arrayPos].src = config.pathPictures + currentImg + "_view" + (currentView+1) + "_size2.jpg";
		
		if( utils.isImageExists(imgToPreload[arrayPos].src) ) {
			$(".pictureContainer img").get(0).setAttribute("src",config.pathPictures + currentImg + "_view" + (currentView+1) + "_size2.jpg");
			zoomProductActivate();
		} else {
			$(".pictureContainer img").get(0).setAttribute("src",lngNoPicture);
			$(zoomBrowserWrap).unbind();
			$("#zoomBrowserWrap").css("cursor","default");
		}
				
		arrayPos++;
		imgToPreload[arrayPos] = new Image();
		imgToPreload[arrayPos].src = config.pathPictures + currentImg + "_view" + (currentView+1) + "_size3.jpg";
		
		if( utils.isImageExists(imgToPreload[arrayPos].src) ) {
			$(".pictureContainer #zoomView img").get(0).setAttribute("src",config.pathPictures + currentImg + "_view" + (currentView+1) + "_size3.jpg");
			zoomProductActivate();
			$(".pictureContainer #zoomMouse").css("display","block");
		} else {
			$(zoomBrowserWrap).unbind();
			$("#zoomBrowserWrap").css("cursor","default");
			$(".pictureContainer #zoomMouse").css("display","none");
		}
	}
};

var minWidth = function() {
	(utils.getWindowWidth()<979) ? $("#main").css({ left: "0px", marginLeft: "0px" }) : $("#main").css({ left: "50%", marginLeft: "-489px" });
	(utils.getWindowHeight()<600) ? $("#main").css({ top: "0px", marginTop: "0px" }) : $("#main").css({ top: "50%", marginTop: "-285px" });
};

var utils = {
	MouseEvent : function(e) {
		this.e = e ? e : window.event; 
		this.source = e.target ? e.target : e.srcElement;
		this.x = this.e.pageX ? this.e.pageX : this.e.clientX;
		this.y = this.e.pageY ? this.e.pageY : this.e.clientY;
		if(window.event) {
			this.x = (document.body.scrollLeft) ? this.x + document.body.scrollLeft : this.x;
			this.y = (document.body.scrollTop) ? this.y + document.body.scrollTop : this.y;
		}
	},
	
	findPos : function(obj) {
		var curleft = obj.offsetLeft || 0;
		var curtop = obj.offsetTop || 0;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
		this.x = curleft;
		this.y = curtop;
	},
	
	debug : function(str) {
		if( !document.getElementById("debug") ) {
			container = document.createElement("p");
			container.setAttribute("id","debug");
			container.setAttribute("style","background:#fff;");
			$("body").append(container);
		}
		
		$("#debug").append(str + "<br />");
	},
	
	isDefined : function(variable) {
		return eval('(typeof('+variable+') != "undefined");');
	},
	
	getWindowHeight : function() {
		var windowHeight = 0;
		if (typeof(window.innerHeight) == 'number')
			windowHeight = window.innerHeight;
		else
			if (document.documentElement && document.documentElement.clientHeight)
				windowHeight = document.documentElement.clientHeight;
			else
				if (document.body && document.body.clientHeight)
					windowHeight = document.body.clientHeight;
		
		return windowHeight;
	},
	
	getWindowWidth : function() {
		var windowWidth = 0;
		if (typeof(window.innerWidth) == 'number')
			windowWidth = window.innerWidth;
		else
			if (document.documentElement && document.documentElement.clientWidth)
				windowWidth = document.documentElement.clientWidth;
			else
				if (document.body && document.body.clientWidth)
					windowWidth = document.body.clientWidth;
		
		return windowWidth;
	},
	
	addResizeEvent : function(func) {
		var oldonresize = window.onresize;
		if (typeof window.onresize != 'function') {
			window.onresize = func;
		} else {
			window.onresize = function() {
				oldonresize();
				func();
			}
		}
	},
	
	isImageLoaded : function(img) {
		if(!img.complete) return false; // IE
		if(typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) return false; // Others
		return true;
	},
	
	isImageExists : function(img) {
		if(window.XMLHttpRequest)
			xmlHttp = new XMLHttpRequest();
		else if (window.ActiveXObject)
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		
		xmlHttp.open("GET",img,false);
		xmlHttp.send(null);
		
		if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
			return true;
		else
			return false;
	},
	
	getUrlParam : function(parameter) { 
    var loc = window.location.href;
    var param_value = "";
  
    var params = loc.split("-");
    for (i=0; i<params.length;i++) {
        param_name = params[i];
        if ((param_name == parameter) && (i+1 < params.length)) {
            param_value = params[i+1];
            break;
        }
    }
    if (param_value) {
        return param_value;
    }
    else {
        return "";
    }
  }
};

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
