(function($){
	/* hoverIntent by Brian Cherne */
	$.fn.hoverIntent = function(f,g) {
		// default configuration options
		var cfg = {
			sensitivity: 7,
			interval: 100,
			timeout: 0
		};
		// override configuration options with user supplied object
		cfg = $.extend(cfg, g ? { over: f, out: g } : f );

		// instantiate variables
		// cX, cY = current X and Y position of mouse, updated by mousemove event
		// pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
		var cX, cY, pX, pY;

		// A private function for getting mouse position
		var track = function(ev) {
			cX = ev.pageX;
			cY = ev.pageY;
		};

		// A private function for comparing current and previous mouse position
		var compare = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			// compare mouse positions to see if they've crossed the threshold
			if ( ( Math.abs(pX-cX) + Math.abs(pY-cY) ) < cfg.sensitivity ) {
				$(ob).unbind("mousemove",track);
				// set hoverIntent state to true (so mouseOut can be called)
				ob.hoverIntent_s = 1;
				return cfg.over.apply(ob,[ev]);
			} else {
				// set previous coordinates for next time
				pX = cX; pY = cY;
				// use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
				ob.hoverIntent_t = setTimeout( function(){compare(ev, ob);} , cfg.interval );
			}
		};

		// A private function for delaying the mouseOut function
		var delay = function(ev,ob) {
			ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
			ob.hoverIntent_s = 0;
			return cfg.out.apply(ob,[ev]);
		};

		// A private function for handling mouse 'hovering'
		var handleHover = function(e) {
			// next three lines copied from jQuery.hover, ignore children onMouseOver/onMouseOut
			var p = (e.type == "mouseover" ? e.fromElement : e.toElement) || e.relatedTarget;
			while ( p && p != this ) { try { p = p.parentNode; } catch(e) { p = this; } }
			if ( p == this ) { return false; }

			// copy objects to be passed into t (required for event object to be passed in IE)
			var ev = jQuery.extend({},e);
			var ob = this;

			// cancel hoverIntent timer if it exists
			if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }

			// else e.type == "onmouseover"
			if (e.type == "mouseover") {
				// set "previous" X and Y position based on initial entry point
				pX = ev.pageX; pY = ev.pageY;
				// update "current" X and Y position based on mousemove
				$(ob).bind("mousemove",track);
				// start polling interval (self-calling timeout) to compare mouse coordinates over time
				if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout( function(){compare(ev,ob);} , cfg.interval );}

			// else e.type == "onmouseout"
			} else {
				// unbind expensive mousemove event
				$(ob).unbind("mousemove",track);
				// if hoverIntent state is true, then call the mouseOut function after the specified delay
				if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout( function(){delay(ev,ob);} , cfg.timeout );}
			}
		};

		// bind the function to the two event listeners
		return this.mouseover(handleHover).mouseout(handleHover);
	};
	
})(jQuery);





/*
 * Superfish v1.4.8 - jQuery menu widget
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 * CHANGELOG: http://users.tpg.com.au/j_birch/plugins/superfish/changelog.txt
 */

