var isPlaying       =    false;
var currentSongNo   =    0;
var numberOfSongs   =    4;
var currentPage     =   "home";
var canPlayMp3;
var canPlayOgg;


var mp3s = new Array();
mp3s[0] = "mp3/RumbaDeAzahar.mp3";
mp3s[1] = "mp3/VamosQueVengo.mp3";
mp3s[2] = "mp3/AiresDeVioleta.mp3";
mp3s[3] = "mp3/GuarapoPaTi.mp3";

var oggs = new Array();
oggs[0] = "ogg/RumbaDeAzahar.ogg";
oggs[1] = "ogg/VamosQueVengo.ogg";
oggs[2] = "ogg/AiresDeVioleta.ogg";
oggs[3] = "ogg/GuarapoPaTi.ogg";

var songnames = new Array();
songnames[0] = "Rumba de Azahar";
songnames[1] = "Vamos Que Vengo";
songnames[2] = "Aires de Violeta";
songnames[3] = "Guarapo Pa Ti";




$(document).ready(function () {
	setSBGImageOptions(1);

	$('#thumbstest').hide().addClass('hidden');
	$('#thumbs1').superbgimage().show().removeClass('hidden');
	$('#thumbs1').stopSlideShow();


	$('#articles').load("home.html", function()
	{	
	    $('#article1').jScrollPane({showArrows:false, hideFocus:true, enableKeyboardNavigation:true, animateScroll:true, animateDuration:1500 });
		$('#article2').jScrollPane({showArrows:false, hideFocus:true, enableKeyboardNavigation:true, animateScroll:true, animateDuration:1500 });
		$('#logodiv').load("logopage.html");
	});


	myAudio = document.getElementById('audio');
	myAudio.play();
	isPlaying = true;
    makeLinkWhite(currentPage);
    
    if (myAudio.canPlayType) {
       // Currently canPlayType(type) returns: "", "maybe" or "probably" 
       canPlayMp3 = !!myAudio.canPlayType && "" != myAudio.canPlayType('audio/mpeg');
       canPlayOgg = !!myAudio.canPlayType && "" != myAudio.canPlayType('audio/ogg; codecs="vorbis"');
    }    
   
    $('#home').click(function() 
	{
		if (currentPage != "home") 
		{
			showPlayer();
			if(currentPage=="gallery") 
			{
			
			// Put this to first load the page so its the same
				setSBGImageOptions(1);

				$('#thumbstest').hide().addClass('hidden');
				$('#thumbs1').superbgimage().show().removeClass('hidden');
				$('#thumbs1').stopSlideShow();
			}
			makeLinkGray(currentPage);
			$("#articles").children().fadeOut(1500, function() 
			{

				$("#articles").children().remove();			
				$('#articles').load("home.html", function()
				{	
				    $('#article1').jScrollPane({showArrows:false, hideFocus:true, enableKeyboardNavigation:true, animateScroll:true, animateDuration:1500 });
					$('#article2').jScrollPane({showArrows:false, hideFocus:true, enableKeyboardNavigation:true, animateScroll:true, animateDuration:1500 });
					$('#logodiv').load("logopage.html");


				});

			});
			currentPage = "home";
			makeLinkWhite(currentPage);
		}
	});
	
	
	$('#bio').click(function() {
		
		if (currentPage !="bio") 
		{	
			showPlayer();
			if(currentPage=="gallery") 
			{
				setSBGImageOptions(2);

				$('#thumbstest').hide().addClass('hidden');
				$('#thumbs1').superbgimage().show().removeClass('hidden');
				$('#thumbs1').stopSlideShow();
			}
		
			makeLinkGray(currentPage);
			$("#articles, #logodiv").children().fadeOut(1500,function() 
			{ 
				$("#articles, #logodiv").children().remove();
				$('#articles').load("bio.html", function()
				{
//					$('#article3').jScrollPane({showArrows:false, hideFocus:true, enableKeyboardNavigation:true, animateScroll:true, animateDuration:1500 });
				});
			});
			currentPage = "bio";
			makeLinkWhite(currentPage);
		}
	});

		
	$('#music').click(function() {		
		if (currentPage !="music") 
		{
			showPlayer();
			if(currentPage=="gallery") 
			{
				setSBGImageOptions(3);

				$('#thumbstest').hide().addClass('hidden');
				$('#thumbs1').superbgimage().show().removeClass('hidden');
				$('#thumbs1').stopSlideShow();
			}
		
			makeLinkGray(currentPage);
			$("#articles, #logodiv").children().fadeOut(1500,function() 
			{ 
				$("#articles, #logodiv").children().remove();
				$('#articles').load("music.html", function()
				{
//					$('#article3').jScrollPane({showArrows:false, hideFocus:true, enableKeyboardNavigation:true, animateScroll:true, animateDuration:1500 });
				});
			});
			currentPage = "music";
			makeLinkWhite(currentPage);
		}
	});
	
	
	
	
	
	$('#video').click(function(e) {
	

		if (currentPage !="video") 
		{
			if(currentPage=="gallery") 
			{
				setSBGImageOptions(4);

				$('#thumbstest').hide().addClass('hidden');
				$('#thumbs1').superbgimage().show().removeClass('hidden');
				$('#thumbs1').stopSlideShow();
			}
		
		
			makeLinkGray(currentPage);
//			myAudio.pause();
//			$("#pauseplay").attr("src", "img/play_dull.png");

		
			$("#articles, #logodiv").children().fadeOut(1500,function() 
			{ 
				$("#articles, #logodiv").children().remove();
				
				$('#articles').load("video.html", function()
				{
//					$('#article3').jScrollPane({showArrows:false, hideFocus:true, enableKeyboardNavigation:true, animateScroll:true, animateDuration:1500 });
				});
			});
			currentPage = "video";
			makeLinkWhite(currentPage);
		}

	
	});
	
	
	$('#gallery').click(function(e) {
		if (currentPage !="gallery") 
		{
			showPlayer();
			makeLinkGray(currentPage);
			$("#articles, #logodiv").children().fadeOut(1500,function() 
			{ 
				$("#articles, #logodiv").children().remove();
				$('#articles').load("gallery.html", function()
				{
//					$('#article3').jScrollPane({showArrows:false, hideFocus:true, enableKeyboardNavigation:true, animateScroll:true, animateDuration:1500 });

					
					
					$('#thumbs1').stopSlideShow();

					
//					$('#thumbs1').hide().addClass('hidden');
					setSBGImageOptionsSlideShow(1);
					$('#thumbstest').superbgimage({reload:true}).show().removeClass('hidden');
							 e.preventDefault();

//					$('#thumbstest').startSlideShow();
					
				});
			});
			currentPage = "gallery";
			makeLinkWhite(currentPage);
		}	
	});
	
	
	
	$('#shows').click(function() {

		if (currentPage !="shows") 
		{
			showPlayer();
			if(currentPage=="gallery") 
			{
				setSBGImageOptions(6);

				$('#thumbstest').hide().addClass('hidden');
				$('#thumbs1').superbgimage().show().removeClass('hidden');
				$('#thumbs1').stopSlideShow();
			}
		
			makeLinkGray(currentPage);
			$("#articles, #logodiv").children().fadeOut(1500,function() 
			{ 
				$("#articles, #logodiv").children().remove();
				$('#articles').load("shows.html", function()
				{
					$('#article5').jScrollPane({showArrows:false, hideFocus:true, enableKeyboardNavigation:true, animateScroll:true, animateDuration:1500 });
				});
			});
			currentPage = "shows";
			makeLinkWhite(currentPage);
		}
	});
	
	
	
	$('#contact').click(function() {
	
		if (currentPage !="contact") 
		{
			showPlayer();
		
			if(currentPage=="gallery") 
			{
				setSBGImageOptions(7);

				$('#thumbstest').hide().addClass('hidden');
				$('#thumbs1').superbgimage().show().removeClass('hidden');
				$('#thumbs1').stopSlideShow();
				
			}
				
			makeLinkGray(currentPage);
			$("#articles, #logodiv").children().fadeOut(1500,function() 
			{ 
				$("#articles, #logodiv").children().remove();
				$('#articles').load("contact.html", function()
				{
//					$('#article3').jScrollPane({showArrows:false, hideFocus:true, enableKeyboardNavigation:true, animateScroll:true, animateDuration:1500 });
				});
			});
			currentPage = "contact";
			makeLinkWhite(currentPage);
		}
	});


  	
  	$('#article2').jScrollPane({showArrows:false, hideFocus:true, enableKeyboardNavigation:true, animateScroll:true, animateDuration:1500 });
  	$('#article1').jScrollPane({showArrows:false, hideFocus:true, enableKeyboardNavigation:true, animateScroll:true, animateDuration:1500 });

 	
  	
	
	$("#nextslide").mousedown(function(){
	   $(this).attr("src", "img/forward.png");
       nextSong(canPlayMp3,canPlayOgg,myAudio);
    });
    
	
	$('#nextslide').mouseup(function() {
	  $(this).attr("src", "img/forward_dull.png");


	});
	
	
	$('#nextslide').mouseout(function() {
	  $(this).attr("src", "img/forward_dull.png");

	});
	
	
	
	$("#prevslide").mousedown(function(){
	   $(this).attr("src", "img/back.png");
	   prevSong(canPlayMp3,canPlayOgg,myAudio);
	
    });
    
	$('#prevslide').mouseup(function() {
	  $(this).attr("src", "img/back_dull.png");
	  
	});
	
	$('#prevslide').mouseout(function() {
	  $(this).attr("src", "img/back_dull.png");
	});
	
	
	
	
	
	
	$("#pauseplay").click(function(){
		if (isPlaying == true) 
		{
		   $(this).attr("src", "img/play_dull.png");
		   isPlaying = false;
	   	   myAudio.pause();
		}
    	
    	
    	else if (isPlaying == false)	
    	{
   	       $(this).attr("src", "img/pause_dull.png");
   	       isPlaying = true;
	       myAudio.play();
		}
	});
	
});



