$("document").ready(function(){
	var pathname = location.pathname;
	reg = /^\/s\//;
	reg2 = /^\/rank\//;
	if(reg.test(pathname) || reg2.test(pathname)){
		imagePath = '/images';
	}else{
		imagePath = 'images';
	}
	$("#lbgoo").attr('checked',true);
	$("#radio_val").val('lbgoo');
	$("#tab_val").val('product');
	init_tab();
	init_radio();
	init_search();
});

function init_tab(){
	$("#hd_r ul").find("li").unbind("click").click(function(){
		$(".sle").removeClass("sle");
		$(this).addClass("sle");
		var tab_id = $(this).attr("id");
		var keys_link = tab_id.replace("tab_","keys_link_");
		$("#ser_link").find("div").each(function(){
			if($(this).attr("id")==keys_link){
				$(this).show();
			}else{
				$(this).hide();
			}
		});
		var tab = tab_id.replace("tab_","");
		$("#tab_val").val(tab);
	});
}

function init_radio(){
	$(":radio").click(function(){
		var id = $(this).attr('id');
		$("#show_search_img").attr("src",imagePath+'/nav_'+id+'.gif');
		$("#radio_val").val(id);
		if(id == 'lbgoo'){
			$("#hd_r").find('li').removeClass('sle');
			$("#tab_product").addClass("sle");
			$("#tab_val").val('product');
			$("#ser_link").find("div").hide();
			$("#keys_link_product").show();
			$("#tab_product").show();
			$("#tab_industry").show();
			$("#tab_model").show();
			$("#tab_website").hide();
			$("#tab_news").hide();
			$("#tab_picture").hide();
			$("#tab_screen").hide();
		}else if(id == 'baidu' || id == 'google'){
			if($("#tab_model").attr('class') == 'sle' || $("#tab_product").attr('class') == 'sle'
				|| $("#tab_industry").attr('class') == 'sle'){
				$("#hd_r").find('li').removeClass('sle');
				$("#tab_website").addClass("sle");
				$("#tab_val").val('website');
				$("#ser_link").find("div").hide();
				$("#keys_link_website").show();
			}
			$("#tab_product").hide();
			$("#tab_industry").hide();
			$("#tab_model").hide();
			$("#tab_website").show();
			$("#tab_news").show();
			$("#tab_picture").show();
			$("#tab_screen").show();
		}
	});
}

function init_search(){
	var url = "";
	$("#bd_btn").unbind("click").click(function(){
		jumptourl();
	});
}

function jumptourl(){
	var key = $("#bd_text").val();
	var radio = $("#radio_val").val();
	var tab = $("#tab_val").val();
	if(radio == "baidu"){
		url = "http://www.baidu.com";
		if(tab == "website"){
			url = "http://www.baidu.com";
			if(key){
				url = url+"/s?wd="+encodeURIComponent(key)+"&ie=utf-8";
			}
		}else if(tab=="picture"){
			url = "http://image.baidu.com";
			if(key){
				url = url+"/i?word="+encodeURIComponent(key)+"&ie=utf-8";
			}
		}else if(tab=="screen"){
			url = "http://video.baidu.com";
			if(key){
				url = url+"/v?word="+encodeURIComponent(key)+"&ie=utf-8";
			}
		}else if(tab=="news"){
			url = "http://news.baidu.com";
			if(key){
				url = url+"/ns?word="+encodeURIComponent(key)+"&ie=utf-8";
			}
		}
	}else if(radio == "google"){
		url = "http://www.google.com.hk";
		if(tab == "industrial" || tab == "website"){
			url = "http://www.google.com.hk";
			if(key){
				url = url+"/search?q="+encodeURIComponent(key);
			}
		}else if(tab=="picture"){
			url = "http://images.google.com.hk/imgcat";
			if(key){
				url = url+"/search?q="+encodeURIComponent(key);
			}
		}else if(tab=="screen"){
			url = "http://www.google.com.hk";
			if(key){
				url = url+"/search?q="+encodeURIComponent(key)+"&tbs=vid:1";
			}
		}else if(tab=="news"){
			url = "http://news.google.com.hk";
			if(key){
				url = url+"/news/search?q="+encodeURIComponent(key);
			}
		}
	}else{
		url = "http://cn.lbgoo.com/index.php?main_page=advanced_search_result&search_in_description=1&keyword="+encodeURIComponent(key);
	}
	if(url){
		window.open(url);
	}
}
