/**************
TabBox
*/

function TabBox(id)
{
	this.init(id);
}
TabBox.prototype = 
{
	_id :"",
	_selected:null,
	_curShowIndex:0,
	init:function(id)
	{
		
		this._id = id;
		var _this = this;
		var aTabs = $("#"+this._id+" .tabs .tab");

		aTabs.each(function(idl){
			
			if($(this).attr("class").indexOf("selected") >= 0)
			{
				_this._selected = this;
				_this._curShowIndex = idl;
				return;
			}	
		});
		var panels = $("#"+this._id+" .tabpanels .tabpanel");
		panels.each(function(idl){
			if(idl == _this._curShowIndex)
				$(panels[idl]).show();
			else
				$(panels[idl]).hide();
			
		});
		aTabs.click(function(){
			
			if(_this._selected)
				$(_this._selected).removeClass("selected");
			_this._selected = this;
			$(_this._selected).addClass("selected");		
			var curIndex = _this.getSelectedTabIndex(_this._selected);
			
			if(curIndex >= 0)
				_this.showTabpanel(curIndex);
		});
	},
	getSelectedTabIndex:function(aElement)
	{
		var aTabs = $("#"+this._id+" .tabs .tab");
		for(var i = 0;i < aTabs.length;i++)
			if(aElement == aTabs[i])
				return i;
		return -1;
	},
	showTabpanel:function(index)
	{
		var panels = $("#"+this._id+" .tabpanels .tabpanel");
		var _this = this;
		
		//$(panels[this._curShowIndex]).fadeIn("fast",function(){
		//	$(panels[index]).fadeOut("fast");
		//});
		$(panels[this._curShowIndex]).hide();
		$(panels[index]).fadeIn("fast");
		this._curShowIndex = index;
	}
}

function ScrollBox(id)
{
	this.init(id);
}
ScrollBox.prototype = 
{
	_id:"",
	hnd : null,
	maxHeight:0,
	scrollbox :null,
		
	init:function(id)
	{
		this._id = id;
		$("#"+this._id+" .tabpanels .inlineContent").css({width:444,height:105,overflow:"hidden"});
		$("#"+this._id+" .tabpanels .inlineContent .ScrollPeanl").css({width:890,display:"inline-block"});
		
		var aTabs = $("#"+this._id+" .over a");
		var _this = this;
		aTabs.each(function(idl){
			
			if($(this).attr("class").indexOf("last") >= 0)
			{
				_this._selected = this;
				_this._curShowIndex = idl;
				return;
			}	
		});
		aTabs.click(function(){
			
			if(_this._selected)
				$(_this._selected).removeClass("last");
			_this._selected = this;
			$(_this._selected).addClass("last");		
			var curIndex = _this.getSelectedTabIndex(_this._selected);
			
			if(curIndex >= 0){
				_this.showTabpanel(curIndex);
				_this.maxHeight =_this.scrollbox.height()-$("#"+_this._id+" .tabpanels .inlineContent").height();
			}
		});
		
		if(0 == _this._curShowIndex){
			$("#tabpanel0").show();
			$("#tabpanel1").hide();
		}
		else if(1 == _this._curShowIndex){
			$("#tabpanel0").hide();
			$("#tabpanel1").show();
		}
		this.scrollbox = $("#"+this._id+" .tabpanels .inlineContent .ScrollPeanl");
		this.maxHeight =this.scrollbox.height()-$("#"+this._id+" .tabpanels .inlineContent").height();
		this.seTscroll();
		
	},
	getSelectedTabIndex:function(aElement)
	{
		var aTabs = $("#"+this._id+" .over a");
		for(var i = 0;i < aTabs.length;i++)
			if(aElement == aTabs[i])
				return i;
		return -1;
	},
	showTabpanel:function(index)
	{
		var ScrollPeanl = $("#"+this._id+" .tabpanels .inlineContent .ScrollPeanl");
		ScrollPeanl.css("margin-top","0px");
		if(index == 0){
			$("#tabpanel0").show();
			$("#tabpanel1").hide();
		}
		else if(index == 1){
			$("#tabpanel0").hide();
			$("#tabpanel1").show();
		}
		this._curShowIndex = index;
	},
	seTscroll:function()
	{
		this.scrollbox.css("margin-top",0);
		this.hnd = setInterval(function(){
			_this.scroll();
		},3000);
		var _this = this;
		$("#"+this._id+" .tabpanels .inlineContent").hover(function(){
			clearInterval(_this.hnd);
		},function(){
			_this.hnd = setInterval(function(){
				_this.scroll();
			},3000);
		});
	},
	scroll:function()
	{
		
		var mTop = this.scrollbox.css("margin-top");
		mTop = parseInt(mTop);
		if((mTop+this.maxHeight) <= 0)
			this.scrollbox.css({marginTop:0});
		else
			this.scrollbox.animate({marginTop:(mTop-20)},800);
	}
}
function setHost(id)
{
	var host = $('<div style="background:url(images/icon_comm.gif) no-repeat left -94px;width:22px;height:22px;position:absolute"></div>').appendTo("body");
	var offset = $("#"+id).offset();
	host.css({top:(offset.top-22),left:(offset.left+20)});
}
function setNew(id)
{
	var host = $('<div style="background:url(images/icon_comm.gif) no-repeat left -122px;width:22px;height:20px;position:absolute"></div>').appendTo("body");
	var offset = $("#"+id).offset();
	host.css({top:(offset.top-10),left:(offset.left+10)});
} 
function setTypeHost()
{	
	var host = $('<div style="background:url(images/icon_comm.gif) no-repeat left -122px;width:22px;height:22px;position:absolute;left:196px;top:730px;"></div>').appendTo("body");
	
}
function   myAddPanel(title,url,desc)  
{  
	if   ((typeof   window.sidebar   ==   'object')   &&   (typeof   window.sidebar.addPanel   ==   'function'))
	{  
		window.sidebar.addPanel(title,url,desc);  
	}  
	else//IE  
	{  
		window.external.AddFavorite(url,title);  
	}  
}
function ysleft(){
    var marginleft=$("#ysimageul");
    var leftvalue=parseFloat(marginleft.css("margin-left"));
    if(leftvalue==-628){
        return;
    }
    leftvalue-=157;
    marginleft.animate({"margin-left":leftvalue+"px"},"slow",function(){
			if(leftvalue==-628){
                            $("#ysleft").addClass("gray_1");}
		});
    if($("#ysright").hasClass("gray_1")){
        $("#ysright").removeClass("gray_1");
    }
}
function ysright(){
    var marginleft=$("#ysimageul");
    var leftvalue=parseFloat(marginleft.css("margin-left"));
    if(leftvalue==0){
        return;
    }
    leftvalue+=157;
    marginleft.animate({"margin-left":leftvalue+"px"},"slow",function(){
			if(leftvalue==0){
                            $("#ysright").addClass("gray_1");
                        }
		});
    if($("#ysleft").hasClass("gray_1")){
        $("#ysleft").removeClass("gray_1");
    }

}
