jQuery.noConflict(); // Gives back $() to prototype

jQuery(document).ready(function () 
	{
		// Find all "menuItem"s, find their background position offset, and passes it to MenuOver
				
		jQuery(".menuItem").each(function(){
			offsets = getBackgroundPosition(jQuery(this));
			MenuOver(jQuery(this), offsets[0]);	
			
			// Extra callback hook, if we want to do something outside of simply changing the hover.
			if (typeof(window.menuCallback) === "function") menuCallback(jQuery(this));
		});
	}
);

jQuery(document).ready(function() {
	//$("a[rel*='external']").attr({ target: "_blank" });
});

function menuCallback(element) {
	// If the title element is set for the element, use this to update the tagline field.
	if(element.attr('title')) {
		element.hover(
		function () {
        	jQuery('#mainMenuTagline').html(element.attr('title'));
      	}, 
      	function () {
       		jQuery('#mainMenuTagline').html('');
      	}
	);

	}
	
	//alert(element.attr('title'));
}

// Returns the background position of an element, as an array of just the numbers.
function getBackgroundPosition(element) {
	bgpos = element.css("background-position");
	// IE Sucks. This is a workaround for it.
	if (typeof(bgpos) === "undefined") {
		bgposx = element.css("background-position-x");
		bgposy = element.css("background-position-y");
		bgpos = bgposx + " " + bgposy;	
	}  
			
	return bgpos.match(/(-)\d{1,5}/g);
}



// Sets the menu over events for the top-level menu items
// element should be a jQuery object
// offset should be X-dimension background position offset.
function MenuOver(element, offset) {
	element.hover(
		function () {
        	element.css("background-position", offset + "px 0px");
      	}, 
      	function () {
       		element.css("background-position", offset + "px -14px");
      	}
	);
}



function picNavOver(tagline) {
	
	$('mainMenuTagline').update(tagline);
}

function picNavOut() {
$('mainMenuTagline').update('');	
	
}

function eseRollOver() {
	$('eseModelOver').show();
	
}

function eseRollOut() {
	$('eseModelOver').hide();
	
}

function showVideoPlayer(elementID)
{
	var so = new SWFObject('mediaplayer.swf','','320','240','7', '#FFFFFF');
  	so.addParam('allowfullscreen','false');
  	so.addVariable('file','assets/Uploads/solcell.flv');
  //	so.addVariable('backcolor','0x000000');
  	so.addVariable('autostart','true');
  	so.write(elementID);
  
	
}

function navigateTo(dest){
	new Effect.Fade('siteLayout', {queue:'end', duration: 0.5, afterFinish: function() {
		new Ajax.Request('/' + dest +'/?flush=1', { method: 'get', onSuccess: function(transport) { 
			$('siteLayout').update(transport.responseText);
			window.location.hash = dest;
			new Effect.Appear('siteLayout', {queue:'end', afterFinish: function(){
			//	if ($('picNav')) showPicNav();
				
			}});
		}});
		
	}});
	
}

function quickNav(dest) {
	window.location.pathname = '/' + dest + '/';
	
	
}

function showPicNav() {
	new	Effect.Appear('picNav1', {duration:0.6});
	new	Effect.Appear('picNav2', {duration:0.6});
	new	Effect.Appear('picNav3', {duration:0.6});
	new	Effect.Appear('picNav4', {duration:0.6});
	new	Effect.Appear('picNav5', {duration:0.6});
	new	Effect.Appear('picNav6', {duration:0.6});
	new	Effect.Appear('picNav7', {duration:0.6});
	new	Effect.Appear('picNav8', {duration:0.6});
	
	
}

function showContactBox() {
	
	new Effect.Opacity('contactBox', {from: 1.0, to: 0.7, duration:0});
	new Effect.BlindDown('contactBox', {fps:99});
	
}

function hideContactBox() {
	Effect.BlindUp('contactBox');
	
}

function loadSchoolList(stateOfAust){
	var blah;
	blah = new Date();
	blah = blah.getTime();
	new Effect.Fade('loadSchools', {queue:'end', duration: 0.5, afterFinish: function() {
		$('loadSchools').update('Loading, please wait...'); 
		$('loadSchools').show();
		new Ajax.Request('/pilot-schools/getSchools/' + stateOfAust +'/?flush=1&ddflkj=' + blah, { method: 'get', onSuccess: function(transport) { 
			if (transport.responseText != "") {
			$('loadSchools').update(transport.responseText);
		} else
		{
			$('loadSchools').update('error'); 
		}
			//window.location.hash = dest;
			new Effect.Appear('loadSchools', {queue:'end', afterFinish: function(){
			//	if ($('picNav')) showPicNav();
				
			}});
		}});
	}});

	
}

//Event.observe(window,'load',function(){
	
//	if (window.location.hash) navigateTo((window.location.hash).sub('#',''));
//	if ($('picNav')) showPicNav();
	//alert('run');
	
	
//});

