
// Flash movie accessor
function $$(id) {
// allow for jQuery style id
	if(id.charAt(0) == '#') {
		id = id.substr(1,id.length);
	}
	if ($.browser.msie) {
		return window[id];
	} else {
		return document[id];
	}
}				
function isReady() {
	console.log("isReady() has been called via Flash externalinterface");
	return true;
}	

/*	******************************
		PLUGIN - Utility Functions 
		Author: Jack Lukic - KNI (all plugins)
		Notes: Used to extend jQuery functionality and shorten code
	******************************	*/

jQuery.fn.extend({
	// test if el is animated
	animated: function() {
		if(this.filter(':animated').size() > 0) {
			return true;
		}
		else {
			return false;	
		}
	},
	// test if el is visible
	visible: function() {
		if(this.filter(':visible').size() > 0) {
			return true;
		}
		else {
			return false;	
		}
	},
	// test if el exists
	exists: function() {
		if(this.size() > 0) {
			return true;
		}
		else {
			return false;	
		}
	}
});


/*	******************************
		PLUGIN - Image Tooltips 
		Author: Jack Lukic - KNI
		Notes: Used to create thumbnail tooltips
		Date: Jan 19, 2009
	******************************	*/
	
jQuery.fn.extend({
	imageTooltip: function(params) {
		// default settings
		var settings = {
			className: 'thumb',
			xOffset: -14,
			yOffset: -4,
			animate: false,
			duration: 300,
			mouseCenter: true
		}
		
		// allow for params to be passed in
		jQuery.extend(settings, params);
		// iterate through all selected
		$(this).each(function() {
			// find image src
			var src = $(this).attr('rel');
			if(src) {
				// attach mouse move event listener with live events jQuery 1.3
				$(this).mousemove(function(cursor){
					var $link = $(this);
					// create hover html if not available
					if(!$link.data('$hover')) {
						var html =	'<div class="image-tooltip">'	+
						'	<div class="'+settings.className+' hover">' +
						'		<div class="overlay"></div>' +
						'		<img src="'+src+'" />' +
						'	</div>'	+
						'</div>';
						// create hover div
						var $hover = $(html);
						// prepend to body so position is always relative to body
						$hover.prependTo('body');
						// attach hover div to this
						$(this).data('$hover',$hover);
					}
					// retreive hover div 
					var $hover = $link.data('$hover');
					if(typeof($hover != 'undefined')) {
						// offset for height of hover
						var hoverHeight = $hover.height();
						
						// center div on mouse if setting enabled
						if(settings.mouseCenter == true) {
							var xOffset = -($hover.width() / 2);
						}
						else {
							var xOffset = settings.xOffset	
						}
						// find cursor location and add offset
						var cursorX = (cursor.pageX) + xOffset ;
						var cursorY = (cursor.pageY - hoverHeight) + settings.yOffset;
						// assign style properties
						$hover.css({
							display: 'block',
							left: cursorX,
							top:  cursorY
						});
					}
				});
				$(this).mouseout(function() {
					// cache hover and link div 
					var $link = $(this);
					var $hover = $link.data('$hover');
					// make sure it sits under any new hover
					if(typeof($hover != 'undefined')) {
						$hover.css({zIndex: 9990});
						// allow for hover to animate 
						if(settings.animate) {
							$hover.fadeOut(settings.duration,function(){
								// remove hover data on callback
								$hover.remove();
								$link.removeData('$hover');
							});	
						} 
						else {
							// remove hover data on callback
							$hover.remove();
							$link.removeData('$hover');						
						}
					}
				});
			}
		});
		// return jQuery object for chaining
		return this;
	}
});

/*	******************************
		PLUGIN - Fancy Dropdowns 
		Author: Jack Lukic - KNI
		Last revision: February 2009
	******************************	*/
