﻿// JSON格式的Images信息
/*
var imageJSONObject = 
	{"Property":{
			"width":260,			//图片宽
			"height":195,			//图片高
			"textFromHeight":20,	//焦点字框高度 (单位为px)
			"textStyle":"f12",		//焦点字class style (不是连接class)
			"textLinkStyle":"p1",	//焦点字连接class style
			"buttonLineOn":"#f60",	//button下划线on的颜色
			"buttonLineOff":"#000",	//button下划线off的颜色
			"TimeOut":5000,			//每张图切换时间 (单位毫秒);<br>
			"TransitionMode":23		//变换模式。大于24（含）时将随机变换
	  	},
	"Image": 
	[
		{"Url": "http://www.pconline.com.cn/digital/dc/pingce/xfl_dc_pcyyr/images/picpath/nv3_pingce_260x195.jpg",
		 "Link": "http://www.pconline.com.cn/digital/dc/pingce/xfl_dc_pcyyr/0608/850129.htm",
		 "Title": "娱乐随身行 三星“蓝调”NV3卡片DC完全评测"},
		{"Url": "http://www.pconline.com.cn/digital/dc/daogou/basics/images/picpath/canon_ef_dg_260x195.jpg",
		 "Link": "http://www.pconline.com.cn/digital/dc/daogou/basics/0608/847555.html",
		 "Title": "红圈白炮 佳能EF卡口单反镜头全面导购"},
		{"Url": "http://www.pconline.com.cn/digital/dc/pingce/smdfpcysr/images/picpath/d80pk_260x195.jpg",
		 "Link": "http://www.pconline.com.cn/digital/dc/pingce/smdfpcysr/0608/848036.html",
		 "Title": "同门之争!尼康单反D80 D70s D200横向对比"},
		{"Url": "http://www.pconline.com.cn/digital/dc/daogou/specialty/images/picpath/1000_5000dg_260x195.jpg",
		 "Link": "http://www.pconline.com.cn/digital/dc/daogou/specialty/0608/848757.html",
		 "Title": "不花冤枉钱!1000-5000元最具人气DC导购"}
	]
};
*/

var imgWidth=260;					//图片宽
var imgHeight=195;					//图片高
var textFromHeight=20;				//焦点字框高度 (单位为px)
var textStyle="f12";				//焦点字class style (不是连接class)
var textLinkStyle="p1";				//焦点字连接class style
var buttonLineOn="#f60";			//button下划线on的颜色
var buttonLineOff="#000";			//button下划线off的颜色
var TimeOut=5000;					//每张图切换时间 (单位毫秒);<br>
var TransitionMode = 23;			//变换模式。大于24（含）时将随机变换
var adNum=0;
var theTimer;

Init();

function Init(){
	try{
		imgWidth = imageJSONObject.Property.width;
		imgHeight = imageJSONObject.Property.height;
		textFromHeight = imageJSONObject.Property.textFromHeight;
		textStyle = imageJSONObject.Property.textStyle;
		textLinkStyle = imageJSONObject.Property.textLinkStyle;
		buttonLineOn = imageJSONObject.Property.buttonLineOn;
		buttonLineOff = imageJSONObject.Property.buttonLineOff;
		TimeOut = imageJSONObject.Property.TimeOut;
		TransitionMode = imageJSONObject.Property.TransitionMode;
	}
	catch(e){
	}
}

//焦点字框高度样式表 开始
/*
var i;
var base = '';
var src = "js/altimage.js";
var scriptTag = document.getElementsByTagName("script"); 
for (i = 0; i < scriptTag.length; i++) {
	if (scriptTag[i].src.match(src)) {
		base = scriptTag[i].src.replace(src, "");
		break;
	}
}
document.write('<link href=css/altimage.css' + '" rel="stylesheet" type="text/css"></link>');
*/
document.write('<style type="text/css">');
document.write('#focuseFrom{width:'+(imgWidth+2)+';margin: 0px; padding:0px;height:'+(imgHeight+textFromHeight)+'px; overflow:hidden;}');
document.write('#txtFrom{height:'+textFromHeight+'px;line-height:'+textFromHeight+'px;width:'+imgWidth+'px;overflow:hidden;}');
document.write('#imgTitle{width:'+imgWidth+';top:-'+(textFromHeight+12)+'px;}');
document.write('</style>');
document.write('<div id="focuseFrom">');
//焦点字框高度样式表 结束

