$(document).ready(function(){
						   
	var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
	var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);

    /***********************************************
    * Background resize code
    ***********************************************/
    $(window).load(function(){
        $("#body-background").fadeIn();
        $("#body-background").ezBgResize();
    });

    $(window).bind("resize", function(){
        $("#body-background").ezBgResize();
    });

	if (jQuery.browser.msie && (ie55 || ie6)) {
		
		$(window).load(function(){
			documentwidth = $(document).width();
			backgroundnewheight = $('#headerwrap').height() + $('#mainwrap').height() + $('#footer').height() +76;
			
			if(documentwidth <= '960') {
				$('#body-background').css({ width: "960px" });
				$('#body-background img').css({ width: "960px" });
			}
			else {
				$('#body-background').css({ width: "100%" });
				$('#body-background img').css({ width: "100%" });
			}
			
			if($('#body-background').height() <= backgroundnewheight) {
				$('#body-background').css({ height: backgroundnewheight });
				$('#body-background img').css({ height: backgroundnewheight });
			}
			else {
				$('#body-background').css({ height: "100%" });
				$('#body-background img').css({ height: "100%" });
			}
		});
		
		$(window).resize(function(){
			documentwidth = $(document).width();
			backgroundnewheight = $('#headerwrap').height() + $('#mainwrap').height() + $('#footer').height() +76;
			
			if(documentwidth <= '960') {
				$('#body-background').css({ width: "960px" });
				$('#body-background img').css({ width: "960px" });
			}
			else {
				$('#body-background').css({ width: "100%" });
				$('#body-background img').css({ width: "100%" });
			}
			
			if($('#body-background').height() <= backgroundnewheight) {
				$('#body-background').css({ height: backgroundnewheight });
				$('#body-background img').css({ height: backgroundnewheight });
			}
			else {
				$('#body-background').css({ height: "100%" });
				$('#body-background img').css({ height: "100%" });
			}
		});
		
	}
	
	
	$(window).resize(function(){
        documentwidth = $(document).width();
		
        if(documentwidth <= '960') {
            $('#headerwrap').css({ width: "960px" });
        }
        else {
            $('#headerwrap').css({ width: "100%" });
        }
    });
	


    /***********************************************
    * Check if the document width is less than or equal to 950px, if yes then set the width to 960
    ***********************************************/
    documentwidth = $(document).width();
    if(documentwidth <= '960') {
        $('#headerwrap').css({ width: 960 });
    }
	
    /***********************************************
    * Check for disclaimer lightbox
    ***********************************************/
	$("a[rel='disclaimer']").colorbox({inline:true, href:"#disclaimer-text"});
    
    /***********************************************
    * Check for fields that need to be cleared on click
    ***********************************************/
    $(".clearable").focus(function () {		
        if ( $(this).val() == $(this).attr("title") ) $(this).val("");
    });

    $(".clearable").blur(function () {		
        if ( $(this).val() == '' ) $(this).val($(this).attr("title"));
    });
	
    /*************************************
    * Search box - autocompleter
    *************************************/
     $("#searchbox").autocomplete("/search-autocomplete.php", {
            width: 193,
            selectFirst: false
    });

    $("#searchbox").result(function(event, data, formatted) {
            if(data) window.location = data[1];
    });
	
});
