/** ********************************************** **/
var core = {
    baseURL : 'http://' + location.host,
    
    /** отслеживаем изменение якоря ссылки ***************************************/
    hashchange : function(e) {
        var hash = location.hash;
        if (hash[1] == '/') {
            $.ajax({
                url : core.baseURL + hash.replace(/^\#/,''),
                data : {ajax:1},
                beforeSend : function() {},
                success : core.content_load,
                complete : function() {}
            });
        }    
    },
    
    /** если якорь изменился то загружаем страницу ***************************************/
    content_load : function(html) {
        $('#content').html(html);
        
        core.ajax_success();
    },
    
    /*********************************************************/
    ajax_success : function() {
        // Launch TipTip tooltip
        $('.tiptip a.button, .tiptip button').tipTip();
        
        // Toggle the dropdown menu's
        $(".dropdown .button, .dropdown button").click(function () {
            $(this).parent().find('.dropdown-slider').slideToggle('fast');
            $(this).find('span.toggle').toggleClass('active');
            return false;
        });
        
        $('input.date').datepicker({dateFormat:"yy.mm.dd"});
    }
}

/** вешаем отслеживание события изменения якоря ********************************************** **/
// $(window).hashchange( core.hashchange );

/** вешаем отслеживание события изменения якоря ********************************************** **/
// $(window).load( core.hashchange );

/** отлавливаем клики по ссылкам чтобы отправлять аякс запросы ******************************* **/
/*$('a[hash]').live('click', function(){
    href = $(this).attr('hash');
    document.location.hash = '#/' + href;
    return false;
})*/

/** выполняем код после загрузки страницы ********************************************** **/
$(document).ready(function() {
    core.ajax_success();
    
    $('table tr:even').addClass('odd');
    
    // Hightlight menu
    $('.topmenu a[href="'+core.baseURL+location.pathname+'"]').addClass('current');
});

// Close open dropdown slider/s by clicking elsewhwere on page
$(document).bind('click', function (e) {
    if (e.target.id != $('.dropdown').attr('class')) {
        $('.dropdown-slider').slideUp();
        $('span.toggle').removeClass('active');
    }
});

$('.for_select[for]').live('click', function(){
    var id = $(this).attr('for');
    $('#'+id).show().focus().click();
    $('#'+id+'_label').hide();
    $(this).hide();
    
    $('#'+id).bind('blur', function(){
        $(this).hide();
        $('#'+id+'_label').show();
        $('.for_select[for='+id+']').show();
        $('#'+id+'_label').text( $('option[value='+$(this).val()+']', $(this)).text() );
        
        $(this).unbind('blur');
    })
    
})


