

var images = [];

function pushIntoHomeGal(img){
	images.push(img);
}

var newSlide = 0;
var totalSlides = 0;

function initHomeGallery(){
	
	totalSlides = images.length;
	for(var i=0;i<images.length;i++){
		(function() {
			if(i != 0){
				$("#dot_" + i).css("opacity", .2);
			}
			var ii = i;
		
			$("#dot_" + i).click(function(){
							
			});
		})();
	}
	
	goFade1();
}

function goFade1(){
	
	$("#home_hero1").fadeIn(2000, function () {
		$("#home_hero2").fadeIn(10, function () {});
		setTimeout(function(){goFadeOut1()},1000);
		$("#home_hero2 img").attr("src", "/thumbs/598x325/files/zc/" + images[newSlide].img2 + "");
  	 });
  	
  	
}
function goFadeOut1(){
	$("#home_hero1").fadeOut(2000, function () {
		nextSlide();
	});
}

function nextSlide(){
	newSlide++;
	if(newSlide == totalSlides){
		newSlide = 0;
	}
	$("#home_hero1 img").attr("src", "/thumbs/598x325/files/zc/" + images[newSlide].img + "");
	
	setTimeout(function(){goFadeOut2()},1000);
	setTimeout(function(){goFade1()},2000);
}
function goFadeOut2(){
	$("#home_hero2").fadeOut(2000, function () {});
}


////////////////////////



function pushIntoGal(img){
	
	images.push(img);

}
var newI = 0;
var oldI = 0;
var galInterval = 5000;


function initGallery(){
 //alert(divName);
	for(var i=0;i<images.length;i++){
		(function() {
			$("#dot_" + i).css("opacity", .2);
			var ii = i;
		
			$("#dot_" + i).click(function(){
				newI = ii;
				clearInterval(galInt);
				rotateGal();
				galInt = setInterval(rotateGal,galInterval);
				
			});
		})();
	}
	$("#dot_" + newI).css("opacity", 1);
	newI++;
	galInt = setInterval(rotateGal,galInterval);
}

function rotateGal(){
	
	for(var i=0;i<images.length;i++){
		$("#dot_" + i).css("opacity", .2);
	}

	$(divName).fadeOut(function(){
	
	$("#dot_" + newI).css("opacity", 1);
	
	$(divName + " img").attr("src", thumbString + images[newI].img + "");
	
	newI++;
	
	if(newI == images.length){
		newI = 0;
	}
	$(divName).onImagesLoad({ 
	selectorCallback: fadeGalIn
});
	//$("#case_hero1").fadeIn();
	
	});
		
}
function fadeGalIn(){
	$(divName).fadeIn();
}

////////////////////////



var quotes = [];

var newQuote = 0;
var totalQuotes = 0;
var quoteInterval = 3000;

var newqI = 0;


function initQuotes(){
	//alert("q " + quotes.length);
	totalQuotes = quotes.length
	for(var i=0;i<quotes.length;i++){
		(function() {
			$("#dots_" + i).css("opacity", .2);
			var ii = i;
		
			$("#dots_" + i).click(function(){
				//newqI = ii;
				//rotateQuote();
				//clearInterval(quoteInt);	
				//quoteInt = setInterval(rotateQuote,quoteInterval);		
			});
		})();
	}
	
	rotateQuote();
	quoteInt = setInterval(rotateQuote,quoteInterval);

}
function rotateQuote(){

	for(var i=0;i<quotes.length;i++){
		$("#dots_" + i).css("opacity", .2);
	}

	$(".home_thumb_4_in").fadeOut(function(){
	
	$("#dots_" + newqI).css("opacity", 1);
	$(".home_thumb_4_in").html(quotes[newqI]);
	
	var newT = 40 - ($(".home_thumb_4_in").height() /2);
	
	$(".home_thumb_4_in").css("margin-top", newT);
	
	newqI++
	if(newqI == totalQuotes){
		newqI = 0;
	}
	$(".home_thumb_4_in").fadeIn();
	
	});
		
}




