// JavaScript Document
$(document).ready(function() {

//init Workshops Menu function
initWorkshopsMenu();

//trigger click from refferring url could be shortened with a select case statement
var url = window.location.href;    
var urlLower = url.toLowerCase();
	
var urlNoString = urlLower.replace('http://www.passionacademy.co.uk/workshops_home.php?screen=','');
//var urlNoString = urlLower.replace('http://localhost/passion/workshops_home.php?screen=','');
var urlNo = parseInt(urlNoString);
//console.log(urlNo);

//set default to show acting only this is a temp function maybe
if(isNaN(urlNo)){
urlNo=1;
}
	 
// console.log(url);
if(urlNo == 1){
	//console.log('acting');
	$('#acting h2').click();
		  }
if(urlNo == 2){
//console.log('professional');
	$('#techniques h2').click();
}
		  
if(urlNo == 3){
//console.log('theatre');
	$('#theatre h2').click();
}
		  
if(urlNo == 4){
	//console.log('screen');
	$('#screen h2').click();
}
		  
if(urlNo == 5){
//console.log('specialist');
	$('#specialist h2').click();
}


//MAILER FORM FUNCTIONS
// prepare Options Object 
var options = { 
    target:     '#mailer-response',
   // url:        'includes/mailing_list_fns.inc.php', 
    success:    function() { 
        //alert('Thanks for your comment!'); 
    } 
}; 
 
// bind to the form's submit event 
$('#mailer-form').submit(function() { 
	// inside event callbacks 'this' is the DOM element so we first 
	// wrap it in a jQuery object and then invoke ajaxSubmit 
	$(this).ajaxSubmit(options); 
 	// !!! Important !!! 
	// always return false to prevent standard browser submit and page navigation 
	return false; 
}); 



	
// pass options to ajaxForm 
//$('#mailer-form').ajaxForm(options);
	
		//$('#mailer-form').ajaxForm({
			// submit the form 
   // $(this).ajaxSubmit(); 
    // return false to prevent normal browser submit and page navigation 
   // return false; 
		//});
	
	

/*
	//FORM FUNCTIONS		
var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone;
  //alert (dataString);return false;
  $.ajax({
    type: "POST",
    url: "",
    data: dataString,
    success: function() {
      $('#contact_form').html("<div id='message'></div>");
      $('#message').html("<h2>Contact Form Submitted!</h2>")
      .append("<p>We will be in touch soon.</p>")
      .hide()
      .fadeIn(1500, function() {
        $('#message').append("<img id='checkmark' src='images/check.png' />");
      });
    }
  });
  return false;
  */
  
  

	


//HIDE INPUT TEXT ON FOCUS
//WILL NEED TO ONLY DO THIS IF VAL EQUALS NAME EMAIL OR SURNAME OTHERWISE IT CLEARS ENTERED VALUE

	//adds a new method to javascript - a trim function
    String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g,"");
    };
   
   
	
	$('#mailer-form #name').focus(function() {
		//console.log($(this).val());	
		
		var mystr = $(this).val();
		mystr=mystr.trim();

		if(mystr == 'Name'){

     		$(this).val('')
			}

      });
	
	$('#mailer-form #surname').focus(function() {
		//console.log($(this).val());	
		
		var mystr = $(this).val();
		mystr=mystr.trim();

		if(mystr == 'Surname'){

     		$(this).val('')
			}

      });
	
	$('#mailer-form #email').focus(function() {
		//console.log($(this).val());	
		
		var mystr = $(this).val();
		mystr=mystr.trim();

		if(mystr == 'Email'){

     		$(this).val('')
			}

      });