jQuery.fn.extend({
	initDropdown: function(params) {
		// grab selector from declaration
		$(this).each(function() {
			var settings = {
				opacity: 0.2,
				shadowOffset: -12,
				choicesID: '.dropdown-choices',
				filterClass: '.disabled, .readonly',
				align: 'default',
				animate: {
					show: {
						duration: 200,
						easing: 'easeInOutQuint'						
					},
					hide: {
						duration: 100,
						easing: 'easeInOutQuint'							
					}
				}
			}
			// allow custom settings to be passed in
			jQuery.extend(settings, params);
			
			// cache dropdown choices
			var $dropdown = $(this);
			var $choices = $(this).find(settings.choicesID);
			
			// Add click functionality to dropdown
			$dropdown.click(function() {
				$(this).removeClass('down');
				// if dropdown is disabled or readonly do not allow click behavior
				if(!($(this).filter(settings.filterClass).visible())) {
					// if dropdown is currently opened, close the dropdown
					if($choices.visible()) {
						// remove active class
						$dropdown.removeClass('active').addClass('hover');
						// hide choices
						$choices.slideUp(settings.animate.hide.duration, settings.animate.hide.easing);
						// Reset styles on dropdowns that aren't this one
						$('.dropdown').not(this).attr('style','');
						// Remove the 'clickaway' div from DOM
						$('.clickaway').remove();
					}
					// otherwise open dropdown 
					else {
						// Make other dropdowns go below this one
						$('.dropdown').not(this).css('z-index','1');
						
						// Add active class
						$dropdown.removeClass('hover').addClass('active');
						
						// assess dropdown height for positioning
						var dropdownHeight = parseInt($(this).height()) + settings.shadowOffset;
						var pos = dropdownHeight;
						
						// if vertically aligned calculate differently
						if(settings.align == 'valign') {
							dropdownHeight = dropdownHeight / 2; 
							var pos = (-(parseInt($choices.height()) / 2) + dropdownHeight) + 'px';
						}
						// if top align calculate differently
						if(settings.align == 'topalign') {
							var pos = (-dropdownHeight) + 'px';
						}
						
						// Add a clickaway div that covers page, to allow people to click away from dropdown
						$('<div/>').addClass('clickaway').css({height: $(document).height() + 'px', opacity: settings.opacity}).appendTo(document.body)
						.click(function() {
							$dropdown.removeClass('active');
							$('.dropdown').not($dropdown).removeAttr('style');
							$(this).remove();	
							$(settings.choicesID).filter(':visible').slideUp(settings.animate.hide.duration, settings.animate.hide.easing);
							return false;
						});
						// show
						$choices.css('top',pos);
						$choices.slideDown(settings.animate.show.duration, settings.animate.show.easing);							
					}
				}
				return false;
			});
			
			$dropdown
				.bind('mousedown', function() {
					if(!$choices.visible()) {
						$(this).addClass('down');			
					}
			    })
			    .bind('mouseup',function() {
					$(this).removeClass('down');	
				})
				.hover(function(){
					if(!$(this).hasClass('active')) {
						$(this).addClass('hover');
					}
				}, function(){
					$(this).removeClass('hover');
				})
			;	
			// Hover effect for dropdown choices
			$choices.find('li').not(settings.filterClass)
				.hover(function(){
					$(this).addClass('hover');
				}, function(){
					$(this).removeClass('hover');
				})
			;	
			
			$choices.find('li a')
				.bind('mousedown', function() {
					$(this).parent().addClass('down');						
				})
				.bind('mouseup', function() {
					var $choice = $(this);
					$choice.parent().removeClass('down');
					$dropdown.removeClass('active');
					// Reset styles on dropdowns that aren't this one
					$('.dropdown').not(this).not('.promotional').attr('style','');
					// Remove the 'clickaway' div from DOM
					$('.clickaway').remove();
					// Result no longer active
					$choice.parent().removeClass('active');
					// Hide the dropdown choice list
					$choice.parent().parent().slideUp(settings.animate.hide.duration, function() {
						// highlight this choice as selected for future visits to dropdown choices
						$choice.parent().addClass('selected');
						$choice.parent().siblings().removeClass('selected');
					});
					// copy to dropdown only text specified in .text of option
					if($(this).find('span.text').exists()) {
						$dropdown.find('.dropdown-text').html($(this).find('span.text').html()+'&hellip;');		
					}
					else {
						// otherwise use all the text in the dropdown
						$dropdown.find('.dropdown-text').html($(this).html());
					}
					// populate hidden field with value
					var choice = $(this).attr('href').substr(1);
					$dropdown.find('input:hidden').val(choice);
					return false;
				});	
			});
	}
});


