﻿// JScript File

/* Helper function to preload images 
(function($) {

})(jQuery)*/

var threshy = 0.01;

function CutSewColorPrep(pid,cid,cnt)
{
	var myPics=new Array(cnt);
	var i=1;
	while(i<=cnt)
	{
		myPics[i-1]=new Array(3);
		
		myPics[i-1][0]='/content/prod/'+pid+'p_'+cid+'c_'+i+'s.jpg';
		myPics[i-1][1]='/content/prod/'+pid+'p_'+cid+'c_'+i+'m.jpg';
		myPics[i-1][2]='/content/prod/'+pid+'p_'+cid+'c_'+i+'b.jpg';
		
		i++;
	}
	$('body').data(cid,myPics);
	$.preLoadImages(myPics);
}

function CutSewColorSwap(cid)
{
	var cClass= ".color"+cid;
	$(".activecolor").each(function(){
		$(this).removeClass('color activecolor').addClass('color');
	});
	$(cClass).each(function(){
		$(this).removeClass('color activecolor').addClass('activecolor');
	});

	var myArray = $('body').data(cid);
	if(myArray[0])
	{
		$("#medimg > img").attr('src',$('body').data(cid)[0][1]);
		$("#medimg").attr('href',$('body').data(cid)[0][2]);
	
		$("#smallimg1:hidden").fadeIn(200);
		$("#smallimg1").attr('src',$('body').data(cid)[0][0]);
		$("#smallimg1").click(function(){
			$("#medimg > img").attr('src',$('body').data(cid)[0][1]);
			$("#medimg").attr('href',$('body').data(cid)[0][2]);
		});
	}
	else
	{
		$("#smallimg1:visible").fadeOut(200);
	}
	if(myArray[1])
	{
		$("#smallimg2:hidden").fadeIn(200);
		$("#smallimg2").attr('src',$('body').data(cid)[1][0]);
		$("#smallimg2").click(function(){
			$("#medimg > img").attr('src',$('body').data(cid)[1][1]);
			$("#medimg").attr('href',$('body').data(cid)[1][2]);
		});
	}
	else
	{
		$("#smallimg2:visible").fadeOut(200);
	}
	if(myArray[2])
	{
		$("#smallimg3:hidden").fadeIn(200);
		$("#smallimg3").attr('src',$('body').data(cid)[2][0]);
		$("#smallimg3").click(function(){
			$("#medimg > img").attr('src',$('body').data(cid)[2][1]);
			$("#medimg").attr('href',$('body').data(cid)[2][2]);
		});
	}
	else
	{
		$("#smallimg3:visible").fadeOut(200);
	}
	if(myArray[3])
	{
		$("#smallimg4:hidden").fadeIn(200);
		$("#smallimg4").attr('src',$('body').data(cid)[3][0]);
		$("#smallimg4").click(function(){
			$("#medimg > img").attr('src',$('body').data(cid)[3][1]);
			$("#medimg").attr('href',$('body').data(cid)[3][2]);
		});
	}
	else
	{
		$("#smallimg4:visible").fadeOut(200);
	}
	if(myArray[4])
	{
		$("#smallimg5:hidden").fadeIn(200);
		$("#smallimg5").attr('src',$('body').data(cid)[4][0]);
		$("#smallimg5").click(function(){
			$("#medimg > img").attr('src',$('body').data(cid)[4][1]);
			$("#medimg").attr('href',$('body').data(cid)[4][2]);
		});
	}
	else
	{
		$("#smallimg5:visible").fadeOut(200);
	}
	
	return false;
}

function CutSewSetup()
{
	var options5 = {zoomWidth: 360, zoomHeight: 480, position : 'right', yOffset :0, xOffset :14, showEffect:'fadein', hideEffect:'fadeout', fadeoutSpeed: 'fast', zoomType:'standard', title :false}
	$(".zoomable").jqzoom(options5);

	//$('.infiniteCarousel').infiniteCarousel();

	$("#newSizeChart").fancybox({overlayColor: '#000'});
	
	$("#medimg").fancybox({overlayColor: '#000'});
	
	$('#guideCarousel').jcarousel({vertical: true,scroll: 3});
	
	$('#alsoBoughtCarousel').jcarousel({
		scroll: 3
	});
}