;(function($){
	$.fn.superfish = function(op){

		var sf = $.fn.superfish,
			c = sf.c,
			$arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
			over = function(){
				var $$ = $(this), menu = getMenu($$);
				clearTimeout(menu.sfTimer);
				$$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function(){
				var $$ = $(this), menu = getMenu($$), o = sf.op;
				clearTimeout(menu.sfTimer);
				menu.sfTimer=setTimeout(function(){
					o.retainPath=($.inArray($$[0],o.$path)>-1);
					$$.hideSuperfishUl();
					if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
				},o.delay);	
			},
			getMenu = function($menu){
				var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
				sf.op = sf.o[menu.serial];
				return menu;
			},
			addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };
			
		return this.each(function() {
			var s = this.serial = sf.o.length;
			var o = $.extend({},sf.defaults,op);
			o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
				$(this).addClass([o.hoverClass,c.bcClass].join(' '))
					.filter('li:has(ul)').removeClass(o.pathClass);
			});
			sf.o[s] = sf.op = o;
			
			$('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
				if (o.autoArrows) addArrow( $('>a:first-child',this) );
			})
			.not('.'+c.bcClass)
				.hideSuperfishUl();
			
			var $a = $('a',this);
			$a.each(function(i){
				var $li = $a.eq(i).parents('li');
				$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
			});
			o.onInit.call(this);
			
		}).each(function() {
			var menuClasses = [c.menuClass];
			if (sf.op.dropShadows  && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
			$(this).addClass(menuClasses.join(' '));
		});
	};

	var sf = $.fn.superfish;
	sf.o = [];
	sf.op = {};
	sf.IE7fix = function(){
		var o = sf.op;
		if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
			this.toggleClass(sf.c.shadowClass+'-off');
		};
	sf.c = {
		bcClass     : 'sf-breadcrumb',
		menuClass   : 'sf-js-enabled',
		anchorClass : 'sf-with-ul',
		arrowClass  : 'sf-sub-indicator',
		shadowClass : 'sf-shadow'
	};
	sf.defaults = {
		hoverClass	: 'sfHover',
		pathClass	: 'overideThisToUse',
		pathLevels	: 1,
		delay		: 500,
		animation	: {opacity:'show'},
		speed		: 'fast',
		autoArrows	: false,
		dropShadows : true,
		disableHI	: false,		// true disables hoverIntent detection
		onInit		: function(){}, // callback functions
		onBeforeShow: function(){},
		onShow		: function(){},
		onHide		: function(){}
	};
	$.fn.extend({
		hideSuperfishUl : function(){
			var o = sf.op,
				not = (o.retainPath===true) ? o.$path : '';
			o.retainPath = false;
			var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
					.find('>ul').hide().css('visibility','hidden');
			o.onHide.call($ul);
			return this;
		},
		showSuperfishUl : function(){
			var o = sf.op,
				sh = sf.c.shadowClass+'-off',
				$ul = this.addClass(o.hoverClass)
					.find('>ul:hidden').css('visibility','visible');
			sf.IE7fix.call($ul);
			o.onBeforeShow.call($ul);
			$ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
			return this;
		}
	});

})(jQuery);






/*
 * Supersubs v0.2b - jQuery plugin
 * Copyright (c) 2008 Joel Birch
 *
 * Dual licensed under the MIT and GPL licenses:
 * 	http://www.opensource.org/licenses/mit-license.php
 * 	http://www.gnu.org/licenses/gpl.html
 *
 *
 * This plugin automatically adjusts submenu widths of suckerfish-style menus to that of
 * their longest list item children. If you use this, please expect bugs and report them
 * to the jQuery Google Group with the word 'Superfish' in the subject line.
 *
 */

