$(document).ready(function(){

	// if ie6 lets patch it up
	version = parseFloat(navigator.appVersion.split("MSIE")[1]);
	if(version < 7) {
		$.ie6fixes();
	}

	// preload images
	// if we remove the slash at the front it will work on localhost home page but mod_rewrite urls dont work
	// keeping the slash will make it work on live server as it will go from the root domain 
	$.preloadImages(
		"/img/nav.png",
		"/img/box_top.png",
		"/img/box_middle.png",
		"/img/box_btm.png",
		"/img/bg-home.jpg",
		"/img/bg-listen.jpg",
		"/img/bg-songwriting.jpg",
		"/img/bg-bio.jpg",
		"/img/bg-news.jpg",
		"/img/bg-links.jpg",
		"/img/bg-buy.jpg",
		"/img/bg-contact.jpg",		
		"/img/background.jpg",
		"/img/h1_listen.png",
		"/img/h1_songwriting.png",
		"/img/h1_bio.png",
		"/img/h1_joincontact.png",
		"/img/h1_join.png",
		"/img/h1_contact.png",
		"/img/h1_newsreviews.png",
		"/img/h1_links.png",
		"/img/h1_buy.png",
		"/img/left-quote.png",
		"/img/right-quote.png",
		"/img/icons.png",
		"/img/link_facebook.jpg",
		"/img/link_lastfm.jpg",
		"/img/link_myspace.jpg",
		"/img/link_twitter.jpg"
	);
	
	// fadeout flash messages on click
	$('.cancel').click(function(){
		$(this).parent().fadeOut();
		return false;
	});

	// fade out good flash messages after 3 seconds
	$('.flash_good').animate({opacity: 1.0}, 3000).fadeOut();
	
	$('ul.listen_lyrics li div').hide();
	
	//lyrics dropdowns
	$('ul.listen_lyrics li a').click(
		function(){	
			if($(this).parent().find("div").css('display') == "none")
			{
				$(this).parent().find("div").show("slide", { direction: "up" }, 1000); 
			} else {
				$(this).parent().find("div").hide("slide", { direction: "up" }, 1000); 
			}
		}
	);
	setInterval("quote_rotate()",8000);
});

var qs = [
		"<span>Real vintage and modern sound on your songs!<br/>Oi Martin, France, 6 July</span>",
		"<span>love your songs really really really well written tunes!! I reckon you'll soon get snapped up!<br/>The Shaws, Wales, July 09</span>",
		"<span>I hope you get the point, I find your music very talented and enjoyable.<br/>KONE, Finland,  July 09</span>",
		"<span>I am known for being brutally honest when it comes to my personal opinion of what I hear, and not everyone makes it to the rank you have in my book. I foresee you going far...<br/>Mona, USA, July 09</span>",
		"<span>pretty awesome music...<br/>Bruce, Scotland, July 09</span>",
		"<span>After only working with Matt for a short while, his great talent as a songwriter became obvious. Publishers should check him out given the consistency of new material and also as his songs are very coverable<br/><br/>Jon Astley, Award winning Mastering Engineer and Producer</span>"];
var current = 0;
		
function quote_rotate() {

	/*
	RANDOM
	var rand = Math.floor(Math.random() * qs.length); 
	$('#quotes').fadeOut('slow', function(){
		$('#quotes').html(qs[rand]);
		$('#quotes').fadeIn('slow');
	});
	*/
	
	/*
	INORDER
	*/
		
	$('#quotes').fadeOut('slow', function(){
		current++;
		if(current >= qs.length) {
			current = 0;
		}
		$('#quotes').html(qs[current]);
		$('#quotes').fadeIn('slow');
	});
}


/*
	Preload Images Function
*/
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

/*
	Jonesys custom function to make items on top of pngs in ie6 clickable
*/

jQuery.pngLinks = function() {
	$("a").each(
		function( intIndex ){
			$(this ).css({ position: "relative"});
		}
	);
	$("input").each(
		function( intIndex ){
			$(this ).css({ position: "relative"});
		}
	);
}

/*
	Jonesys ie6 fixes function
*/

jQuery.ie6fixes = function() {
	$(document).pngFix({sizingMethod:"crop"});
	$(".textbox_middle").pngFix({sizingMethod:"scale"});

	$('a.home:hover').css({backgroundPosition: '0px 40px'});
	//$('a.listen').css({background-position-x: '-73px',  background-position-x: '0px'});
	
	$.pngLinks();
}

