//spces页上页用的车辆显示
function car_tats(){
	var imgs = $(sheetimg).length;
	var sheet = $("#cars_tab>dl")
	sheet.each(function(i){
		var _this = $(this)
		var img = _this.find('img');
		if(sheetimg[i].isthis) _this.addClass("on");
		if (!sheetimg[i].isthis){
			_this.bind('mouseover',function(){_this.addClass("over");$(img).attr('src',sheetimg[i].on);})	;
			_this.bind('mouseout',function(){_this.removeClass("over");$(img).attr('src',sheetimg[i].off)});
		}
	})
	// alert(sheet.length)
}
function specTable(){
	var table = $('.layerdiv table')
	table.each(function(i){
		var a = $(this);
		var tr = a.find("tr")
		var td = a.find("td")
		m = tr.length;n = td.length;
		td.each(function(j){
			$(this).removeClass('body03B');$(this).removeClass('body01');
			$(this).addClass('body01');
			//if(j<n/m){ $(this).addClass('body03B')}else{$(this).addClass('body01');}
		})
		tr.each(function(j){
			$(this).removeClass('bgWhite')
			$(this).removeClass('bgColor03')
			if (j==0){
				$(this).addClass("bgColor11");
				$(this).find("td").addClass('body03B');
			}else{
				if( j%2==0){
					$(this).addClass("bgWhite");
				}else{
					$(this).addClass("bgColor03");
				}
			}
		})
	});
}

function init_sheet(){
	$('.tabsheet a').first().addClass('current')
	$('#tempHTML').html($('#tabs-0').html());
	var sheet = $('.tabsheet a');
	sheet.each(function(i){
		var _this =$(this);
		var html=$('#tabs-'+i).html();
		_this.bind('click',function(){
			sheet.removeClass('current');
			_this.addClass('current');
			$('#tempHTML').html(html);
			$(".layerdiv table tr").find("td:first").css('padding-left','10px');
		})
	})
}

function win_open (url,width,height){
	if(url!=null){
		window.open(url, 'new', 'height='+height+',width='+width+',top=300,left=100');
	}

}
/*
得到cookie: var allcookies = $.cookie('Products');//Products 是cookie名

生成新的cookie:  var newcookies = "";
if ($.cookie('Products') == null) {
newcookies += commodityId + "|" + type + "=1";//给cookie赋相应的值
$.cookie('Products', newcookies, { expires: 7, path: '/' });//重置名为product的cookie值
}
清空的为：    $.cookie('Products', '', { expires: -1, path: '/' });

*/

var history = new Array()
function history_set(id,name,brief){
	var newCar = {carid:id,carname:name,carbrief:brief};
	// var oldHistory =  $.cookie('History');
	/*var cookies = $.cookie('History');
	var oldHistory = new Array()
	oldHistory	= cookies;

	oldHistory.push(newCar)
	*/	if ($.cookie('History') == null) {alert("im")}else{
	var cookies = $.cookie('History');
	var oldHistory = new Array()
	oldHistory	= cookies; alert(cookies.length)

	// oldHistory.push(newCar)

}
$.cookie('History', newCar, { expires: 7, path: '/' });
//var History= $.cookie('History');
//	alert(History.length)
}
function show_history(str){
	var a = Array();
	alert('test')
}


function history_add(carid){
	var query = SiteRoot + "plugins/history/history.asp?action=add&carid="+carid;
	$.get(query,function(data){//
	})
}

function history_show (){
	var query =  SiteRoot +"plugins/history/history.asp?action=show";
	var uiHistory = $("</div>")

	$.get(query,function(D){
		try{
			var data =jQuery.parseJSON(D)
		}catch(e){
			//alert(D)
			$.get(SiteRoot +'plugins/history/history.asp?action=reload',function(msg){
				alert(D)
			})
			return false;
		}
		uiUL = (this.uiUL = $('<ul/>'))

		$(data).each(function(i){
			var newCar = data[i];
			var carId = newCar.carid;
			var carname = newCar.carname;
			var carImg = newCar.carimg;
			var carBrief = newCar.carbrief;
			var brandid = newCar.brandid; var brandname = newCar.brandname;
			var href = SiteRoot + "car.asp?carid="+carId;
			if (carId!= 0 ){
				uiLI =(this.uiLI = $('<li/>'))
				.html("<a href='"+href+"' title='"+carname+"'>"+brandname+ " - "+carname+ "</a>")
				.appendTo(uiUL)
				.poshytip({
					content: function(updateCallback) {
						window.setTimeout(function() {
							updateCallback('<div><a href="'+href+'"><img src="'+carImg+'" border="0"/></a></div>');
						}, 300);
						return 'Loading...';
					}
				})
			}
		})

		///alert($(uiUL).html())
		//uiUL.appendTo(uiWin)
		if($('#mod-history')){$('#mod-history').html(uiUL)}
	})

}
//IE6下PNG透明问题
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	if ((version >= 5.5) && (version < 7) && (document.body.filters))
	{

		for(var j=0; j<document.images.length; j++)
		{
			var img = document.images[j]
			var imgName = img.src.toUpperCase()
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
			{
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
				img.outerHTML = strNewHTML
				j = j-1
			}
		}
	}
}