////////////////////////ASKS



var newI = 0;
var newIl = 0;
var newIr = 1;

var askInterval = 5000;

function initAsks(){
	newIl = asksCount -1;
	
 //alert(divName);
	for(var i=0;i<asksCount;i++){
		(function() {
			$("#dot_" + i).css("opacity", .2);
			var ii = i;
		
			$("#dot_" + i).click(function(){
				newI = ii;
				clearInterval(galInt);
				rotateAsk();
				galInt = setInterval(rotateAsk,askInterval);
				
			});
		})();
		//$("#just_img_" + i).css("left", "600px");
	}
	//$("#dot_" + newI).css("opacity", 1);
	//newI++;
	galInt = setInterval(rotateAsk,askInterval);
	rotateAsk();
}

var aniSpeed = 1000;

function rotateAsk(){
	$("#just_msg").fadeOut(300);
	
	newIl = newI -1;
	newIr = newI +1;
	newIx = newI -2;
	if(newIx == -1){
		newIx = asksCount -1;
	}
	if(newIx == -2){
		newIx = asksCount -2;
	}
	if(newIl == -1){
		newIl = asksCount -1;
	}
	if(newIr == asksCount){
		newIr = 0;
	}
	
	for(var i=0;i<asksCount;i++){
		$("#dot_" + i).css("opacity", .2);
		$("#just_img_" + i).css("z-index", "299");
	}	
	$("#dot_" + newI).css("opacity", 1);
	$("#just_img_" + newI).css("z-index", "300");
		
	$("#just_img_" + newI).animate({
	    left: '180',
	    top: '0',
	    opacity: '1.0',
	}, aniSpeed);
	$("#just_img_" + newI + " img").animate({
	    width: '536'
	}, aniSpeed);
	
	var thiTLa = $("#just_txt_" + newI).attr('tl');
	$("#just_txt_" + newI).animate({
	    fontSize: '28px',
	    lineHeight: '34px',
	    left: '130px',
	    top: thiTLa
	}, aniSpeed);
	var thiBLa = $("#just_txt2_" + newI).attr('tl');
	$("#just_txt2_" + newI).animate({
	    fontSize: '16px',
	    left: '131px',
	    top: thiBLa
	}, aniSpeed);

	
	$("#just_img_" + newIl).animate({
	    left: '-180',
	    top: '60',
	    opacity: '.5',
	}, aniSpeed);
	$("#just_img_" + newIl + " img").animate({
	    width: '350'
	}, aniSpeed);
	
	var thiTLl =  (parseInt($("#just_txt_" + newIl).attr('tl')) * .6) + 'px';
	$("#just_txt_" + newIl).animate({
	    fontSize: '18px',
	    lineHeight: '21px',
	    left: '90px',
	    top: thiTLl
	}, aniSpeed);
	var thiBLl = -2 + (($("#just_txt2_" + newIl).attr('tl') /1.6)) + 'px';
	$("#just_txt2_" + newIl).animate({
	    fontSize: '10px',
	    left: '91px',
	    top: thiBLl
	}, aniSpeed);
	$("#just_img_" + newIr).animate({
	    left: '730',
	    top: '60',
	    opacity: '.5',
	}, aniSpeed);	
	$("#just_img_" + newIr + " img").animate({
	    width: '350'
	}, aniSpeed);
	var thiTLr = (parseInt($("#just_txt_" + newIr).attr('tl')) * .6) + 'px';
	$("#just_txt_" + newIr).animate({
	    fontSize: '18px',
	    lineHeight: '21px',
	    left: '90px',
	    top: thiTLr
	}, aniSpeed);
	var thiBLr = -2 + (($("#just_txt2_" + newIr).attr('tl') /1.6)) + 'px';
	//alert(thiBLr);
	$("#just_txt2_" + newIr).animate({
	    fontSize: '10px',
	    left: '91px',
	    top: thiBLr
	}, aniSpeed);
	$("#just_img_" + newIx).animate({
	    left: '-500',
	    top: '60',
	    opacity: '0',
	}, aniSpeed, function(){
		$(this).css("left", "1000px");
		
		
		$("#just_msg").fadeIn(aniSpeed, function () {
		  setTimeout(aniFadeOut,askInterval - aniSpeed - aniSpeed);
		 });
	});
	for(var i=0;i<asksCount;i++){
		if(i != newI && i != newIl && i != newIr && i != newIx){
			$("#just_img_" + i).css("left", "1000px");
		}
	}	
	
	newI++;
	newIl++;
	newIr++;
	newIx++;
	
	if(newI == asksCount){
		newI = 0;
	}
		
}
function aniFadeOut(){
	$("#just_msg").fadeOut(aniSpeed);
}



