var musicArray = new Array();
var albumArray = new Array();
var currentMusic = -1;
var currentImage = null;
var currentVideo = null;
$(window).load(function(){
   init();
});
function init(){
   $('#playlist').jScrollPane({
        showArrows:true
    });
    $('#generalContent').jScrollPane({
        showArrows:true
    });
    $('#musicContent').jScrollPane({
        showArrows:true
    });
    $('#newsContent').jScrollPane({
        showArrows:true
    });
    $('#dateContent').jScrollPane({
        showArrows:true
    });
    if(imageCarousel){
        $(".thumbBox").jCarouselLite({
            btnNext: "#upButton",
            btnPrev: "#downButton",
            mouseWheel: 'true',
            vertical: 'true',
            circular: 'true',
            speed: 1000
        });
    }
    if(videoCarousel){
        $(".thumbBox2").jCarouselLite({
            btnNext: "#upButton2",
            btnPrev: "#downButton2",
            mouseWheel: 'true',
            vertical: 'true',
            circular: 'true',
            speed: 1000
        });
    }
    if(currentImage){
        centerImage(currentImage);
    }
    for(var i in albumArray){
        $("#albumLeft_" + albumArray[i]).height($("#albumRight_" + albumArray[i]).height());
    }
    $('#content_0').hide();
    $('#content_1').hide();
    $('#content_2').hide();
    $('#content_3').hide();
    $('#content_4').hide();
    $('#content_5').hide();
    $('#loading').hide();

    //set the click events for each playButton
    $(".playButton").each(function(intIndex){
        $(this).bind("click", function(){
            var musicId = musicArray[intIndex];
            toggleMusic(musicId, intIndex);
        });
    });

    //set the click events for each tab
    $(".tab").each(function(intIndex){
        $(this).bind("click", function(){
            clickTab(intIndex);
        });
    });
    
    activeTab(currentTab);
    if(currentVideo){
        showNewVideo(currentVideo);
    }
}
function clickTab(tab){
    if(currentTab != tab){
        inactiveTab(tab);
    }
    else{
        activeTab(tab);
    }
}

function activeTab(tab){
    $("#tab_" + tab).addClass('active');
    $("#content_" + tab).fadeIn(1000);
    currentTab = tab;
}

function inactiveTab(tab){
    $("#tab_" + currentTab).removeClass('active');
    $("#content_" + currentTab).fadeOut(1000, activeTab(tab));
}

function toggleMusic(musicId, index){
    if(currentMusic == index){
        $("#item_" + currentMusic).removeClass('current');
        $("#item_" + currentMusic).addClass('item');
        currentMusic = -1;
        stopPlayer();
    }
    else{
        if(currentMusic>=0){
            $("#item_" + currentMusic).removeClass('current');
            $("#item_" + currentMusic).addClass('item');
        }
        $("#item_" + index).removeClass('item');
        $("#item_" + index).addClass('current');
        currentMusic = index;
        sendToPlayer(musicId);
    }
}

function loadPhoto(image){
    if(image != currentImage){
        $("#image_" + currentImage).fadeOut(2000, centerImage(image));
    }
}

function centerImage(image){
    var img = $("#image_" + image);
    img.css("margin-left", ((594-img.width())/2));
    img.css("margin-top", ((434-img.height())/2));
    img.fadeIn(2000);
    currentImage = image;
}

function changeVideo(videoId){
    if(videoId != currentVideo){
        $("#video_" + currentVideo).hide(showNewVideo(videoId));
    }
}

function showNewVideo(videoId){
    $("#video_" + videoId).show();
    currentVideo = videoId;
}
