$(document).ready(function(){ 
    startFacebook();
    makeLinks();
    $('.page').css('display','none');
    $('#splash').animate({opacity:0}, 1800, function() {$('#splash').remove();});
    $('div').corner();
    $('a').corner();
    setTimeout(function () {$('.club').each(function (i) {
	var $el = $(this);
	setTimeout(function () {
		$el.animate({opacity:0.7}, 100);
	}, 100 * (i));
    });}, 1800);
    setTimeout(function () {$('#sidebar .comicCell').each(function (i) {
	var $el = $(this);
	setTimeout(function () {
		$el.animate({opacity:0.7,backgroundColor:"#881111"}, 150);
		$el.animate({backgroundColor:"#000000"}, 550);
	}, 600 * (i));
	$('#logo').toggle(true);
    });}, 1800);
    setTimeout(function () {$('#content > .comicCell').each(function (i) {
	var $el = $(this);
	setTimeout(function () {
		$el.animate({opacity:0.7}, 700);
	}, 600 * (i));
    });}, 2400);
});



function startFacebook() {
    //window.fbAsyncInit = function() {
        FB.init({
              appId  : '139055419457151',
              cookie : true, // enable cookies to allow the server to access the session
              xfbml  : true  // parse XFBML
        });
    //};
}

function makeLinks() {
    $('a[href=#bookings]').click(function() {
	cleanPage();
	setTimeout(function () {
	    $('a[href=#bookings] hr').css('border-color','firebrick');
	    $('#loading').css('display','none');
	    $('._bookings').each(function (i) {
	    var $el = $(this);
	    setTimeout(function () {
		    $el.fadeIn('slow');
	    }, 600 * (i));
	});}, ($('.page').length*350));
    });
    $('a[href=#mix]').click(function() {
	cleanPage();
	setTimeout(function () {
	    $('a[href=#mix] hr').css('border-color','firebrick');
	    $('#loading').css('display','none');
            $('.mixloader').each(function(){
                $(this).html('<iframe src="Zipper.php" class="mixloader" scrolling="no" frameborder="0" /><br/><br/>');
            });
	    $('._mix').each(function (i) {
	    var $el = $(this);
	    setTimeout(function () {
		    $el.fadeIn('slow');
	    }, 600 * (i));
	});}, ($('.page').length*350));
    });
    $('a[href=http://www.youtube.com/5ftheroes]').click(function() {
	cleanPage();
	setTimeout(function () {
	    $('a[href=http://www.youtube.com/5ftheroes] hr').css('border-color','firebrick');
	    $('#loading').css('display','none');
	}, ($('.page').length*350));
    });
    $('a[href=#bio]').click(function() {
	cleanPage();
	setTimeout(function () {
	    $('a[href=#bio] hr').css('border-color','firebrick');
	    $('#loading').css('display','none');
	    $('._bio').each(function (i) {
	    var $el = $(this);
	    setTimeout(function () {
		    $el.fadeIn('slow');
	    }, 600 * (i));
	});}, ($('.page').length*350));
    });
    $('a[href=#gallery]').click(function() {
	cleanPage();
	setTimeout(function () {
	    $('a[href=#gallery] hr').css('border-color','firebrick');
	    $('#loading').css('display','none');
            $('.galleryloader').each(function(){
                $(this).html('<iframe src="Gallery.php" class="galleryloader" scrolling="no" frameborder="0" />');
            });
	    $('._gallery').each(function (i) {
	    var $el = $(this);
	    setTimeout(function () {
		    $el.fadeIn('slow');
	    }, 600 * (i));
	});}, ($('.page').length*350));
    });
    $('a[href=#uni]').click(function() {
	cleanPage();
	setTimeout(function () {
	    $('a[href=#uni] hr').css('border-color','firebrick');
	    $('#loading').css('display','none');
	    $('._uni').each(function (i) {
	    var $el = $(this);
	    setTimeout(function () {
		    $el.fadeIn('slow');
	    }, 600 * (i));
	});}, ($('.page').length*350));
    });
    $('a[href=images/uni_barcode.png]').click(function() {
	cleanPage();
	setTimeout(function () {
	    $('a[href=#bookings] hr').css('border-color','firebrick');
	    $('#loading').css('display','none');
	    $('._uni_barcode').each(function (i) {
	    var $el = $(this);
	    setTimeout(function () {
		    $el.fadeIn('slow');
	    }, 600 * (i));
	});}, ($('.page').length*350));
    });
    $('a[href=images/youssef_barcode.png]').click(function() {
	cleanPage();
	setTimeout(function () {
	    $('a[href=#bookings] hr').css('border-color','firebrick');
	    $('#loading').css('display','none');
	    $('._youssef_barcode').each(function (i) {
	    var $el = $(this);
	    setTimeout(function () {
		    $el.fadeIn('slow');
	    }, 600 * (i));
	});}, ($('.page').length*350));
    });
    $('.barcode').attr('href', '#');
    $('.barcode').removeAttr('target');
}

function cleanPage() {
    $('#loading').css('display','inline-block');
    $('hr').css('border-color','white');
    $($('.page').get().reverse()).each(function (i) {
	var $el = $(this);
	setTimeout(function () {
		$el.fadeOut(300);
	}, 300 * (i));
    });
}
