// JavaScript Document
var imgWidth=240;
var imgHeight=150;
var _timeOut_=5000;
var show_text = true; //是否显示焦点文字
var timeOut=_timeOut_;
var timeOut2=_timeOut_/2;//onmouseout img后需要切换的时间
var now=0;              //第一张图
var target="_blank";   //打开方式
var button_on ='on'; //当前焦点对应按钮的样式名
var button_off ='';//非当前焦点对应按钮的样式名

//不可修改区域
var imgUrl = new Array();
var imgText = new Array();
var imgLink = new Array();
var imgAlt= new Array();
var menuList = new Array();//菜单menu
var ver=2; //兼容浏览器版本 默认2 为非ie
var firstTime=true;
var n =-1;		


//菜单menu
menuList[++n]='导购';imgUrl[n]='images/1.gif';imgText[n]="6款A0级小车型";imgLink[n]='http://auto.cnfol.com/070620/169,1700,3077259,02.shtml';imgAlt[n]='“特色车推荐';


//菜单menu
menuList[++n]='购车';imgUrl[n]='http://images.cnfol.com/articles/18_106903.jpg';imgText[n]="小康家庭的最爱";imgLink[n]='http://auto.cnfol.com/070620/169,1700,3076600,01.shtml';imgAlt[n]='“家庭最爱';


//菜单menu
menuList[++n]='新车';imgUrl[n]='http://images.cnfol.com/articles/17_106902.jpg';imgText[n]="4款新车快报";imgLink[n]='http://auto.cnfol.com/070618/169,1692,3069839,02.shtml';imgAlt[n]='“新车';


//菜单menu
menuList[++n]='酷车';imgUrl[n]='http://images.cnfol.com/articles/16_106901.jpg';imgText[n]="真正的牛车牌";imgLink[n]='http://auto.cnfol.com/070618/169,1686,3070943,10.shtml';imgAlt[n]='“牛车牌';



var count=0;
for (var i=0;i<imgUrl.length;i++) {
if( (imgUrl[i]!="") && (imgText[i]!="")&& (imgLink[i]!="")&& (imgAlt[i]!="")) {
	count++;
} else {
	break;
}
}
//重写css
var each_width=Math.ceil((imgWidth-(count-1))/count);
var last_width=imgWidth-each_width*(count-1)-(count)+1;
p$("<style>");
p$("<!--");
p$("#f_menu a");
p$("#f_menu #f_menu"+(count-1)+"{width:"+last_width+"px; margin:0;}");
p$("-->");
p$("</style>");

function change(){
if (ver==1){
	with($('f_img').filters[0]){
		Transition=1;
		apply();
		play(); 
	}
}
if (firstTime){ firstTime=false;timeOut=_timeOut_/1000;}
else{	 
	 $('f_img').src=imgUrl[now];
	 $('f_img').alt=imgAlt[now];
	 $('f_imgLink').href=imgLink[now];
	 if (show_text) $('f_text').innerHTML=imgText[now];		
	 for (var i=0;i<count;i++) {
		$('b'+i).className="button";
		$('f_menu'+i).className="";
	 }
	 $('b'+now).className="on";	
	 $('f_menu'+now).className="on";	 
	 now=(now>=imgUrl.length-1)?0:now+1;
	 timeOut=_timeOut_;		 
}
theTimer=setTimeout("change()", timeOut);
}
function b_change(num){
window.clearInterval(theTimer); 
now=num;
firstTime=false;
change();
}
//draw 渐变line (即css:f_line)
function draw_line(){
var div = document.createElement("div");	
div.id = 'f_line';
$('f_infoDiv').insertBefore(div,$('f_infoDiv').childNodes.item(0));			
}
//表现层 start	
//menu
for(var i=0;i<count;i++){
	var menu = document.createElement("a");		

	//menu.className="f_menu"+i;
	menu.id="f_menu"+i;
	menu.href='#';
	menu.value=i;		
	menu.onmouseover=function()
	{
	b_change(this.value);
	};
	menu.title=imgAlt[i];
	menu.innerHTML=menuList[i];
	$('f_menu').appendChild(menu);
}
//图片
var a = document.createElement("a");		
a.id="f_imgLink";
a.target=target;
a.href=imgLink[now];	
$('f_imgDiv').appendChild(a);

var img = document.createElement("img");	
img.id="f_img";
img.width=imgWidth;
img.height=imgHeight;
img.src=imgUrl[now];
img.alt=imgAlt[now];
a.appendChild(img);

//数字按钮
for (var i=count-1;i>=0;i--){
	var div_bg = document.createElement("div");		
	div_bg.id = 'div_bg'+i;
	div_bg.className='bg';
	$('f_buttonDiv').appendChild(div_bg);	
	var a = document.createElement("a");		
	a.id = 'b'+i;
	a.className = (i==now+1)?"button_on":"button_off";		
	a.title=imgAlt[i];
	a.innerHTML=i+1;
	a.href='javascript:b_change('+i+')';		
	$('div_bg'+i).appendChild(a);	
	var div= document.createElement("div");
	$('f_buttonDiv').appendChild(div);			
}	    
if (show_text) $('f_text').innerHTML = imgText[now];
//表现层 end
$('f_img').onmouseover=function()
{
window.clearInterval(theTimer);
}
$('f_img').onmouseout=function(){theTimer=setTimeout("change()", timeOut2);}
try{  //滤镜版本
  new ActiveXObject("DXImageTransform.Microsoft.Fade");
  $('f_img').filters[0].play();	  
  ver=1;
  draw_line(); 
  }
catch (e)
{
ver=2;
}
var theTimer = setTimeout("change()", _timeOut_/1000);