$(document).ready(function () {
    $('#post_review').hide(1);
    
    $('#post_review_btn').click(function () {
	$('#post_review').toggle();
        return false;
    });

    $('#submit_review').click(function () {
	$('form[name=review]').submit();
    });

    $('.div_more_drop_down_top').click(function () {
	$('ul.more_categories').slideToggle('medium');
    });

    $('img.menu_class').click(function () {
	$('ul.the_menu').slideToggle('medium');
    });
    
    $('img.menu_class3').click(function () {
	$('#nearby_cities').slideToggle('medium');
    });

    $( "#tabs" ).tabs();

    //Default Action
    $(".tab_content1").hide(); //Hide all content
    $("ul.tabs1 li:first").addClass("active").show(); //Activate first tab
    $(".tab_content1:first").show(); //Show first tab content

    //On Click Event
    $("ul.tabs1 li").click(function() {
            $("ul.tabs1 li").removeClass("active"); //Remove any "active" class
            $(this).addClass("active"); //Add "active" class to selected tab
            $(".tab_content1").hide(); //Hide all tab content
            var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
            $(activeTab).fadeIn(); //Fade in the active content
            return false;
    });

    //Default Action
    $(".tab_content3").hide(); //Hide all content
    $("ul.tabs3 li:first").addClass("active").show(); //Activate first tab
    $(".tab_content3:first").show(); //Show first tab content

    //On Click Event
    $("ul.tabs3 li").click(function() {
            $("ul.tabs3 li").removeClass("active"); //Remove any "active" class
            $(this).addClass("active"); //Add "active" class to selected tab
            $(".tab_content3").hide(); //Hide all tab content
            var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
            $(activeTab).fadeIn(); //Fade in the active content
            return false;
    });

    $('#search_phrase').keypress(checkSubmit);
    $('#location').keypress(checkSubmit);
    $('#search_phrase').focus(function() {
        if($('#search_phrase').val() == "Business Name or Category") {
            $('#search_phrase').val("");
        }
    });
    $('#search_phrase').blur(function() {
        if($('#search_phrase').val() == "") {
            $('#search_phrase').val("Business Name or Category");
        }
    });
    $('#location').focus(function() {
        if($('#location').val() == "Las Vegas, NV, USA") {
            $('#location').val("");
        }
    });
    $('#location').blur(function() {
        if($('#location').val() == "") {
            $('#location').val("Las Vegas, NV, USA");
        }
    });
    var height = 0;
    $('#twitter_up').click(function () {
        if(height<0) {
            height = height+100;
            $(".twtr-tweets").animate({"top": height+"px"}, "slow");
        }
        return false;
    });
    $('#twitter_down').click(function () {
        if(-height>$('.twtr-tweets').outerHeight()-300) {
            height = 0;
        } else {
            height = height-100;
        }
        $('.twtr-tweets').animate({"top": height+"px"}, "slow");
        return false;
    });
});

function cat_list_in(id_image, id, url) {
        if(url == "") {
            url = "/lib/images/zlinked/logo_small.png";
        }
        for (i=1;i<=3;i++) {
            if(i == id) {
                $('#bullet_cat_'+id_image+'_'+id).addClass("div_bullet_orange_element");
                $('#bullet_cat_'+id_image+'_'+id).removeClass("div_bullet_green_element");
            } else {
                $('#bullet_cat_'+id_image+'_'+i).addClass("div_bullet_green_element");
                $('#bullet_cat_'+id_image+'_'+i).removeClass("div_bullet_orange_element");
            }
        }
        $('#img_cat_'+id_image).attr('src', url);
}

function checkSubmit(e) {
        var key_code = (window.event) ? e.keyCode : e.which;
        if (key_code == 13) {
            searchSubmit();
        }
}

function searchSubmit() {
        if($('#search_phrase').val() == "Link to What?") {
            $('#search_phrase').val("");
        }
        if($('#location').val() == "My Current Location (e.g. Orlando, FL)") {
            $('#location').val("");
        }
        setTimeout(function(){$('form[name=search]').submit();}, 500);
}

function SaveDefaultLocation() {
        var location = document.search.location.value;

        if (location.length <= 0) return;

        $.ajax({
           type: "POST",
           url: "/ajax/SetDefaultLocation/" + location,
           data: null,
           success: function(corrected_address){
                        var values = corrected_address.split('~');

                        document.search.location.value = values[0];
                        $('#setLocation').attr({href: "JavaScript:ResetDefaultLocation();"});
                        $("#setLocation").html(values[1]);
           }
         });

}

function ResetDefaultLocation() {
        $.ajax({
           type: "POST",
           url: "/ajax/ResetDefaultLocation",
           data: null,
           success: function(default_address){
                 var values = default_address.split('~');

                 document.search.location.value = values[0];
                 $('#setLocation').attr({href: "JavaScript:SaveDefaultLocation();"});
                 $("#setLocation").html(values[1]);
           }
         });
}

