// JavaScript Document

var skin = 'blue';
$(function(){
	//----------皮肤切换------------
	
	if(GetCookie('skin'))
	{
		skin = GetCookie('skin')
	}
	$('html').attr('class',skin);
	$.each( $('#skin-box a'),
		function(){
			if(GetCookie('skin')==$(this).attr('name'))
			{
				$(this).attr('class',GetCookie('skin')+'-current');
			}
			$(this).bind('click',function(){
				$.each( $('#skin-box a'),function(){$(this).attr('class',$(this).attr('name'))});
				$('html').attr('class',$(this).attr('name'));
				$(this).attr('class',$(this).attr('name')+'-current');
				SetCookie('skin',$(this).attr('name'),999999);
			});
	});
	//----------搜索切换------------
	$.each( $('#header-search-menu a'),
		function(){
			$(this).bind('click',function(){
				$.each( $('#header-search-menu a'),function(){$(this).attr('class','')});
				$('#video').attr('class','last');
				$(this).attr('class','current');
				$("#header-search-icon").attr('class','');
				$("#header-search-icon").addClass('search_icon');
				$("#header-search-icon").addClass('search_'+$(this).attr('id'));
				ChangeSearchTab($(this).attr('name'));
			});
	});
	//----------标签切换------------
	$.each( $('#tab-header a'),
		function(){
			$(this).bind('click',function(){
				$.each( $('#tab-header a'),function(){$(this).attr('class','')});
				$(this).attr('class','current');
				$.each( $('#tab-content div'),function(){$(this).css('display','none')});
				$("#tab-"+$(this).attr('name')).css('display','block');
			});
	});	
});


//------------切换搜索引擎------------
function ChangeSearchTab(szType)
{
	switch (szType)
	{
	case 'google':
		$('#SearchForm').attr('action','http://www.google.com.hk/search');
		$('#SearchKeywords').attr('name','q');
		break;

	case 'baidu':
		$('#SearchForm').attr('action','http://www.baidu.com/s');
		$('#SearchKeywords').attr('name','word');
		break;

	case 'mp3':
		$('#cts').attr('value','134217728');
		$('#SearchForm').attr('action','http://mp3.baidu.com/m');
		$('#SearchKeywords').attr('name','word');
		break;

	case 'images':
		$('#cts').attr('value','201326592');
		$('#SearchForm').attr('action','http://image.baidu.com/i');
		$('#SearchKeywords').attr('name','word');
		break;

	case 'zhidao':
		$('#tns').attr('value','ikaslist');
		$('#cts').attr('value','17');
		$('#SearchForm').attr('action','http://zhidao.baidu.com/q');
		$('#SearchKeywords').attr('name','word');
		break;

	case 'news':
		$('#SearchForm').attr('action','http://news.baidu.com/ns');
		$('#tns').attr('value','news');
		$('#SearchKeywords').attr('name','word');
		break;

	case 'video':
		$('#cts').attr('value','301989888');
		$('#SearchForm').attr('action','http://video.baidu.com/v');
		$('#SearchKeywords').attr('name','word');
		break;
	}
}
function ShowDate()
{
	var day = "";
	var year = "";
	var month = "";
	var myweekday = "";
	mydate = new Date();
	myweekday = mydate.getDay();
	mymonth = mydate.getMonth() + 1;
	myday = mydate.getDate();
	myyear = mydate.getYear();
	year = (myyear>200) ? myyear : 1900 + myyear;
	if(myweekday == 0) 
		weekday="星期日";
	else if(myweekday == 1)
		weekday="星期一";
	else if(myweekday == 2)
		weekday="星期二";
	else if(myweekday == 3)
		weekday="星期三";
	else if(myweekday == 4)
		weekday="星期四";
	else if(myweekday == 5)
		weekday="星期五";
	else if(myweekday == 6)
		weekday="星期六";
	$('#data_y_m').html(year+"."+mymonth);
	$('#data_d').html(myday);
	$('#data_w').html(weekday);
	return false;
}


function SetCookie(name, value, hours)
{
	var expire = "";
	if(hours != null)
	{
		expire = new Date((new Date()).getTime() + hours * 3600000);
		expire = "; expires=" + expire.toGMTString();
	}
		document.cookie = name + "=" + escape(value) + expire;
}

function GetCookie(name)
{
	var cookieValue = "";
	var search = name + "=";
	if(document.cookie.length > 0)
	{ 
		offset = document.cookie.indexOf(search);
		if (offset != -1)
		{ 
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
			cookieValue = unescape(document.cookie.substring(offset, end))
		}
	}
	return cookieValue;
}