// });



	
//WORKSHOP MENU
function initWorkshopsMenu() {
	//hide all screen divs
	$('.menu-screens').hide();
	//hide all but first info screen
	$(".menu-screens").find('div.info-screen:gt(0)').hide();
	//$('#menu ul').addClass('notsel');

  	/*$('.menu-item h2').click(function() {
		var $myscreen = $(this).parent().find('div.menu-screens');
		$myscreen.find('ul').toggleClass('notsel');
		$myscreen.stop().slideToggle('normal');
		console.log($myscreen);
	});*/
	
	$('.menu-item h2').hover(function() {
		$(this).css('cursor','pointer'); 
		}, function() {
		$(this).css('cursor','auto'); 
	});
	
	$('.menu-item h2').click(function() { 
		var $myscreen = $(this).parent().find('div.menu-screens');
		
		//$myscreen.css('height', '266px');
		//$myscreen.find('div:eq(0)').show();
		//$myscreen.find('ul').show();
		//$(this).blend(400);
		//$('.menu-item .menu-screens').blend(400);
		//$myscreen.find('.menu-screens').blend(400);
		//$('.menu-item .menu-screens').click();
		
		$myscreen.find('ul').css('z-index','0').end().animate({
															
 			height: 'toggle'
 			}, 500, function() {
    		// Animation complete.
				$myscreen.find('ul').css('z-index','1');
  			});
	});

//function to show u need to alter the height of the div to slide it down a set amount
// Define the slider and the starting height
/*var div = $("#slider");
var startHeight = 100;

// Set the height to 100% so you can get the absolute height
div.css('height', '100%');
var openHeight = div.height();

// Set back to start height and then do animation
div.css('height', startHeight+'px');
div.animate({'height': openHeight}, {duration: 500});

*/


	/*$('.menu-item h2').mouseover(function() {
		var $myscreen = $(this).parent().find('div.menu-screens');
		
		$myscreen.css('height', '10px').animate({
		height: 'toggle',
		
		 opacity:100,
		
		   }, 100, function() {
    // Animation complete.
	
	 
  });*/
		
/*$('.menu-item h2').hover(
	function () {
	  	var $myscreen = $(this).parent().find('div.menu-screens');
		$myscreen.find('div').hide();
		$myscreen.find('ul').hide();
		$myscreen.css('height', '10px').animate({
		height: 'toggle',
		opacity:100
		}, 100 );
	  
  }, 
	function () {
		var $myscreen = $(this).parent().find('div.menu-screens');
		$myscreen.animate({
		height: 'toggle',
		opacity:100
		}, 100,function(){
		
		});
  }
);*/


	

	$('.menu-screens li a').mouseover(function() {
		var linkID = $(this).attr("id");
		//console.log(linkID);
	
		var $mydiv = $(this).parent().parent().parent().find("div.info-screen[id=info"+ linkID +"]");
		//console.log($mydiv);
	
		var $otherdiv = $(this).parent().parent().parent().find("div.info-screen[id!=info"+ linkID +"]");
		//console.log($otherdiv);
	
		if (! $mydiv.is(':visible')){
			$otherdiv.hide();
			$mydiv.show();
		}; 
		
	});
	
	
	
//add blend effect to menu headers
/*
$('#menu #acting h2').blend(400);
$('#menu #techniques h2').blend(400);
$('#menu #theatre h2').blend(400);
$('#menu #specialist h2').blend(400);
$('#menu #membership h2').blend(400);
*/	
//end initWorkshopsMenu function
}

//$('#pure-intro a').blend(400);
//THIS NEEDS SORTING ON NON HOME PAGES
//GET REFERENCE TO AND HALT HOME PAGE FLASH MOVIE PLAYBACK INITIALLY
/*
var movieName = "HOME_SCREEN";

function getFlashMovieObject(movieName){
	if (window.document[movieName]){
	return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1){
		if (document.embeds && document.embeds[movieName])
			return document.embeds[movieName]; 
	}else{ // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
		return document.getElementById(movieName);
	}
} 

var flashObj = getFlashMovieObject(movieName);

if(flashObj != null) {
	//stop playback
	flashObj.StopPlay();
}

//FADE LARGE DIV OUT ON HOME PAGE ONCE ONLY ELSE HIDE
//START FLASH MOVIE PLAYBACK WHENDIV HAS FADED
//should probably append the overlay div to the page otherwise itll be on there if javascript fails.
var url = document.referrer.toLowerCase();
				
var pmatch = url.indexOf("http://www.passionacademy.co.uk");
var rmatch = url.indexOf("http://www.romancart.com");

	if (pmatch !=-1 || rmatch != -1) {
		$("#home-overlay").hide();
		//play flash
		flashObj.Play();
	} else {
		//setTimeout(function() { $("#home-overlay").fadeOut(2000); }, 3000);
		setTimeout(function() {fadeHomeScreen(); }, 2000);
		//$("#home-overlay").delay('fast').fadeOut(2000).remove();
		
	}
//fade out home screen and play flash movie
function fadeHomeScreen(){
	 
	 $('#home-overlay').fadeOut(1500, function() {
    // Animation complete, platy flash
	flashObj.Play();
  });

}
*/

//AUDIENCE WITH COLOURBOX WINDOW CONTROLS
/*
$(".guest-link").colorbox({
		opacity:0.80,
		speed:350,
		width:'900px',
		height:'90%'
	});

$("#guest-info-scrollable").scrollable({
			size: 1,
			clickable: false,
			vertical: true
});
*/

//end of document ready
});
