/**
 * Copyright (c) 2005 - 2010, James Auldridge
 * All rights reserved.
 *
 * Licensed under the BSD, MIT, and GPL (your choice!) Licenses:
 *  http://code.google.com/p/cookies/wiki/License
 *
 */
var jaaulde = window.jaaulde || {};
jaaulde.utils = jaaulde.utils || {};
jaaulde.utils.cookies = ( function()
{
	var resolveOptions, assembleOptionsString, parseCookies, constructor, defaultOptions = {
		expiresAt: null,
		path: '/',
		domain:  null,
		secure: false
	};
	/**
	* resolveOptions - receive an options object and ensure all options are present and valid, replacing with defaults where necessary
	*
	* @access private
	* @static
	* @parameter Object options - optional options to start with
	* @return Object complete and valid options object
	*/
	resolveOptions = function( options )
	{
		var returnValue, expireDate;

		if( typeof options !== 'object' || options === null )
		{
			returnValue = defaultOptions;
		}
		else
		{
			returnValue = {
				expiresAt: defaultOptions.expiresAt,
				path: defaultOptions.path,
				domain: defaultOptions.domain,
				secure: defaultOptions.secure
			};

			if( typeof options.expiresAt === 'object' && options.expiresAt instanceof Date )
			{
				returnValue.expiresAt = options.expiresAt;
			}
			else if( typeof options.hoursToLive === 'number' && options.hoursToLive !== 0 )
			{
				expireDate = new Date();
				expireDate.setTime( expireDate.getTime() + ( options.hoursToLive * 60 * 60 * 1000 ) );
				returnValue.expiresAt = expireDate;
			}

			if( typeof options.path === 'string' && options.path !== '' )
			{
				returnValue.path = options.path;
			}

			if( typeof options.domain === 'string' && options.domain !== '' )
			{
				returnValue.domain = options.domain;
			}

			if( options.secure === true )
			{
				returnValue.secure = options.secure;
			}
		}

		return returnValue;
		};
	/**
	* assembleOptionsString - analyze options and assemble appropriate string for setting a cookie with those options
	*
	* @access private
	* @static
	* @parameter options OBJECT - optional options to start with
	* @return STRING - complete and valid cookie setting options
	*/
	assembleOptionsString = function( options )
	{
		options = resolveOptions( options );

		return (
			( typeof options.expiresAt === 'object' && options.expiresAt instanceof Date ? '; expires=' + options.expiresAt.toGMTString() : '' ) +
			'; path=' + options.path +
			( typeof options.domain === 'string' ? '; domain=' + options.domain : '' ) +
			( options.secure === true ? '; secure' : '' )
		);
	};
	/**
	* parseCookies - retrieve document.cookie string and break it into a hash with values decoded and unserialized
	*
	* @access private
	* @static
	* @return OBJECT - hash of cookies from document.cookie
	*/
	parseCookies = function()
	{
		var cookies = {}, i, pair, name, value, separated = document.cookie.split( ';' ), unparsedValue;
		for( i = 0; i < separated.length; i = i + 1 )
		{
			pair = separated[i].split( '=' );
			name = pair[0].replace( /^\s*/, '' ).replace( /\s*$/, '' );

			try
			{
				value = decodeURIComponent( pair[1] );
			}
			catch( e1 )
			{
				value = pair[1];
			}

			if( typeof JSON === 'object' && JSON !== null && typeof JSON.parse === 'function' )
			{
				try
				{
					unparsedValue = value;
					value = JSON.parse( value );
				}
				catch( e2 )
				{
					value = unparsedValue;
				}
			}

			cookies[name] = value;
		}
		return cookies;
	};

	constructor = function(){};

	/**
	 * get - get one, several, or all cookies
	 *
	 * @access public
	 * @paramater Mixed cookieName - String:name of single cookie; Array:list of multiple cookie names; Void (no param):if you want all cookies
	 * @return Mixed - Value of cookie as set; Null:if only one cookie is requested and is not found; Object:hash of multiple or all cookies (if multiple or all requested);
	 */
	constructor.prototype.get = function( cookieName )
	{
		var returnValue, item, cookies = parseCookies();

		if( typeof cookieName === 'string' )
		{
			returnValue = ( typeof cookies[cookieName] !== 'undefined' ) ? cookies[cookieName] : null;
		}
		else if( typeof cookieName === 'object' && cookieName !== null )
		{
			returnValue = {};
			for( item in cookieName )
			{
				if( typeof cookies[cookieName[item]] !== 'undefined' )
				{
					returnValue[cookieName[item]] = cookies[cookieName[item]];
				}
				else
				{
					returnValue[cookieName[item]] = null;
				}
			}
		}
		else
		{
			returnValue = cookies;
		}

		return returnValue;
	};
	/**
	 * filter - get array of cookies whose names match the provided RegExp
	 *
	 * @access public
	 * @paramater Object RegExp - The regular expression to match against cookie names
	 * @return Mixed - Object:hash of cookies whose names match the RegExp
	 */
	constructor.prototype.filter = function( cookieNameRegExp )
	{
		var cookieName, returnValue = {}, cookies = parseCookies();

		if( typeof cookieNameRegExp === 'string' )
		{
			cookieNameRegExp = new RegExp( cookieNameRegExp );
		}

		for( cookieName in cookies )
		{
			if( cookieName.match( cookieNameRegExp ) )
			{
				returnValue[cookieName] = cookies[cookieName];
			}
		}

		return returnValue;
	};
	/**
	 * set - set or delete a cookie with desired options
	 *
	 * @access public
	 * @paramater String cookieName - name of cookie to set
	 * @paramater Mixed value - Any JS value. If not a string, will be JSON encoded; NULL to delete
	 * @paramater Object options - optional list of cookie options to specify
	 * @return void
	 */
	constructor.prototype.set = function( cookieName, value, options )
	{
		if( typeof options !== 'object' || options === null )
		{
			options = {};
		}

		if( typeof value === 'undefined' || value === null )
		{
			value = '';
			options.hoursToLive = -8760;
		}

		else if( typeof value !== 'string' )
		{
			if( typeof JSON === 'object' && JSON !== null && typeof JSON.stringify === 'function' )
			{
				value = JSON.stringify( value );
			}
			else
			{
				throw new Error( 'cookies.set() received non-string value and could not serialize.' );
			}
		}


		var optionsString = assembleOptionsString( options );

		document.cookie = cookieName + '=' + encodeURIComponent( value ) + optionsString;
	};
	/**
	 * del - delete a cookie (domain and path options must match those with which the cookie was set; this is really an alias for set() with parameters simplified for this use)
	 *
	 * @access public
	 * @paramater MIxed cookieName - String name of cookie to delete, or Bool true to delete all
	 * @paramater Object options - optional list of cookie options to specify ( path, domain )
	 * @return void
	 */
	constructor.prototype.del = function( cookieName, options )
	{
		var allCookies = {}, name;

		if( typeof options !== 'object' || options === null )
		{
			options = {};
		}

		if( typeof cookieName === 'boolean' && cookieName === true )
		{
			allCookies = this.get();
		}
		else if( typeof cookieName === 'string' )
		{
			allCookies[cookieName] = true;
		}

		for( name in allCookies )
		{
			if( typeof name === 'string' && name !== '' )
			{
				this.set( name, null, options );
			}
		}
	};
	/**
	 * test - test whether the browser is accepting cookies
	 *
	 * @access public
	 * @return Boolean
	 */
	constructor.prototype.test = function()
	{
		var returnValue = false, testName = 'cT', testValue = 'data';

		this.set( testName, testValue );

		if( this.get( testName ) === testValue )
		{
			this.del( testName );
			returnValue = true;
		}

		return returnValue;
	};
	/**
	 * setOptions - set default options for calls to cookie methods
	 *
	 * @access public
	 * @param Object options - list of cookie options to specify
	 * @return void
	 */
	constructor.prototype.setOptions = function( options )
	{
		if( typeof options !== 'object' )
		{
			options = null;
		}

		defaultOptions = resolveOptions( options );
	};

	return new constructor();
} )();

