﻿// JScript File
if(typeof YAHOO=="undefined"||!YAHOO)
{
	var YAHOO={};
}
YAHOO.namespace=function()
{
	var a=arguments,o=null,i,j,d;
	for(i=0;i<a.length;i=i+1)
	{
		d=a[i].split(".");o=YAHOO;
		for(j=(d[0]=="YAHOO")?1:0;j<d.length;j=j+1)
		{	o[d[j]]=o[d[j]]||{};
			o=o[d[j]];
		}
	}
	return o;
};
YAHOO.namespace('sea.fp');
YAHOO.sea.fp._mac = 0;
YAHOO.sea.fp._opera = 0;


YAHOO.sea.fp.TodayVSet=function(id,autoRotate)
{
	this.init(id,autoRotate);
};

YAHOO.sea.fp.TodayVSet.prototype={init:function(id,autoRotate)
{
	this.obj=YAHOO.util.Dom.get(id);
	this.animComplete=true;
	this.mouseovertimeout=0;
	this.autoRotatePaused=true;
	this.mouseOverred=false;
	this.autoRotateConf=autoRotate;
	var pft=YAHOO.util.Dom.getElementsByClassName('vpv-ft','',this.obj)[0];
	var pvtabs=YAHOO.util.Dom.getElementsBy(function(el)
	{
		if(el.parentNode.className=='vpv-ft')
		{
			return true;
		}
		else
		{
			return false;
		}
	},'li',pft);
	this.pvimgs=new Array();
	this.pvtabs=pvtabs;
	this.stopAnim=null;
	this.controller=null;
	var that=this,i;
	for(i=0;i<pvtabs.length;i++)
	{
		var pvid='gl2-ct1-'+(i+1)+'vpv';
		this.pvimgs[i]=YAHOO.util.Dom.getElementsBy(function(el)
		{
			return true;
		},'img',pvid)[0];
		YAHOO.util.Event.on(pvtabs[i],'click',this.switchClick,that,false);
		YAHOO.util.Event.on(pvtabs[i],'mouseover',this.handleMouseOver,that,false);
		YAHOO.util.Event.on(pvtabs[i],'mouseout',this.handleMouseOut,that,false);
	}

	this.curTab=0;
	var that=this;
	if(autoRotate===true)
	{
		this.timeout=setTimeout(function() 
		{
			that.autoRotate();
		},10000);
	}
	},
	registerFunction:function(fn,obj)
	{
		this.stopAnim=fn;
		this.controller=obj;
	},
	switchClick:function(e,obj)
	{
		var that=this;(function()
		{
			obj.autoRotatePaused=true;
			obj.mouseOverred=true;
			if(obj.timeout!=0)
			{
				clearTimeout(obj.timeout);
			}

			obj.switchTab(that);
			YAHOO.util.Event.preventDefault(e);
			})();
		},handleMouseOut:function(e,obj)
		{
			clearTimeout(obj.mouseovertimeout);
			if(obj.mouseOverred==true&&obj.autoRotatePaused==true)
			{
				obj.mouseOverred=false;
				obj.timeout=setTimeout(function()
				{
					obj.autoRotate();
				},12000);
			}
		},handleMouseOver:function(e,obj)
		{
			clearTimeout(obj.mouseovertimeout);
			var that=this;
			obj.mouseovertimeout=setTimeout(function()
			{
				obj.processMouseOver(obj,that);
			},500);
		},processMouseOver:function(obj,tab)
		{
			obj.autoRotatePaused=true;
			obj.mouseOverred=true;
			if(obj.timeout!=0)
			{
				clearTimeout(obj.timeout);
			}

			if(obj.stopAnim)
			{
				obj.stopAnim(this.controller);
			}
			obj.switchTab(tab);
		},switchTab:function(node)
		{
			clearTimeout(this.timeout);
			var YUD=YAHOO.util.Dom,YUE=YAHOO.util.Event,c,c_ctn,n,n_ctn;
			if(this.animComplete==false){return;}

			c=YUD.getElementsByClassName('on','',node.parentNode)[0];
			c_ctn=c.id+'vpv';
			n_ctn=node.id+'vpv';
			if(c.id===node.id){return;}

			var node_id=node.id;
			var node_idx=node_id.charAt(node_id.length-1)-1;
			this.curTab=node_idx;
			if(!this.pvimgs[node_idx].src)
			{
				this.pvimgs[node_idx].src=YAHOO.sea.fp.TodayImages[node_idx];
			}
			if(YAHOO.sea.fp._ff===1&&YAHOO.sea.fp._ffv==="2.0.0")
			{
				YUD.removeClass(c,'on');
				YUD.removeClass(c.id+'vpv','on');
				YUD.addClass(n_ctn,'on');
				YUD.addClass(node,'on');
			}
			else
			{
				this.animComplete=false;
				var an1=new YAHOO.util.Anim(c_ctn,{opacity:{from:1,to:0}},0.4,YAHOO.util.Easing.easeOut);
				var an2=new YAHOO.util.Anim(n_ctn,{opacity:{from:0,to:1}},0.5,YAHOO.util.Easing.easeOut);
				an2.onStart.subscribe(function()
				{
					YUD.setStyle(n_ctn,'opacity',0);
					YUD.addClass(n_ctn,'on');
				});
				var that=this;
				an1.onStart.subscribe(function()
				{
					YUD.removeClass(c,'on');
					YUD.addClass(node,'on');
				});
				an2.onComplete.subscribe(function()
				{
					YUD.removeClass(c.id+'vpv','on');
					that.animComplete=true;
				});
				an1.animate();
				an2.animate();
			}
		},rotate:function()
		{
			var that=this;
			var hasOneRotation=false;
			++this.curTab;
			if(this.curTab>=this.pvtabs.length)
			{
				this.curTab=0;hasOneRotation=true;
			}

			this.switchTab(this.pvtabs[this.curTab]);
			return hasOneRotation;
		},autoRotate:function()
		{
			if(this.autoRotateConf==false){return;}

			var that=this;
			that.autoRotatePaused=false;
			++this.curTab;
			if(this.curTab>=this.pvtabs.length){this.curTab=0;}
			this.switchTab(this.pvtabs[this.curTab]);
			this.timeout=setTimeout(function(){that.autoRotate();},10000);
	  }
  };    