var shoobieTimer;
var animation = 1
function shoobieAnim(){
    var randomDelay = parseInt(Math.random() * 2000) + 2000;
    if (animation == 1) {
        $('.shoobie').sprite({
            fps: 12,
            no_of_frames: 4,
            play_frames: 4
        });
    }else if (animation == 2) {
        $('.lollie').sprite({
            fps: 12,
            no_of_frames: 4,
            play_frames: 4
        });
    }else if (animation == 3) {
        $('.rockie').sprite({
            fps: 12,
            no_of_frames: 4,
            play_frames: 4
        });
    }else if (animation == 4) {
        $('.shellie').sprite({
            fps: 12,
            no_of_frames: 4,
            play_frames: 4
        });
    }
     animation = parseInt(Math.random() * 4) + 1;
shoobieTimer = setTimeout("shoobieAnim()", randomDelay);
//    console.log(randomDelay);
}

var topContent = "";

$(document).ready(function(){

// Setup of Carousel
$("#carousel").carouFredSel({
    items				: 1,
    direction			: "left",
    scroll : {
        items			: 1,
        effect			: "easeOutBounce",
        duration		: 1000,
        pauseOnHover	: false
    },
    pagination          : "#carousel_pag"
});

//    var currentTopContent = $('#top_content > div').is(':visible');
//    $('.btn_buynow').click(function(){
//        alert(currentTopContent);
//    });

// Toggle between Carousel and Sizzler
$('.btn_sizzler').click(function(){
    if (topContent != "") {
        $(topContent).fadeOut();
    }
    $('#image_carousel').fadeOut();
    $('#video_intro').fadeOut();
    $('#video_sizzler').fadeIn();
	$('.btn_sizzler').fadeOut();
	$('.btn_videointro').fadeIn();
});
$('.btn_videointro').click(function(){
    if (topContent != "") {
        $(topContent).fadeOut();
    }
    $('#image_carousel').fadeOut();
    $('#video_intro').fadeIn();
    $('#video_sizzler').fadeOut();
	$('.btn_sizzler').fadeIn();
	$('.btn_videointro').fadeOut();
});

$('.btn_gallery').click(function(){
    if (topContent != "") {
        $(topContent).fadeOut();
    }
    $('#image_carousel').fadeIn();
    $('#video_intro').fadeOut();
	$('#video_sizzler').fadeOut();
});

$('.btn_carousel').click(function(){
    if (topContent != "") {
        $(topContent).fadeOut();
    }
    $('#video_intro').fadeOut();
    $('#video_sizzler').fadeOut();
    $('#image_carousel').fadeIn();
});

// Setup of buttons
$('.btn_close').click(function(){
    $(this).parent().fadeOut();
    $('#image_carousel').fadeIn();
});

$('.btn_character').click(function(){
    var relTag = $(this).attr('rel');
    if (topContent != "") {
        $(topContent).fadeOut();
    }
    topContent = "#" + relTag;
    $('#image_carousel').fadeOut();
    $('#video_intro').fadeOut();
    $('#video_sizzler').fadeOut();
    $(topContent).fadeIn();
});

// Setup of Spritely objects
/*
    $('.shoobie').sprite({
        fps: 15,
        no_of_frames: 5,
        play_frames: 5
    });*/
shoobieTimer = setTimeout("shoobieAnim(1)", 4000);
/*
    $('.lollie').sprite({
        fps: 12,
        no_of_frames: 4,
        play_frames: 4
    });*/
//lollieTimer = setTimeout("lollieAnim()", 10000);
});