//Image JSON模型的属性和方法
var imageMembersCount = imageJSONObject.Image.length;
function imgUrl(index)		{return imageJSONObject.Image[index].Url;}
function imgTitle(index)	{return imageJSONObject.Image[index].Title;}
function imgLink(index)	{return imageJSONObject.Image[index].Link;}
function imgText(index)	{return '<A HREF="' + imgLink(index) + '" TARGET="_blank" class="'+ textLinkStyle +'">' + imgTitle(index) + '</A>';}

function changeimg(n){
	window.clearInterval(theTimer);
	adNum=n-1;
	nextAd();
}

function goUrl()	{window.open(imgLink(adNum),'_blank');}

//NetScape开始
if (navigator.appName == "Netscape")
{
	document.write('<style type="text/css">');
	document.write('.buttonDiv{height:4px;width:21px;}');
	document.write('</style>');
	
	function nextAd(){
		if(adNum<imageMembersCount-1)adNum++;
		else adNum=0;
		theTimer=setTimeout("nextAd()", TimeOut);
		document.images.imgInit.src=imgUrl(adNum);
		document.images.imgInit.alt=imgText(adNum);	
		document.getElementById('focustext').innerHTML=imgText(adNum);
		document.getElementById('link'+adNum).style.background=buttonLineOn;
		document.getElementById('imgLink').href=imgLink(adNum);
		for (var i=0;i<imageMembersCount;i++)
		{
		   if (i!=adNum){document.getElementById('link'+i).style.background=buttonLineOff;}
		}	
	}
	
	document.write('<a id="imgLink" href="'+imgLink(0)+'" target=_blank class="p1"><img src="'+imgUrl(0)+'" name="imgInit" width='+imgWidth+' height='+imgHeight+' border=1 alt="'+imgTitle(0)+'" class="imgClass"></a><div id="txtFrom"><span id="focustext" class="'+textStyle+'">'+imgText(0)+'</span></div>')
	document.write('<div id="imgTitle">');
	document.write('<div id="imgTitle_down">');
	
	//数字按钮代码开始
	for(var i=0;i< imageMembersCount;i++){document.write('<a href="javascript:changeimg('+i+')" class="button" style="cursor:hand" title="'+ imgTitle(i) +'">'+ (i+1) +'</a>');}
	//数字按钮代码结束
	
	document.write('</div>');
	document.write('</div>');
	document.write('</div>');
	nextAd();
}
//NetScape结束
//IE开始
else
{
	var count = 0;
	for (i=0;i< imageMembersCount;i++) {
		if( (imgUrl(i)!="") && (imgLink(i)!="") && (imgText(i)!="") ) {
			count++;
		} else {
			break;
		}
	}
	
	function playTran(){
		if (document.all)
			document.getElementById("imgInit").filters.revealTrans.play();		
	}
	
	var key=0;
	function nextAd(){
		if(adNum<count-1)adNum++ ;
		else adNum=0;
		
		if( key==0 ){
			key=1;
		} else if (document.all){
			document.getElementById("imgInit").filters.revealTrans.Transition = TransitionMode;
			document.getElementById("imgInit").filters.revealTrans.apply();
			playTran();
		}
		document.getElementById("imgInit").src=imgUrl(adNum);
		document.getElementById("imgInit").alt=imgTitle(adNum);	
		document.getElementById('link'+adNum).style.background=buttonLineOn;
		for (var i=0; i<count ;i++)
		{
		   if (i!=adNum){document.getElementById('link'+i).style.background=buttonLineOff;}
		}	
		focustext.innerHTML=imgText(adNum);
		theTimer=setTimeout("nextAd()", TimeOut);
	}
	
	document.write('<a target=_self href="javascript:goUrl()"><img style="FILTER: revealTrans(duration=1,transition=' + TransitionMode + ';" src="javascript:nextAd()" width='+imgWidth+' height='+imgHeight+' border=0 vspace="0" id="imgInit" class="imgClass"></a>');
	document.write('<div id="txtFrom"><span id="focustext" class="'+textStyle+'"></span></div>');
	document.write('<div id="imgTitle">');
	document.write('<div id="imgTitle_down"> <a class="trans"></a>');
	
	//数字按钮代码开始
	for(var i=0; i<count; i++){document.write('<a id="link'+i+'"  href="javascript:changeimg('+i+')" class="button" style="cursor:hand" title="'+imgTitle(i)+'" onFocus="this.blur()">'+ (i+1) +'</a>');}
	//数字按钮代码结束
	
	document.write('</div>');
	document.write('</div>');
	document.write('</div>');
}
//IE结束

changeimg(0);