$(document).ready(function(){
	$('ul.sf-menu').superfish();
	if ($.browser.safari) {
		$('.sf-menu').css('font-size','.65em');
		$('#user input[@type=text]').css('top','0');
		$('.sf-menu a').css('padding-top','12px');
		$('.sf-menu li li a').css('padding','3px');
	}
	$('#navigation a#'+nav_id).addClass('nav_active');
	fixNav();
	$('form[@name=user]').submit(function(){
		var msg = check_top_login();
		if (msg == '') {
			return true;
		} else {
			alert(msg);
			return false;
		}
	});
	if ($('.callout').length > 0) {
		$('.callout_txt').equalizeCols();
		if (!($.browser.safari || ($.browser.msie && parseInt($.browser.version) < 7))) {
			$('.callout').corner("bottom 10px");
		}
	}
	if ($('.wide_callout').length > 0) {
		$('.wide_callout_inside').equalizeCols();
	}
	if (typeof sIFR == "function"){
		//sIFR.bHideBrowserText = true;
		sIFR.setup();
		sIFR.replaceElement("h2.white", named({sFlashSrc: "/assets/flash/badaboombb.swf", sColor: "#FFFFFF", sCase: "upper", sWmode: "transparent", sFlashVars: ""}));
		sIFR.replaceElement("h2", named({sFlashSrc: "/assets/flash/badaboombb.swf", sColor: "#008752", sCase: "upper", sWmode: "transparent", sFlashVars: ""}));
		sIFR.replaceElement("h3.white", named({sFlashSrc: "/assets/flash/badaboombb.swf", sColor: "#FFFFFF", sCase: "upper", sWmode: "transparent", sFlashVars: ""}));
		sIFR.replaceElement("h3", named({sFlashSrc: "/assets/flash/badaboombb.swf", sColor: "#008752", sCase: "upper", sWmode: "transparent", sFlashVars: ""}));
		sIFR.replaceElement(".callout_hdr", named({sFlashSrc: "/assets/flash/badaboombb.swf", sColor: "#FFFFFF", sCase: "upper", sWmode: "transparent", sFlashVars: "textalign=center&offsetTop=2"}));
		sIFR.replaceElement(".wide_callout_hdr span", named({sFlashSrc: "/assets/flash/badaboombb.swf", sColor: "#FFFFFF", sCase: "upper", sWmode: "transparent", sFlashVars: "textalign=center&offsetTop=4"}));
		sIFR.replaceElement("#wallpaper_callout_txt", named({sFlashSrc: "/assets/flash/badaboombb.swf", sColor: "#fff797", sCase: "upper", sWmode: "transparent", sFlashVars: ""}));
		sIFR.replaceElement(".label_txt", named({sFlashSrc: "/assets/flash/badaboombb.swf", sColor: "#fcf296", sCase: "upper", sWmode: "transparent", sFlashVars: "textalign=right"}));
	}
	setTimeout("closeMsgs()", 120000);
});
$.fn.superfish.defaults = {
	hoverClass:    'sfHover',          // the class applied to hovered list items
	//pathClass:   'overideThisToUse', // the class you have applied to list items that lead to the current page
	pathLevels:    1,                  // the number of levels of submenus that remain open or are restored using pathClass
	delay:         700,                // the delay in milliseconds that the mouse can remain outside a submenu without it closing
	animation:     {opacity:'show'},   // an object equivalent to first parameter of jQuery�s .animate() method
	speed:         'normal',           // speed of the animation. Equivalent to second parameter of jQuery�s .animate() method
	autoArrows:    false,               // if true, arrow mark-up generated automatically = cleaner source code at expense of initialisation performance
	dropShadows:   false,               // completely disable drop shadows by setting this to false
	disableHI:     false,              // set to true to disable hoverIntent detection
	onInit:        function(){},       // callback function fires once Superfish is initialised � 'this' is the containing ul
	onBeforeShow:  function(){},       // callback function fires just before reveal animation begins � 'this' is the ul about to open
	onShow:        function(){},       // callback function fires once reveal animation completed � 'this' is the opened ul
	onHide:        function(){}        // callback function fires after a sub-menu has closed � 'this' is the ul that just closed
};
function check_top_login() {
	var errors = new Array();
	var user_email = $('input[@name=user_email]').val();
	var user_pswd = $('input[@name=user_password]').val();
	if (user_email == '') errors.push('Please enter your email address');
	if (user_pswd == '') {
		errors.push('Password is required');
	} else if (user_pswd.length < 8) {
		errors.push('Password must be 8 characters');
	}
	var msg = '';
	for(e in errors) {
		msg += errors[e]+"\n";
	}
	return msg;
}
function fixNav() {
	var i = 0;
	while ($('.sf-menu').get(0).offsetHeight > parseInt($('#navigation').css('height'))) {
		var pdg = parseInt($('.sf-menu a').css('padding-left')) - 1;
		$('.sf-menu a').css('padding-left', pdg+'px');
		//alert('set: '+pdg+"\nactual: "+$('.sf-menu a').css('padding-left'));
		i++;
		if (i > 10 || pdg < 3) break;
	}
	i = 0;
	var fsz = 9;
	while ($('.sf-menu').get(0).offsetHeight > parseInt($('#navigation').css('height'))) {
		$('.sf-menu li.top').css('font-size','.'+fsz+'em');
		fsz--;
		i++;
		if (i > 10 || fsz < 5) break;
	}
}
function closeMsgs() {
	$('#msgs').fadeOut();
}
