jQuery(window).load(function(){
    /*if (location.href.indexOf('#!') == -1) {
	current_url=location.href.replace(ttHome,"").replace(/^\//, "");
	if(current_url!=''){
	    location.href = ttHome+"/#!/"+current_url;
	    tt_ajax_call();
	}
    }*/
    });
jQuery(document).ready(function(){
    jQuery('#navigation a, .entry-title a, .pager-list a, a.comment-count, #wp-calendar a, .entry-tags a, .author a, .recentcomments a:last-child, .recent-news-item a, .footer-bottom-menu a, li.menu-item a, li.cat-item a, li.page_item a, .author-link a, .comment-replay-link a, .entry-content a.more-link, form#commentform .form-submit input#submit, #commentform p a, a.ajax-link, #archives li a, .entry-image-slide a, .hover-content a, .widget_recent_entries a').live('click',function(e){
        if(!jQuery(this).hasClass('anchorLink')&&!e.ctrlKey&&!e.shiftKey&&jQuery(this).attr('target')!='_blank'){
            if(jQuery(this).attr('href')!='#'){
                var link_url=jQuery(this).attr('href');
                if(!(link_url.indexOf('http') === 0)){
                    link_url='http://'+window.location.host+link_url;
                }
                if(!(link_url.indexOf(ttHome)===0)) return;
                var post_slug = link_url.replace(ttHome,"").replace(/^\//, "");
                if(post_slug!=''){
                    window.location=ttHome+'/#!/'+post_slug;
                // jQuery.address.crawlable(true).value(post_slug);
                }
		    
                else{
                    window.location.hash='!';
                }
            //tt_ajax_call();
            }
            return false;
        }
    });
    if(location.href.indexOf('#!')!=-1){
        tt_ajax_call();
    }else{
        showBody();
        theme_scripts();
        initScripts('body');
        tt_init_custom_scripts();
    }
    jQuery(window).hashchange( function(e) {
        tt_ajax_call();
    });

    jQuery.validator.setDefaults({
        submitHandler:function(frm){
            var data = jQuery(frm).serialize();
            jQuery('#container_main').html('<div class="tt_ajax_loading"></div>');
            showBody();
            jQuery.post(jQuery(frm).attr('action'), data, function(response) {
                //alert(response);
                $retVal=jQuery(response).find('#container_main').children();
                jQuery('#container_main').html($retVal);
                showBody();
                theme_scripts();
                initScripts('body');
                tt_init_custom_scripts();
            });
            return false;
        }
    });
    jQuery('#searchform').live('submit',function(){
        var post_slug = '?s='+jQuery(this).find('#s').val();

        jQuery.address.crawlable(true).value(post_slug);
        return false;
    });    
});

function tt_ajax_call(){
    jQuery('#container_main').html('<div class="tt_ajax_loading"></div>');
    showBody();
    jQuery.ajax({
        url:location.href.replace("#!/",""),
        success: function(responce){
            $retVal=jQuery(responce).find('#container_main').children();
            jQuery('#container_main').html($retVal);
            theme_scripts();
            initScripts('body');
            tt_init_custom_scripts();
            showBody();
            jQuery('body,html').animate({
                scrollTop:0
            },'slow');
        }
    });
}


