
/* 

START jQUERY 

*/
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}



$(document).ready(function(){

	/*
	
	PRELOAD SOME IMAGES
	
	*/
	
	$.preloadImages(
		"common/images/nav.png", 
		"common/images/nav-bio.png",
		"common/images/nav-buy.png",
		"common/images/nav-contact.png",
		"common/images/nav-links.png",
		"common/images/nav-lyrics.png",
		"common/images/nav-media.png",
		"common/images/logo.png",
		"common/images/album-cover.jpg"
	);
	
	
	
	/*
	
	NAV, and hand written copy links
	
	*/
	
	$(".nav-map, .link-copy, .link-ep, .buy-it a").click(function () {
	
		// turn on nav		
		//$("#nav").attr("src","common/images/nav-" + returnNavTarget(this.href) + ".png");
		
		// close all pages
		$(".page").hide();
		
		// open relevant page
		var thePage = $(this).attr("href")
		$(thePage).show();
		
		// don't skip down the page
		return false;
	
	});
	
	$(".nav-map").hover(
		function () {
			$("#nav").attr("src","common/images/nav-" + returnNavTarget(this.href) + ".png");
		}, 
		function () {
			$("#nav").attr("src","common/images/nav.png");
		}
	);
	
	/*
	
	LYRICS
	
	*/
	
	$(".track-list a").click(function () {
	
		// turn off all track-list links
		$(".track-list a").removeClass("on");
	
		// turn on link just clicked	
		$(this).addClass("on");		
		
		// close all songs
		$(".song").removeClass("lyrics-open");
		$(".song").hide();
		
		// open relevant song
		var theSong = $(this).attr("href")
		$(theSong).show();
		
		// don't skip down the page
		return false;
	
	});
	
	/*
	
	MEDIA
	
	*/
	
	$(".media-list a").click(function () {
	
		// turn off all media-list links
		$(".media-list a").removeClass("on");
	
		// turn on link just clicked	
		$(this).addClass("on");		
		
		// close all songs
		$(".media").removeClass("media-open");
		$(".media").hide();
		
		// open relevant media
		var theMedia = $(this).attr("href")
		$(theMedia).show();
		
		
		// if it's the video embed it
		if (theMedia == "#media-video") {
			
			
			var params = {wmode:"window", allowScriptAccess:"always", menu:"true", quality:"high", scale:"showall", width:"320", height:"240"};
			swfobject.embedSWF("common/flash/cc-video-01.swf", "media-video", "320", "240", "9.0.0", false, params);	
			
		} else {
					
			$("#media-video").hide();
			var params = {wmode:"window", allowScriptAccess:"always", menu:"true", quality:"high", scale:"showall", width:"0", height:"0"};
			swfobject.embedSWF("common/flash/cc-video-01.swf", "media-video", "0", "0", "9.0.0", false, params);
		
		}
		
		// don't skip down the page
		return false;
	
	});
	
	/*
	
	PHOTOS
	
	*/
	
	$("#photos a").click(function () {
	
		// turn off all track-list links
		$("#photos a").removeClass("on");
	
		// turn on link just clicked	
		$(this).addClass("on");		
		
		// set source of placeholder image to the one clicked on
		
		var thePic = $(this).attr("href")	
		$("#photos img").attr("src",thePic);
		
		// don't skip down the page
		return false;
	
	});
	
	/*
	
	LOGO - Clicking it hides all pages
	
	*/
	
	$("#logo").click(function () {	
		
		//$("#nav").attr("src","common/images/nav.png");
		$(".page").hide();
		
		// don't skip down the page
		return false;
	
	});	
	
	/*
	
	INITIALIZE FIELD VALUE RESET (looks for presence of "alt" attribute in the input tag)
	
	*/
	$("input[alt!='']").focus(function(){
		setValue(this,"onfocus"); 
		return false;
	});
	$("input[alt!='']").blur(function(){
		setValue(this,"onblur"); 
		return false;
	});

 });
 
 function returnNavTarget(pHREF) {
 
 	// grab the string to the right of the #
 
 	var retVal = pHREF.split("#",2)[1];
 	
 	return retVal;
 	
 }
 
 /* setValue clear's a text input's value and resets it to the input's alt attribute if the user doesn't enter a value */
function setValue(pEl,pSwitch) {	
	if (pSwitch == "onfocus") {
		if (pEl.value == pEl.alt) {
			pEl.value = "";	
		}
	}
	if (pSwitch == "onblur") {
		if (pEl.value == "") {
			pEl.value = pEl.alt;
		}
	}
}