$(document).ready(function(){

	//IE speedier hover changes:
	try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {}
	
	//GA Document tracking:
    filetypes = /\.doc$|\.xls$|\.exe$|\.zip$|\.pdf$|\.mp3$|\.psd$/i;
    $("a").each(function(){
		if ( typeof $(this).attr("href") != 'undefined') {
         if ($(this).attr("href").match(filetypes)) {
            var url = $(this).attr("href").replace(/^(http\:\/\/)*(www\.)*(ceridian\.co.uk")*\//i, "")
            $(this).click(function() {pageTracker._trackPageview("/" + url);})
        }
		}
    });
	 
	 //codaSlider instantiation:
	if($('#slider1').length || $('#slider2').length){
			jQuery(window).bind("load", function() {
				jQuery("#slider1").codaSlider()
				jQuery("#slider2").codaSlider()
			});
	};
	
	//video embedding
	if($('div[id*=Vid]').length){
		$.getScript("http://payroll.ceridian.co.uk/hr/jQueryFlash.min.js");
		$.getScript("http://payroll.ceridian.co.uk/hr/videos4.js");
	};

	//fixing advanced selectors for IE:
	$('input[type=text]').focus(function() {$(this).addClass("focus");});
	$('input').blur(function() {$(this).removeClass("focus");});
	$('input[type=text]').addClass("textInput");
	$('.bannerNavIn').mouseover(function(){ $(this).addClass('IEHoverHack');});
	$('.bannerNavIn').mouseout(function(){ $(this).removeClass('IEHoverHack');});
	
	//zebra striped tables:
	$(".tableX tr").removeClass("alt");
	$(".tableX tr:even").addClass("alt");
	$(".noStripes tr").removeClass("alt");
	
	//megadropdowns
	var overlay = $('#overlay');
	var allDDs = $('#headerInsert div.megaDD');

	function materialise(theDD,clicked){
		allDDs.hide();
		clicked.parent().parent().find('.on').removeClass().end().andSelf().addClass('on');
		$(theDD).show();
		overlay.css('opacity','0.46')
				 .show()
				 .click(function(){ banish(); });
	}
	
	function banish(){
		overlay.hide();
		allDDs.hide();
		$('#prodNav, #prodNav li').removeClass();	
	}

	$('#prodNav').click(function(e){
		var clicked = $(e.target);
		if (clicked.is('a')){
			var theDD = clicked.attr('rel');
			if (!$(theDD).is(':visible')) {
				materialise(theDD,clicked);
			} else {
				banish();
			}
		}
		return false;
	});

});