
$(window).load(function() {
	
	if ( $.browser.msie ) {
	 } else {
		 FullScreenBackground('#bgimg');
		$("#bg").fadeIn('slow', function() {
        	$("body").removeClass("bgPre");
      });
	 }

		$('.wIcon img').tipsy({gravity: 's',html: false});
	
});

$(window).resize(function() {
	FullScreenBackground('#bgimg');
});


function FullScreenBackground(theItem){
	var winWidth=$(window).width();
	var winHeight=$(window).height();
	var imageWidth=$(theItem).width();
	var imageHeight=$(theItem).height();
	var picHeight = imageHeight / imageWidth;
	var picWidth = imageWidth / imageHeight;

	if ((winHeight / winWidth) < picHeight) {
		$(theItem).css("width",winWidth);
		$(theItem).css("height",picHeight*winWidth);
	} else {
		$(theItem).css("height",winHeight);
		$(theItem).css("width",picWidth*winHeight);
	};
	$(theItem).css("margin-left",(winWidth / 2) - (($(theItem).width()) / 2));
	$(theItem).css("margin-top",(winHeight / 2) - ($(theItem).height() / 2));
}



$(document).ready(function(){
	

	soundManager.url = '/javascript/soundmanager/';
	soundManager.flashVersion = 9; // optional: shiny features (default = 8)
	soundManager.useFlashBlock = false; // optionally, enable when you're ready to dive in
	/*
	 * read up on HTML5 audio support, if you're feeling adventurous.
	 * iPad/iPhone and devices without flash installed will always attempt to use it.
	*/


	var iH = $("#content2").height();
	$("#side2_b").css('min-height',iH+'px');
	$("#side_b").css('min-height',iH+'px');
	$(".treeviewRecords").show();
	
	$(".onOffLabel label").click( function (){
		$(this).parents('.onOffLabel').find('div').each(function() { $(this).slideToggle('fast'); });
	});		
	
	
	$(".relativeWithItems .header span").click( function (){
		$(this).parents('.relativeWithItems').find('.itemsContent').each(function() { $(this).slideToggle('fast'); });
	});		
	
	$.expr[':'].icontains = function(obj, index, meta, stack){
	return (obj.textContent || obj.innerText || jQuery(obj).text() || '').toLowerCase().indexOf(meta[3].toLowerCase()) >= 0;
	};	
	
	$.expr[":"].econtains = function(obj, index, meta, stack){
	return (obj.textContent || obj.innerText || $(obj).text() || "").toLowerCase() == meta[3].toLowerCase();
	}	
	
	$("#searchRelInput").keyup( function (){
		var searchValue = $("#searchRelInput").val();
		
		if(searchValue!=""){
			$('.relativeWithItems').find('a').each( function (){
				$(this).parents('.relativeItem').addClass('displayNone');
			});
			
			$('.relativeWithItems').find('a:icontains("'+searchValue+'")').each( function (){
				$(this).parents('.relativeItem').removeClass('displayNone');
			});
		}else{
			$('.relativeWithItems').find('a').each( function (){
				$(this).parents('.relativeItem').removeClass('displayNone');
			});			
		}
	});			
	
});

function getCookieData(){ // decompile data from cookie
cookieContent=getCookie(cookieName)
if(!cookieContent){return}

retrievedData=cookieContent

return retrievedData;

}

// An adaptation of Dorcht's cookie functions.

function setCookie(name, value, expires, path, domain, secure){
if (!expires){expires = new Date()}
document.cookie = name + "=" + escape(value) + 
((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
((path == null) ? "" : "; path=" + path) +
((domain == null) ? "" : "; domain=" + domain) +
((secure == null) ? "" : "; secure")

}

function getCookie(name) {
var arg = name + "="
var alen = arg.length
var clen = document.cookie.length
var i = 0
while (i < clen) {
var j = i + alen
if (document.cookie.substring(i, j) == arg){
return getCookieVal(j)
}
i = document.cookie.indexOf(" ", i) + 1
if (i == 0) break
}
return null
}

function getCookieVal(offset){
var endstr = document.cookie.indexOf (";", offset)
if (endstr == -1)
endstr = document.cookie.length
return unescape(document.cookie.substring(offset, endstr))
}

function deleteCookie(name,path,domain){
document.cookie = name + "=" +
((path == null) ? "" : "; path=" + path) +
((domain == null) ? "" : "; domain=" + domain) +
"; expires=Thu, 01-Jan-00 00:00:01 GMT"
}

