//alert('javascript included.');
var time = 600;
function picX(n){
	var cX = parseInt($('.tent'+n +' img').css('left')) - 920;
	return cX;
}
var tentLoads = 0;
function initTents(){
	tentIt();

	//openTent();
	//doTents();
}
$(document).ready(function(){
	//initTents();
	//$('.homeImage').attr('src', homeArr[0]);
	//tentIt();
});
function timeTent(){
	setTimeout("tentIt()", 3500);
}
var homeCurrent = 0;
function showHome(){
		$('.c1').fadeOut(400, function(){
			$('.cLeft').animate({left: '-350px'}, {duration:1700, easing:"easeOutBack"});
			$('.cRight').animate({left: '360px'}, {duration:1700, easing:"easeOutBack", complete:timeTent});
		});
}
function tentIt(){
	//jQuery.easing.def = "easeOutBack";
	var homeCount = homeArr.length - 1;
	$('.c1').fadeIn(1300, function(){
		$('.cLeft, .cRight').css({"left":0});
		switch(homeCurrent){
			case homeCount:
			homeCurrent = 0;
			break;
			default:
			homeCurrent += 1;
			break;
		}
		$('.homeImage').attr('src', homeArr[homeCurrent]);
	});
}
function doTents(){
	this.homeCount = homeArr.length;
	this.homeCurrent = 0;
	this.advHome = function(){
		$('.c1').fadeIn(500, function(){
			$('.cLeft, .cRight').css({"left":0});
			//alert('homeCurrent: '+homeCurrent+' homeCount: '+homeCount);
			if(homeCurrent < homeCount){
				homeCurrent += 1;
			} else {
				homeCurrent = 0;
			}
			$('.homeImage').attr('src', homeArr[homeCurrent]).show();
		});
	}
	this.moves = function(){
		$('.cLeft').animate({left: '-350px'}, 900);
		$('.cRight').animate({left: '360px'}, 900, function(){
			advHome();
		});
	}
	this.fadeIns = function(){
		$('.cLeft').show();
		$('.cRight').show();
		$('.c1').fadeOut(400, function(){
			moves();
		});
		//$('.c1').animate({opacity: 0}, {duration: 400, queue: false, complete:moves});
	}
	this.fadeIns();
}
function loadTents(){
	tentLoads += 1;
	numTents = $('.tentPic').length - 1;
	if(tentLoads == numTents){
		initTents();
	}
}
var homeImg = 0;
var assetFade = 0;
function resetHomeImg(){
	var homeCount = homeArr.length;
	$('.homeImage, .cLeft, .cRight').fadeOut(700, function(){
		switch(assetFade){
			case 0:
			case 1:
			assetFade += 1;
			break;
			case 2:
			assetFade = 0;
			$('.c1').fadeIn(1800, function(){
				if(homeImg == homeCount + 1){
					homeImg = 0;
				} else {
					homeImg += 1;
				}
				$('.cLeft, .cRight').css({left: '0px'});
				$('.homeImage').attr('src', homeArr[homeImg]).show();
			});
			break;
		}
	});
}
var adv = 1;
function advanceHome(){
	switch(adv){
		case 1: adv +=1;
		break;
		case 2: adv = 0;
		setTimeout("resetHomeImg()", 2700);
		break;
	}
}
function openTent(){
	$('.cLeft').show();
	$('.cRight').fadeIn(900, function(){
			$('.c1').fadeOut(700, function(){
				$('.cLeft').animate({left: '-350px'}, {duration: 900, queue: false});
				$('.cRight').animate({left: '360px'}, {duration: 900, queue: false, complete:advanceHome});
			});
	});
	//$('.homeImage').show();
	//var newX = picX(1) - 920;
	//$('.tent1 img').css('left', picX(1) - 920);
	/*
if(tent < 7){
		$('.c' + parseInt(tent + 1)).fadeIn(300, function(){
			$('.c' + tent).fadeOut(550, function(){
				tent += 1;
				openTent();
			});
		});
	} else {
		setTimeout("resetHomeImg()", 2700);
	}
*/
		/*
$('.c2').fadeIn(300, function(){
			$('.c1').fadeOut(550, function(){
				$('.c3').fadeIn(300, function(){
					$('.c2').fadeOut(550, function(){
						$('.c4').fadeIn(300, function(){
							$('.c3').fadeOut(550, function(){
								$('.c5').fadeIn(300, function(){
									$('.c4').fadeOut(550, function(){
										$('.c6').fadeIn(300, function(){
											$('.c5').fadeOut(550, function(){
												$('.c7').fadeIn(300, function(){
													$('.c6').fadeOut(550, function(){
		setTimeout("resetHomeImg()", 2700);
													});
												});
											});
										});
									});
								});
							});
						});
					});
				});
			});
		});
*/
}
var homeMain = 0;
function replaceHomeMain(){
	if(homeMain == homeArr.length - 1){
		homeMain = 0;
	} else {
		homeMain += 1;
	}
	$('.homeImage').attr('src', homeArr[homeMain]);
}
function setMarker(){
	var marker = '<img class="marker" src="/assets/graphics/markerWhite.png"/>';
	$('.' + main).append(marker);
}
function hideMe(){
	$('.thumbSpace').slideUp(250, function(){
		$('.thumbSpace').remove();
	});
}
function scrollThumb(dir){
	switch(dir){
		case 'up':
		$('.thumbShell:first').replaceWith('<div id="" class="thumbSpace"></div>').appendTo('.thumbRow');
		hideMe();
	break;
		case 'down':
		$('.thumbRow').prepend('<div id="" class="thumbPush"></div>');
		$('.thumbPush').slideDown(250, function(){
			$(this).replaceWith($('.thumbShell:last'));
		});
	break;
	}
	
}
function thumbFades(){
	$('.thUp, .thDown').bind('mouseover', function(){
		$(this).fadeTo(250, .6);
	}).bind('mouseout', function(){
		$(this).fadeTo(250, 1);
	});
}
function initThumbScroll(){
	thumbFades();
	$('.thUp').fadeTo(250, 1).bind('click', function(){
		scrollThumb('up');
	});
	$('.thDown').fadeTo(250, 1).bind('click', function(){
		scrollThumb('down');
	});
}
var desOn = 0;
function designerRoll(desNum){
	var fadeSpeed = 250;
	//$('.testRoll').html(desNum);
	if(desNum != desOn){
	//alert(collection['designers'][0]['products'][0]['images'][0]['img_name']);str = str.replace(/\n/g, '<br />');
		if(collection['designers'][desNum] !== undefined){
			desOn = desNum;
			var desText = collection['designers'][desNum]['des_text'];
			desText = desText.replace(/\n/g, '<br />');
			//$('.designerText').fadeOut(fadeSpeed, function(){
			$('.designerText').hide();
				$('.desNameDisplay').html(collection['designers'][desNum]['des_name']);
				$('.desTextDisplay').html(desText);
				$('.designerText').fadeIn(fadeSpeed);
			//});
			//$('.collectionMain').fadeOut(fadeSpeed, function(){
			$('.collectionMain').hide();
				var base = collection['designers'][desNum]['products'];
				if(base != undefined && base[0] != undefined && base[0]['images'] != undefined){
					$('.collectionMain').attr('src', '/images/products/' + collection['designers'][desNum]['products'][0]['images'][0]['img_name']).fadeIn(fadeSpeed);
				}
			//});
		}
	}
}
function showInfo(el){
	hideInfo();
	$(el).children('.gallInfo:hidden').slideDown(250);
}
function hideInfo(el){
	$('.gallInfo:visible').slideUp(250);
}
function gallOver(el){
	$(el).fadeTo(250, .6);
}
function gallOut(el){
	$(el).fadeTo(250, 1)
}
function gallNext(){
	hideInfo();
	$('.gallImg:first').replaceWith('<div class="gallSpacer"></div>').appendTo($('.gallSlide'));
	$('.gallSpacer').animate({width: "0px"}, 450);
}
function gallPrev(){
	hideInfo();
	$('.gallSlide').prepend('<div class="gallPusher"></div>');
	$('.gallPusher').animate({width: "400px"}, 450, function(){
		$('.gallPusher').replaceWith($('.gallImg:last'));
	});
}
function thumbOver(th){
	$(th).children('.thumbnail').fadeTo(250, .6);
}
function thumbOut(th){
	$(th).children('.thumbnail').fadeTo(250, 1);
}
var mainPic = 1;
var mainProd = 1;
var mainHold = false;
var prodHold = false;
function removeZoom(){
}
function doMain(prod, num, thumb){
	var mainSpeed = 400;
	var thSrc = $(thumb).children('.thumbnail').attr('src');
	if(mainHold == false && prodHold == false){
		if(num != mainPic || prod != mainProd){
			$('.faded').removeClass('faded');
			$(thumb).children('.thumbnail').addClass('faded');
			mainHold = true;
			mainPic = num;
			//$('.output').html(num);
	$('.mainPic').prependTo($('.mainLarge'));
	$('.zoomPad').remove();
			$('.mainPic').fadeOut(mainSpeed, function(){
				var options = {zoomType: 'innerzoom'};
				$('.mainLarge').attr('href', thSrc).jqzoom(options);
				$('.mainPic').attr('src', thSrc).fadeIn(mainSpeed);
				//$('.mainLarge');
				mainHold = false;
			})
		} else {
			return false;
		}
		if(prod != mainProd){
			prodHold = true;
			mainProd = prod;
			$('.prodText, .prodColorSize, .swatchShell').fadeOut(mainSpeed, function(){
				$('.prodText').html(collection['designers'][des]['products'][prod]['prod_text']);
				$('.prodColorSize').html(collection['designers'][des]['products'][prod]['prod_colorsize']);
				$('.prodText, .prodColorSize').fadeIn(mainSpeed, function(){
					$('.swatchShell.prod_'+prod).fadeIn(mainSpeed);
					prodHold = false;
				});
			});
		}
	}
}
$(function(){
	//alert(collection[des]['product'][0]['prod_text']);
	$('.thumbShell').length > 4 ? initThumbScroll() : void(0);
	$('.thumbShell.thumbWidth:first').click();
	$('.collectionScrollContent').jScrollPane();
	$('.twoTextShell').jScrollPane();
	$('.eventScroll').jScrollPane();
	$('.jScrollPaneDrag').height(40).html("<img class='' src='/assets/graphics/scrollDrag.png'/>");
	if($('.jScrollPaneTrack').length > 0){
		$('img.scrollTrack').show();
		$('.twoTextContent').addClass('narrow');
	}
	
});$(document).ready(function(){  
    //$('.mainLarge').jqzoom(options);  
}); 


