/* Javascript functions for the LALA Studio Website */
/* (c) Stephan Reed 2009 */

function getHTTPObject() {
	var xmlHttp;
  	try {
    	/* Firefox, Opera 8.0+, Safari */
    	xmlHttp=new XMLHttpRequest();
  		}
  	catch (e) {
    	/* newer IE */
    	try {
    	  	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    		}
    	catch (e) {
      		/* older IE */
      		try {
        		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      			}
      		catch (e) {
        		alert("Your browser is old and does not have AJAX support!");
        		return false;
      			}
    		}
  		}
	return xmlHttp;
}

function scrollPhotos( pos ) {
 // Scroll the photo section
 var to = pos + "px";

 $('#pBox').scrollTo( pos, 1000, {axis:'x', easing: 'easeInOutQuad'} );
}

function getPage( page, artist ) {
 // Get a page via AJAX

 $('#loader').show();
 $('#middle').html( "" );			// Gets rid of scroll-bars if there are any

 var xmlHttp = getHTTPObject();

 xmlHttp.onreadystatechange=function() {
  	if(xmlHttp.readyState==4) {
		// Set the new content
   		$('#middle').html( xmlHttp.responseText );

		// Set the new title
		document.title = $('#title').val();

		var bio = $('#bio').val();
		var artist = $('#artist').val();

		// Set the bio link if there is one
		var side = "";
	
		if( bio == 1 )
			side += "<a href=\"#\" onClick=\"showBio(); return false;\">Artist's Bio</a><br />";
	
		// Set the PDF link if there is one
		var pdf = $('#pdf').val();
		if( pdf != "" )
			side += "<a href=\"" + pdf + "\">Download PDF</a>";
	
		$('#side').html( side );

		// Hide the loader animation
		$('#loader').hide();
  		}
 	}

var url = "index_ajax.php?page=" + page;

if( page == "artist" || page == "bio" )
	url += "&artist=" + artist;


xmlHttp.open("GET", url, true);
xmlHttp.send(null);
// alert( url );
}

function showBio( ) {
 $('#artist_bio').fadeIn("slow");
}

function hideBio( ) {
 $('#artist_bio').fadeOut("slow");
}

function sendEmail( ) {
 // Submit the email form using AJAX
 var xmlHttp = getHTTPObject();

 xmlHttp.onreadystatechange=function() {
  	if(xmlHttp.readyState==4) {
		// Set the new content
   		$('#middle').html( xmlHttp.responseText );

		// Hide the loader
 		$('#loader').hide();
  		}
 	}

 var e_name = escape( $('#name').val() );
 var e_email = escape( $('#email').val() );
 var e_msg = escape( $('#msg').val() );

 var url = "send_mail.php?name=" + e_name + "&email=" + e_email + "&msg=" + e_msg;

 xmlHttp.open("GET", url, true);
 xmlHttp.send(null);
// alert( url );

 $('#loader').show();
 $('#middle').html( "" );			// Gets rid of scroll-bars if there are any
}
