
$.extend({
getUrlVars: function(){
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
	hash = hashes[i].split('=');
	vars.push(hash[0]);
	vars[hash[0]] = hash[1];
}
return vars;
},
  
getUrlVar: function(name){
	return $.getUrlVars()[name];
}
	
});



//Code for translate drop down menu
$(document).ready(function(){  
		$("ul.subnav").parent().append("<span></span>");
		$("ul.topnav li span").click(function() { //When trigger is clicked...
			
			//Following events are applied to the subnav itself (moving subnav up and down)
			$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
	
			$(this).parent().hover(function() {
			}, function(){	
				$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
			});
	
			//Following events are applied to the trigger (Hover events for the trigger)
			}).hover(function() { 
				$(this).addClass("subhover"); //On hover over, add class "subhover"
			}, function(){	//On Hover Out
				$(this).removeClass("subhover"); //On hover out, remove class "subhover"
		});
});  

//Code for school drop down menu
$(document).ready(function() {


		function megaHoverOver(){
			$(this).find(".sub").stop().fadeTo('fast', 1).show(); 
			(function($) {
				
				jQuery.fn.calcSubWidth = function() {
					rowWidth = 0;
					
					$(this).find("ul").each(function() {
						rowWidth += $(this).width(); 
					});
				};
			})(jQuery); 
		
			if ( $(this).find(".row").length > 0 ) { 
		
				var biggestRow = 0;	
		
				$(this).find(".row").each(function() {	
					$(this).calcSubWidth(); 
					
					if(rowWidth > biggestRow) {
						biggestRow = rowWidth;
					}
				});
		
				$(this).find(".sub").css({'width' :biggestRow}); 
				$(this).find(".row:last").css({'margin':'0'});  
		
			} else { 
		
				$(this).calcSubWidth();  
				$(this).find(".sub").css({'width' : rowWidth}); 
		
			}
		}
		
		function megaHoverOut(){
		  $(this).find(".sub").stop().fadeTo('fast', 0, function() { 
			  $(this).hide();  
		  });
		}

var config = {
     sensitivity: 2,
     interval: 100, 
     over: megaHoverOver,
     timeout: 500, 
     out: megaHoverOut 
};

$("ul#topnav li .sub").css({'opacity':'0'});
$("ul#topnav li").hoverIntent(config); 

});

var currentURL = window.location.href;
var splitOne = currentURL.substring(currentURL.lastIndexOf("//") + 2);
var splitTwo = splitOne.split('.sharpschool.net/');

var byName = $.getUrlVar('hl');

if(byName == 'en')
{
	$(document).ready(function(){ 
		$('ul.topnav li span').click(function() {
			$('ul.subnav').remove();
			parent.location.replace('http://'+splitTwo[0]+'.sharpschool.net');
		});
	});
}