jQuery.fn.extend({
	initMarquee: function(params) {
		
		var settings = {
			wrapperClass: '.wrapper',
			controlClass: '.controls',
			itemsPerScreen: 3,
			animationDuration: 800,
			easing: 'easeInOutCirc',
			beforeCallback: function($marquee){},
			afterCallback: function($marquee){}
		}
		jQuery.extend(settings, params);
		
		$(this).each(function() {
			
			var $marquee = $(this);
			
			var $wrapper = $marquee.find(settings.wrapperClass);
			var $controlContainer = $marquee.find(settings.controlClass);
			var $movables = $wrapper.children().eq(0);
			
			var distancePerPage = -($wrapper.width());
			var numberItems = $movables.children().size();
			var numberPages = numberItems / settings.itemsPerScreen;
						
			// Construct pager html
			$controlContainer.html( pagerConstructor(numberPages) );			
			var $controls = $controlContainer.children();
			
			// Add events for controls
			$controls
				.click(function() {
					if($(this).filter('active').size() < 1) {
						// Change active state
						$controls.removeClass('active');
						$(this).addClass('active');
											  
						// Calculate distance of move
						var page = $controls.index( $(this) );
						
						var distance = (page) * distancePerPage;
						
						settings.beforeCallback( $marquee );
						
						$movables.animate( 
							{ marginLeft: distance },
							settings.animationDuration, 
							settings.easing, 
							function() {
								settings.afterCallback( $marquee )	
							}
						);
						return false;						 
					}
				});
				
			
			function pagerConstructor(pages) {
				var html = '';
				var curPage = ' class="active"';
				for(i=0; i < pages; i++) {
					html += '<li'+ curPage + '><a href="#">' + i + '</a></li>';
					curPage = '';
				}
				return html;
			};
			
		});
		
	}

});



