var playAll = true;
var trackIndex = 0;
var api;

$(document).ready(function(){	

	var el = $('#content').jScrollPane({showArrows:true});
	api = el.data('jsp');

	$("div.link_button").mouseover(function(){
		$(this).css('border','1px solid #c0c0c0');
		}).mouseout(function(){
			$(this).css('border','1px solid #fff');
			});
				
//	$('#content').focus();

//	initScroller();

	$('a.home').click(function(e){
		home();
		document.title = 'Josienne Clarke / About';
		e.PreventDefault;
		return false;
	});


	$('a.gallery').click(function(e){
		gallery();
		document.title = 'Josienne Clarke / Gallery';
		e.PreventDefault;
		return false;
	});

	$('a.gigs').click(function(e){
		gigs();
		document.title = 'Josienne Clarke / Gigs';
		e.PreventDefault;
		return false;
	});

	$('a.music').click(function(e){
		music();
		document.title = 'Josienne Clarke / Music';
		e.PreventDefault;
		return false;
	});

	$('a.album').click(function(e){
		album();
		document.title = 'Josienne Clarke / One Light Is Gone';
		e.PreventDefault;
		return false;
	});

	$('a.contact').click(function(e){
		contact();
		document.title = 'Josienne Clarke / Contact';
		e.PreventDefault;
		return false;
	});

	if($('body').attr('id') == 'gallery')
		gallery();
	if($('body').attr('id') == 'music')
		music();
		
});

function playTrack(t,n) {
	$("#jq_player").jPlayer("setMedia", {mp3: t}).jPlayer("play");
		$("#trackname").fadeOut(function(){
	$("#trackname").text(n);
	$("#trackname").fadeIn();
	});
	return false;
} 

function initScroller(){
	//$('#content').jScrollPane({autoReinitialise:true,showArrows:true});
}

function home(){
/*	$('#content').fadeOut(function(){
		$.get('/content/about.php',function(data){
			$('#content').html(data);
			$('#content').onImagesLoad({ 
		            selectorCallback: initScroller
		        }); 
			$('#content').fadeIn();
		});
	});*/

	api.getContentPane().fadeOut(function(){
		$.get('./content/home.php',function(data){
			api.getContentPane().html(data);
			api.reinitialise();
			api.getContentPane().fadeIn();
		});
	});
}

function gallery(){
		$.get('./content/gallery.php',function(data){
			api.getContentPane().html(data);
			$('#content img.img_thumb').css('display','none');			
			$('#content img.img_thumb').each(function(){
			var rnd = Math.floor(Math.random()*11) * 600;
			$(this).load(function(){$(this).delay(rnd).fadeIn();});
		});

				$("a[rel^='prettyPopin']").prettyPopin();
				$("a[rel^='prettyPhoto']").prettyPhoto();
				api.reinitialise();
		});
}

function gigs(){
	api.getContentPane().fadeOut(function(){
		$.get('./content/gigs.php',function(data){
			api.getContentPane().html(data);
			api.reinitialise();
			api.getContentPane().fadeIn();
		});
	});
}

function music(){
	var jpPlayInfo = $("#jplay-info");
	api.getContentPane().fadeOut(function(){
		$.get('./content/music.php',function(data){
			api.getContentPane().html(data);
			api.reinitialise();
			api.getContentPane().fadeIn();

	
			});
	});

}

function album(){
	api.getContentPane().fadeOut(function(){
		$.get('./content/album.php',function(data){
			api.getContentPane().html(data);
			api.reinitialise();
			api.getContentPane().fadeIn();
		});
	});
}

function contact(){
	api.getContentPane().fadeOut(function(){
		$.get('./content/contact.php',function(data){
			api.getContentPane().html(data);
			api.reinitialise();
			api.getContentPane().fadeIn();
			if($("#contactForm").length > 0)
	{
		var validator = $("#contactForm").validate({
		rules: {
			contactName:"required",
			contactEmail: {
				required: true,
				email: true
			}
		},
		messages:{
			contactName:"!",
			contactEmail:{
				required:"!",
				email:"!"
			}
		},
		errorPlacement: function(error, element) {
			error.appendTo( element.parent() );
		},
		success:"success",
			submitHandler: function(form) {
				$(".ajaxLoader").show();
				$(form).ajaxSubmit();
				$(".ajaxLoader").hide();
				$(".messageSent").show("slow",
				function(){
					$(".messageSent").fadeTo(3000,1).slideUp("slow")
				});
			$("#contactForm").resetForm();
		}
		});
	}
		});
	});
}


