// extending browser detect of IE6 b/c of IE7 bug...
// credit: http://jamazon.co.uk/web/2008/03/14/jquerybrowserversion-doesnt-recognise-ie7/
$.browser.msie6 = $.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent);

$(document).ready(function(){
// set body.has-js to cue CSS changes
	$("body").addClass("has-js");
// search input reset
	$("#searchbox-main").focus(function() {
		if ( $(this).val() == "search the site") {
			$(this).val('');
		}
	}).blur(function() {
        	if ( $(this).val() == "") {
        		$(this).val('search the site');
        	}
        });
// Nav Tabs
	$("li.welfare").addClass("show");
	$("body.pension li.pension").addClass("show").parent().parent().find("li.welfare").removeClass("show"); // should be an IF...
	$("#mainmenu .welfare a.tabs, a#welfare-ie").click(function(){
		$("li.welfare .smenubox").slideDown("slow").parent().addClass("show");
		$("li.pension .smenubox").slideUp("slow").parent().removeClass("show");
		$("body").removeClass("jq-pension").addClass("jq-welfare");
		return false;
	});
	$("#mainmenu .pension a.tabs, a#pension-ie").click(function(){
		$("li.pension .smenubox").slideDown("slow").parent().addClass("show");
		$("li.welfare .smenubox").slideUp("slow").parent().removeClass("show");
		$("body").removeClass("jq-welfare").addClass("jq-pension");
		return false;
	});
// LifeEvents Menu
	$("body.lifeevents.top li.lifeevents div.smenubox").slideDown("slow");
	$("li.lifeevents h2 a").attr('href','#').click(function(){
		$(this).parent().parent().children("div.smenubox").slideToggle();
		return false;
	});

// Staff hover bios WITH IE6 workaround --rest of IE6 rules below
	if ($.browser.msie && (parseInt($.browser.version) < 7) ) {
		//madness
		$("#group li").append('<a class="ie6sux" href="#">&nbsp;&nbsp;&nbsp;&nbsp;</a>');
		$("#group li a").hover(function() {
			$(this).parent().addClass("sfhover");
		}, function() {
			$(this).parent().removeClass("sfhover");
		});
	} else {
		$("#group>ul>li").hover(function() {
			if ( $("#group>ul").hasClass("halt") ) {
				
			} else {
				$(this).children(".show-me").fadeIn(1000).parent("#group li").addClass("has-open");
			}
		}, function() {
			if ( $(this).hasClass("has-open") && $("#group>ul").hasClass("halt") ) {
				
			} else {
				$(this).children(".show-me").hide().parent("#group li").removeClass("has-open");
			}
		}).click(function() {
			if ( $("#group>ul").hasClass("halt") ) {
				$(".show-me").removeClass("open").hide().parent("#group li").removeClass("has-open").parent("#group>ul").removeClass("halt");
			} else {
				$(this).children(".show-me").show().addClass("open").parent().parent("#group>ul").addClass("halt");
			}
		});
	}

//News item bubble fix for IE
//credit: http://www.vancelucas.com/article/fixing-ie7-z-index-issues-with-jquery/
	if ($.browser.msie) {
		if (parseInt($.browser.version) <= 7) {
			$(function() {
				var zIndexNumber = 5000;
				$(".annc li, #staff>*").each(function() {
					$(this).css('zIndex', zIndexNumber);
					zIndexNumber -= 10;
				});
				var zIndexNumber = 5000;
				$("#group li").each(function() {
					$(this).css('zIndex', zIndexNumber);
					zIndexNumber += 10;
				});
			});
			$(".annc ul.menu li a").hover(function(){
				$(this).children("span.pops").show();
			}, function() {
				$(this).children("span.pops").hide();
			});
			$("a.tabs-ie").click(function(){
				return false;
			});
		}
	}
});