// Smooth Hover
jQuery.fn.extend({	
	smoothHover: function(selector, time) {
		if(typeof(time) == 'undefined') {
			var time = 300; 	
		}
		$(this).each(function() {
			$(this).hover(function() {
				if(typeof(selector) == 'undefined') {
					var $hover = $(this);	
				}
				else {
					var $hover = $(this).find(selector);	
				}
				// stop animation and reset inline styles to prevent getting stuck
				if($hover.animated()) {
					$hover.stop();	
				}
				$hover.attr('style','').show();
			},function() {
				if(typeof(selector) == 'undefined') {
					var $hover = $(this);	
				}
				else {
					var $hover = $(this).find(selector);	
				}
				// MSIE cannot fade transparent PNGs so just hide
				if($.browser.msie) {
					$hover.hide();	
				}
				else {
					$hover.fadeOut(time);
				}
			});
		});
		return this;
	}
});



	
jQuery.fn.extend({
	hoverClass: function(className, params) {
		if(typeof(className) == 'undefined') {
			var className = 'hover';
		}
		if(typeof(className) == 'object') {
			params = className;
			className = 'hover';
		}
		var settings = {
			useLive: false,
			context: 'body',
			filter: ''
		}
		$.extend(settings, params);
		
		var userAgent = navigator.userAgent;
		var iPad = userAgent.match(/iPad/i) != null;
		var iPhone = userAgent.match(/iPhone/i) != null;
		
		if(!iPad && !iPhone) {
			if(settings.useLive) {	
				$(this, settings.context).live('mouseover',function(){
					if(settings.filter == '' || $(this).filter(settings.filter).size() == 0) { 
						$(this).addClass(className);
					}
				});
				$(this, settings.context).live('mouseout', function() {
					if(settings.filter == '' || $(this).filter(settings.filter).size() == 0) {
						$(this).removeClass(className);							  
					}
				});	
			}
			else {
				$(this).each(function() {
						$(this).hover(function(){
							if(settings.filter == '' || $(this).filter(settings.filter).size() == 0) {
								$(this).addClass(className);							  
							}				   
						},
						function() {
							if(settings.filter == '' || $(this).filter(settings.filter).size() == 0) {
								$(this).removeClass(className);							  
							}
						});
				});
			}
		}
		return this;
	},
	touchClass: function(className, params) {
		if(typeof(className) == 'undefined') {
			var className = 'hover';
		}
		if(typeof(className) == 'object') {
			params = className;
			className = 'hover';
		}
		var settings = {
			filter: ''
		}
		$.extend(settings, params);
		
		var userAgent = navigator.userAgent;
		var iPad = userAgent.match(/iPad/i) != null;
		var iPhone = userAgent.match(/iPhone/i) != null;
		
		if(iPad || !iPhone) {
			$(this).each(function() {
				$(this)
					.bind('touchstart', function(){
						if(settings.filter == '' || $(this).filter(settings.filter).size() == 0) {
							$(this).addClass(className);							  
						}				   
					})
					.bind('touchend', function() {
						if(settings.filter == '' || $(this).filter(settings.filter).size() == 0) {
							$(this).removeClass(className);							  
						}
					})
				;
			});
		}
		return this;
	},
	downClass: function(className, params) {
		if(typeof(className) == 'undefined') {
			var className = 'down';
		}
		if(typeof(className) == 'object') {
			params = className;
			className = 'down';
		}
		var settings = {
			useLive: false,
			context: 'body',
			filter: ''
		}
		$.extend(settings, params);
		
		var userAgent = navigator.userAgent,
			iPad = userAgent.match(/iPad/i) != null,
			iPhone = userAgent.match(/iPhone/i) != null,
			downEvent = 'mousedown',
			upEvent = 'mouseup'
		;			
		if(iPad || iPhone) {
			downEvent = 'touchstart';
			upEvent = 'touchend';	
		}
		
		if(settings.useLive) {	
			$(this, settings.context).live(downEvent,function(){
				if(settings.filter == '' || $(this).filter(settings.filter).size() == 0) { 
					$(this).addClass(className);
					if(!(iPad || iPhone)) {
						$(this).one('mouseleave', function() {
							$(this).removeClass(className);	
						});
					}	
				}
			});
			$(this, settings.context).live(upEvent, function() {
				if(settings.filter == '' || $(this).filter(settings.filter).size() == 0) {
					$(this).removeClass(className);							  
				}
			});	
		}
		else {
			$(this).each(function() {
				$(this)
					.bind(downEvent, function(){
						if(settings.filter == '' || $(this).filter(settings.filter).size() == 0) {
							$(this).addClass(className);
							if(!(iPad || iPhone)) {
								$(this).one('mouseleave', function() {
									$(this).removeClass(className);	
								});
							}						  
						}				   
					})
					.bind(upEvent, function() {
						if(settings.filter == '' || $(this).filter(settings.filter).size() == 0) {
							$(this).removeClass(className);							  
						}
					})
				;
			});
		}
		return this;
	},
	focusClass: function(className, params) {
		if(typeof(className) == 'undefined') {
			var className = 'active';
		}
		if(typeof(className) == 'object') {
			params = className;
			className = 'active';
		}
		var settings = {
			filter: ''
		}
		$.extend(settings, params);
		
		$(this).each(function() {
			$(this)
				.focus(function(){
					if(settings.filter == '' || $(this).filter(settings.filter).size() == 0) {
						$(this).addClass(className);							  
					}				   
				})
				.blur(function() {
					if(settings.filter == '' || $(this).filter(settings.filter).size() == 0) {
						$(this).removeClass(className);							  
					}
				})
			;
		});
		return this;
	},
	forceHover: function() {
		$(this).each(function() {
			var $this = $(this);
			var offset = $this.offset();
			var width = $this.width();
			var height = $this.height();
			// look for first mousemove event
			$(document).bind('mousemove.poll', function(e) {
				var offsetX = e.pageX - offset.left;
				var offsetY = e.pageY - offset.top;
				if( (offsetX >= 0) && (offsetX <= width) && (offsetY <= height) && (offsetY >= 0) ) {
					$this.trigger('mouseover');
				}
				$(document).unbind('mousemove.poll');
			});
		});
		return this;
	}
});


/*	******************************
		PLUGIN - Resolution Class 
		Author: Jack Lukic - KNI
		Last revision: July 2009
	******************************	*/
jQuery.fn.extend({
	resolutionClass: function(width, largeClass) {
		
		// used for reference in resize event
		var $this = $(this);
		$(this).each(function() {
			if($(window).width() > width) {
				$this.addClass(largeClass);
			}
			else {
				$this.removeClass(largeClass);	
			}
			// Add resize event
			$(window).bind('resize.fitToDocument', function() {
				if($(window).width() > width) {
					$this.addClass(largeClass);	
				}
				else {
					$this.removeClass(largeClass);	
				}
			});
				
		});
		return this;
	}
});


/*	******************************
		PLUGIN - Dim Screen
		Author: Jack Lukic - KNI 
		Last revision: June 2009
	******************************	*/
