/////////////////////////////////////首页标签
function indexTab(){
	if($("#indexTabs").length > 0){
		$("#indexTabs ul li").each(function(i){
			$(this).click(function(){
				$("#indexTabs ul li").removeClass("on");
				$("#indexTabs div").removeClass("on");
				$(this).addClass("on");
				$($("#indexTabs div").get(i)).addClass("on");
			});
		});
	}
}
/////////////////////////////////////左右栏等高
function eqalHeight(){
	if($("body")){
		$(".Left").css("height","auto");
		$(".Right").css("height","auto");
		if($(".Left").height()<$(".Right").height()){
			$(".Left").height($(".Right").height());
		}else if($(".Left").height()>$(".Right").height()){
			$(".Right").height($(".Left").height());
		}
		//$("#ContentHeight").css("height","auto");
	}
}
/////////////////////////////////////外观
function ext(){
	if($("#exCon").length>0){
		$("#extBanner a.hotArea").each(function(i){
			$(this).mouseover(function(){
				$("#exCon .conDetail").hide();
				$("#exCon .conDetail").eq(i).show();
				$(".conNav li").removeClass("on");
				$(".conNav li").eq(i).addClass("on");
				$(".Right").css("height","auto");
				$(".Left").css("height","auto");
				eqalHeight();
			});
		});
		$(".conNav li").each(function(i){
			$(this).mouseover(function(){
				$("#exCon .conDetail").hide();
				$("#exCon .conDetail").eq(i).show();
				$(".conNav li").removeClass("on");
				$(this).addClass("on");
				$(".Right").css("height","auto");
				$(".Left").css("height","auto");
				eqalHeight();
			});
		});
	}
}
/////////////////////////////////////半透明图片修复
function fixPng(){
	if($("img.png").length>0){
		if($.browser.msie&&$.browser.version == "6.0"){
			$("img.png").each(function(){
				$(this).hide();
				$(this).parent().css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale', src='"+$(this).attr('src')+"')");
			});
		}
	}
}
/////////////////////////////////////内饰
function int(){
	if($("#intCon").length>0){
		$("#intBanner a.hotArea").each(function(i){
			$(this).mouseover(function(){
				$("#intCon .conDetail").hide();
				$("#intCon .conDetail").eq(i).show();
				$(".conNav li").removeClass("on");
				$(".conNav li").eq(i).addClass("on");
				$(".Right").css("height","auto");
				$(".Left").css("height","auto");
				eqalHeight();
			});
		});
		$("#intBanner2 a.hotArea").each(function(i){
			$(this).mouseover(function(){
				$("#intCon .conDetail").hide();
				$("#intCon .conDetail").eq(i).show();
				$(".conNav li").removeClass("on");
				$(".conNav li").eq(i).addClass("on");
				$(".Right").css("height","auto");
				$(".Left").css("height","auto");
				eqalHeight();
			});
		});
		$(".conNav li").each(function(i){
			$(this).mouseover(function(){
				$("#intCon .conDetail").hide();
				$("#intCon .conDetail").eq(i).show();
				$(".conNav li").removeClass("on");
				$(".conNav li").eq(i).addClass("on");
				$(".Right").css("height","auto");
				$(".Left").css("height","auto");
				eqalHeight();
			});
		});
	}
}
/////////////////////////////////////图库
function gallery(){
	if($("#gallery").length>0){
		$("#gallery li").each(function(i){
			$(this).append("<span></span>");
			$(this).mouseover(function(){$(this).addClass("on")});
			$(this).mouseout(function(){$(this).removeClass("on")});
			$(this).mouseover(function(){
				if($(this).attr("className").indexOf("now")>0){
					return;
				}else if($(this).attr("className").indexOf("now")==-1){
					$("#gallery li").removeClass("on");
					$("#gallery li").removeClass("now");
					$(this).addClass("now");
					$("#galLarge img").load(function(){
						$("#galLarge").css("background","");
						$("#galLarge img").fadeIn("slow");
					});
					$("#galLarge").css("background","url(images/loading.gif) 50% 50% no-repeat");
					$("#galLarge img").attr("src","");
					$("#galLarge img").attr("src",this.getAttribute("value"));
					$("#galLarge img").hide();
				}
			});				   
		});
		$("#gallery li").eq(0).addClass("now");
	}
}
/////////////////////////////////////内饰颜色选择
function color(){
	if($("#color1").length>0){
		$("#color1 #colo1Tumb li").each(function(i){
			$(this).append("<span></span>");
			//$(this).mouseover(function(){$(this).addClass("on")});
			$(this).mouseout(function(){$(this).removeClass("on")});
			$(this).mouseover(function(){
				//$("#color1 #colo1Tumb li").removeClass("on");
				$("#color1 #colo1Tumb li").removeClass("now");
				$(this).addClass("now");
				$(".colo1Lar").hide();
				$(".colo1Lar").eq(i).show();
			});				   
		});
		$("#color1 #colo1Tumb li").eq(0).addClass("now");
	}
}
/////////////////////////////////////外观颜色选择
function picker(){
	if($("#picker").length>0){
		$("#picker li").each(function(){
			$(this).click(function(){
				if($(this).find("a").attr("className").indexOf("on")==0){
					return;
				}else{
					$("#picker li a").removeClass("on");
					$(this).find("a").addClass("on");
					$("#colo2Lar img").load(function(){
						$("#colo2Lar").css("background","");
						$("#colo2Lar img").fadeIn("slow");
					});
					$("#colo2Lar").css("background","url(images/loading.gif) 50% 50% no-repeat");
					$("#colo2Lar img").attr("src","");
					$("#colo2Lar img").attr("src",this.getAttribute("value"));
					$("#colo2Lar img").hide();				
					}
			});
		});
	}
}
////////////////////////////////////////配备表规格表样式
function tableSty(){
	$("table.styA tr").each(function(){
	$(this).find("td").eq(0).css("textAlign","left");
	$(this).find("td").eq(0).css("paddingLeft","15px");
	});
}
////////////////////////////////////////配备表规格表下拉
function tableSlide(){
	$("table.styA tr.title").each(function(){
		$(this).find("h4").append("<span>显示项目</span>");
		$(this).addClass("hid");
		$(this).nextAll().hide();
		$(this).click(function(){
			if($(this).attr("className").indexOf("hid")>-1){
				$(this).removeClass("hid");
				$(this).nextAll().show();
				$(this).find("span").text("隐藏项目");
				setTimeout(function(){eqalHeight();},5);
			}else{
				$(this).addClass("hid");
				$(this).nextAll().hide();
				$(this).find("span").text("显示项目");
				setTimeout(function(){eqalHeight();},5);
			}
		});	
	});
	$("table.styA tr.title").eq(0).removeClass("hid");
	$("table.styA tr.title").eq(0).nextAll().show();
	$("table.styA tr.title").eq(0).find("span").text("隐藏项目");
}

