/*
	HAS Europe
	common.js
	
	Includes various javascript functions that are common to all pages
*/

$(document).ready(function() {
	
	// Zebra Stripe table rows
	$(".datatable tbody tr:even").addClass("even");
	$(".details p:even").addClass("even");
		   
	if($('dl').length > 0) {	   
		$('dl').accordion({ autoHeight: false });
	}
	
	$('a[rel=popup]').click(function() {
		var url = $(this).attr('href');
		window.open(url);
		return false;
	});
		   
	$('body').removeClass('nojs').addClass('jsenabled');

	// If the browser is IE6, replace the homepage PNG with a GIF version
	// If not, perform all hover-based functions
	var $ie6 = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
	if ($ie6) {
		var $oldimage = $('#home #aside img').attr("src");
		var $newimage = $oldimage.replace("png", "gif");
		$('#home #aside img').attr("src", $newimage);
	}
	else {
		menuHover();
		linkHover();
		ancillaryHover();
	}
	
	// Apply fading hover state to main menu
	
	function menuHover() {
	
		$('#header li')
			.find('a')            
			.append('<span class="hover" />').each(function () {                    
				var $span = $('> span.hover', this).css('opacity', 0);                    
				$(this).hover(function () {                      
					$span.stop().fadeTo("fast", 1);                    
				}, function () {                      
					$span.stop().fadeTo("fast", 0);                    
				});                
		});
		
	}
		
	// Add sliding arrow to masthead links

	function linkHover() {

		$('#home #main a, #footer .right li a')
			.append('<span class="hover" />').each(function () {                    
				var $span = $('> span.hover', this).css('opacity', 0);                    
				$(this).hover(function () {                      
					$span.stop().animate({"left" : "-4px", "opacity" : 1}, "fast");                    
				}, function () {                      
					$span.stop().animate({"left" : "-16px", "opacity" : 0}, "fast");                     
				});                
		});
	
	}	
	
	function ancillaryHover() {
		
		$("#ancillary .section").append('<span class="ancillaryhover">&nbsp;</span>');
		$(".ancillaryhover").css("opacity", 0);
	
		$("#ancillary .section").hover(function() {
			$(".ancillaryhover", this).stop().animate({"opacity" : 1}, "fast");										
		}, function() {
			$(".ancillaryhover", this).stop().animate({"opacity" : 0}, "fast");					
		});
		
	}
	
});
