/*
	
	Project Name Global Javascript Functions
	By  - ISITE Design

*/

//start the jQuery functions
$(document).ready(function() {

    // add class to drop downs and buttons for IE <6
    if (document.all) {
        $("#nav li, button").hover(
			function() { $(this).addClass("over"); },
			function() { $(this).removeClass("over"); }
	    );
    } // if document.all

    // add class to html to differentiate Chrome from Safari
    var chrome = /Chrome/;
    if (chrome.test(navigator.appVersion)) $('html').addClass('chrome');

    // Input Setter - see documentation below
    $("#newsletter-signup input, #sitesearch input").inputSetter(1);

    // apply internal span to buttons for backgrounding
    $("button").wrapInner('<span></span>');

    if ($('.home-page').length > 0) {
        var flashvars = { xmlPath: "/_resources/xml/menulinks.xml" };
        var params = { wmode: 'transparent' };
        var attributes = {};

        swfobject.embedSWF("_resources/flash/home.swf", "flashreplace", "940", "319", "9.0.0", "expressInstall.swf", flashvars, params, attributes);


    }
    // test for calendar, hide if there
    if ($('#CalendarReplace').length > 0) {
        $('#CalendarReplace').addClass('hidenonjs');
    }

    // test if we have an email form submission and look for an email form name if we have one
    // this is for the newsletter signup
    if ($('EmailAddress') && $.query.get('email')) {
        $('[name=EmailAddress]').val($.query.get('email'));
    }



});      // document ready / end jquery functions

// newsletter sign-up redirect
function nsu(emailAddy) {
    // /Newsletter.aspx?email={0}
    window.location = '/newslettersignup.aspx?email=' + emailAddy;
}

// clean console.log
function cl(logit){ if(window.console&&window.console.firebug) { console.log(logit) } };//cl()
// example: cl("If you use cl() instead of console.log(), it won't break IE when you forget to take it out.");

/*

	12.19.08 - pdf
	
	Input Setter
	pull label and insert as field. clear with click.	
	optional lower param if == 1, string toLowerCase	

	ex: $("#sitesearch input").inputSetter(1); // makes default text lowercase
		$("#sitesearch input").inputSetter(); // no lowercasing

*/

jQuery.fn.inputSetter = function(lower) {	
	return this.each(function() {
		var $input = $(this);
		var $label = $("label[for='"+$input.attr("id")+"']");
		var labeltext = lower && lower==1 ? $label.text().toLowerCase() : $label.text();
		$label.hide();	
		$input.val(labeltext);		
		$input.focus(function() { if (this.value == labeltext) { this.value = ""; }	})
			  .blur(function() { if (!this.value.length) { this.value = labeltext; } });		
	});
};

function HttpRequest(url, callback, async) {

    function GetCallback() {
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
                http_callback(http_request);
            } else {
                alert('There was a problem with the HTTP request. (HTTP Error ' + http_request.status + ' ' + http_request.statusText + ')');
                return false;
            }
        }
    }

    // validate parameters
    if (typeof (async) == 'undefined') {
        async = true;
    }

    if (typeof (callback) != 'function' && async) {
        alert("No callback defined. A callback must be defined for async requests.");
        return false;
    }

    // these can have multiple copies over function calls
    // thus isolating them from event handler overwritings
    var http_request = false;
    var http_callback = callback;


    // create the httprequest object
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            //http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) { }
        }
    }

    if (!http_request) {
        alert('Your browser does not support HTTP requests.');
        return false;
    }

    if (async) {
        http_request.onreadystatechange = GetCallback;
    }
    http_request.open('GET', url, async);
    http_request.send(null);

    // for non-async requests, we just return the request object when we're done
    if (!async) {
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
                return http_request;
            } else {
                alert('There was a problem with the request. (HTTP Error ' + http_request.status + ' ' + http_request.statusText + ')');
                return false;
            }
        }
    }
}