/* ============================================================================= */
/* =====------===  boilerplate functions  ===------===== */

// usage: log('inside coolFunc', this, arguments);

window.log = function(){
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  if(this.console) {
      arguments.callee = arguments.callee.caller;
      console.log( Array.prototype.slice.call(arguments) );
  }
};

(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});

// HASH STRING PARSER (replaces query string parser - for Contact Us pages)

hashSt = function hashSt(ji) {
	if (window.location.hash.length > 1) {   
		var hu = window.location.hash;
		if (hu.search('\\?') > -1) {
			hu = (hu.split("?"))[1];
			window.log("?: "+hu);
		}
		else {
			hu = hu.substring(1);
			window.log("#: "+hu);
		}
		var gy = hu.split("&");	
		window.log("gy: "+gy);
		for (var i = 0; i < gy.length; i++) {
			var ft = gy[i].split("=");
			if (ft[0] == ji) {
				return ft[1];
			}
		}
	}
	return '';
};


/* ============================================================================= */
/* =====------===   jQuery plugins  ===------===== */

/*------------------------------------------------------------------------------
Function:       FunctionHandler()
Author:         Aaron Gustafson (aaron at easy-designs dot net)
Creation Date:  2009-04-02
Version:        0.2
Homepage:       http://github.com/easy-designs/FunctionHandler.js
License:        MIT License (see homepage)
Note:           If you change or improve on this script, please let us know by
                emailing the author (above) with a link to your demo page.
------------------------------------------------------------------------------*/
(function($){
  
  var
  FunctionHandler = {
    'version': '0.2'
  },
  pages = {};
  
  function initialize()
  {
    var body_id = $('body').attr('id');
    if ( body_id != false &&
         typeof( pages[body_id] ) != 'undefined' ){
      run( pages[body_id] );
    }
    if ( typeof( pages['*'] ) != 'undefined' )
    {
      run( pages['*'] );
    }
  }
  $(document).ready(initialize);

  /**
   * FunctionHandler::register()
   * registers a callback for a given page
   *
   * @param mixed id - either an array or a string; strings can be single IDs, *, 
   *                   or a comma-separated list
   * @param function callback - the function to call on the page
   * 
   * @return bool - true for success, false for failure
   */
  FunctionHandler.register = function( id, callback )
  {
    
    // fail if we don't get the right stuff
    if ( ( typeof( id ) != 'string' &&
           ! ( id instanceof Array ) ) ||
         typeof( callback ) != 'function' )
    {
      return false;
    }
    
    // create the page array if need be
    if ( typeof( id ) == 'string' &&
         id.indexOf( ', ' ) != -1 )
    {
      id = id.split(', ');
    }
    
    // id is an array?
    if ( id instanceof Array )
    {
      for ( var i=id.length-1; i >= 0; i-- )
      {
        add( id[i], callback );
      }
    }
    
    // id is a string
    else
    {
      add( id, callback );
    }
    
    return true;
  };
  
  function add( id, callback )
  {
    if ( typeof( pages[id] ) == 'undefined' ){
      pages[id] = [];
    }
    pages[id].push( callback );
  }
  
  function run( arr )
  {
    if ( ! ( arr instanceof Array ) )
    {return;}
    for ( var i=arr.length-1; i >= 0; i-- )
    {arr[i]();}
  }
  
  // set the global object
  window.FunctionHandler = FunctionHandler;
  
  window.log("FunctionHandler is ready.");
  
})(jQuery);
/**
* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne brian(at)cherne(dot)net
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);


/* ============================================================================= */
/* =====------===   function handles  ===------===== */

//<![CDATA[
FunctionHandler.register('*', function(){

	// ------------- GOOGLE ANALYTICS ----------------//

	$(function(){
	
		window.log("FunctionHandler: * scripts are running!");
		
		window._gaq = [['_setAccount','UA-22720780-1'],['_trackPageview'],['_trackPageLoadTime'],['_setAccount','UA-6101188-25'],['_trackPageview'],['_trackPageLoadTime']];
		Modernizr.load({
			load: ('https:' == location.protocol ? '//ssl' : '//www') + '.google-analytics.com/ga.js'
		});
	
	});
	
	// ------------- FAQ interactions ----------------//
	
	$(function(){
	
		$(".faq_answer").slideUp(0);
	
		$(".faq_question").each(function(){
			
			var entry_id = $(this).data("entry_id");
			
			$(this).click(function(e){
			
				$("#faq_answer_" + entry_id).slideToggle();
				e.preventDefault();
			
			});
			
			$("<p><a href=\"\" class=\"gray\">&uarr; (close)</a></p>").addClass("faq_close").data("entry_id",entry_id).appendTo("#faq_answer_" + entry_id);
		
		});
		
		$(".faq_close").each(function(){
			
			var entry_id = $(this).data("entry_id");
			
			$(this).click(function(e){
			
				$("#faq_answer_" + entry_id).slideUp();
				e.preventDefault();
			
			});
		
		});	
	
	});
	
	// -------------- HASH STRING behaviors ------------- //

	$(function(){
	
		var play_video = (window.location.hash).match(/playVideo/i);
		if (play_video){
		
			window.log("hash: " +  window.location.hash);
			window.log("playVideo: " + hashSt('playVideo'));
			
			window.log("YouTube video flag detected...");
			var ytid = $("#primary_video").data("ytid");
			
			window.log("YouTube video playing: "+ ytid);
			$("<a />")
				.attr("href","http://www.youtube.com/watch?v="+ytid)
				.attr("id","play_video_a")
				.addClass("lightbox")
				.appendTo("body");
				
			window.setTimeout(
				function(){$("#play_video_a").click();},
				300
				);

		}

	});

	
});
//]]>
