//sidebar navigation functions

$(window).load(function(){
    
    var url = window.location.href;
    var d_url = "http://www.hamdirestaurants.com/index.php";
    //d_url = d_url.replace("http://", "");
    //var url_explode = d_url.split("/");
    //var servername = url_explode[0] + "/" + url_explode[1];
    //servername = "http://" + servername + "/";
    var servername = d_url;

    var menu_count = 0;
    var maps_count = 0;
    var index_count= 0;
    
    
    $(".sidebar_a").click(function(){ return false;})
    //this group of functions controls the appearance of the active menu item
    var tabs = $("li.menu_list a.sidebar_a");
    tabs.bind("click", function(){
        tabs.removeClass("active");
        $(this).addClass("active");
        
        var tab_id = $(this).attr("id");
        var s_tab_id = tab_id.toLowerCase();
        if(tab_id == "Home"){
            document.title = "Welcome to Hamdi Restaurants";
            //window.location.href = servername + "#";
            //return false;
        }
        else {
          document.title = "Hamdi Restaurants :: " + tab_id;
          //window.location.href = servername + "#" + s_tab_id;
          //return false;
        };
        
        var ref = $(this).attr("href");
        
        
        $("#main_content").load(ref + " #content", function(){
            $(this).show("slide", {direction : "left"}, 500);
        });
        
        if(ref == "services.php"){
            /*
           $("#right_side_box").load(ref + " #rsb", function(){
                $.getScript("./js/slider.js");
                $(this).show("slide", {direction : "right"}, 500);
            });
            */
            window.location = "services.php";
           
        }
        if(ref == "index.php"){
           $("#right_side_box").load(ref + " #rsb", function(){
                $.getScript("./js/index.js");
                $(this).show("slide", {direction : "right"}, 500);
            });
        }
        if(ref == "menu.php" && browser != "Explorer"){
           $("#right_side_box").load(ref + " #rsb", function(){
                $.getScript("./js/menu.js");
                $(this).show("slide", {direction : "right"}, 500);
            });
        }
        if(ref == "menu.php" && browser == "Explorer"){
           $("#right_side_box").load(ref + " #rsb", function(){
                $.getScript("./js/menu_ie.js");
                $(this).show();
            });
        }
        if(ref == "locations.php"){
           $("#right_side_box").load(ref + " #rsb", function(){
                $.getScript("./js/maps.js");
                $(this).show("slide", {direction : "right"}, 500);
            });
        }
        if(ref == "contact.php"){
           $("#right_side_box").load(ref + " #rsb", function(){
                $(this).show("slide", {direction : "right"}, 500);
            });
        }
        
        return false;
        
    });
    
    
    /* Footer Controls
    #
    #
    #
    */
    
                //this group of functions controls the behaviour of the footer links
                $("#footer_about").bind("click", function(){
                    $("#main_content").load("index.php #content", function(){
                        $(this).show("slide", {direction : "left"}, 500);
                    });
                    
                    $("#right_side_box").load("index.php #rsb", function(){
                        if(index_count < 1){
                           $.getScript("./js/index.js");
                           index_count += 1;
                        }
                        $.getScript("./js/index.js");
                        $(this).show("slide", {direction : "right"}, 500);
                    });
                    
                    $(".sidebar_a").removeClass("active");
                    $(".home").addClass("active");
                    //window.location = "index.php";
                });
                
                $("#footer_hours").bind("click", function(){
                    /*
                    $("#main_content").load("services.php #content", function(){
                        $(this).show("slide", {direction : "left"}, 500);
                    });
                    
                    $("#right_side_box").load("services.php #rsb", function(){
                        if(slider_count < 1){
                           $.getScript("./js/slider.js");
                           slider_count += 1;
                        }
                        $.getScript("./js/slider.js");
                        $(this).show("slide", {direction : "right"}, 500);
                    });
                    
                    
                    $(".sidebar_a").removeClass("active");
                    $(".services").addClass("active");
                    */
                    window.location = "services.php";
                });
                
                $("#footer_locations").bind("click", function(){
                    $("#main_content").load("locations.php #content", function(){
                        $(this).show("slide", {direction : "left"}, 500);
                    });
                    
                    $("#right_side_box").load("locations.php #rsb", function(){
                        if(maps_count < 1){
                            $.getScript("./js/maps.js");
                            maps_count += 1;
                        }
                        $.getScript("./js/maps.js");
                        $(this).show("slide", {direction : "right"}, 500);
                    });
                    
                    $(".sidebar_a").removeClass("active");
                    $(".locations").addClass("active");
                    //window.location = "locations.php";
                });

});
    