function floatAD(url,imgsrc,width,height){
	var strHTML='<a href="'+url+'" target="_blank"><img src="'+imgsrc+'" width="'+width+'" height="'+height+'" border="0"></a>';
	var ASAD			= document.createElement("div");
	ASAD.setAttribute("id","ad");
	ASAD.style.position	= "absolute";
	ASAD.innerHTML		= strHTML;
	document.getElementsByTagName("body")[0].appendChild(ASAD);
	var x = 50,y = 60 //浮动层的初始位置，分别对应层的初始X坐标和Y坐标
	var xin = true, yin = true //判断层的X坐标和Y坐标是否在在控制范围之内，xin为真是层向右移动，否则向左；yin为真是层向下移动，否则向上
	var step = 1 //层移动的步长，值越大移动速度越快
	var delay = 10 //层移动的时间间隔,单位为毫秒，值越小移动速度越快
	var obj=document.getElementById("ad") //捕获id为ad的层作为漂浮目标

	this.floatA=function() {
		var L=T=0 //层移动范围的左边界(L)和上边界(T)坐标
		var R= document.body.clientWidth-obj.offsetWidth //层移动的右边界
		var B = document.body.clientHeight-obj.offsetHeight //层移动的下边界
		obj.style.left = x + document.body.scrollLeft //更新层的X坐标，实现X轴方向上的运动；document.body.scrollLeft为文档区域的滚动条向右拉的距离，以保证在滚动条右拉时层仍在可见范围内
		obj.style.top = y + document.body.scrollTop //更新层的Y坐标，实现Y轴方向上的运动；document.body.scrollTop为文档区域的滚动条向下拉的距离，以保证在滚动条下拉时层仍在可见范围内
		x = x + step*(xin?1:-1) //通过判断层的范围决定层在X轴上的运动方向
		if (x < L) { xin = true; x = L} //层超出左边界时的处理
		if (x > R){ xin = false; x = R} //层超出右边界时的处理
		y = y + step*(yin?1:-1) //通过判断层的范围决定层在Y轴上的运动方向
		if (y < T) { yin = true; y = T } //层超出上边界时的处理
		if (y > B) { yin = false; y = B } //层超出下边界时的处理
	}
	var itl= setInterval("floatA()", delay) //每delay秒执行一次floatAD函数
	obj.onmouseover=function(){clearInterval(itl)} //层在鼠标移上时清除上面的间隔事件，实现层在的鼠标移上时停止运动的效果
	obj.onmouseout=function(){itl=setInterval("floatA()", delay)} //层在鼠标移开时开始间隔事件，实现层在的鼠标移开时继续运动的效果
}
//========================================================================
//定义list前面背景移动效果
//========================================================================
var leftnavX = -10;
var arrowX = -6;
function aimArrow(theId){
	var dy=theId.style.backgroundPosition;

	var theObj = theId.id
	anArrow(theObj);
}
function anArrow(id){

	var theObj =document.getElementById(id);
	if (arrowX < 25) {
		arrowX = arrowX+2;
		theObj.style.backgroundPosition = arrowX+"px 2px ;";
		setTimeout("anArrow('"+id+"')",1);
	} else if (arrowX == 26) {
		theObj.style.backgroundPosition = "25px 2px";
		arrowX = -6;
	}
}
//resize the picture
function DrawImage(ImgD,iwidth,iheight){  //add by yang , 2011.07.29
	var image=new Image();
	image.src=ImgD.src;
	if(image.width>0 && image.height>0){ //it's  the image,

		if(image.width/image.height>= iwidth/iheight){ // to hieght base on height
			if(image.width>iwidth){
				ImgD.width=iwidth;
				ImgD.height=(image.height*iwidth)/image.width;
			}else{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		}else{
			if(image.height>iheight){
				ImgD.height=iheight;
				ImgD.width=(image.width*iheight)/image.height;
			}else{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		}
		// if resized width less than iwidth then margin
		if (iwidth > ImgD.width){
			var marginW = 	(iwidth - ImgD.width)/2;
			//$(ImgD).css('margin',' 0 '+marginW+"px");
			ImgD.style.margin = '0 '+marginW+"px";
		}
		//  if resized height less than iheight then margin
		if (iheight > ImgD.height){
			var marginH = 	(iheight - ImgD.height)/2;
			//$(ImgD).css('margin',marginH + 'px 0');
			ImgD.style.margin = marginH + 'px 0';
		}
	}
}