////////////////////////////////////////配备表规格表初始化
var tableArr = new Array;
var delBtns = new Array;

function tableInit(){
	$("table.styA tr").each(function(i){
		tableArr[i] = new Array;
		var k = 0;
		$(this).children().each(function(){
			var _a = $(this).attr("colspan");
			if(_a == "1" || _a == undefined){
				tableArr[i][k] = $(this);
				tableArr[i][k].data("type","_cell");
				k+=1;
			}else if(Number(_a)>1){
				_a = Number(_a);
				while(_a>0){
					_a-=1;
					tableArr[i][k] = $(this);
					tableArr[i][k].data("type","_colsCell");
					tableArr[i][k].data("_colspan",Number($(this).attr("colspan")));
					k+=1;
				}
			}
		});
	});
/////////////////////////////////////按钮数组初始化
	$("table.styA tr.btn td:gt(0)").each(function(i){
		delBtns[i] = new Object;
		delBtns[i]._id = i+1;
		delBtns[i]._visible = true;
		delBtns[i]._avalible = true;
		$(this).click(function(){
			hideCell(i+1,"del");
			if(findIdRight(i)){
				showCell(findIdRight(i)+1);
			}else if(findIdRight(i) == undefined){
				showCell(findIdLeft(i)+1);
			}
		});

	});
///////////////////////////////////删除按钮和显示全部按钮	
	$("table.styA tr.btn td:eq(0)").click(function(){
		for(j=0; j<delBtns.length; j++){
			delBtns[j]._avalible = true;
			if(delBtns[j]._visible){
				hideCell(delBtns[j]._id,"hide");
			}
			for(k=1; k<=3; k++){
				showCell(k);
			}
		}
	});
///////////////////////////////////向右按钮
	$("img#leftArrow").click(function(){
		var i=delBtns.length-1;
		while(i>0){
			if(delBtns[i]._visible){
				break;
			}
			i--;
		}
		hideCell(i+1);
		
		i=0;
		while(i<delBtns.length){
			if(delBtns[i]._visible){
				break;
			}
			i++;
		}
		showCell(findIdLeft(i)+1);
	});
///////////////////////////////////向左按钮
	$("img#rightArrow").click(function(){
		var i=delBtns.length-1;
		while(i>0){
			if(delBtns[i]._visible){
				break;
			}
			i--;
		}
		showCell(findIdRight(i)+1);
		i=0;
		while(i<delBtns.length){
			if(delBtns[i]._visible){
				break;
			}
			i++;
		}
		hideCell(i+1);
	});
	
	for(k=4; k<=7; k++){
		hideCell(k,"hide");
	}
///////////////////////////////////按钮显示状态初始化
	arrowStat();
}
///////////////////////////////////查找右侧可用列
function findIdRight(i){
	var _numA = i;
	while(_numA<delBtns.length-1){
		_numA++;
		if(delBtns[_numA]._visible == false && delBtns[_numA]._avalible == true){
			return _numA;
			break;
		}
	}
}
///////////////////////////////////查找左侧可用列
function findIdLeft(i){
	_numA = i;
	while(_numA>0){
		_numA--;
		if(delBtns[_numA]._visible == false && delBtns[_numA]._avalible == true){
			return _numA;
			break;
		}
	}
}
///////////////////////////////////隐藏列
function hideCell(num,mode){
	if(delBtns[num-1]._visible == true){
		for(i=0; i<tableArr.length; i++){
			if(tableArr[i][num].data("type") == "_cell"){
				tableArr[i][num].hide();
			}else if(tableArr[i][num].data("type") == "_colsCell"){
				var _b = Number(tableArr[i][num].attr("colspan"));
				if(_b>1){
					tableArr[i][num].attr("colSpan",_b-1);
				}else if(_b==1){
					tableArr[i][num].hide();
					tableArr[i][num].data("colStat","hidden");
				}
			}
		}
		delBtns[num-1]._visible = false;
	}
	if(mode == "del"){
		delBtns[num-1]._avalible = false;
	}
	arrowStat();
}
///////////////////////////////////显示列
function showCell(num){
	if(delBtns[num-1]._visible == false && delBtns[num-1]._avalible == true){
		for(i=0; i<tableArr.length; i++){
			if(tableArr[i][num].data("type") == "_cell"){
				tableArr[i][num].show();
			}else if(tableArr[i][num].data("type") == "_colsCell"){
				if(tableArr[i][num].data("colStat") == "hidden"){
					tableArr[i][num].show();
					tableArr[i][num].data("colStat","showed");
				}else{
					var _b = Number(tableArr[i][num].attr("colspan"));
					tableArr[i][num].attr("colSpan",_b+1);
				}
			}
		}
		delBtns[num-1]._visible = true;
	}
	arrowStat();
}
///////////////////////////////////更新左右箭头状态
function arrowStat(){
	var i=delBtns.length-1;
	while(i>0){
		if(delBtns[i]._visible){
			break;
		}
		i--;
	}
	if(findIdRight(i)!=undefined){
		$("img#rightArrow").show();
	}else{
		$("img#rightArrow").hide();
	}
	i=0;
	while(i<delBtns.length){
		if(delBtns[i]._visible){
			break;
		}
		i++;
	}
	if(findIdLeft(i)!=undefined){
		$("img#leftArrow").show();
	}else{
		$("img#leftArrow").hide();
	}
}

////////////////////////////////////////触发表格功能
function tableFunc(){
	if($("table.styA").length>0){
		tableSlide();
		tableInit();
		tableSty();
	}
}
var a = 0;
var obj;
function xunhuan(){
if(a == obj.length) a = 0;
obj.hide();
obj.eq(a).fadeIn("normal");
a++;
setTimeout(xunhuan,3000);
}

var b = 0;
var objB;
function xunhuan2(){
if(b == objB.length) b = 0;
objB.hide();
objB.eq(b).fadeIn("normal");
b++;
setTimeout(xunhuan2,4000);
}
////////////////////////////////////////图片轮播

function autoPlayA(){
	if($("#safety2b").length>0){
		obj = $("#safety2b img");
		xunhuan();
	}
}
function autoPlayB(){
	if($("#safety2c").length>0){
		objB = $("#safety2c img");
		xunhuan2();
	}
}
$(document).ready(indexTab);
$(document).ready(ext);
$(document).ready(int);
$(document).ready(fixPng);
$(document).ready(gallery);
$(document).ready(color);
$(document).ready(picker);
$(document).ready(tableFunc);
$(document).ready(autoPlayA);
$(document).ready(autoPlayB);
$(document).ready(eqalHeight);