function ClassicColorPrep(pid,cid,cunt)
{
	var randy = Math.random();
	

	if(cunt>2) cunt=2;
	var myPics=new Array(cunt);
	myPics[0]=new Array(3);
	myPics[0][0]='/content/prod/'+pid+'p_'+cid+'c_zoomm.jpg';
	myPics[0][1]='brolo';
	myPics[0][2]=GetRandyZoom(randy,'/content/prod/'+pid+'p_'+cid+'c_zoomb.jpg');
	
	var i=1;
	while(i<=cunt)
	{
		myPics[i]=new Array(3);
		myPics[i][0]='/content/prod/'+pid+'p_'+cid+'c_'+i+'m.jpg';
		myPics[i][1]='/content/prod/'+pid+'p_'+cid+'c_'+i+'b.jpg';
		myPics[i][2]=GetRandyZoom(randy,'/content/prod/'+pid+'p_'+cid+'c_zoomb.jpg');
		i++;
	}
	//Add the zoom

	$('body').data(cid,myPics);
	$.preLoadImages(myPics);
}

function GetRandyZoom(randy,def)
{
if(randy < threshy * 0.33) return '/images/productspage/random_bow2.gif';
else if(randy < threshy * 0.66) return '/images/productspage/random_bosom.jpg';
else if (randy < threshy) return '/images/productspage/random_love.gif';
return def;
}

function ClassicColorSwap(cid)
{
	var cClass= ".color"+cid;
	$(".activecolor").each(function(){
		$(this).removeClass('color activecolor').addClass('color');
	});
	$(cClass).each(function(){
		$(this).removeClass('color activecolor').addClass('activecolor');
	});

	var myArray = $('body').data(cid);
	if(myArray[0])
	{
		$("#smallzoom:hidden").fadeIn(200);
		$("#smallzoom > img").attr('src',$('body').data(cid)[0][0]);
		$("#smallzoom").attr('href',$('body').data(cid)[0][2]);
	}
	else
	{
		$("#smallzoom:visible").fadeOut(200);
	}
	if(myArray[1])
	{
		$("#medimg > img").attr('src',$('body').data(cid)[1][1]);
		$("#medimg").attr('href',$('body').data(cid)[1][2]);
		
		$("#smallimg1:hidden").fadeIn(200);
		$("#smallimg1").attr('src',$('body').data(cid)[1][0]);
		$("#smallimg1").click(function(){
			$("#medimg > img").attr('src',$('body').data(cid)[1][1]);
			$("#medimg").attr('href',$('body').data(cid)[1][2]);
		});
	}
	else
	{
		$("#smallimg1:visible").fadeOut(200);
	}
	if(myArray[2])
	{
		$("#smallimg2:hidden").fadeIn(200);
		$("#smallimg2").attr('src',$('body').data(cid)[2][0]);
		$("#smallimg2").click(function(){
			$("#medimg > img").attr('src',$('body').data(cid)[2][1]);
			$("#medimg").attr('href',$('body').data(cid)[2][2]);
		});
	}
	else
	{
		$("#smallimg2:visible").fadeOut(200);
	}
	if(myArray[3])
	{
		$("#smallimg3:hidden").fadeIn(200);
		$("#smallimg3").attr('src',$('body').data(cid)[3][0]);
		$("#smallimg3").click(function(){
			$("#medimg > img").attr('src',$('body').data(cid)[3][1]);
			$("#medimg").attr('href',$('body').data(cid)[3][2]);
		});
	}
	else
	{
		$("#smallimg3:visible").fadeOut(200);
	}
	
	return false;
}

function ClassicSetup()
{
	$("#newSizeChart").fancybox({overlayColor: '#000'});
	$("#medimg").fancybox({overlayColor: '#000'});	
	$('#alsoBoughtCarousel').jcarousel({scroll: 3});
	$("#smallzoom").fancybox({overlayColor: '#000'});
}


function NoZoomColorPrep(pid,cid,cnt)
{
	var myPics=new Array(cnt);
	var i=1;
	while(i<=cnt)
	{
		myPics[i-1]=new Array(3);
		if(i==1) { myPics[i-1][0]='/content/prod/'+pid+'p_'+cid+'c_0m.jpg'; }
		else { myPics[i-1][0]='/content/prod/'+pid+'p_'+cid+'c_'+i+'m.jpg'; }
		myPics[i-1][1]='/content/prod/'+pid+'p_'+cid+'c_'+i+'b.jpg';
		myPics[i-1][2]='#';
		i++;
	}
	$('body').data(cid,myPics);
	$.preLoadImages(myPics);
}

function NoZoomColorSwap(cid)
{
	return CutSewColorSwap(cid);
}

function NoZoomSetup()
{
	$("#newSizeChart").fancybox({overlayColor: '#000'});
	$('#alsoBoughtCarousel').jcarousel({
		scroll: 3
	});
}

/* Function to setup the photo swap/zoom/colors */

function SetupStuffs()
{
	var cache = [];
	// Arguments are image paths relative to the current page.
	$.preLoadImages = function() {
		var args_len = arguments.length;
		for (var i = args_len; i--;) {
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			cache.push(cacheImage);
		}
	}
}

function repeat(str, num) {
	return new Array( num + 1 ).join( str );
}

