var openemployment = false;

var daffys = function() {
	
	
	function init()
	{
		// set up header roll overs
		$(".module .header").hover(
			function() { $(this).parent().addClass("hover"); },
			function() { $(this).parent().removeClass("hover"); });
	
		// listen for module clicks
		$(".module .header").click(	_onModuleClick );
		
		// listen for main menu clicks
		$("#navigation ul li a").click( _onNavClick );
		
		// initialize scroll
		$('html,body').scrollTop(0);
		
		$('#inside-scroller').marquee('brandscroll');
		
		// footer
		_initFooter();
		
	}
	
	// handles main menu click events
	// scrolls to module and attempts top open
	function _onNavClick( $event )
	{
		if( $(this).attr("id") == "employment"){
			
			openemployment = true;
			//alert('employment: '+openemployment);
		}
		
		$event.stopImmediatePropagation();
		
		var id = $(this).attr("class");
		var padding = 12;
		var speedPerPixel = 1.75;
		var currScroll = $('html,body').scrollTop();
		var targScroll = $(".module-wrapper #module-"+id).offset().top - padding;
		var time = Math.abs(currScroll-targScroll)*speedPerPixel;
		
		$('html,body').animate({scrollTop: targScroll},
			time,
			constants.animation.ease
		);
		debug.trace( "attempt to open module " + id );
		moduleManager.openModule( id );
		
		return false;
	}
	
	// toggles open/close module
	function _onModuleClick( $event )
	{
		$event.stopImmediatePropagation();
		
		module = $(this).parent();
		id = module.attr("id").split("-")[1];
		
		if( id != "brands"){
			moduleManager.toggleModule( id );
		}
		
		
		return false;
	}
	
	function _initFooter()
	{
		$("#footer ul li a.popup").bind("click", _onPopupFooterClick );
	}
	
	function _onPopupFooterClick()
	{
		var myW = window.open($(this).attr("href"), "daffys-legal", "height=600,width=550,scrollbars=yes,resizable=yes,statusbar=yes,toolbar=yes"); 
		return false;
	}
	
	return {
		init: init
	};
}();
$(document).ready( function() {

	daffys.init();
	
	//$('.module.brands .header a').click(brandsHead);
	
});

function brandsHead(pShowScroller){
	if(pShowScroller){
		$('#brand-scroller').show();
		$('#brand-title').hide();
	}else{
		$('#brand-scroller').hide();
		$('#brand-title').show();
	}
}
