$(document).ready(function(){
    buttonHover("#header ul li","hover");
    buttonHover(".s_button","s_button_hover");
    buttonHover(".b_button","b_button_hover");
    buttonHover(".r_button","b_button_hover");
    buttonHover(".normalButton","normalButton_hover");
    buttonHover(".pop_hot_city li","hover");
    $("table tr:even td").addClass("split");
    hotCity();
    hoverPopLayer(".everyday_price",".pop_room_rate",-190,18);
    hoverPopLayer(".forget_password",".pop_forget_password",0,18);
    hoverPopLayer(".currency",".pop_currency",0,15);
});

function buttonHover(id,className){
    $(id).each(function(){
        $(this).hover(function() {
                $(this).addClass(className);
            },
            function() {
                $(this).removeClass(className);
            });
    });
}

function hotCity(){
    $("#hot_city").each(function(){
        $(this).click(function(){
            if($(".pop_hot_city").css("display") == "none"){
                offsetValue(this,".pop_hot_city",0,22);
                $(".pop_hot_city").show();
                $(".pop_hot_city li").each(function(){
                    $(this).mousedown(function(){
                        var currentValue = $(this).text();
                        $("#hot_city").val(currentValue);
                        $(".pop_hot_city").hide();
                    });
                });
            }
            else{
                $(".pop_hot_city").hide();
            }
        });
		$(document).mousedown(function(){
			 $(".pop_hot_city").hide();
		});
    });
}

function hoverPopLayer(element,popClassName,leftNumber,topNumber){
    $(element).hover(
        function(){
            offsetValue(this,popClassName,leftNumber,topNumber);
            $(popClassName).show();
        },
        function(){
            $(popClassName).hide();
        }
    );
}

function offsetValue(object,popClassName,leftNumber,topNumber){
    var offset = $(object).offset();
    var offsetLeft = offset.left + leftNumber +"px";;
    var offsetTop = offset.top + topNumber +"px";
    $(popClassName).css({"left":offsetLeft,"top":offsetTop});
}