// JavaScript Document
$(document).ready(function(){
		/*rotation*/
		function change_img_menu (index_val,opt_name){
			$(opt_name +" .rotation_content > a").hide();
			$(opt_name +" .rotation_content > a").children(".rotation1_content_text").hide();
			$(opt_name +" .rotation_menu > li").removeClass("on_this");
			$(opt_name +" .rotation_content > a").eq(index_val).show();
			$(opt_name +" .rotation_content > a").eq(index_val).children(".rotation1_content_text").show();
			$(opt_name +" .rotation_menu > li").eq(index_val).addClass("on_this");
		}
		function show(index_val,opt_name){
			var index_size = $(opt_name+" .rotation_menu > li").length;
			if(index_val < index_size) {
				change_img_menu (index_val,opt_name);
			}else{
				change_img_menu (0,opt_name);
			}
			index_val++;
			if(index_val >= index_size) {
				index_val = 0;
			}
			t = setTimeout(function(){show(index_val,opt_name)}, 3000);
		}
		function show2(index_val2,opt_name){
			var index_size = $(opt_name+" .rotation_menu > li").length;
			if(index_val2 < index_size) {
				change_img_menu (index_val2,opt_name);
			}else{
				change_img_menu (0,opt_name);
			}
			index_val2++;
			if(index_val2 >= index_size) {
				index_val2 = 0;
			}
			t2 = setTimeout(function(){show2(index_val2,opt_name)}, 3000);
		}
		show(0,"#rotation1");
		$("#rotation1 .rotation_menu > li").hover(function(){
			var index_val = $("#rotation1 .rotation_menu > li").index(this);
			change_img_menu (index_val,"#rotation1");
			clearInterval(t);
		},function(){
			var index_val = $("#rotation1 .rotation_menu > li").index(this);
			show(index_val,"#rotation1")
		})
		$("#rotation1 .rotation_content > a").hover(function(){
			var index_val = $("#rotation1 .rotation_content > a").index(this);
			change_img_menu (index_val,"#rotation1");
			clearInterval(t);
		},function(){
			var index_val = $("#rotation1 .rotation_content > a").index(this);
			show(index_val,"#rotation1")
		})
		/*carousel*/
		offset_width = 0; //当前偏移坐标
		target_width = 0; //偏移目标坐标
		offset_seepd = 12;//移动速度越大越快
		added_string = "";
		unit_size_show = 4;
		offset_unit = $("#carousel_content").width();
		unit_size = $("#carousel_content .carousel_content_body > p.index_product_unit").length;
		unit_width = $("#carousel_content .carousel_content_body > p.index_product_unit").width();
		total_width = unit_size * unit_width;
		for(i=0;i<unit_size;i++){
			if(i<unit_size_show){
				added_string += '<p class="index_product_unit">'+$("#carousel_content .carousel_content_body > p.index_product_unit").eq(i).html()+'</p>';
			}
			if(i>=(unit_size-unit_size_show)){
				added_string += '<p class="index_product_unit">'+$("#carousel_content .carousel_content_body > p.index_product_unit").eq(i).html()+'</p>';
			}
		}
		$("#carousel_content .carousel_content_body").html($("#carousel_content .carousel_content_body").html()+added_string);
		unit_new_size = $("#carousel_content .carousel_content_body > p.index_product_unit").length;
		total_new_width = unit_new_size * unit_width;
		$("#carousel_content > .carousel_content_body").width(total_new_width);
		function move_content(target_width,offset_seepd,offset_width,move_direction){
				if(move_direction == "left"){offset_width = offset_width - offset_seepd;}
				if(move_direction == "right"){offset_width = offset_width + offset_seepd;}
				if(offset_width == target_width){
					if(Math.abs(target_width) >= Math.abs(total_width)){
						offset_width = 0;
					}
					$("#carousel_content > .carousel_content_body").css("margin-left",offset_width+"px");
				}else{
					$("#carousel_content > .carousel_content_body").css("margin-left",offset_width+"px");
					setTimeout(function(){move_content(target_width,offset_seepd,offset_width,move_direction)});
				}
		}

		$("#carousel_body .carousel_button_right").click(function(){
			offset_margin = $("#carousel_content > .carousel_content_body").css("margin-left");
			offset_target = target_width+"px";
			if(offset_margin == offset_target){
				target_width = offset_width - offset_unit
				if(Math.abs(target_width) < Math.abs(total_width)){
					move_content(target_width,offset_seepd,offset_width,"left");
					offset_width = target_width;
				}else{
					move_content(target_width,offset_seepd,offset_width,"left");
					offset_width = 0;
					target_width = 0;
					move_content(target_width,offset_seepd,offset_width);
				}
			}
		})
		$("#carousel_body .carousel_button_left").click(function(){
			offset_margin = $("#carousel_content > .carousel_content_body").css("margin-left");
			offset_target = target_width+"px";
			if(offset_margin == offset_target){
				target_width = offset_width + offset_unit;
				if(target_width <= 0 ){
					move_content(target_width,offset_seepd,offset_width,"right");
					offset_width = target_width;
				}else{
					offset_width = 2*offset_unit-total_new_width;
					target_width = offset_width + offset_unit
					move_content(target_width,offset_seepd,offset_width,"right");
					offset_width = target_width;
				}
			}
		})
		/*tab*/
		$("#top_selling_tab_items .tab_items_group:first").show();
		$("#top_selling_tab_items .tab_items_group li:first").addClass("on_this");
		/*$("#top_selling_tab_items .tab_items_group li:first span.price").html("<font>"+$("#top_selling_tab_items .tab_items_group li:first span.price font").html()+"</font>");*/
		$("#top_selling_tab a").mouseover(function(){
			$("#top_selling_tab a").removeClass("on_this");
			$("#top_selling_tab_items .tab_items_group").hide();
			/*$("#top_selling_tab_items .tab_items_group li.on_this span.price").html("￥<font>"+$("#top_selling_tab_items .tab_items_group li.on_this span.price font").html()+"</font>");*/
			$("#top_selling_tab_items .tab_items_group li").removeClass("on_this");
			var index_val = $("#top_selling_tab a").index(this);
			$("#top_selling_tab a").eq(index_val).addClass("on_this");
			$("#top_selling_tab_items .tab_items_group").eq(index_val+1).show();
			/*$("#top_selling_tab_items .tab_items_group").eq(index_val+1).children("li").eq(0).children(".items_right").children("span.price").html("<font>"+$("#top_selling_tab_items .tab_items_group").eq(index_val+1).children("li").eq(0).children(".items_right").children("span.price").children("font").html()+"</font>");*/

			$("#top_selling_tab_items .tab_items_group").eq(index_val+1).children("li").eq(0).addClass("on_this");
		})
		$("#top_selling_tab_items .tab_items_group li").mouseover(function(){
			/*$("#top_selling_tab_items .tab_items_group li.on_this span.price").html("￥<font>"+$("#top_selling_tab_items .tab_items_group li.on_this span.price font").html()+"</font>");*/
			$("#top_selling_tab_items .tab_items_group li").removeClass("on_this");
			var index_val = $("#top_selling_tab_items .tab_items_group li").index(this);
			/*$("#top_selling_tab_items .tab_items_group li").eq(index_val).children(".items_right").children("span.price").html("<font>"+$("#top_selling_tab_items .tab_items_group li").eq(index_val).children(".items_right").children("span.price").children("font").html()+"</font>");*/
			$("#top_selling_tab_items .tab_items_group li").eq(index_val).addClass("on_this");
		})
})