;(function($){ // $ will refer to jQuery within this closure

	$.fn.supersubs = function(options){
		var opts = $.extend({}, $.fn.supersubs.defaults, options);
		// return original object to support chaining
		return this.each(function() {
			// cache selections
			var $$ = $(this);
			// support metadata
			var o = $.meta ? $.extend({}, opts, $$.data()) : opts;
			// get the font size of menu.
			// .css('fontSize') returns various results cross-browser, so measure an em dash instead
			var fontsize = $('<li id="menu-fontsize">&#8212;</li>').css({
				'padding' : 0,
				'position' : 'absolute',
				'top' : '-999em',
				'width' : 'auto'
			}).appendTo($$).width(); //clientWidth is faster, but was incorrect here
			// remove em dash
			$('#menu-fontsize').remove();
			// cache all ul elements
			$ULs = $$.find('ul');
			// loop through each ul in menu
			$ULs.each(function(i) {	
				// cache this ul
				var $ul = $ULs.eq(i);
				// get all (li) children of this ul
				var $LIs = $ul.children();
				// get all anchor grand-children
				var $As = $LIs.children('a');
				// force content to one line and save current float property
				var liFloat = $LIs.css('white-space','nowrap').css('float');
				// remove width restrictions and floats so elements remain vertically stacked
				var emWidth = $ul.add($LIs).add($As).css({
					'float' : 'none',
					'width'	: 'auto'
				})
				// this ul will now be shrink-wrapped to longest li due to position:absolute
				// so save its width as ems. Clientwidth is 2 times faster than .width() - thanks Dan Switzer
				.end().end()[0].clientWidth / fontsize;
				// add more width to ensure lines don't turn over at certain sizes in various browsers
				emWidth += o.extraWidth;
				// restrict to at least minWidth and at most maxWidth
				if (emWidth > o.maxWidth)		{ emWidth = o.maxWidth; }
				else if (emWidth < o.minWidth)	{ emWidth = o.minWidth; }
				emWidth += 'em';
				// set ul to width in ems
				$ul.css('width',emWidth);
				// restore li floats to avoid IE bugs
				// set li width to full width of this ul
				// revert white-space to normal
				$LIs.css({
					'float' : liFloat,
					'width' : '100%',
					'white-space' : 'normal'
				})
				// update offset position of descendant ul to reflect new width of parent
				.each(function(){
					var $childUl = $('>ul',this);
					var offsetDirection = $childUl.css('left')!==undefined ? 'left' : 'right';
					$childUl.css(offsetDirection,emWidth);
				});
			});
			
		});
	};
	// expose defaults
	$.fn.supersubs.defaults = {
		minWidth		: 9,		// requires em unit.
		maxWidth		: 25,		// requires em unit.
		extraWidth		: 0			// extra width can ensure lines don't sometimes turn over due to slight browser differences in how they round-off values
	};
	
})(jQuery); // plugin code ends







/*
 * jQuery Form Example Plugin 1.4.1
 * Populate form inputs with example text that disappears on focus.
 *
 * e.g.
 *  $('input#name').example('Bob Smith');
 *  $('input[@title]').example(function() {
 *    return $(this).attr('title');
 *  });
 *  $('textarea#message').example('Type your message here', {
 *    className: 'example_text'
 *  });
 *
 * Copyright (c) Paul Mucur (http://mucur.name), 2007-2008.
 * Dual-licensed under the BSD (BSD-LICENSE.txt) and GPL (GPL-LICENSE.txt)
 * licenses.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
(function($) {
  
  $.fn.example = function(text, args) {
    
    /* Only calculate once whether a callback has been used. */
    var isCallback = $.isFunction(text);
    
    /* Merge the arguments and given example text into one options object. */
    var options = $.extend({}, args, {example: text});
    
    return this.each(function() {
      
      /* Reduce method calls by saving the current jQuery object. */
      var $this = $(this);
      
      /* Merge the plugin defaults with the given options and, if present,
       * any metadata.
       */
      if ($.metadata) {        
        var o = $.extend({}, $.fn.example.defaults, $this.metadata(), options);
      } else {
        var o = $.extend({}, $.fn.example.defaults, options);
      }
      
      /* The following event handlers only need to be bound once
       * per class name. In order to do this, an array of used
       * class names is stored and checked on each use of the plugin.
       * If the class name is in the array then this whole section 
       * is skipped. If not, the events are bound and the class name 
       * added to the array.
       *
       * As of 1.3.2, the class names are stored as keys in the
       * array, rather than as elements. This removes the need for
       * $.inArray().
       */
      if (!$.fn.example.boundClassNames[o.className]) {
      
        /* Because Gecko-based browsers cache form values
         * but ignore all other attributes such as class, all example
         * values must be cleared on page unload to prevent them from
         * being saved.
         */
        $(window).unload(function() {
          $('.' + o.className).val('');
        });
      
        /* Clear fields that are still examples before any form is submitted
         * otherwise those examples will be sent along as well.
         * 
         * Prior to 1.3, this would only be bound to forms that were
         * parents of example fields but this meant that a page with
         * multiple forms would not work correctly.
         */
        $('form').submit(function() {
        
          /* Clear only the fields inside this particular form. */
          $(this).find('.' + o.className).val('');
        });
      
        /* Add the class name to the array. */
        $.fn.example.boundClassNames[o.className] = true;
      }
    
      /* Internet Explorer will cache form values even if they are cleared
       * on unload, so this will clear any value that matches the example
       * text and hasn't been specified in the value attribute.
       *
       * If a callback is used, it is not possible or safe to predict
       * what the example text is going to be so all non-default values
       * are cleared. This means that caching is effectively disabled for
       * that field.
       *
       * Many thanks to Klaus Hartl for helping resolve this issue.
       */
      if ($.browser.msie && !$this.attr('defaultValue') && (isCallback || $this.val() == o.example))
        $this.val('');
      
      /* Initially place the example text in the field if it is empty
       * and doesn't have focus yet.
       */
      if ($this.val() == '' && this != document.activeElement) {
        $this.addClass(o.className);
        
        /* The text argument can now be a function; if this is the case,
         * call it, passing the current element as `this`.
         */
        $this.val(isCallback ? o.example.call(this) : o.example);
      }
      
      /* Make the example text disappear when someone focuses.
       *
       * To determine whether the value of the field is an example or not,
       * check for the example class name only; comparing the actual value
       * seems wasteful and can stop people from using example values as real 
       * input.
       */
      $this.focus(function() {
        
        /* jQuery 1.1 has no hasClass(), so is() must be used instead. */
        if ($(this).is('.' + o.className)) {
          $(this).val('');
          $(this).removeClass(o.className);
        }
      });
    
      /* Make the example text reappear if the input is blank on blurring. */
      $this.blur(function() {
        if ($(this).val() == '') {
          $(this).addClass(o.className);
          
          /* Re-evaluate the callback function every time the user
           * blurs the field without entering anything. While this
           * is not as efficient as caching the value, it allows for
           * more dynamic applications of the plugin.
           */
          $(this).val(isCallback ? o.example.call(this) : o.example);
        }
      });
    });
  };
  
  /* Users can override the defaults for the plugin like so:
   *
   *   $.fn.example.defaults.className = 'not_example';
   */
  $.fn.example.defaults = {
    className: 'example'
  };
  
  /* All the class names used are stored as keys in the following array. */
  $.fn.example.boundClassNames = [];
  
})(jQuery);


