jQuery.extend( {
    dimScreen: function(speed, opacity, callback) {
		if(typeof speed == 'function') {
            callback = speed;
            speed = null;
        }
        if(typeof opacity == 'function') {
            callback = opacity;
            opacity = null;
        }
        if(speed < 1 && speed > 0) {
            var placeholder = opacity;
            opacity = speed;
            speed = placeholder;
        }
        if(opacity >= 1) {
            var placeholder = speed;
            speed = opacity;
            opacity = placeholder;
        }
		
		speed = (speed >= 0) ? speed : 200;
        opacity = (opacity > 0) ? opacity : 0.22;
		
		if($('#dimmer').size() < 1) {
			jQuery('<div/>').attr('id','dimmer-wrapper').appendTo("#container").html(jQuery('<div/>').attr('id','dimmer'));
			var curOpacity = $('#dimmer').css('opacity');
			
			if(curOpacity != opacity) {
				if(speed == 0) {
					$('#dimmer').css({ opacity: opacity, visibility: 'visible' });
					$('#dimmer-wrapper').css({ visibility: 'visible' });
				}
				else {
					$('#dimmer, #dimmer-wrapper').css({	visibility: 'visible'});
					$('#dimmer').css({ opacity: '0.00'});
					
					$('#dimmer').fadeTo(speed, opacity, callback);
				}			
			}
		}
	},
    unDimScreen: function(speed) {
		speed = (speed >= 0 && typeof(speed) != 'undefined') ? speed : 200;
		if($('#dimmer').size() > 0) {
			if(speed == 0) {
				return $('#dimmer, #dimmer-wrapper').css({
					visibility: 'hidden'
				});
				$('#dimmer, #dimmer-wrapper').remove();
			}
			else {
				$('#dimmer').fadeTo(speed, '0.00', function(){					
					$('#dimmer, #dimmer-wrapper').remove();
				});
			}
		}
	}
});


