$(function() {
	
	// Gallery Events
	if (typeof $.fn.fancybox == 'function') {
		$(".b-gallery-item a, a.lightbox").fancybox({
				'titlePosition': 'inside',
				'titleFormat': formatTitle,
				'padding': 0,
				'overlayOpacity': 0.66,
				'overlayColor': '#000'
		});
	}
	
	function formatTitle(title) { 
		if ((title != '')) {
			if((title.indexOf('|') > -1)) {
				return ("<h2>" + title.replace("|", "</h2><p>") + "</p>");
			} else {
				return '<p>' + title + '</p>';
			}
		} else {
			return title;
		}
	}

	
	
});





$(function(){
	
	$('.b-track-list a').each(function(){
		$(this).attr('title', 'Click to play/stop track');
	});
	$('.b-track-list a').click(function() {
		//console.log('done');
		var sMP3 = $(this).attr('href');
		
		if($(this).hasClass('played')){
			$("#jpId").jPlayer("stop");
			$(this).removeClass('loading played');
		} else {
			$('.b-track-list a').removeClass('loading played')
			$("#jpId").jPlayer( "clearFile" ).jPlayer("setFile", sMP3).jPlayer("play");
			$(this).addClass('loading played')
			
			var timeout = setTimeout ("$('.b-track-list a').removeClass('loading')", 5000);
		}
		
		return false;
	});
	
	$("#jpId").jPlayer( {
		swfPath: "/assets/templates/d/js/"
	});

});





