$(document).ready(function() {

// This loads data to #content div

    var contentWrapID = '___content-wrapper';
    
    $('#content').wrap('<div id="' + contentWrapID + '"></div>');
    
    function showNewContent() { 
        $("#" + contentWrapID).slideDown();
        $('.load').fadeOut();   
    }
    
    function pageload1(hash) {  
        if(hash) {
            $("#" + contentWrapID).load(hash + " #content",'',function(){
                if($('img:last',this).get(0)) {
                    $('img:last',this).load(function(){
                        showNewContent();
                    });
                } else {
                    showNewContent();
                }

            });
        } else {
            $("#" + contentWrapID).load("index.html #content");
        }
    }

    
    $('#topnav li a').click(function(){        
        var hash = $(this).attr('href');
        hash = hash.replace(/^.*#/, '');
        $("#" + contentWrapID).slideUp(300,function(){
            $.historyLoad(hash);
        });
        if(!$('.load').get(0)) {
            $('#container').append('<span class="load">LOADING...</span>');
        }
        $('.load').fadeIn('fast');
  $('#topnav li a').removeClass('current'); 
  $(this).addClass('current');
  $('#search').val("Google...");
        return false;
  
 
    
    });





//This loads data to #content2 div


    var contentWrapID2 = '___content-wrapper2';
    
    $('#content2').wrap('<div id="' + contentWrapID2 + '"></div>');
    
    function showNewContent2() {
		FB.XFBML.Host.parseDomElement($("#content2")[0]);
		FB.XFBML.Host.get_areElementsReady().waitUntilReady(function() {								 
});
        $("#" + contentWrapID2).slideDown();
        $('.load').fadeOut();		
    }
    
    function pageload2(hash2) {
        if(hash2) {
            $("#" + contentWrapID2).load(hash2 + " #content2",'',function(){
			$('.pic a').lightBox({		
		imageLoading: 'lightbox/images/loading.gif',
		imageBtnClose: 'lightbox/images/close.gif',
		imageBtnPrev: 'lightbox/images/prev.gif',
		imageBtnNext: 'lightbox/images/next.gif'

	});
			Shadowbox.setup();
																	  
                if($('img:last',this).get(0)) {
                    $('img:last',this).load(function(){
					
                        showNewContent2();
						
                    });
                } else {
                    showNewContent2();
                }

            });
        } else {
            $("#" + contentWrapID2).load("index.html #content2");
        }
    }

    function pageload(hash) {
  if (hash == "index.html")  {pageload1(hash); return;}
  if (hash == "featured.html")  {pageload1(hash); return;}
  if (hash == "contact.html") {pageload1(hash); return;}
      pageload2(hash);
      
}


    $.historyInit(pageload);
    
    $('#vert-navbar li a, .live-streambtn, .fanboxbtn, #paulmblog-btn, .privacy-policy').click(function(){
        var hash2 = $(this).attr('href');
        hash2 = hash2.replace(/^.*#/, '');
        $("#" + contentWrapID2).slideUp(300,function(){
            $.historyLoad(hash2);
        });
        if(!$('.load').get(0)) {
            $('#container').append('<span class="load" >LOADING...</span>');
        }
        $('.load').fadeIn('normal');
  $('#vert-navbar li a').removeClass('current'); 
  $(this).addClass('current');
  $('#search').val("Google...");
        return false;
  
 
    
    });

});