/*
 *  jQuery Form Validator v. 1.1
 *  Author: Daniele Di Bernardo
 *  http://www.marzapower.com/
 *  
 *  This plugin is a modified version from this plugin:
 *      http://marcgrabanski.com/code/clean-form-validation
 *  by Marc Grabanski
 *
 *
 *  The jQuery Form Validator plugin is licensed under a Creative Commons License and is copyrighted (C)2008-2009 by Daniele Di Bernardo.
 *  The license page can be found at: http://creativecommons.org/licenses/by-nc-sa/2.5/it/
 * 
 */
 
/**
 * More detailed info can be found at the web page http://www.marzapower.com/blog/show/250 or
 * in the README.txt file that you should have received with this script.
 *
 */
    
 
var ValidatorClass = function() {};

ValidatorClass.prototype = {

    init: function (settings) {
        var mySettings = settings;
        
        /*
         * Default values
         */
        if (settings['requiredFieldMsg'] == undefined)  mySettings['requiredFieldMsg']   = 'Red fields are required';
        if (settings['emailFieldMsg'] == undefined)     mySettings['emailFieldMsg']      = 'Blue fields must contain a valid email address';
        if (settings['numericFieldMsg'] == undefined)   mySettings['numericFieldMsg']    = 'Green fields must contain numbers';
        if (settings['integerFieldMsg'] == undefined)   mySettings['integerFieldMsg']    = 'Blue fields must contain integer values';
        if (settings['bindEvent'] == undefined)         mySettings['bindEvent']          = 'click';
        if (settings['allowNullNumbers'] == undefined 
            || settings['allowNullNumbers'] != true)    mySettings['allowNullNumbers']   = false;
        
        if (settings['errorColors'] == undefined)
            mySettings['errorColors'] = {
                isRequired: '#FDD',
                isEmail:    '#CCE',
                isNumeric:  '#DFD',
                isInteger:  '#CCE',
                hasRegex:   '#CCC'
            };
        
        this.settings = mySettings;
        this.form = $(this.settings["form"]);
        
        this.setElementsBinding();
        
    },
    
    reset: function() {
        var _this = this;
        
        if(this.settings) {
	        $(this.settings['bindElement']).each( function(index, element) {
	            $(element).unbind(_this.settings['bindEvent']);
	        });
	        this.settings = null;
        }
    },
    
    setElementsBinding : function() {
        var _this = this;
        
        if (this.isArray(this.settings['bindElement'])) {
            $.each(this.settings['bindElement'], function(i, el) {
                _this.bindElement(_this.settings['bindElement'][i], _this.settings['callback'][i]);
            });
        } else {
            this.bindElement(this.settings['bindElement'], this.settings['callback']);
        }
    },

    bindElement: function (element, callback) {
        var _this = this;

        $(element).bind(this.settings['bindEvent'], function() {
            error = _this.validate();

            if (_this.isEmpty(error)) {
                callback();
            } else {
                alert(error);
                return false;
            }
        });

    },
    
    validate: function () {
        error = '';
        validationTypes = new Array("isRequired", "isEmail", "isNumeric", "isInteger", "hasRegex");
        
        for (var n = 0; n < validationTypes.length; ++n) {    
            var x = this.settings[validationTypes[n]];
            var alreadyAlerted = false;
            
            if (x != null) {
                for(var i = 0; i < x.length; ++i)  {
                    var inputField;
                    var inputType;
                    var regex;
                    var message;
                    var name;
                    
                    if (validationTypes[n] != 'hasRegex') {
                        name = x[i];   
                    } else {
                        name = x[i][0];
                        regex = x[i][1];
                        message = x[i][2];
                    }
                    
                    var split = name.split('@');
                    if (split.length == 2) {
                        name = split[0];
                        inputType = split[1];
                    } else {
                        inputType = 'input';
                    }
                    
                    inputField = $(this.form).find(inputType + '[name=' + name + ']');
                    if ($(inputField).size() == 0) {
                        message = "Could not find a field with name '" + name + "' and type '" + inputType + "'!";
                        return message;
                    }
                    
                    switch (validationTypes[n]) {
                        case "isRequired" :
                            valid = !this.isEmpty($(inputField).val());
                            errorMsg = this.settings["requiredFieldMsg"];
                            break;
                        case "isEmail" :
                            valid = this.isEmail($(inputField).val());
                            errorMsg = this.settings["emailFieldMsg"];
                            break;
                        case "isNumeric" :
                            valid = this.isNumeric($(inputField).val());
                            errorMsg = this.settings["numericFieldMsg"];
                            break;
                        case "isInteger" :
                            valid = this.isInteger($(inputField).val());
                            errorMsg = this.settings["integerFieldMsg"];
                            break;
                        case "hasRegex" :
                            valid = this.testRegex($(inputField).val(), regex);
                            errorMsg = message;
                            break;
                    }
                    
                    if(!valid) {
                        if (!alreadyAlerted || validationTypes[n] == 'hasRegex') {
                            error += errorMsg + "\n";
                            alreadyAlerted = true;
                        }
                        $(inputField).css('background-color', this.settings["errorColors"][validationTypes[n]]);
                    } else {
                        $(inputField).css('background-color', '');
                    }
                }
            }
        }
        
        return error;
    },
    
    // returns true if the string is not empty
    isEmpty: function (str) {
        return (str == null) || (str == undefined) || (str.length == 0) || /^\s.$/.test(str) ;
    },
    
    // returns true if the string is a valid email
    isEmail: function (str) {
        if(this.isEmpty(str)) return false;
        var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
        return re.test(str);
    },
    
    // returns true if the string only contains characters 0-9 and is not null
    isNumeric: function (str) {
        if(this.isEmpty(str) && !this.settings['allowNullNumbers']) return false;
        if (isNaN(str)) return false;
        return true;
    },
    
    isInteger: function (str) {
        if (this.isEmpty(str) && !this.settings['allowNullNumbers']) return false;
        if (!str.match(/^[-]?\d+$/)) return false;
        return true;
    },
    
    isArray: function (obj) {
        return obj.constructor == Array;
    },
    
    testRegex : function (str, regex) {
        return regex.test(str);
    }

};





