/*
	# Copyright 2009, Hoop Associates Ltd
	# Hoop Associates   www.thisishoop.com	 mail@hoopassociates.co.uk
*/
var 
heightSet = false, // this var is used to prevent infinite loop in IE6
buildNav = function(elem){
	var span, li;
	$("#" + elem + " ul li").each(
	function(){
		if ($("ul:first", this).length) {
			var 
				ch = $("ul:first", this).css("display") != 'none' ? '&ndash;' : '+', 
				li = this;
			$("a:first", li).prepend('<span class="exp">' + ch + '&nbsp;</span>');
			$('span:first', this).click(function(){
				span = this;
				$("ul:first", li).animate({
					height: 'toggle'
				}, 200, function(){
					$(span).html(($(this).css("display") == "none") ? "+&nbsp;" : "&ndash;&nbsp;");
				});
				return false;
			});
		}
	});
},
fixBugs = function(){
	// FF2/Mac Opacity Bug
	($.browser.mozilla && parseFloat($.browser.version) < 1.9 && navigator.appVersion.indexOf('Mac') !== -1) && $('body').css('-moz-opacity',.999);
	if ($.browser.msie) {
		// IE6 background css flickering bug
		try{document.execCommand('BackgroundImageCache', false, true);} 
		catch(e){};
		// IE6 transaprent PNG background fix
		if (/MSIE ((5\.5)|6)/i.test(navigator.userAgent) && navigator.platform == "Win32"){
			$(".iecsspng").each(function(){
				var bgIMG = $(this).css('background-image');
				if (bgIMG.indexOf(".png") != -1){
					var iebg = bgIMG.split('url("')[1].split('")')[0];
					$(this).css('background-image', 'none');
					$(this).get(0).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + iebg + "',sizingMethod='scale')";
				}
			});
		}
	}
},
SetHeightOfDiv = function(){
	var theDiv = document.getElementById('body'), pageHeight = getPageSizeWithScroll();
	if (theDiv) {
		theDiv.style.height = "auto";
		theDiv.style.height = getPageSizeWithScroll()+"px";
		window.heightSet = true;
	}
},
getPageSizeWithScroll = function(){
	return ($(document).height() - (/msie 6/.test(navigator.userAgent.toLowerCase()) ? 5 : 0))
	if (window.innerHeight && window.scrollMaxY) { // Firefox	  
		yWithScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
	}
	else if (window.innerHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = window.innerHeight;
	}
	else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
	}
	return yWithScroll;
};

String.prototype.text = function(){
	var str = this;
	try { str = decodeURIComponent(str); } 
	catch(e) {}
	str = (str && str.length) ? $.trim(str.replace(/<\S[^><]*>/g, '')) : '';
	return str;
}
String.prototype.safeEscape = function(){
	return encodeURIComponent($.trim(this)).replace(/%20/g, "+").toString();
}

$(function(){
	fixBugs();
	buildNav("nav");
	var resizeTimer = null;
	//
	//$(window).bind('resize', function(){
	//	if (!window.heightSet) {
	//		(resizeTimer) && clearTimeout(resizeTimer);
	//		resizeTimer = setTimeout(SetHeightOfDiv, 100);
	//	} else {
	//		window.heightSet = true;
	//	}
	//	});
	//var checkheight = setInterval(SetHeightOfDiv, 500);
});
//window.onload = SetHeightOfDiv;
