// 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'));
			});
	});
});


//------------切换搜索引擎------------
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 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;
}
