/* Tells jQuery to do all the following code once the body has loaded */
$(document).ready(function(){
						   
	/* ***************************************
	JAVASCRIPT STYLE SHEET
	Inserts a style sheet into the <head>. Contains styles that are ONLY needed for Javascript functionality
	*************************************** */
	$('<link href="css/global-js.css" type="text/css" rel="stylesheet">').appendTo('head');	
	
	
	/* ***************************************
	WIDGETS
	*************************************** */
	
	
	// ACCORDION
	$('#accordion').accordion({ alwaysOpen: false, active: false, autoHeight: false, header: "h3", collapsible: true });
	
	
	
	// CYCLE LITE SLIDESHOW
	
		// Foreword
		$('#slideshow1 div').after('<div><img src="images/foreword2.jpg" width="320" height="466" alt="" /><p>Dancers Scott Clark and Gill Clarke. Different Trains, 1990. Photographer: David Buckland.</p></div> <div><img src="images/foreword3.jpg" width="320" height="466" alt="" /><p>Dancer Gill Clarke. Bird Song, 2004. Photographer: Joel Chester Fildes.</p></div> <div><img src="images/foreword4.jpg" width="320" height="466" alt="" /><p>Dancer Laurent Cavanna. In Plain Clothes, 2006. Photographer: Gautier Deblonde.</p></div> <div><img src="images/foreword5.jpg" width="320" height="466" alt="" /><p>Dancers in performance. The Art of Touch, 1995. Photographer: Sean Hudson.</p></div> <div><img src="images/foreword6.jpg" width="320" height="466" alt="" /><p>Dancer Deborah Saxon. Wanting To Tell Stories, 1993. Photographer: Hugo Glendinning.</p></div>');
		$('#slideshow1').cycle({ fx: 'fade', speed:  1000, timeout:  5000 });
		
		// Collaborators
		$('#slideshow2 div').after('<div><img src="images/collaborators2.jpg" width="320" height="466" alt="" /><p>Dancers Scott Clark and Gill Clarke. Different Trains, 1990. Photographer: David Buckland.</p></div> <div><img src="images/collaborators3.jpg" width="320" height="466" alt="" /><p>Dancer Gill Clarke. Bird Song, 2004. Photographer: Joel Chester Fildes.</p></div> <div><img src="images/collaborators4.jpg" width="320" height="466" alt="" /><p>Dancer Laurent Cavanna. In Plain Clothes, 2006. Photographer: Gautier Deblonde.</p></div> <div><img src="images/collaborators5.jpg" width="320" height="466" alt="" /><p>Dancers in performance. The Art of Touch, 1995. Photographer: Sean Hudson.</p></div> <div><img src="images/collaborators6.jpg" width="320" height="466" alt="" /><p>Dancer Deborah Saxon. Wanting To Tell Stories, 1993. Photographer: Hugo Glendinning.</p></div>');
		$('#slideshow2').cycle({ fx: 'fade', speed:  1000, timeout:  5000 });
	
		
		
	/* ***************************************
	EQUAL HEIGHTS
	Sets the height of all elements in a row
	to the height of the tallest element
	*************************************** */	
	$('ul.listings').equalHeights();
	
		
		
	/* ***************************************
	LOGIN FORM	
	*************************************** */
	// CREATE <OL> FOR NOT LOGGED IN LINKS
	$('#login h2').after('<ol id="login-menu"><li id="sign-in"><a href="#form-login">Sign in</a></li></ol>');
	$('#register, #help').appendTo('#login-menu');
	
	// SHOW/HIDE LOGIN FORM
	$('#login').addClass('hidden');
	$('#form-login, #password').hide();
	$('#sign-in a').click(function() { 
		$('#login').toggleClass('hidden');
		$('#form-login, #password').toggle('slow');
		return false
		}).show();

		
	
	/* ***************************************
	DIALOGUE BOXES	
	*************************************** */
	
		// Scrapbook
		$('.scrapbook-area').hide();
		$('.scrapbook-area').prepend('<p class="close"><span>Close</span></p>');
		$('.scrapbook').click(function(){
			$(this).parent().next('.scrapbook-area').toggle('slow');
			return false
		}).show();
		
		$('.close').click(function(){
			$(this).parent().toggle('slow');   
		}).show();
		
		// Metadat pop-up (Using jTip)
		$('.jTip').show(); /* makes icon/link visible again after body has finished loading */
	
		
		
	/* ***************************************
	OVER LABELS
	For smal forms. Positions labels over fields
	*************************************** */
	$('#login form').addClass('over-label');
	
	if ($('#login_u').length != 0) { 
		if (($('#login_u').val()).length != 0) {
		   $('#login_u').prev('label').addClass('hidden');
		};
  	};
	
	if ($('#login_p').length != 0) { 
		if (($('#login_p').val()).length != 0) {
		   $('#login_p').prev('label').addClass('hidden');
		};
	};	
	
	$('#login form :input').focus(function() {
		$(this).prev('label').addClass('hidden');
	});
	
	$('#login form :input').blur(function() { 
		if ($(this).val() == '') { 
			$(this).prev('label').removeClass('hidden');
		}
		else ($(this).prev('label').addClass('hidden'));
	});

		
	
	/* ***************************************
	OPEN LINKS IN NEW WINDOW	
	1. Looks for all links with rel="external" and opens them in a new window
	2. Adds custom title attribute based on file type
	*************************************** */	
	$('a[href$=".pdf"]').attr('title','PDF Document - Opens in a new window').click( function() {
		window.open( $(this).attr('href') );
		return false;
	});
		


		
/* ***************************************
DON'T DELETE - End of code run once body has loaded
*************************************** */
});
	
	
		
/* ***************************************
AJAX	
*************************************** */

function loadaajaxdancers(id) {
	
	// Dancer Profiles
	// used for the dancers list page (index.php?view=dancers) to load via ajax load comand into dom id #dancer-profile	
	$('#dancer-profile').load('recordajax.php?id='+id+'&ajaxtype=dancerajax');return false;
	//$('#dancer-profile').load('recordajax.php?id='+id+'&ajaxtype=dancerajax&debug=1');return false; // debug version	
}
