// JavaScript Document

//加入收藏夹，支持ie和ff
function addBookmark(title) {
	 var url=parent.location.href;
	 if (window.sidebar) { 
			window.sidebar.addPanel(title, url,""); 
	 } else if( document.all ) {
	 window.external.AddFavorite( url, title);
	 } else if( window.opera && window.print ) {
	 return true;
	 }
}


/*
站内搜索框所需的js文件，需要搭配jquery使用

*/


jQuery.fn.KindSelectBox = jQuery.fn.sBox = function(options){
	options = $.extend({
		animated : false
	},options);
	var _self = this;
	var _parent = _self.parent();
	var wrapHtml = '<div class="KindSelectBox"></div>';
	var $wrapHtml = $(wrapHtml).appendTo(_parent);
	var selectedOptionValue = _self.find("option:selected").attr("value");
	var selectedOptionTxt = _self.find("option:selected").text();
	var name = _self.attr("name");
	var id = _self.attr("id");
	var inputHtml = '<input type="hidden" value="'+selectedOptionValue+'" name="'+name+'" id="'+id+'"/>';
	$(inputHtml).appendTo($wrapHtml);
	var aHtml = '<a class="KindSelectValue" href="#">'+selectedOptionTxt+'</a>';

	$(aHtml).appendTo($wrapHtml);
	var ulHtml = '<ul class="KindSelectBoxOptions"></ul>';
	var $ulHtml = $(ulHtml).appendTo($wrapHtml);
	var liHtml = "";
	_self.find("option").each(function(){
		if($(this).attr("selected")){
			liHtml += '<li class="KindSelectBoxItem"><a href="#" class="selected" rel="'+$(this).attr("value")+'">'+$(this).text()+'</a></li>';
		}else{
			liHtml += '<li class="KindSelectBoxItem"><a href="#" rel="'+$(this).attr("value")+'">'+$(this).text()+'</a></li>';
		}
	});
	$(liHtml).appendTo($ulHtml);

	$(".KindSelectValue",$wrapHtml).click(function(){
		$(this).blur();	
		if( $(".KindSelectBoxOptions",$wrapHtml).is(":hidden") ){
			if(options.animated){
				$(".KindSelectBoxOptions").slideUp("fast");
				$(".KindSelectBoxOptions",$wrapHtml).slideDown("fast");
			}else{
				$(".KindSelectBoxOptions").hide();
				$(".KindSelectBoxOptions",$wrapHtml).show();
			}
		}
		return false;
	});
	$(".KindSelectBoxItem a",$wrapHtml).click(function(){
		$(this).blur();
		var value = $(this).attr("rel");
		var txt = $(this).text();
		$("#"+id).val(value);
		$(".KindSelectValue",$wrapHtml).text(txt);
		$(".KindSelectBoxItem a",$wrapHtml).removeClass("selected");
		$(this).addClass("selected");
		if(options.animated){
			$(".KindSelectBoxOptions",$wrapHtml).slideUp("fast");
		}else{
			$(".KindSelectBoxOptions",$wrapHtml).hide();
		}
		return false;
	});
	$(document).click(function(event){
		if( $(event.target).attr("class") != "KindSelectBox" ){
			if(options.animated){
			$(".KindSelectBoxOptions",$wrapHtml).slideUp("fast");
			}else{
				$(".KindSelectBoxOptions",$wrapHtml).hide();
			}
		}
	});
	_self.remove();
	return _self;
}


$(document).ready(

	
	function(){
		
		$("#searchkind").sBox({animated:true});


		var DefaultSearchValue = '可输入店名、路段、菜系等关键词';
		var DefaultSearchValue_Short = '店名、地段或菜系';

		
		$("#query").val(DefaultSearchValue_Short);
		$("#query").click(
			function(){
				if($(this).val()==DefaultSearchValue_Short) $(this).val("");;
			}
		)
		$("#query").blur(
			function(){
				if($(this).val()=="") $(this).val(DefaultSearchValue_Short);
			}
		)
		
		
		$("#lv2_head1000-query").val(DefaultSearchValue);
		$("#lv2_head1000-query").click(
			function(){
				if($(this).val()==DefaultSearchValue) $(this).val("");;
			}
		)
		$("#lv2_head1000-query").blur(
			function(){
				if($(this).val()=="") $(this).val(DefaultSearchValue);
			}
		)
		
		
		$("#bottom_search-query").val(DefaultSearchValue);
		$("#bottom_search-query").click(
			function(){
				if($(this).val()==DefaultSearchValue) $(this).val("");;
			}
		)
		$("#bottom_search-query").blur(
			function(){
				if($(this).val()=="") $(this).val(DefaultSearchValue);
			}
		)
	
	}
	

	
	
); 