function nextSong(mp3support,oggsupport,audioelement) {

	// in case it was paused and next song was clicked
	isPlaying = true;  
	$("#pauseplay").attr("src", "img/pause_dull.png");

	currentSongNo = (currentSongNo + 1) % numberOfSongs;
	
	if (mp3support == true) {
		audioelement.src = mp3s[currentSongNo];
	} else if (oggsupport == true) {
		audioelement.src = oggs[currentSongNo];
	}

	audioelement.load();
	audioelement.play();
	$("#slidecounter").html((currentSongNo+1)+"/4");
	$("#slidecaption").html("Capricho - "+songnames[currentSongNo]);

};

function prevSong(mp3support,oggsupport,audioelement) {
	// in case it was paused and prev song was clicked
	isPlaying = true;  
	$("#pauseplay").attr("src", "img/pause_dull.png");

	currentSongNo = (currentSongNo - 1) % numberOfSongs;
	if (currentSongNo < 0 ) 
	{
		currentSongNo += 4;
	};
	
	if (mp3support == true) {
		audioelement.src = mp3s[currentSongNo];
	} else if (oggsupport == true) {
		audioelement.src = oggs[currentSongNo];
	}

	audioelement.load();
	audioelement.play();
   	$("#slidecounter").html((currentSongNo+1)+"/4");
   	$("#slidecaption").html("Capricho - "+songnames[currentSongNo]);
   	  	
};

