$.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];
  }
});
function fixHeights() {
	var initialMainHeight = $('#main').height();
	if($(window).height() > 718) {
		if (!$('#wrapperbottom').hasClass("bottomFix")) {
			$('#wrapperbottom').addClass("bottomFix");
		}
		$('#wrapperbottom').css('top',719);
		$('#wrapperbottom').height(700);
		$('#main').css('padding-bottom',$(document).height()-initialMainHeight-95);
	} else {
		if ($('#wrapperbottom').hasClass("bottomFix")) {
			$('#wrapperbottom').removeClass("bottomFix");
		}
		$('#wrapperbottom').height(95);
		if(initialMainHeight>615) {
			$('#wrapperbottom').css('top',initialMainHeight+115);
		}
		$('#main').css('padding-bottom',25);
		
	}
	
}
function buildMenus() {
        $("ul.menus").supersubs({ 
            minWidth:    6,   // minimum width of sub-menus in em units 
            maxWidth:    35,   // maximum width of sub-menus in em units 
            extraWidth:  1
                               // due to slight rounding differences and font-family 
        }).superfish({
			delay:0,
			speed:100
			});  // call supersubs first, then superfish, so that subs are 
                         // not display:none when measuring. Call before initialising 
                         // containing tabs for same reason. 
	 $("ul.menus li ul li:last-child").addClass("last");
 	 $("ul.menus li ul li:first-child").addClass("first");
	 $("ul.menus li:last-child").addClass("mlast");
	 $("ul.menus li ul").not(":has(li)").remove();	
}
function loadMain() {
	if ($.getUrlVar('id')!=null) {
		var bodyClass = "mainBg"+$.getUrlVar('id');
		var contentClass = "contentBg";
		if($.getUrlVar('id')==5 || $.getUrlVar('id')==6 || $.getUrlVar('id')==7 || $.getUrlVar('id')==12 || $.getUrlVar('id')==19 || $.getUrlVar('id')==21 || $.getUrlVar('id')==22 || $.getUrlVar('id')==27) {
			var contentClass = "contentBg9";
		}
		$(document.body).addClass(bodyClass);
		$('#content').addClass(contentClass);
	} 
	else {
			$('#content').addClass('contentBg9');
	}
	
	if ($.getUrlVar('type') == "home") {
		$('#content').removeClass('contentBg').addClass('contentBgHome');
	}
	fixHeights();
	buildMenus();
	$(window).resize(function() {	
		fixHeights();
	});
}
function fixWidths() {
	if ($(window).width() >= 700) {
		$('#wrappertop').css('left',($(window).width()-$('#wrappertop').width())/2);
		$('#wrapperbottom').css({'marginLeft':'0', 'marginRight':'auto'});
		$('#wrapperbottom').css('left',0);	
	}
}
function fixIE() {
	fixWidths();
	$(window).resize(function() {	
		fixWidths();
	});
}
