function headerImage(image_name){
	return "<img src='images/"+ image_name +"' width='1200' />";
}
			
function flashPlayerPlay(title, mp3){
	var mp3Location = "http://www.jonigreene.net/media/mp3/";
	$("#nowPlaying").html(title);
	document.getElementById("mp3player").SetVariable("player:jsUrl", mp3Location + mp3);
	document.getElementById("mp3player").SetVariable("player:jsPlay", "");
}
			
			//Jquery Funciton Calls
			$(function(){
    
				$.ajaxSetup ({  
					cache: true  
				});  
				
				$.cacheImage([
					'images/home.jpg',
					'images/news.jpg',
					'images/bio.jpg',
					'images/clinics.jpg',
					'images/performances.jpg',
					'images/works.jpg',
					'images/photos.jpg'
				]);		
				
				
				$("#photos").ajaxComplete(function(event,request, settings){
				        $('#gallery a').lightBox();
				});	
				$("#closeCart").live("click", function(){
					$("#shoppingCart").hide('blind');
					return false;
				});
				$("#works").ajaxComplete(function(event,request, settings){
					// Accordion
					$("#bandAccordion").accordion({ header: "h3", autoHeight: false, active: false });
					$("#choralAccordion").accordion({ header: "h3", autoHeight: false, active: false });
					$("#chamberAccordion").accordion({ header: "h3", autoHeight: false, active: false });
						
					// Tabs
					$('#worksTabs').tabs();
					
					//Player stop button on works page
					$(".ui-icon-stop").live("click", function(){
						document.getElementById("mp3player").SetVariable("player:jsStop", "");
						return false;
					});				
					$(".ui-icon-cart").live("click", function(){
						$("#shoppingCart").toggle('blind');
						return false;
					});	
					//Play buttons for pieces
					$("#circianPlay").click(function(){
						flashPlayerPlay("Circean Waters", "Circean%20Waters%20IUCB%20Concert.mp3");
					});
					$("#moonscapePlay").click(function(){
						flashPlayerPlay("Moonscape Awakening (10/14/08)", "MoonscapeAwakening_IUConcertBand.mp3");
					});						
					$("#moonscapeRevisedPlay").click(function(){
						flashPlayerPlay("Moonscape Awakening <i>(revised)</i> (9/20/09)", "MoonscapeAwakening_MM.mp3");
					});						
					$(".autumnI-VIPlay").click(function(){
						flashPlayerPlay("Autumn Reflections I-VI.", "Autumn%20Reflections%20edited%20-%20senior%20recital.mp3");
					});		
					$("#huesPlay").click(function(){
						flashPlayerPlay("Un Aliento de Color I. Hues in the Wind", "HuesInTheWind_MM.mp3");
					});			
					$("#lucretiaIPlay").click(function(){
						flashPlayerPlay("Lucretia I. The Jewel of Rome", "Lucretia%20I.mp3");
					});			
					$("#lucretiaIIPlay").click(function(){
						flashPlayerPlay("Lucretia II. Perfidious Beauty", "Lucretia%20II.mp3");
					});		
					$("#lucretiaIIIPlay").click(function(){
						flashPlayerPlay("Lucretia III. Headlong to Death", "Lucretia.mvt.III_3.24.09.mp3");
					});		
					$("#ephemeraPlay").click(function(){
						flashPlayerPlay("Ephemera", "01%20Ephemera.mp3");
					});		
					$("#tchinaPlay").click(function(){
						flashPlayerPlay("T'china Lema'an Haifa", "Tchina%20Lemaan%20Haifa%20edited%20-%20senio.mp3");
					});		
					$("#crackedPlay").click(function(){
						flashPlayerPlay("Cracked", "Cracked%20edited%20-%20senior%20recital.mp3");
					});		
					$("#interventionPlay").click(function(){
						flashPlayerPlay("Intervention", "Intervention.mp3");
					});		
					$("#wavePlay").click(function(){
						flashPlayerPlay("I. Wave", "WaveAndImpulse-Wave.mp3");
					});		
					$("#impulsePlay").click(function(){
						flashPlayerPlay("II. Impulse", "WaveAndImpulse-Impulse.mp3");
					});							
				});			
				$("#contact").click(function(){  
					$("#contactDialog").dialog('open')
				});				
			});


		
function pageload(hash) {  
    if (hash) getPage();      
}  
          
function getPage() {  
    var data = document.location.hash.replace(/^.*#/, '');  
    if (data != ""){
		if (data == "photos"){
			$('#pageContainer').html('').load(data + ".php");
		} else {
			$('#pageContainer').html('').load(data + ".html");
		}
		//$("#pageHeaderImage").html(headerImage(data + ".jpg"));
		$('#pageContainer').fadeIn('fast');
		data = '';
	}
}  
		
$(document).ready(function () {  
	$("#contactSubmit").submit(function(){
		var str = $(this).serialize();
		$.ajax({
			type: "POST",
			url: "sekretContact.php",
			data: str,
			success: function(msg){
				$("#note").ajaxComplete(function(event, request, settings){
					if(msg.replace(/\s+$/,"") == 'OK') {
						result = 'Your message has been sent. Thank you!';
						$("#fields").hide('blind');
					} else {
						result = msg;
					}
					$(this).html(result);
				});
			}
		});
		return false;
	});

	//Contact Dialog
	$("#contactDialog").dialog({ autoOpen: false, width: 550 });
				
      	//Check if url hash value exists (for bookmark)  
	$.historyInit(pageload); 

          
    //highlight the selected link  
    $('a[href=' + document.location.hash + ']').addClass('selected');  
      
    //Seearch for link with REL set to ajax  
    $('a[rel=ajax]').click(function () {  
          
        //grab the full url  
        var hash = this.href;  
          
        //remove the # value  
        hash = hash.replace(/^.*#/, '');  
          
        //for back button  
        $.historyLoad(hash);   
		
        //clear the selected class and add the class class to the selected link  
        $('a[rel=ajax]').removeClass('selected');  
        $(this).addClass('selected');  
        $('#pageContainer').hide();  
		
		//run the ajax  
        getPage();  
      
        //cancel the anchor tag behaviour  
        return false;  
    });   
});  