
// Setup the initial state
function initTabs() {
	$('#album-content > li:not(#cd1)').hide();
	$('#album-content li#cd1').show();
}

// Simple class swap for the carousel images
function switchAlbumClass (o) {
	$('#covers a').removeClass();
	$(o).addClass('selected');
}

// Content swaping for tabs
function switchContent (o) {
	var currentContent = $('#covers a.selected').attr('href');
	var newContent     = $(o).attr('href');
	var strRange 	   = new Array( (currentContent.length -4),
									 currentContent.length      );
	
	$( currentContent.substring( strRange[0], strRange[1]) ).fadeOut(500, function () {
		$( newContent.substring( strRange[0], strRange[1]) ).fadeIn(500);
	});
}

function changeSelection (o) {
	// If clicked cover has a class do nothing
	if ($(o).attr('class') !== '') {
		return false;
	}
	switchContent(o);
	switchAlbumClass(o);
}

$(document).ready(function() { 
	
	$("#album-content").before("<div id='carousel'><a href='#' class='prev'>previous</a><div id='toc'><ul id='covers'><li><a class='selected' href='#cd1'><img src='/clients/alesana/img/Album_where_sm.png' alt='Where Myth Fades...' /></a></li><li><a href='#cd2'><img src='/clients/alesana/img/Album_on_frail.png' alt='On Frail Wings...' /></a></li><li><a href='#cd3'><img src='/clients/alesana/img/Album_try_this.png' alt='Try This With ...' /></a></li></ul></div><a href='#' class='next'>previous</a></div>");
	
  	$("#toc").jCarouselLite({
    	btnNext: ".next",
    	btnPrev: ".prev"
	});
	
	// Simple Tooltip 
    $("#covers a").append("<cite></cite>");
   
    $("#covers a").hover(function() {
    	$(this).find("cite").animate({opacity: "show", top: "22"}, "slow");
    	var hoverText = $(this).find("img").attr("alt");
        $(this).find("cite").text(hoverText);
    }, function() {
    	$(this).find("cite").animate({opacity: "hide", top: "10"}, "fast");
    });
	
	// Bind onClick the changeSelection function
	$("#covers a").bind("click" ,function(e) {
		changeSelection(this);
		return false;
	});
	
	initTabs();
	
}); 