/**
 * jquery.numberformatter - Formatting/Parsing Numbers in jQuery
 * Written by Michael Abernethy (mike@abernethysoft.com)
 *
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * Date: 1/26/08
 *
 * @author Michael Abernethy
 * @version 1.1.0
 *
 *
 * This plugin can be used to format numbers as text and parse text as Numbers
 * Because we live in an international world, we cannot assume that everyone
 * uses "," to divide thousands, and "." as a decimal point.
 *
 * The format() function will take the text within any selector by calling
 * text() or val() on them, getting the String, and applying the specified format to it.
 * It will return the jQuery object
 *
 * The parse() function will take the text within any selector by calling text()
 * or val() on them, turning the String into a Number, and returning these
 * values in a Number array.
 * It WILL BREAK the jQuery chain, and return an Array of Numbers.
 *
 * The syntax for the formatting is:
 * 0 = Digit
 * # = Digit, zero shows as absent
 * . = Decimal separator
 * - = Negative sign
 * , = Grouping Separator
 * % = Percent (multiplies the number by 100)
 * For example, a format of "#,###.00" and text of 4500.20 will
 * display as "4.500,20" with a locale of "de", and "4,500.20" with a locale of "us"
 *
 *
 * As of now, the only acceptable locales are 
 * United States -> "us"
 * Arab Emirates -> "ae"
 * Egypt -> "eg"
 * Israel -> "il"
 * Japan -> "jp"
 * South Korea -> "kr"
 * Thailand -> "th"
 * China -> "cn"
 * Hong Kong -> "hk"
 * Taiwan -> "tw"
 * Australia -> "au"
 * Canada -> "ca"
 * Great Britain -> "gb"
 * India -> "in"
 * Germany -> "de"
 * Vietnam -> "vn"
 * Spain -> "es"
 * Denmark -> "dk"
 * Austria -> "at"
 * Greece -> "gr"
 * Brazil -> "br"
 * Czech -> "cz"
 * France  -> "fr"
 * Finland -> "fi"
 * Russia -> "ru"
 * Sweden -> "se"
 * Switzerland -> "ch"
 * 
 * TODO
 * Separate positive and negative patterns separated by a ":" (e.g. use (#,###) for accounting)
 * More options may come in the future (currency)
 **/
     
 (function(jQuery) {

     function FormatData(dec, group, neg) {
       this.dec = dec;
       this.group = group;
       this.neg = neg;
     };

     function formatCodes(locale) {

         // default values
         var dec = ".";
         var group = ",";
         var neg = "-";

         if (locale == "us" ||
             locale == "ae" ||
             locale == "eg" ||
             locale == "il" ||
             locale == "jp" ||
             locale == "sk" ||
             locale == "th" ||
             locale == "cn" ||
             locale == "hk" ||
             locale == "tw" ||
             locale == "au" ||
             locale == "ca" ||
             locale == "gb" ||
             locale == "in"
            )
         {
              dec = ".";
              group = ",";
         }

         else if (locale == "de" ||
             locale == "vn" ||
             locale == "es" ||
             locale == "dk" ||
             locale == "at" ||
             locale == "gr" ||
             locale == "br"
            )
         {
              dec = ",";
              group = ".";
         }
         else if (locale == "cz" ||
              locale == "fr" ||
             locale == "fi" ||
             locale == "ru" ||
             locale == "se"
            )
         {
              group = " ";
              dec = ",";
         }
         else if (locale == "ch")
          {
              group = "'";
              dec = ".";
          }
     
        return new FormatData(dec, group, neg);

    };

 jQuery.formatNumber = function(number, options) {
     var options = jQuery.extend({},jQuery.fn.parse.defaults, options);
     var formatData = formatCodes(options.locale.toLowerCase());

     var dec = formatData.dec;
     var group = formatData.group;
     var neg = formatData.neg;
     
     var numString = new String(number);
     numString = numString.replace(".",dec).replace("-",neg);
     return numString;
 };

 jQuery.fn.parse = function(options) {

     var options = jQuery.extend({},jQuery.fn.parse.defaults, options);

     var formatData = formatCodes(options.locale.toLowerCase());

     var dec = formatData.dec;
     var group = formatData.group;
     var neg = formatData.neg;

     var valid = "1234567890.-";

     var array = [];
     this.each(function(){

         var text = new String(jQuery(this).text());
         if (jQuery(this).is(":input"))
            text = new String(jQuery(this).val());

         // now we need to convert it into a number
         text = text.replace(group,'').replace(dec,".").replace(neg,"-");
         var validText = "";
         var hasPercent = false;
         if (text.charAt(text.length-1)=="%")
             hasPercent = true;
         for (var i=0; i<text.length; i++)
         {
            if (valid.indexOf(text.charAt(i))>-1)
               validText = validText + text.charAt(i);
         }
         var number = new Number(validText);
         if (hasPercent)
         {
            number = number / 100;
            number = number.toFixed(validText.length-1);
         }
         array.push(number);
     });

     return array;
 };

 jQuery.fn.format = function(options) {

     var options = jQuery.extend({},jQuery.fn.format.defaults, options);
     
     var formatData = formatCodes(options.locale.toLowerCase());

     var dec = formatData.dec;
     var group = formatData.group;
     var neg = formatData.neg;
     
     var validFormat = "0#-,.";

     return this.each(function(){
         var text = new String(jQuery(this).text());
         if (jQuery(this).is(":input"))
            text = new String(jQuery(this).val());

         // strip all the invalid characters at the beginning and the end
         // of the format, and we'll stick them back on at the end
         // make a special case for the negative sign "-" though, so 
         // we can have formats like -$23.32
         var prefix = "";
         var negativeInFront = false;
         for (var i=0; i<options.format.length; i++)
         {
            if (validFormat.indexOf(options.format.charAt(i))==-1)
                prefix = prefix + options.format.charAt(i);
            else if (i==0 && options.format.charAt(i)=='-')
            {
               negativeInFront = true;
               continue;
            }
            else
                break;
         }
         var suffix = "";
         for (var i=options.format.length-1; i>=0; i--)
         {
            if (validFormat.indexOf(options.format.charAt(i))==-1)
                suffix = options.format.charAt(i) + suffix;
            else
                break;
         }

         options.format = options.format.substring(prefix.length);
         options.format = options.format.substring(0, options.format.length - suffix.length);


        // now we need to convert it into a number
        var number = new Number(text.replace(group,'').replace(dec,".").replace(neg,"-"));

        // special case for percentages
        if (suffix == "%")
           number = number * 100;

        var returnString = "";
        
        var decimalValue = number % 1;
        if (options.format.indexOf(".") > -1)
        {
           var decimalPortion = dec;
           var decimalFormat = options.format.substring(options.format.lastIndexOf(".")+1);
           var decimalString = new String(decimalValue.toFixed(decimalFormat.length));
           decimalString = decimalString.substring(decimalString.lastIndexOf(".")+1);
           for (var i=0; i<decimalFormat.length; i++)
           {
              if (decimalFormat.charAt(i) == '#' && decimalString.charAt(i) != '0')
              {
                 decimalPortion += decimalString.charAt(i);
                 break;
              }
              else if (decimalFormat.charAt(i) == "0")
              {
                 decimalPortion += decimalString.charAt(i);
              }
           }
           returnString += decimalPortion
        }
        else
           number = Math.round(number);
        
        var ones = Math.floor(number);
        if (number < 0)
            ones = Math.ceil(number);

        var onePortion = "";
        if (ones == 0)
        {
           onePortion = "0";
        }
        else
        {
           // find how many digits are in the group
           var onesFormat = "";
           if (options.format.indexOf(".") == -1)
              onesFormat = options.format;
           else
              onesFormat = options.format.substring(0, options.format.indexOf("."));
           var oneText = new String(ones);
           var groupLength = 9999;
           if (onesFormat.lastIndexOf(",") != -1)
               groupLength = onesFormat.length - onesFormat.lastIndexOf(",")-1;
           var groupCount = 0;
           for (var i=oneText.length-1; i>-1; i--)
           {
             onePortion = oneText.charAt(i) + onePortion;

             groupCount++;

             if (groupCount == groupLength && i!=0)
             {
                 onePortion = group + onePortion;
                 groupCount = 0;
             }

           }
        }

        returnString = onePortion + returnString;

        // handle special case where negative is in front of the invalid
        // characters
        if (number < 0 && negativeInFront && prefix.length > 0)
        {
           returnString = returnString.substring(1);
           prefix = neg + prefix;
        }

        returnString = prefix + returnString + suffix;

        if (jQuery(this).is(":input"))
           jQuery(this).val(returnString);
        else
           jQuery(this).text(returnString);

     });
 };

 jQuery.fn.parse.defaults = {
      locale: "us"
 };

 jQuery.fn.format.defaults = {
      format: "#,###.00",
      locale: "us"
 };


 })(jQuery);