( function()
{
	if( window.jQuery )
	{
		( function( $ )
		{
			$.cookies = jaaulde.utils.cookies;

			var extensions = {
				/**
				* $( 'selector' ).cookify - set the value of an input field, or the innerHTML of an element, to a cookie by the name or id of the field or element
				*                           (field or element MUST have name or id attribute)
				*
				* @access public
				* @param options OBJECT - list of cookie options to specify
				* @return jQuery
				*/
				cookify: function( options )
				{
					return this.each( function()
					{
						var i, nameAttrs = ['name', 'id'], name, $this = $( this ), value;

						for( i in nameAttrs )
						{
							if( ! isNaN( i ) )
							{
								name = $this.attr( nameAttrs[ i ] );
								if( typeof name === 'string' && name !== '' )
								{
									if( $this.is( ':checkbox, :radio' ) )
									{
										if( $this.attr( 'checked' ) )
										{
											value = $this.val();
										}
									}
									else if( $this.is( ':input' ) )
									{
										value = $this.val();
									}
									else
									{
										value = $this.html();
									}

									if( typeof value !== 'string' || value === '' )
									{
										value = null;
									}

									$.cookies.set( name, value, options );

									break;
								}
							}
						}
					} );
				},
				/**
				* $( 'selector' ).cookieFill - set the value of an input field or the innerHTML of an element from a cookie by the name or id of the field or element
				*
				* @access public
				* @return jQuery
				*/
				cookieFill: function()
				{
					return this.each( function()
					{
						var n, getN, nameAttrs = ['name', 'id'], name, $this = $( this ), value;

						getN = function()
						{
							n = nameAttrs.pop();
							return !! n;
						};

						while( getN() )
						{
							name = $this.attr( n );
							if( typeof name === 'string' && name !== '' )
							{
								value = $.cookies.get( name );
								if( value !== null )
								{
									if( $this.is( ':checkbox, :radio' ) )
									{
										if( $this.val() === value )
										{
											$this.attr( 'checked', 'checked' );
										}
										else
										{
											$this.removeAttr( 'checked' );
										}
									}
									else if( $this.is( ':input' ) )
									{
										$this.val( value );
									}
									else
									{
										$this.html( value );
									}
								}
								
								break;
							}
						}
					} );
				},
				/**
				* $( 'selector' ).cookieBind - call cookie fill on matching elements, and bind their change events to cookify()
				*
				* @access public
				* @param options OBJECT - list of cookie options to specify
				* @return jQuery
				*/
				cookieBind: function( options )
				{
					return this.each( function()
					{
						var $this = $( this );
						$this.cookieFill().change( function()
						{
							$this.cookify( options );
						} );
					} );
				}
			};

			$.each( extensions, function( i )
			{
				$.fn[i] = this;
			} );

		} )( window.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);

/*
 * fontResizer - jQuery Plugin
 *
 * Examples and documentation at: <http://paperplanesdesign.com/cubed/Font-Resizer/fontResizer.html>
 *
 * Copyright (c) 2011 Justin Wehrman
 *
 * Version: 2.0.0 (11/11/2010)
 * Requires: jQuery v1.3+
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
(function($) {
	$.fn.fontResizer = function ( options ) {
		var date = new Date();
		var currYear = date.getFullYear();
		var currMonth = date.getMonth();
		var currDay = date.getDate();
		var cExpire = new Date(currYear + 1, currMonth, currDay);
		var cExpireDate = cExpire.toUTCString();
		var defaults = {
			sizeType: 'px',
			minFont: 10,
			maxFont: 18,
			fontSet: 14,
			setFontOn: 'ON',
			increment: 1,
			incrementDisable: 'DISABLED',
			$increaseClickItem: $('.increaseClickItem'),
			$decreaseClickItem: $('.decreaseClickItem'),
			$setFontButton: $('.setFontSize'),
			cookieName: 'fontResizer',
			cookieExpire: cExpireDate,
			cookiePath: '/',
			cookieSet: options.cookieName + '=' + options.fontSet + ';path=' + options.cookiePath + ' ;expires=' + options.cookieExpire,
			endClick: function () {
				blur;
				return false;
			},
			increaseFontSize: function () {
				if (options.fontSet < options.maxFont) {
					options.fontSet += options.increment;
				} else {
					options.endClick();
				}
				$content.css('fontSize',options.fontSet + options.sizeType);
				document.cookie = options.cookieName + '=' + options.fontSet + ';path=' + options.cookiePath + ' ;expires=' + options.cookieExpire;
				options.setCurrentFontButton();
			},
			decreaseFontSize: function () {
				if (options.fontSet > options.minFont) {
					options.fontSet -= options.increment;
				} else {
					options.endClick();
				}
				$content.css('fontSize',options.fontSet + options.sizeType);
				document.cookie = options.cookieName + '=' + options.fontSet + ';path=' + options.cookiePath + ' ;expires=' + options.cookieExpire;
				options.setCurrentFontButton();
			},
			setFontSize: function ( fSize ) {
				fSize = $(this).attr('title');
				fSize = parseInt(fSize);
				options.fontSet = fSize;
				$content.css('fontSize',fSize + options.sizeType);
				document.cookie = options.cookieName + '=' + options.fontSet + ';path=' + options.cookiePath + ' ;expires=' + options.cookieExpire;
			},
			checkfontSetCookie: function () {
				var results = document.cookie.match( '(^|;) ?' + options.cookieName + '=([^;]*)(;|$)' );
				if (results) {
					$content.css('fontSize',unescape(results[2]) + options.sizeType);
					options.setCurrentFontButton();
				}
			},
			setCurrentFontButton: function () {
				if (options.$setFontButton.length !== 0) {
					options.$setFontButton.each(function() {
						$(this).attr('title') == options.fontSet ? $(this).addClass(options.setFontOn) : $(this).removeClass(options.setFontOn);
					});
					options.setIncreaseDecreaseVisibility();
				}
			},
			setIncreaseDecreaseVisibility: function () {
				var maxReached = options.fontSet >= options.maxFont;
				var minReached = options.fontSet <= options.minFont;
				maxReached ? options.$increaseClickItem.addClass(options.incrementDisable) : options.$increaseClickItem.removeClass(options.incrementDisable);
				minReached ? options.$decreaseClickItem.addClass(options.incrementDisable) : options.$decreaseClickItem.removeClass(options.incrementDisable);
			}
		};
		var options = $.extend(defaults, options);
		var $content = this;
		return this.each(function() {
			options.checkfontSetCookie();
			if ($(this).css('fontSize')) {
				options.fontSet = parseInt($(this).css('fontSize').replace(options.sizeType,''));
				options.$increaseClickItem.click(options.increaseFontSize).click(options.setIncreaseDecreaseVisibility).click(options.endClick);
				options.$decreaseClickItem.click(options.decreaseFontSize).click(options.setIncreaseDecreaseVisibility).click(options.endClick);
				options.$setFontButton.click(function(event){
					options.$setFontButton.each(function() {
						if ($(this).hasClass(options.setFontOn)) { $(this).removeClass(options.setFontOn); }
					});
					$(this).addClass(options.setFontOn);
				}).click(options.setFontSize).click(options.setIncreaseDecreaseVisibility).click(options.endClick);
			}
		});
	};
})(jQuery);

/**
 * jquery.youtubin.js
 * Copyright (c) 2009 Jon Raasch (http://jonraasch.com/)
 * Licensed under the Free BSD License (see http://dev.jonraasch.com/youtubin/docs#licensing)
 * 
 * @author Jon Raasch
 *
 * @projectDescription    jQuery plugin to allow simple and unobtrusive embedding of youtube videos with a variety of options
 * 
 * @documentation http://dev.jonraasch.com/youtubin/docs
 *
 * @version 1.2
 * 
 * @requires jquery.js (tested with v 1.3.2)
 * 
 * @optional SwfObject 2
 * 
 * NOT AFFILIATED WITH YOUTUBE
 */


( function( $ ) {    
    var youtubinCount = 0;
    var youtubinMode  = 0;
    
    $.youtubin = function(options, box) {
        var options = options || {};
        
        // if iphone and iphoneBoot not set or true, just die so youtube link can stay
        if ( (typeof options.iphoneBoot == 'undefined' || options.iphoneBoot )  && ( (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) ) ) return false;
        
        // if first time
        if ( !youtubinMode ) {
            if ( typeof( swfobject ) == 'undefined' ) youtubinMode = 'noScript';
            else youtubinMode = '2';
        }
        
        if ( typeof( box ) == 'undefined' || !box ) {
            options.scope = options.scope || $('body');
            $('a[href^=http://www.youtube.com/watch?v=]', options.scope).youtubin(options);
            
            return false;
        }
        
        // define options
        options.swfWidth  = options.swfWidth || "425";
        options.swfHeight = options.swfHeight || "344";
        options.flashVersion = options.flashVersion || "8";
        options.expressInstall = options.expressInstall || "";
        
        options.flashvars = options.flashvars || {};
        options.params    = options.params || {
            menu : "false",
            loop : "false",
            wmode : "opaque"
        };
        
        options.replaceTime = options.replaceTime || 'auto';
        options.keepLink = options.keepLink || (options.replaceTime == 'click');
        options.wrapper = options.wrapper || '<div class="youtubin-video"></div>';
        
        options.autoplay = typeof options.autoplay != 'undefined' ? options.autoplay : ( options.replaceTime == 'click' );
        
        options.srcOptions = options.srcOptions || '?hl=en&fs=1' + ( options.autoplay ? '&autoplay=1' : '' );
        options.method = options.method || 'href';
        
        options.target = options.target || false;
        
        
        var $box = $(box);
        
        // depending on replaceTime trigger replacement or attach click event
        if (options.replaceTime == 'auto') replaceIt();
        else if (options.replaceTime == 'click') $box.click( function(ev) { ev.preventDefault(); replaceIt(); });
        
        function replaceIt() {
            function checkId($tgt) {
                var boxId = $tgt.attr('id');
                if ( !boxId.length ) {
                    boxId = getNewId();
                    $tgt.attr('id', boxId);
                }
                
                return boxId;
            }
            
            function getNewId() {
                var boxId = 'youtubin-' + youtubinCount;
                youtubinCount++;
                
                return boxId;
            }
            
            var src = $box.attr(options.method);
    
            // build swf url from youtube link
            if ( src.substr(0,31) == 'http://www.youtube.com/watch?v=' ) src = 'http://www.youtube.com/v/' + src.substr(31) + options.srcOptions;
        
            // set the target
            if ( options.target ) {
                var $tgt = options.target;
                var boxId = checkId($tgt);
            }
            else if ( options.keepLink ) {
                var boxId = getNewId();
                $box.after($('<div id="'+boxId+'"></div>'));
                
                var $tgt = $('#'+boxId);
                $tgt.css('clear', 'both');
            }
            else {
                var $tgt = $box;
                var boxId = checkId($tgt);
            }
            
            // embed the swf according to youtubinMode
            switch(youtubinMode) {
                case '2' :
                    swfobject.embedSWF(src, boxId, options.swfWidth, options.swfHeight, options.flashVersion, options.expressInstall, options.flashvars, options.params);
                break;
                
                default : 
                    $tgt.html('<object width="' + options.swfWidth + '" height="' + options.swfHeight + '"><param name="movie" value="' + src + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="' + src + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' + options.swfWidth + '" height="' + options.swfHeight + '"></embed></object>');
                break;
            }
            
            // (hack) must redefine boxId here or it will cause error in IE
            //if (options.wrapper) $('#'+boxId).wrap(options.wrapper);
        }
        
    };
    
    $.fn.youtubin = function(options) {
        this.each( function() {new $.youtubin( options, this );});
        return this;
    };
})( jQuery );



// Doc ready - this won't happen until the doc is loaded
$(function(){
		//browser check
if ( $.browser.msie ) {
  $("body").addClass("explorer"  + parseInt($.browser.version) );
}
if ( $.browser.opera ) {
  $("body").addClass("opera"  +  parseInt($.browser.version) );
}
if ( $.browser.webkit ) {
  $("body").addClass("webkit");
}
if ( $.browser.mozilla ) {
  $("body").addClass("firefox");
}
			//remove the no-js class from the body to prove that javascript has loaded
			$("body").removeClass('no-js');
		   	
		    //do the menus
			//cache nav
		var nav = $("#mainNav");

		//add indicators and hovers to submenu parents
		nav.find("li").each(function() {
			if ($("ul",this).length > 0) {

				//$("<span>").text(" ").appendTo($(this).children(":first"));

				//show subnav on hover
				$(this).hoverIntent(function() {
					$("ul:first",this).stop(true, true).slideDown('fast');
					$(this).closest('li').addClass('selected');
				},
				//hide subnav on hover out
				function() {
					$("ul:first",this).stop(true, true).slideUp('fast');
					$(this).closest('li').removeClass('selected');
				});
			}
		});
		 $(".cycle").cycle({timeout:8000});
		 $('#content p,#content ul,#content ol, #content td').fontResizer({minFont:13,maxFont:20,increment:2});  
		   });
// window ready - this won't happen until the entire window (incl. images) is loaded
$.fn.setAllToMaxHeight = function(){
return this.height( Math.max.apply(this, $.map( this , function(e){ return $(e).height() }) ) );
}

// usage: $('div.unevenheights').setAllToMaxHeight()
$(window).load(function(){
	$('.groupHeights').setAllToMaxHeight();
	$("a.button, a.buttonRight").wrap('<p class="clearfix" />');
			$("body.explorer6 .hNav").append('<div class="clear"></div>');
});