function makeLinkWhite(link) {
	$("#"+link).addClass("clickedlink");
	$("#"+link).removeClass("offlink");
}

function makeLinkGray(link) {
	$("#"+link).removeClass("clickedlink");
	$("#"+link).addClass("offlink");
}

function setSBGImageOptions(startslide) {
		$.fn.superbgimage.options = {
		id: 'superbgimage', // id for the containter
		z_index: -1, // z-index for the container
		inlineMode: 0, // 0-resize to browser size, 1-do not resize to browser-size
		showimage: startslide, // number of first image to display
		vertical_center: 1, // 0-align top, 1-center vertical
		transition: 1, // 0-none, 1-fade, 2-slide down, 3-slide left, 4-slide top, 5-slide right, 6-blind horizontal, 7-blind vertical, 90-slide right/left, 91-slide top/down
		transitionout: 1, // 0-no transition for previous image, 1-transition for previous image
		randomtransition: 0, // 0-none, 1-use random transition (0-7)
		showtitle: 0, // 0-none, 1-show title
		slideshow: 0, // 0-none, 1-autostart slideshow
		slide_interval: 5000, // interval for the slideshow
		randomimage: 0, // 0-none, 1-random image
		speed: 600, // animation speed
		preload: 1, // 0-none, 1-preload images
		onShow: null, //superbgimage_show, // function-callback show image
		onClick: null, // function-callback click image
		onHide: null, // superbgimage_hide, // function-callback hide image
		onMouseenter: null, // superbgimage_mouseenter, // function-callback mouseenter
		onMouseleave: null, //superbgimage_mouseleave, // function-callback mouseleave
		onMousemove: null, // superbgimage_mousemove // function-callback mousemove
};

};

function setSBGImageOptionsSlideShow(startslide) {
		$.fn.superbgimage.options = {
		id: 'superbgimage', // id for the containter
		z_index: -1, // z-index for the container
		inlineMode: 0, // 0-resize to browser size, 1-do not resize to browser-size
		showimage: startslide, // number of first image to display
		vertical_center: 1, // 0-align top, 1-center vertical
		transition: 1, // 0-none, 1-fade, 2-slide down, 3-slide left, 4-slide top, 5-slide right, 6-blind horizontal, 7-blind vertical, 90-slide right/left, 91-slide top/down
		transitionout: 1, // 0-no transition for previous image, 1-transition for previous image
		randomtransition: 0, // 0-none, 1-use random transition (0-7)
		showtitle: 0, // 0-none, 1-show title
		slideshow: 0, // 0-none, 1-autostart slideshow
		slide_interval: 5000, // interval for the slideshow
		randomimage: 0, // 0-none, 1-random image
		speed: 600, // animation speed
		preload: 1, // 0-none, 1-preload images
		onShow: null, // function-callback show image
		onClick: superbgimage_click, // function-callback click image
		onHide: null, // function-callback hide image
		onMouseenter: null, // function-callback mouseenter
		onMouseleave: null, // function-callback mouseleave
		onMousemove: null // function-callback mousemove
};

};


function showPlayer() {
	
	if ($("#controls-wrapper").css("display") == "none") {
	   $("#controls-wrapper").fadeIn();
	}

};