/*	******************************
		PLUGIN - Third Party
		Author: Various
	******************************	*/

/* Small open source code snippet to add :containsCaseInsensitive pseudoclass */
jQuery.extend(jQuery.expr[':'], {
containsCaseInsensitive: "(a.textContent||a.innerText||jQuery(a).text ()||'').toLowerCase().indexOf((m[3]||'').toLowerCase())>=0"
});

// small open source replace all prototype, from jQuery BB
String.prototype.replaceAll = function(strTarget, strSubString){
	var strText = this;
	var intIndexOfMatch = strText.indexOf(strTarget);
	while (intIndexOfMatch != -1) {
		strText = strText.replace(strTarget, strSubString)
		intIndexOfMatch = strText.indexOf(strTarget);
	}
	return(strText);
}

/*
 * jQuery.Preload
 * Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com
 * Dual licensed under MIT and GPL.
 */
;(function($){var n=$.preload=function(c,d){if(c.split)c=$(c);d=$.extend({},n.defaults,d);var f=$.map(c,function(a){if(!a)return;if(a.split)return d.base+a+d.ext;var b=a.src||a.href;if(typeof d.placeholder=='string'&&a.src)a.src=d.placeholder;if(b&&d.find)b=b.replace(d.find,d.replace);return b||null}),g={loaded:0,failed:0,next:0,done:0,total:f.length};if(!g.total)return m();var h='<img/>',j=d.threshold;while(--j>0)h+='<img/>';h=$(h).load(k).error(k).bind('abort',k).each(l);function k(e){g.found=e.type=='load';g.image=this.src;var a=g.original=c[this.index];g[g.found?'loaded':'failed']++;g.done++;if(d.placeholder&&a.src)a.src=g.found?g.image:d.notFound||a.src;if(d.onComplete)d.onComplete(g);if(g.done<g.total)l(0,this);else{if(h.unbind)h.unbind('load').unbind('error').unbind('abort');h=null;m()}};function l(i,a,b){if($.browser.msie&&g.next&&g.next%n.gap==0&&!b){setTimeout(function(){l(i,a,1)},0);return!1}if(g.next==g.total)return!1;a.index=g.next;a.src=f[g.next++];if(d.onRequest){g.image=a.src;g.original=c[g.next-1];d.onRequest(g)}};function m(){if(d.onFinish)d.onFinish(g)}};n.gap=14;n.defaults={threshold:2,base:'',ext:'',replace:''};$.fn.preload=function(a){n(this,a);return this}})(jQuery);

