
var imgid = 'image';
var imgdir = 'fullsize';
var imgext = '.jpg';
var thumbid = 'thumbs';
var auto = true;
var autodelay = 2;
var slideShow=function(){
	var ys,ta,ia,st,fs,ci,t,tar,tarl;
	ta=document.getElementById(thumbid);
	ia=document.getElementById(imgid);
	t=ta.getElementsByTagName('li');
	//var m=document.getElementsByTagName('span');
	fs=5;
	return{
		init:function(){
			len=t.length;
			tar=[];
			for(i=0;i<len;i++){
				var id=t[i].value;
				tar[i]=id;
				//m[i].onmouseover=new Function("slideShow.getimg('"+id+"')");
				if(i==0)
				{this.getimg(id)}
			}
			tarl=tar.length;
		},
		getimg:function(id){
			//Active the corresponding image tab;
			for(var k = 1; k <= fs; k++ )
			{
				if( k != id)
				{
					//document.getElementById("image"+k).style.border = "";
				}
				
			}
			//document.getElementById("image"+id).style.border="solid";
			if(auto){clearTimeout(ia.timer)}
			if(ci!=null){
				var ts,tsl,x;
				ts=ia.getElementsByTagName('img');
				tsl=ts.length;
				x=0;
				for(x;x<tsl;x++){
					if(ci.id!=id){var o=ts[x];
					clearInterval(o.timer);
					o.timer=setInterval(function(){slideShow.fdout(o)},fs)}
				}
			}
			if(!document.getElementById(id)){
				var i=document.createElement('img');
				$("#image").html("");
				ia.appendChild(i);
				i.id=id; i.av=0; i.style.opacity=0;
				i.style.filter='alpha(opacity=0)';
				var source=document.getElementById("img"+id).src;
				//i.src=imgdir+'/'+id+imgext;
				i.src=source;
				i.style.width="266px";
				i.style.height="66px";
				i.style.cursor="pointer";
				
				$("#image img").click(function(){
						
						var width = 550;
						var height = 550;
						var left = parseInt((screen.availWidth/2) - (width/2));
						var top = parseInt((screen.availHeight/2) - (height/2));
						var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable=no,left=" + left + ",top="                                  + top +"screenX=" + left + ",screenY=" + top;
						myWindow =window.open("image_banner.php", "HotNews", windowFeatures);
						if (window.focus)
						{
							myWindow.focus();
						}
						
											   
					}
											   
					);
			}else{
				i=document.getElementById(id); clearInterval(i.timer);
			}
			i.timer=setInterval(function(){slideShow.fdin(i)},fs);
		},
		nav:function(d){
			var c=0;
			for(key in tar){if(tar[key]==ci.id){c=key}}
			if(tar[parseInt(c)+d]){
				this.getimg(tar[parseInt(c)+d]);
			}else{
				if(d==1){
					this.getimg(tar[0]);
				}else{this.getimg(tar[tarl-1])}
			}
		},
		auto:function(){ia.timer=setInterval(function(){slideShow.nav(1)},autodelay*1000)},
		fdin:function(i){
			if(i.complete){i.av=i.av+fs; i.style.opacity=i.av/100; i.style.filter='alpha(opacity='+i.av+')'}
			if(i.av>=100){if(auto){this.auto()}; clearInterval(i.timer); ci=i}
		},
		fdout:function(i){
			i.av=i.av-fs; i.style.opacity=i.av/100;
			i.style.filter='alpha(opacity='+i.av+')';
			if(i.av<=0){clearInterval(i.timer); if(i.parentNode){i.parentNode.removeChild(i)}}
		}		
	};
}();
window.onload=function(){slideShow.init()};

