
var step = 0;


$(document).ready( function () {

	//client testimonials
	$(".link-prev").click( function () { testLeft() } );
	$(".link-next").click( function () { testRight() } );

	//Video colorbox
	//$('.video-box .placeholder a').colorbox( { width: "480", height: "500", iframe:true});
	//$('.video-box .placeholder a').colorbox( { width: "490", inline:true, href:"#videocontent"});
	$('.video-box .placeholder a').acModal({
		contentType: "iframe",
		title: "AmeriCommerce Product Overview",
		src: "http://www.youtube.com/embed/AUdDnUFeBFI?rel=0"
	})
	
	
	//Who is Using AC?
	var $allwhos = $('.who1, .who2, .who3, .who4, .who5')
	
	mHeight = $(window).height() * .98;
	mWidth = $(window).width() * .98;
	
	/*for(x=1;x<6;x++){
		//console.log($(".who"+x));
		url = $(".who"+x).attr("href");
		title = $(".who"+x).attr("title");
		$(".who"+x).acModal( { modalWidth: mWidth, modalHeight: mHeight, modalContent: "iframe", src : url, modalTitle : title });
	}*/
	
	$('.who1, .who2, .who3, .who4, .who5').each( function() {
		url = $(this).attr("href");
		title = $(this).attr("title");
		
		$(this).acModal( { 
			modalWidth: mWidth, 
			modalHeight: mHeight, 
			contentType: "iframe", 
			src : url, 
			title : title });
	});
	
	$allwhos.hover( function() { $allwhos.parent().removeClass("active"); });
	
	$allwhos.hover( function() {
		$(this).parent().addClass("active");
		$(".item-list .container em").html( $(this).attr("title") ); 
		$(".item-list .container a").attr("href", $(this).attr("href") ); 
	});
	
	//Affliates
	var mgn = 0;
	var prev;
	var next;
	var max = ($("#logoul li").length) * 122 - 915;
	
	$(".btn-prev").hover( function() { 
		mgn = parseInt( $("#logoul").css("margin-left").replace("px","") );
		if (mgn>100) $("#logoul").animate({marginLeft:"0px"}, 100) 
		else prev = setInterval('mgn = parseInt( $("#logoul").css("margin-left").replace("px","") ); if (mgn<0) $("#logoul").animate({marginLeft:"+=5px"},20)',20);
	}, function() {clearInterval(prev) })
	.click( function() {
		clearInterval(prev);
		$("#logoul").stop(true,true).animate({marginLeft:"100px"},500).animate({marginLeft:"-50px"},100).animate({marginLeft:"0px"},100);
	
	});
		
	$(".btn-next").hover( function() {
		
			next = setInterval('max = ($("#logoul li").length) * 122 - 915; mgn = parseInt( $("#logoul").css("margin-left").replace("px","") ); if (mgn > -1*max) $("#logoul").animate({marginLeft:"-=5px"}, 20) ',20);
	}, function() { 
		clearInterval(next);
	})
	.click( function() {
		clearInterval(next);
		max = ($("#logoul li").length) * 122 - 915;
		$("#logoul").stop(true,true).animate({marginLeft:-1*max-100+"px"},500).animate({marginLeft:-1*max+50+"px"},100).animate({marginLeft:-1*max+"px"},100);
	
	});

	
	//$(".visual div:gt(0)").hide();
	//setTimeout("fadeTo(0)",2000);
	$(".slide-text div:eq(0)").show();
	setTimeout("imageSlideup(0)",8500);

});

function imageSlideup(x) {

	$(".slide-text div:eq("+x+")").fadeOut("slow");
	
	if(x==0){
		$(".top-box .visual div:first").css({marginTop:"0px"})
		$(".top-box .visual div:first").animate({marginTop:"-=282px"},"slow");
		x++
	} else if(x<3){
		$(".top-box .visual div:first").animate({marginTop:"-=282px"},"slow");
		
		x++;
		}
	else {
		//$(".top-box .visual div:first").animate({marginTop:"0px"},"fast");
		
		//$(".top-box .visual div:first").css({marginTop:"0px"})
		$(".top-box .visual div:first").animate({marginTop:"-=282px"},"slow");
		x=0;
	}
	
	$(".slide-text div:eq("+x+")").fadeIn("slow");
	$("ul.switcher li").removeClass("active");
	$("ul.switcher li:eq("+x+")").addClass("active");
	
	setTimeout("imageSlideup("+x+")",8500);
}

function fadeTo(x) {
	$(".visual div").fadeOut();
	$(".visual div:eq("+x+")").delay(500).fadeIn();
	$("ul.switcher li").removeClass("active");
	$("ul.switcher li:eq("+x+")").addClass("active");
	
	switch(x)
	{
	case 0:
		$(".top-box-container2 strong").html("Multiple Storefronts");
		$(".top-box-container2 p").html("Manage different catalogs, customers and designs from one console.");
		break;
	case 1:
		$(".top-box-container2 strong").html("Depth of Features like NO Other");
		$(".top-box-container2 p").html("AmeriCommerce picks up where others leave off.");
		break;
	case 2:
		$(".top-box-container2 strong").html("Search Engine Friendly (SEO)");
		$(".top-box-container2 p").html("Optimized by default with incredible tools for complete control.");
		break;
	case 3:
		$(".top-box-container2 strong").html("PCI Compliant High Security");
		$(".top-box-container2 p").html("Why risk your business with a non-compliant environment? ");
		break;
	}		
	
	if(x==3) x=0;
	else x++;
	
	setTimeout("fadeTo("+x+")",3000);
}

function testLeft() {
	if (step>0){
		step -= 1;
		scrollTest(step);
	}
}

function testRight() {
	if (step<2){
		step += 1;
		scrollTest(step);
	}
}

function scrollTest(x) {
	var margin = x * -570;
	$("#galul").animate({marginLeft:margin+"px"});
}



