
// =======================
// Firebug Logging
// ==========================
function log(stuff){
	if(window.console){
		window.console.log(stuff);
	}
}


//=======================
// Account for anchor hashes in URL
//==========================

function goToHash(a){
	a = a?a:window.location.hash;

	if(a == '#login'){
		$.nyroModalManual({url:'/login'});
	}else if(a == '#register'){
		$.nyroModalManual({url:'/register'});
	}else if(a == '#recover-password'){
		$.nyroModalManual({url:'/recover_password'});
	}
}

//=======================
// Initial DOM loaded
//==========================
$(document).ready(function(){
	formDefaults();

//	$('nav.main li').hover(function(){
//		$(this).find('.dropdown').hide().animate({height:'auto',opacity:'toggle'},200);
//	},function(){
//		$(this).find('.dropdown').animate({height:'toggle',opacity:'toggle'},200);
//	});
	$.nyroModalSettings({
		openSelector:'.modal',
		windowResize:false,
		hideContent:function(elts, settings, callback){
			$('#nyroModalWrapper').hide();
			callback();
		}
	});
	
	$('a.modal').nyroModal();
	
	if($.browser.msie){
		$("#ie_browser_notice").slideDown();
	}
	
	goToHash();

	$("#topNav2 li").each(function() {
		if ($(this).find("ul").length > 0) {
			$("<span>").html(" <img src='/img/dropdown-arrow.png'").appendTo($(this).children(":first"));
			//show subnav on hover
			$(this).mouseenter(function() {
				$(this).find("ul").stop(true, true).slideDown();
			});
			//hide submenus on exit
			$(this).mouseleave(function() {
				$(this).find("ul").stop(true, true).slideUp();
			});
		}
		
	});
	
	$('#SearchQForm, #top-search').submit(function(){
		if($(this).attr('id') == 'top-search'){
			var q = $('#SearchQ').val();
		}else{
			var q = $('#SearchQuery').val();
		}
		if(q != ''){
			window.location.href = '/search/q/'+q;
		}
		return false;
	});
});

jQuery.fn.highlight = function (str, className){
    return this.each(function (){
        this.innerHTML = this.innerHTML.replace(
            new RegExp(str, "gi"),
            "<span class=\"" + className + "\">" + str + "</span>"
        );
    });
};

