var all = new Array("none","act_can","actpouch","saxi","go","bodytrim","dropit","invigorita","none");
var t_speed = 600;
var h_img = 380;
var h_imgs = 240;
var box_w = 400;
var box_h = 400;
var pos = 1;
var info_box_in = false;
var is_ie;
var is_main;
var started = false;
var start_slide;

$(document).ready(function(){
	//$("#left_slide").mouseenter(left_move);
	$("#left_slide").mouseenter(light_larr);
	$("#left_slide").mouseleave(dim_larr);
	$("#left_slide").click(left_move);
	$("#left_arrow").mouseenter(light_larr);
	$("#left_arrow").mouseleave(dim_larr);
	$("#left_arrow").click(left_move);
	
	//$("#right_slide").mouseenter(right_move);
	$("#right_slide").mouseenter(light_rarr);
	$("#right_slide").mouseleave(dim_rarr);
	$("#right_slide").click(right_move);
	$("#right_arrow").mouseenter(light_rarr);
	$("#right_arrow").mouseleave(dim_rarr);
	$("#right_arrow").click(right_move);
	
	if(is_main){
		
		if(is_ie){
			$("#carousel_canvas").mouseenter(function(){$("#info_box").stop(true,true).show();});
			$("#carousel_canvas").mouseleave(function(){$("#info_box").stop(true,true).hide();});
		}
		else{
			$("#carousel_canvas").mouseenter(function(){$("#info_box").stop(true,true).fadeIn(300)});
			$("#carousel_canvas").mouseleave(function(){$("#info_box").stop(true,true).fadeOut(200)});
			$("#info_box_text").css({width:'520px'});
		}
		
		$(".carousel_item").click(function(){
			//						   
		});
										  
	}else $("#info_box").show();
	$("#info_box").mouseenter(function(){info_box_in = true;});
	$("#info_box").mouseleave(function(){info_box_in = false;});
	
	if(!is_main){
		$("#product_carousel").css({height:'200px',marginLeft:'-14px',borderTop:'3px solid #ccc',background:'url(images/scbg.jpg) repeat-x'});
		if(is_ie) $("#product_carousel").css({/*marginBottom:'-18px'*/});
		$("#left_slide").css({height:'200px'});
		$("#right_slide").css({height:'200px'});
		$("#carousel_canvas").css({height:'200px'});
		$(".carousel_item").css({height:'200px'});
		$("#left_arrow").css({top:'80px'});
		$("#right_arrow").css({top:'80px'});
		$("#info_box").css({width:'330px',height:'110px',bottom:'45px',left:'380px'});
		$("#info_box_back").css({height:'100%',width:'100%'});
		if(is_ie) $("#info_box_text").css({width:'340px',height:'110px'});
		else $("#info_box_text").css({width:'320px',height:'110px'});
		t_speed = 300;
	}
	
	

});

function light_larr(){
		$("#left_arrow").attr("src","images/slide_arrow_left2.png");
		$("#left_slide").css({opacity:.4,backgroundColor:'#080808'});
	}
	
function dim_larr(){
	$("#left_arrow").attr("src","images/slide_arrow_left.png");
	$("#left_slide").css({backgroundColor:'#000'});
}
function light_rarr(){
	$("#right_arrow").attr("src","images/slide_arrow_right2.png");
	$("#right_slide").css({opacity:.4,backgroundColor:'#080808'});
}

function dim_rarr(){
	$("#right_arrow").attr("src","images/slide_arrow_right.png");
	$("#right_slide").css({backgroundColor:'#000'});
}


function right_move(){
	if (!$("div").is(':animated') && started ) {
		var left = parseInt(document.getElementById("carousel_canvas").style.marginLeft);
		if(!left) left = 0;
		if(pos == 7) return;
		$("#carousel_canvas").stop(true,false).animate({marginLeft:left- box_w},t_speed);
		grow(all[pos+1],t_speed);
		shrink(all[pos],t_speed);
		++pos;
		++start_slide;
		document.getElementById("info_box_text").innerHTML = document.getElementById(all[pos]+"_text").innerHTML;
	}

}

function left_move(){
	if (!$("div").is(':animated') && started) {
		if(pos == 1) return;
		var left = parseInt(document.getElementById("carousel_canvas").style.marginLeft);
		if(!left) left = 0;						
		$("#carousel_canvas").stop(true,false).animate({marginLeft:left+ box_w},t_speed);
		shrink(all[pos],t_speed);
		grow(all[pos-1],t_speed);
		--pos;
		--start_slide;
		document.getElementById("info_box_text").innerHTML = document.getElementById(all[pos]+"_text").innerHTML;
	}
	
}

function on_start(){
	pos = start_slide;
	document.getElementById("info_box_text").innerHTML = document.getElementById(all[pos]+"_text").innerHTML;
	$("#carousel_canvas").css({visibility:"visible"});
	if(is_main){ 
		document.getElementById("carousel_canvas").style.marginLeft = 229-((start_slide-1)*box_w);
		for(var i = 1;i < 8; i++){
			if(i != start_slide)
				shrink(all[i],0);
			else
				grow(all[i],0);
		}
	}
	else{ 
		document.getElementById("carousel_canvas").style.marginLeft = 200-((start_slide-1)*box_w);
		for(var i = 1;i < 8; i++){
			if(i != start_slide)
				shrink(all[i],0);
			else
				grow(all[i],0);
		}
	}
	
	started = true;
	
}

function grow(id,speed){
	if(id == "none") return;
	var ratio = $("#"+id+"_i").height()/$("#"+id+"_i").width();
	var w =h_img/ratio;
	var x = ( box_w-w)/2; if(!is_main) x = 0;
	$("#"+id+"_i").stop(true,false).animate({height:h_img,width:w,marginTop:( box_h-h_img)/2,marginLeft:x},speed);
	
}

function shrink(id,speed){
	if(id == "none") return;
	var ratio = $("#"+id+"_i").height()/$("#"+id+"_i").width();
	var w = h_imgs/ratio;
	var x = ( box_w-w)/2;
	$("#"+id+"_i").stop(true,false).animate({height:h_imgs,width:w,marginTop:( box_h-h_imgs)/2,marginLeft:x},speed);
}
