/* 

	HOB Global Javascript Functions
	By Bryan Ledford and friends | ISITE Design

*/

//start the jQuery functions
$(document).ready(function() {
	
	$.getScript = function(url, callback, cache){
		$.ajax({
				type: "GET",
				url: url,
				success: callback,
				dataType: "script",
				cache: cache
		});
	};
	
	// track this page view
	$.getScript("/_resources/js/analytics.js", null, true);
	
	// track links to docs and external sites
	$.getScript("/_resources/js/taglinks.js", null, true);
	
	// flash detection
	$.getScript("/_resources/js/swfobject.js", null, true);
	
	$(".english a.adults").click(function () {
		launchCourse("/htdocs/en/a", "9");
		return false;
	});
	$(".english a.young").click(function () {
		launchCourse("/htdocs/en/y", "9");
		return false;
	});
	$(".english a.teens").click(function () {
		launchCourse("/HOB_teens_en.html", "6");
		return false;
	});
	$(".english a.kids").click(function () {
		launchCourse("/HOB_kids_en.html", "6");
		return false;
	});
	$(".spanish a.adults").click(function () {
		launchCourse("/htdocs/es/a", "9");
		return false;
	});
	$(".spanish a.young").click(function () {
		launchCourse("/htdocs/es/y", "9");
		return false;
	});
	$(".spanish a.teens").click(function () {
		launchCourse("/HOB_teens_es.html", "6");
		return false;
	});
	$(".spanish a.kids").click(function () {
		launchCourse("/HOB_kids_es.html", "6");
		return false;
	});
	
	// add class "last" to the last li in any list.  Used as a styling hook since :last-child isn't widely supported via css.  thank you jquery.
    $("ul li:last-child").addClass("last");

});// document ready / end jquery functions


/* clear search field on click - made into plugin so it can easily be used more than once. */
jQuery.fn.inputClear = function() {
	return this.focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
};

// alternate version of the above. pull label and insert as field. clear with click.
jQuery.fn.inputSetter = function() {

	return this.each(function() {

		var $input = $(this);
		var $label = $("label[for='"+$input.attr("id")+"']");
		var labeltext = $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;
			}
		});

	});
};

// course launching
function launchCourse(url, fpversion)
{
	if (swfobject.hasFlashPlayerVersion(fpversion))
	{
		document.location.href = url;
	}
	else
	{
		document.location.href = "flash.html";
	}
}


// clean console.log.  Wont break IE6 if you leave it in your code.  cl("stuff to log")
function cl(logit){ if(window.console&&window.console.firebug) { console.log(logit) } };//cl()

// Swith between languages
function switchpage(select) { 
    var index; 

  for(index=0; index<select.options.length; index++) 
    if(select.options[index].selected) 
      { 
        if(select.options[index].value!="") 
          window.location.href=select.options[index].value; 
        break; 
      } 
}