// On Load
$(document).ready(function(){		
	
	positionFooter(); 
	function positionFooter(){
		$("#footer").css({position: "absolute",top:($(window).scrollTop()+$(window).height()-$("#footer").height())+"px"})	
	}
 
	$(window)
		.scroll(positionFooter)
		.resize(positionFooter)
	
	/* Rollovers */
	/***********************************************/	
	$("a img").hover(
	 function(){ this.src = this.src.replace("-out","-over"); },
	 function(){ this.src = this.src.replace("-over","-out"); }
	);
	
});

// Event Handlers
$(function(){

	/* Search Bar Interaction */
	/***********************************************/
	$("input#search").click(function(){
		sv = 'catalogue search'
		if($(this).val().toLowerCase() == sv){
			$(this).val("");
		}
		$(this).blur(function(){
			if($(this).val() == ""){
				$(this).val(sv.toUpperCase());					  
			}
		});
	});

	// Subnav Functionality
	/***********************************************/	
	$("#mainNav ul#main li a").mouseover(function() {
		
		$("#mainNav ul#main li a").each(function() {
			$(this).removeClass('active');
		});
		$("ul.subNav").each(function() {
			$(this).hide();
		});
		
		navItem = $(this).attr('rel');
		$("#subNav-"+navItem).fadeIn('normal');	
		if($(this).attr('rel').length > 0){
			if(!$(this).hasClass('current')){	
				$(this).addClass('active');
			}
		}
		
		$(this).mouseleave(function(){
			if(!$(this).attr('rel').length > 0){										
				$(this).removeClass('active');
			}
		});
		
		$("#subNav-"+navItem+" li a.tertiary").mouseover(function(){		
			c = $(this);					
			c.addClass('active');
			
			dd = $("#subNav-"+navItem+" li."+$(this).parent().attr("class")+" ul");
			$(this).parent().each(function(i){
				$("#subNav-"+navItem+" li ul:eq(i)").hide();						  
			});
			dd.fadeIn('fast');
			
			dd.parent().mouseleave(function(){
				dd.fadeOut('fast');
				c.removeClass('active');
			});

		});
		
	});	
	
	/* FAQ */
	$('ul.accordian a.q').click(function(){
		if($(this).next().css('display') == 'none')
			$(this).next().slideDown('normal');
		else
			$(this).next().slideUp('normal');
		return false;
	});

});