var page; /*Let loose the jQuery!*/
$(function () {
   AudioPlayer.setup("/js/player.swf", {  
                width: 290,
                transparentpagebg: "yes"
            });  

    $('#news').live('change', function(event) {console.log(event); }); 

 $('#news').tumblr({
                url:        'http://alexwand.tumblr.com',
                loading:    '#loading'
            });
    $.fn.audio = function() {

        if(swfobject.hasFlashPlayerVersion("9.0.115"))
        {
            $(this).attr('id',$(this).html());
            AudioPlayer.embed($(this).attr('id'), {soundFile: $(this).attr('href'),titles:$(this).html()});  
        }
        else
        {
            $(this).html('<audio controls="controls"><source src="'+ $(this).attr("href") +'" type="audio/mp3" /></audio>');
        }
    };

$('a[title=audio]') 
    .livequery(function(event) { 
    $(this).audio();
    }); 

    
    $('a[title=facebookAlbum]').each(function(){
        $(this).replaceWith($('<p>').fbGenerator({
                id: $(this).attr('href'),
                type: "album"
        }));
    });

    $('.page').hide();
    $('.page[rel!=hidden]').each(function () {
        $(this).hide();
        var navigation = $('#Navigation');
        var id = $(this).attr('id');
   'fast'     //If the page is in the hash ie(we are either loading the page, or creating the page as we click)
        if (document.location.hash.slice(2) == id) {
            setTimeout(function () {
                page = id;
                $('#' + id).fadeIn('fast');
            }, 200);
        }
        //Create a button to the page
        var button = $("<a href='#" + id + "'>/" + id.replace(/-/gi, " ") + "   </a></br>");
        button.id = id;
        button.attr('rel', id);
        button.click(function () {
            changePage($(this).attr('rel'))
        });
        navigation.prepend(button);
    }); 
    $("a[title=link]").each(function(){
        var link=$(this);
        link.attr('rel', link.attr('href').toString().replace('#',''));
        link.click(function(event){
            changePage($(this).attr("rel"));
        });  
    });
    $('body').hide();
    setTimeout('$("body").fadeIn();', 100);

 $.history.init(function(hash){
        if(hash == "") {
            var pages=$(".page");
            var landing=pages[pages.length-1].id;
            changePage(landing)
        } else {
            changePage(hash);
        }
    });


    function changePage(pg){

        jQuery.history.load(pg);

            if (page == pg) {
                return true;
            }
            if (page == undefined){
                page = pg;
                $('#' + page).fadeIn('fast');
                return true;
            }
            last='#'+page
            page = pg;


            if ($.browser.msie && $.browser.version.substr(0,1)<9) {
                $(last).hide(function(){
                    $('#' + page).show();
                });    
            }else{
                $(last).fadeOut('fast',function(){
                    $('#' + page).fadeIn();
                });
                
            }


 
    }

});