////////////////////////Values



var newI = 0;
var newIl = 0;
var newIr = 1;

var valInterval = 5000;


function initValues(){
	newIl = asksCount -1;
	
 //alert(divName);
	for(var i=0;i<asksCount;i++){
		(function() {
			$("#dot_" + i).css("opacity", .2);
			var ii = i;
		
			$("#dot_" + i).click(function(){
				newI = ii;
				clearInterval(galInt);
				rotateVal();
				galInt = setInterval(rotateVal,valInterval);
				
			});
		})();
		//$("#just_img_" + i).css("left", "600px");
		var marT = 20 - ($("#just_img_" + i + " .val_text").height() /2);
		$("#just_img_" + i + " .val_text").css("margin-top", marT);
	}
	//$("#dot_" + newI).css("opacity", 1);
	//newI++;
	
	for(var i=0;i<asksCount;i++){
		
			$("#just_img_" + i).css("opacity", "-0.0");
		
	}	
	
	galInt = setInterval(rotateVal,valInterval);
	rotateVal();
}

var aniSpeed = 1000;

function rotateVal(){
	//$(just_msg).fadeOut(300);
	
		
	
	newIl = newI -1;
	newIr = newI +1;
	newIx = newI -2;
	if(newIx == -1){
		newIx = asksCount -1;
	}
	if(newIx == -2){
		newIx = asksCount -2;
	}
	if(newIl == -1){
		newIl = asksCount -1;
	}
	if(newIr == asksCount){
		newIr = 0;
	}
	
	for(var i=0;i<asksCount;i++){
		$("#dot_" + i).css("opacity", .2);
		$("#just_img_" + i).css("z-index", "299");
	}	
	$("#dot_" + newI).css("opacity", 1);
	$("#just_img_" + newI).css("z-index", "300");
		
	$("#just_img_" + newI).animate({
	    //left: '60',
	    top: '86',
	    opacity: '1.0',
	}, aniSpeed);
		$("#just_img_" + newIl).animate({
	   // left: '-680',
	    top: '460',
	    opacity: '0',
	}, aniSpeed);
	
	$("#just_img_" + newIr).animate({
	    //left: '730',
	   	top: '-460',
	    opacity: '0',
	}, aniSpeed);	
	
	$("#just_img_" + newIx).animate({
	    //left: '-700',
	    top: '500',
	    opacity: '0',
	}, aniSpeed, function(){
		$(this).css("top", "-600px");
		//$(just_msg).fadeIn(aniSpeed, function () {
		  //setTimeout(aniFadeOut,valInterval - aniSpeed - aniSpeed);
		// });
	});
	for(var i=0;i<asksCount;i++){
		if(i != newI && i != newIl && i != newIr && i != newIx){
			$("#just_img_" + i).css("top", "-600px");
		}
	}	
	
	newI++;
	newIl++;
	newIr++;
	newIx++;
	
	if(newI == asksCount){
		newI = 0;
	}
		
}
function aniFadeOut(){
	//$(just_msg).fadeOut(aniSpeed);
}



















