$(function(){

    if($(".tooltip_province").length){
        $(".tooltip_province").tooltip({relative: true, effect: 'slide', slideOutSpeed: 500, slideInSpeed: 500})
    }

    oMasterController.set_navigation('home');

    $("#province").change(function () {
        $("#province option:selected").each(function () {            
            oMasterController.towns_for($(this).val())
        });
    });

    $("#btn_newsletter").click(function () {
        if($('#newsletter_email').val() != 'Subscribe to our Newsleter, now!'){
            oMasterController.subscribe_to_newsletter($('#newsletter_email').val());
            oMasterView.subscribe_successsfull();
        }
    });

    $('#newsletter_email').click(function(){
        $('#newsletter_email').val('');
    });

    $(".btn_search:visible").click(function () {

        if($('#selection').val() == 'accommodation'){
            window.location = "/accommodation/"+$("#province").val()+"/"+$("#towns").val()+"/"+$("#accomodation_categories").val()+"/";
        }
        if($('#selection').val() == 'tours_safaris'){
            window.location = "/tours/"+$("#province").val()+"/"+$("#tour_categories").val()+"/";
        }
        if($('#selection').val() == 'lesuire_guide'){
            window.location = "/leisure/"+$("#province").val()+"/"+$("#towns").val()+"/"+$("#attraction_categories").val()+"/";
        }
    });

    $('#nav_accomodation').click(function(){

        $('#selection').val('accommodation');
        $('#nav_accomodation span label').html('<b>Accommodation &raquo;</b>')
        $('#nav_tours_safaris span label').html('Tours &amp; Guides')
        $('#nav_lesuire_guide span label').html('Leisure')

        $('#nav_provinces').show();
        $('#nav_regions').hide();
        $('#nav_towns').show();
        $('#nav_empty').hide();

        $('#nav_accomodation_categories').show();
        $('#nav_tour_categories').hide();
        $('#nav_attraction_categories').hide();

        $('#note_accomodation').show();
        $('#note_tours_safaris').hide();
        $('#note_lesuire_guide').hide();
    });

    $('#nav_tours_safaris').click(function(){

        $('#selection').val('tours_safaris');
        $('#nav_accomodation span label').html('Accommodation')
        $('#nav_tours_safaris span label').html('<b>Tours &amp; Guides &raquo;</b>')
        $('#nav_lesuire_guide span label').html('Leisure')

        $('#nav_provinces').show();
        $('#nav_regions').hide();
        $('#nav_towns').hide();
        $('#nav_empty').show();

        $('#nav_accomodation_categories').hide();
        $('#nav_tour_categories').show();
        $('#nav_attraction_categories').hide();

        $('#note_accomodation').hide();
        $('#note_tours_safaris').show();
        $('#note_lesuire_guide').hide();

    });

    $('#nav_lesuire_guide').click(function(){

        $('#selection').val('lesuire_guide');
        $('#nav_accomodation span label').html('Accommodation')
        $('#nav_tours_safaris span label').html('Tours &amp; Guides')
        $('#nav_lesuire_guide span label').html('<b>Leisure</b>')

        $('#nav_provinces').show();
        $('#nav_regions').hide();
        $('#nav_towns').show();
        $('#nav_empty').hide();

        $('#nav_accomodation_categories').hide();
        $('#nav_tour_categories').hide();
        $('#nav_attraction_categories').show();

        $('#note_accomodation').hide();
        $('#note_tours_safaris').hide();
        $('#note_lesuire_guide').show();
    });                     

});
