/**
 * jQuery.placeholder - Placeholder plugin for input fields
 * Written by Blair Mitchelmore (blair DOT mitchelmore AT gmail DOT com)
 * Licensed under the WTFPL (http://sam.zoy.org/wtfpl/).
 * Date: 2008/10/14
 *
 * @author Blair Mitchelmore
 * @version 1.0.1
 *
 **/
new function($) {
    $.fn.placeholder = function(settings) {
        settings = settings || {};
        var key = settings.dataKey || "placeholderValue";
        var attr = settings.attr || "placeholder";
        var className = settings.className || "placeholder";
        var values = settings.values || [];
        var block = settings.blockSubmit || false;
        var blank = settings.blankSubmit || false;
        var submit = settings.onSubmit || false;
        var value = settings.value || "";
        var position = settings.cursor_position || 0;

        
        return this.filter(":input").each(function(index) { 
            $.data(this, key, values[index] || $(this).attr(attr)); 
        }).each(function() {
            if ($.trim($(this).val()) === "")
                $(this).addClass(className).val($.data(this, key));
        }).focus(function() {
            if ($.trim($(this).val()) === $.data(this, key)) 
                $(this).removeClass(className).val(value)
                if ($.fn.setCursorPosition) {
                  $(this).setCursorPosition(position);
                }
        }).blur(function() {
            if ($.trim($(this).val()) === value)
                $(this).addClass(className).val($.data(this, key));
        }).each(function(index, elem) {
            if (block)
                new function(e) {
                    $(e.form).submit(function() {
                        return $.trim($(e).val()) != $.data(e, key)
                    });
                }(elem);
            else if (blank)
                new function(e) {
                    $(e.form).submit(function() {
                        if ($.trim($(e).val()) == $.data(e, key)) 
                            $(e).removeClass(className).val("");
                        return true;
                    });
                }(elem);
            else if (submit)
                new function(e) { $(e.form).submit(submit); }(elem);
        });
    };
}(jQuery);
;
/**
 * Equal Heights Plugin
 * Equalize the heights of elements. Great for columns or any elements
 * that need to be the same size (floats, etc).
 * 
 * Version 1.0
 * Updated 12/10/2008
 *
 * Copyright (c) 2008 Rob Glazebrook (cssnewbie.com) 
 *
 * Usage: $(object).equalHeights([minHeight], [maxHeight]);
 * 
 * Example 1: $(".cols").equalHeights(); Sets all columns to the same height.
 * Example 2: $(".cols").equalHeights(400); Sets all cols to at least 400px tall.
 * Example 3: $(".cols").equalHeights(100,300); Cols are at least 100 but no more
 * than 300 pixels tall. Elements with too much content will gain a scrollbar.
 * 
 */

(function($) {
	$.fn.equalHeights = function(minHeight, maxHeight) {
		tallest = (minHeight) ? minHeight : 0;
		this.each(function() {
			if($(this).height() > tallest) {
				tallest = $(this).height();
			}
		});
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function() {
			$(this).height(tallest).css("overflow","auto");
		});
	}
})(jQuery);;
/*
	
	jQuery selectBox (version 1.0.7)
	
		A cosmetic, styleable replacement for SELECT elements.
	
		Homepage:   http://abeautifulsite.net/blog/2011/01/jquery-selectbox-plugin/
		Demo page:  http://labs.abeautifulsite.net/projects/js/jquery/selectBox/
		
		Copyright 2011 Cory LaViska for A Beautiful Site, LLC.
		
	Features:

		- Supports OPTGROUPS
		- Supports standard dropdown controls
		- Supports multi-select controls (i.e. multiple="multiple")
		- Supports inline controls (i.e. size="5")
		- Fully accessible via keyboard
		- Shift + click (or shift + enter) to select a range of options in multi-select controls
		- Type to search when the control has focus
		- Auto-height based on the size attribute (to use, omit the height property in your CSS!)
		- Tested in IE7-IE9, Firefox 3-4, recent webkit browsers, and Opera
	
	
	License:
		
		Licensed under both the MIT license and the GNU GPLv2 (same as jQuery: http://jquery.org/license)
	
	
	Usage:
		
		Link to the JS file:
			
			<script src="jquery.selectbox.min.js" type="text/javascript"></script>
		
		Add the CSS file (or append contents to your own stylesheet):
		
			<link href="jquery.selectbox.min.css" rel="stylesheet" type="text/css" />
		
		To create:
			
			$("SELECT").selectBox([settings]);
	
	
	Settings:
		
		To specify settings, use this syntax: $("SELECT").selectBox('settings', { settingName: value, ... });
			
			menuTransition: ['default', 'slide', 'fade'] - the show/hide transition for dropdown menus
			menuSpeed: [integer, 'slow', 'normal', 'fast'] - the show/hide transition speed
	
	
	Methods:
		
		To call a method use this syntax: $("SELECT").selectBox('methodName', [options]);
		
			create - Creates the control (default method)
			destroy - Destroys the selectBox control and reverts back to the original form control
			disable - Disables the control (i.e. disabled="disabled")
			enable - Enables the control
			value - if passed with a value, sets the control to that value; otherwise returns the current value
			options - pass in either a string of HTML or a JSON object to replace the existing options
			control - returns the selectBox control element (an anchor tag) for working with directly
	
	
	Events:
		
		Events are fired on the original select element. You can bind events like this:
			
			$("SELECT").selectBox().change( function() { alert( $(this).val() ); } );
			
			focus - Fired when the control gains focus
			blur - Fired when the control loses focus
			change - Fired when the value of a control changes
	
	
	Change Log:
		
		v1.0.0 (2011-04-03) - Complete rewrite with added support for inline and multi-select controls
		v1.0.1 (2011-04-04) - Fixed options method so it doesn't destroy/recreate the control when called.
		                    - Added a check for iOS devices (their native controls are much better for 
		                      touch-based devices; you can still use selectBox API methods for theme)
		                    - Fixed issue where IE window would lose focus on XP
		                    - Fixed premature selection issue in Webkit browsers
		v1.0.2 (2011-04-13) - Fixed auto-height for inline controls when control is invisible on load
		                    - Removed auto-width for dropdown and inline controls; now relies 100% on CSS
		                      for setting the width
		                   	- Added 'control' method for working directly with the selectBox control
		v1.0.3 (2011-04-22) - Fixed bug in value method that errored if the control didn't exist
		v1.0.4 (2011-04-22) - Fixed bug where controls without any options would render with incorrect heights
		v1.0.5 (2011-04-22) - Removed 'tick' image in lieu of background colors to indicate selection
		                    - Clicking no longer toggles selected/unselected in multi-selects; use CTRL/CMD and 
		                      SHIFT like in normal browser controls
		                    - Fixed bug where inline controls would not receive focus unless tabbed into
		v1.0.6 (2011-04-29) - Fixed bug where inline controls could be "dragged" when selecting an empty area
		v1.0.7 (2011-05-18) - Expanded iOS check to include Android devices as well
		                    - Added autoWidth option; set to false on init to use CSS widths for dropdown menus
		                      
	Known Issues:
	
		- The blur and focus callbacks are not very reliable in IE7. The change callback works fine.
	
*/
if(jQuery) (function($) {
	
	$.extend($.fn, {
		
		selectBox: function(method, data) {
			
			var typeTimer, typeSearch = '';
			
			
			//
			// Private methods
			//
			
			
			var init = function(select, data) {
				
				// Disable for iOS devices (their native controls are more suitable for a touch device)
				if( navigator.userAgent.match(/iPad|iPhone|Android/i) ) return false;
				
				// Element must be a select control
				if( select.tagName.toLowerCase() !== 'select' ) return false;
				
				select = $(select);
				if( select.data('selectBox-control') ) return false;
				
				var control = $('<a class="selectBox" />'),
					inline = select.attr('multiple') || parseInt(select.attr('size')) > 1;
				
				var settings = data || {};
				if( settings.autoWidth === undefined ) settings.autoWidth = true;
				
				// Inherit class names, style, and title attributes
				control
					.addClass(select.attr('class'))
					.attr('style', select.attr('style') || '')
					.attr('title', select.attr('title') || '')
					.attr('tabindex', parseInt(select.attr('tabindex')))
					.css('display', 'inline-block')
					.bind('focus.selectBox', function() {
						if( this !== document.activeElement ) $(document.activeElement).blur();
						if( control.hasClass('selectBox-active') ) return;
						control.addClass('selectBox-active');
						select.trigger('focus');
					})
					.bind('blur.selectBox', function() {
						if( !control.hasClass('selectBox-active') ) return;
						control.removeClass('selectBox-active');
						select.trigger('blur');
					});
				
				if( select.attr('disabled') ) control.addClass('selectBox-disabled');
				
				// Generate control
				if( inline ) {
					
					//
					// Inline controls
					//
					var options = getOptions(select, 'inline');
					
					control
						.append(options)
						.data('selectBox-options', options)
						.addClass('selectBox-inline')
						.addClass('selectBox-menuShowing')
						.bind('keydown.selectBox', function(event) {
							handleKeyDown(select, event);
						})
						.bind('keypress.selectBox', function(event) {
							handleKeyPress(select, event);
						})
						.bind('mousedown.selectBox', function(event) {
							if( $(event.target).is('A.selectBox-inline') ) event.preventDefault();
							if( !control.hasClass('selectBox-focus') ) control.focus();
						})
						.insertAfter(select);
					
					// Auto-height based on size attribute
					if( !select[0].style.height ) {
						
						var size = select.attr('size') ? parseInt(select.attr('size')) : 5;
						
						// Draw a dummy control off-screen, measure, and remove it
						var tmp = control
							.clone()
							.removeAttr('id')
							.css({
								position: 'absolute',
								top: '-9999em'
							})
							.show()
							.appendTo('body');
						tmp.find('.selectBox-options').html('<li><a>\u00A0</a></li>');
						optionHeight = parseInt(tmp.find('.selectBox-options A:first').html('&nbsp;').outerHeight());
						tmp.remove();
						
						control.height(optionHeight * size);
						
					}
					
					disableSelection(control);
					
				} else {
					
					//
					// Dropdown controls
					//
					
					var label = $('<span class="selectBox-label" />'),
						arrow = $('<span class="selectBox-arrow" />');
					
					label.text( $(select).find('OPTION:selected').text() || '\u00A0' );
					
					var options = getOptions(select, 'dropdown');
					options.appendTo('BODY');
					
					control
						.data('selectBox-options', options)
						.addClass('selectBox-dropdown')
						.append(label)
						.append(arrow)
						.bind('mousedown.selectBox', function(event) {
							if( control.hasClass('selectBox-menuShowing') ) {
								hideMenus();
							} else {
								event.stopPropagation();
								// Webkit fix to prevent premature selection of options
								options.data('selectBox-down-at-x', event.screenX).data('selectBox-down-at-y', event.screenY);
								showMenu(select);
							}
						})
						.bind('keydown.selectBox', function(event) {
							handleKeyDown(select, event);
						})
						.bind('keypress.selectBox', function(event) {
							handleKeyPress(select, event);
						})
						.insertAfter(select);
					
					disableSelection(control);
						
				}
				
				// Store data for later use and show the control
				select
					.addClass('selectBox')
					.data('selectBox-control', control)
					.data('selectBox-settings', settings)
					.hide();
				
			};
			
			
			var getOptions = function(select, type) {
				
				var options;
				
				switch( type ) {
					
					case 'inline':
						

						options = $('<ul class="selectBox-options" />');
						
						if( select.find('OPTGROUP').length ) {
							
							select.find('OPTGROUP').each( function() {
								
								var optgroup = $('<li class="selectBox-optgroup" />');
								optgroup.text($(this).attr('label'));
								options.append(optgroup);
								
								$(this).find('OPTION').each( function() {
									var li = $('<li />'),
										a = $('<a />');
									li.addClass( $(this).attr('class') );
									a.attr('rel', $(this).val()).text( $(this).text() );
									li.append(a);
									if( $(this).attr('disabled') ) li.addClass('selectBox-disabled');
									if( $(this).attr('selected') ) li.addClass('selectBox-selected');
									options.append(li);
								});
								
							});
						
						} else {
						
							select.find('OPTION').each( function() {
								var li = $('<li />'),
									a = $('<a />');
								li.addClass( $(this).attr('class') );
								a.attr('rel', $(this).val()).text( $(this).text() );
								li.append(a);
								if( $(this).attr('disabled') ) li.addClass('selectBox-disabled');
								if( $(this).attr('selected') ) li.addClass('selectBox-selected');
								options.append(li);
							});
							
						}
						
						options
							.find('A')
								.bind('mouseover.selectBox', function(event) {
									addHover(select, $(this).parent());
								})
								.bind('mouseout.selectBox', function(event) {
									removeHover(select, $(this).parent());
								})
								.bind('mousedown.selectBox', function(event) {
									event.preventDefault(); // Prevent options from being "dragged"
									if( !select.selectBox('control').hasClass('selectBox-active') ) select.selectBox('control').focus();
								})
								.bind('mouseup.selectBox', function(event) {
									hideMenus();
									selectOption(select, $(this).parent(), event);
								});
						
						disableSelection(options);
						
						return options;
					
					case 'dropdown':
						
						options = $('<ul class="selectBox-dropdown-menu selectBox-options" />');
						
						if( select.find('OPTGROUP').length ) {
							
							select.find('OPTGROUP').each( function() {
								
								var optgroup = $('<li class="selectBox-optgroup" />');
								optgroup.text($(this).attr('label'));
								options.append(optgroup);
								
								$(this).find('OPTION').each( function() {
									var li = $('<li />'),
										a = $('<a />');
									li.addClass( $(this).attr('class') );
									a.attr('rel', $(this).val()).text( $(this).text() );
									li.append(a);
									if( $(this).attr('disabled') ) li.addClass('selectBox-disabled');
									if( $(this).attr('selected') ) li.addClass('selectBox-selected');
									options.append(li);
								});
								
							});
							
						} else {
							
							if( select.find('OPTION').length > 0 ) {
								select.find('OPTION').each( function() {
									var li = $('<li />'),
										a = $('<a />');
									li.addClass( $(this).attr('class') );
									a.attr('rel', $(this).val()).text( $(this).text() );
									li.append(a);
									if( $(this).attr('disabled') ) li.addClass('selectBox-disabled');
									if( $(this).attr('selected') ) li.addClass('selectBox-selected');
									options.append(li);
								});
							} else {
								options.append('<li>\u00A0</li>');
							}
							
						}
						
						options
							.data('selectBox-select', select)
							.css('display', 'none')
							.appendTo('BODY')
							.find('A')
								.bind('mousedown.selectBox', function(event) {
									event.preventDefault(); // Prevent options from being "dragged"
									if( event.screenX === options.data('selectBox-down-at-x') && event.screenY === options.data('selectBox-down-at-y') ) {
										options.removeData('selectBox-down-at-x').removeData('selectBox-down-at-y');
										hideMenus();
									}
								})
								.bind('mouseup.selectBox', function(event) {
									if( event.screenX === options.data('selectBox-down-at-x') && event.screenY === options.data('selectBox-down-at-y') ) {
										return;
									} else {
										options.removeData('selectBox-down-at-x').removeData('selectBox-down-at-y');
									}
									selectOption(select, $(this).parent());
									hideMenus();
								}).bind('mouseover.selectBox', function(event) {
									addHover(select, $(this).parent());
								})
								.bind('mouseout.selectBox', function(event) {
									removeHover(select, $(this).parent());
								});
						
						disableSelection(options);
						
						return options;
					
				}
				
			};
			
			
			var destroy = function(select) {
				
				select = $(select);
				
				var control = select.data('selectBox-control');
				if( !control ) return;
				var options = control.data('selectBox-options');
				
				options.remove();
				control.remove();
				select
					.removeClass('selectBox')
					.removeData('selectBox-control')
					.removeData('selectBox-settings')
					.show();
				
			};
			
			
			var showMenu = function(select) {
				
				select = $(select);
				var control = select.data('selectBox-control'),
					settings = select.data('selectBox-settings'),
					options = control.data('selectBox-options');
				if( control.hasClass('selectBox-disabled') ) return false;
				
				hideMenus();
				
				// Auto-width
				if( settings.autoWidth ) options.css('width', control.outerWidth() - (parseInt(control.css('borderLeftWidth')) + parseInt(control.css('borderLeftWidth'))));
				
				// Menu position
				options.css({
					top: control.offset().top + control.outerHeight() - (parseInt(control.css('borderBottomWidth'))),
					left: control.offset().left
				});
				
				// Show menu
				switch( settings.menuTransition ) {
					
					case 'fade':
						options.fadeIn(settings.menuSpeed);
						break;
					
					case 'slide':
						options.slideDown(settings.menuSpeed);
						break;
					
					default:
						options.show(settings.menuSpeed);
						break;
					
				}
				
				// Center on selected option
				var li = options.find('.selectBox-selected:first');
				keepOptionInView(select, li, true);
				addHover(select, li);
				
				control.addClass('selectBox-menuShowing');
				
				$(document).bind('mousedown.selectBox', function(event) {
					if( $(event.target).parents().andSelf().hasClass('selectBox-options') ) return;
					hideMenus();
				});
				
			};
			
			
			var hideMenus = function() {
				
				if( $(".selectBox-dropdown-menu").length === 0 ) return;
				$(document).unbind('mousedown.selectBox');
				
				$(".selectBox-dropdown-menu").each( function() {
					
					var options = $(this),
						select = options.data('selectBox-select'),
						control = select.data('selectBox-control'),
						settings = select.data('selectBox-settings');
					
					switch( settings.menuTransition ) {
						
						case 'fade':
							options.fadeOut(settings.menuSpeed);
							break;
						
						case 'slide':
							options.slideUp(settings.menuSpeed);
							break;
							
						default:
							options.hide(settings.menuSpeed);
							break;
						
					}
					
					control.removeClass('selectBox-menuShowing');
					
				});
				
			};
			
			
			var selectOption = function(select, li, event) {
				
				select = $(select);
				li = $(li);
				var control = select.data('selectBox-control'),
					settings = select.data('selectBox-settings');
				
				if( control.hasClass('selectBox-disabled') ) return false;
				if( li.length === 0 || li.hasClass('selectBox-disabled') ) return false;
				
				if( select.attr('multiple') ) {
					
					// If event.shiftKey is true, this will select all options between li and the last li selected
					if( event.shiftKey && control.data('selectBox-last-selected') ) {
						
						li.toggleClass('selectBox-selected');
						
						var affectedOptions;
						if( li.index() > control.data('selectBox-last-selected').index() ) {
							affectedOptions = li.siblings().slice(control.data('selectBox-last-selected').index(), li.index());
						} else {
							affectedOptions = li.siblings().slice(li.index(), control.data('selectBox-last-selected').index());
						}
						
						affectedOptions = affectedOptions.not('.selectBox-optgroup, .selectBox-disabled');
						
						if( li.hasClass('selectBox-selected') ) {
							affectedOptions.addClass('selectBox-selected');
						} else {
							affectedOptions.removeClass('selectBox-selected');
						}
						
					} else if( event.metaKey ) {
						li.toggleClass('selectBox-selected');
					} else {
						li.siblings().removeClass('selectBox-selected');
						li.addClass('selectBox-selected');
					}
					
				} else {
					li.siblings().removeClass('selectBox-selected');
					li.addClass('selectBox-selected');
				}
				
				if( control.hasClass('selectBox-dropdown') ) {
					control.find('.selectBox-label').text(li.text());
				}
				
				// Update original control's value
				var i = 0, selection = [];
				if( select.attr('multiple') ) {
					control.find('.selectBox-selected A').each( function() {
						selection[i++] = $(this).attr('rel');
					});
				} else {
					selection = li.find('A').attr('rel');
				}
				
				// Remember most recently selected item
				control.data('selectBox-last-selected', li);
				
				// Change callback
				if( select.val() !== selection ) {
					select.val(selection);
					select.trigger('change');
				}
				
				return true;
				
			};
			
			
			var addHover = function(select, li) {
				select = $(select);
				li = $(li);
				var control = select.data('selectBox-control'),
					options = control.data('selectBox-options');
				
				options.find('.selectBox-hover').removeClass('selectBox-hover');
				li.addClass('selectBox-hover');
			};
			
			
			var removeHover = function(select, li) {
				select = $(select);
				li = $(li);
				var control = select.data('selectBox-control'),
					options = control.data('selectBox-options');
				options.find('.selectBox-hover').removeClass('selectBox-hover');
			};
			
			
			var keepOptionInView = function(select, li, center) {
				
				if( !li || li.length === 0 ) return;
				
				select = $(select);
				var control = select.data('selectBox-control'),
					options = control.data('selectBox-options'),
					scrollBox = control.hasClass('selectBox-dropdown') ? options : options.parent(),
					top = parseInt(li.offset().top - scrollBox.position().top),
					bottom = parseInt(top + li.outerHeight());
				
				if( center ) {
					scrollBox.scrollTop( li.offset().top - scrollBox.offset().top + scrollBox.scrollTop() - (scrollBox.height() / 2) );
				} else {
					if( top < 0 ) {
						scrollBox.scrollTop( li.offset().top - scrollBox.offset().top + scrollBox.scrollTop() );
					}
					if( bottom > scrollBox.height() ) {
						scrollBox.scrollTop( (li.offset().top + li.outerHeight()) - scrollBox.offset().top + scrollBox.scrollTop() - scrollBox.height() );
					}
				}
				
			};
			
			
			var handleKeyDown = function(select, event) {
				
				//
				// Handles open/close and arrow key functionality
				//
				
				select = $(select);
				var control = select.data('selectBox-control'),
					options = control.data('selectBox-options'),
					totalOptions = 0,
					i = 0;
				
				if( control.hasClass('selectBox-disabled') ) return;
				
				switch( event.keyCode ) {
					
					case 8: // backspace
						event.preventDefault();
						typeSearch = '';
						break;
					
					case 9: // tab
					case 27: // esc
						hideMenus();
						removeHover(select);
						break;
					
					case 13: // enter
						if( control.hasClass('selectBox-menuShowing') ) {
							selectOption(select, options.find('LI.selectBox-hover:first'), event);
							if( control.hasClass('selectBox-dropdown') ) hideMenus();
						} else {
							showMenu(select);
						}
						break;
						
					case 38: // up
					case 37: // left
						
						event.preventDefault();
						
						if( control.hasClass('selectBox-menuShowing') ) {
							
							var prev = options.find('.selectBox-hover').prev('LI');
							totalOptions = options.find('LI:not(.selectBox-optgroup)').length;
							i = 0;
							
							while( prev.length === 0 || prev.hasClass('selectBox-disabled') || prev.hasClass('selectBox-optgroup') ) {
								prev = prev.prev('LI');
								if( prev.length === 0 ) prev = options.find('LI:last');
								if( ++i >= totalOptions ) break;
							}
							
							addHover(select, prev);
							keepOptionInView(select, prev);
							
						} else {
							showMenu(select);
						}
						
						break;
						
					case 40: // down
					case 39: // right
					
						event.preventDefault();
						
						if( control.hasClass('selectBox-menuShowing') ) {
							
							var next = options.find('.selectBox-hover').next('LI');
							totalOptions = options.find('LI:not(.selectBox-optgroup)').length;
							i = 0;
							
							while( next.length === 0 || next.hasClass('selectBox-disabled') || next.hasClass('selectBox-optgroup') ) {
								next = next.next('LI');
								if( next.length === 0 ) next = options.find('LI:first');
								if( ++i >= totalOptions ) break;
							}
							
							addHover(select, next);
							keepOptionInView(select, next);
							
						} else {
							showMenu(select);
						}
						
						break;
						
				}
				
			};
			
			
			var handleKeyPress = function(select, event) {
				
				//
				// Handles type-to-find functionality
				//
				
				select = $(select);
				var control = select.data('selectBox-control'),
					options = control.data('selectBox-options');
				
				if( control.hasClass('selectBox-disabled') ) return;
				
				switch( event.keyCode ) {
					
					case 9: // tab
					case 27: // esc
					case 13: // enter
					case 38: // up
					case 37: // left
					case 40: // down
					case 39: // right
						// Don't interfere with the keydown event!
						break;
					
					default: // Type to find
						
						if( !control.hasClass('selectBox-menuShowing') ) showMenu(select);
						
						event.preventDefault();
						
						clearTimeout(typeTimer);
						typeSearch += String.fromCharCode(event.charCode || event.keyCode);
						
						options.find('A').each( function() {
							if( $(this).text().substr(0, typeSearch.length).toLowerCase() === typeSearch.toLowerCase() ) {
								addHover(select, $(this).parent());
								keepOptionInView(select, $(this).parent());
								return false;
							}
						});
						
						// Clear after a brief pause
						typeTimer = setTimeout( function() { typeSearch = ''; }, 1000);
						
						break;
						
				}
				
			};
			
			
			var enable = function(select) {
				select = $(select);
				select.attr('disabled', false);
				var control = select.data('selectBox-control');
				if( !control ) return;
				control.removeClass('selectBox-disabled');
			};
			
			
			var disable = function(select) {
				select = $(select);
				select.attr('disabled', true);
				var control = select.data('selectBox-control');
				if( !control ) return;
				control.addClass('selectBox-disabled');
			};
			
			
			var setValue = function(select, value) {
				select = $(select);
				select.val(value);
				value = select.val();
				var control = select.data('selectBox-control');
				if( !control ) return;
				var settings = select.data('selectBox-settings'),
					options = control.data('selectBox-options');
				
				// Update label
				control.find('.selectBox-label').text( $(select).find('OPTION:selected').text() || '\u00A0' );
				
				// Update control values
				options.find('.selectBox-selected').removeClass('selectBox-selected');
				options.find('A').each( function() {
					if( typeof(value) === 'object' ) {
						for( var i = 0; i < value.length; i++ ) {
							if( $(this).attr('rel') == value[i] ) {
								$(this).parent().addClass('selectBox-selected');
							}
						}
					} else {
						if( $(this).attr('rel') == value ) {
							$(this).parent().addClass('selectBox-selected');
						}
					}
				});
				
				if( settings.change ) settings.change.call(select);
				
			};
			
			
			var setOptions = function(select, options) {
				
				select = $(select);
				var control = select.data('selectBox-control'),
					settings = select.data('selectBox-settings');
				
				switch( typeof(data) ) {
					
					case 'string':
						select.html(data);
						break;
						
					case 'object':
						select.html('');
						for( var i in data ) {
							if( data[i] === null ) continue;
							if( typeof(data[i]) === 'object' ) {
								var optgroup = $('<optgroup label="' + i + '" />');
								for( var j in data[i] ) {
									optgroup.append('<option value="' + j + '">' + data[i][j] + '</option>');
								}
								select.append(optgroup);
							} else {
								var option = $('<option value="' + i + '">' + data[i] + '</option>');
								select.append(option);
							}
						}
						break;
					
				}
				
				if( !control ) return;
				
				// Remove old options
				control.data('selectBox-options').remove();
				
				// Generate new options
				var type = control.hasClass('selectBox-dropdown') ? 'dropdown' : 'inline',
					options = getOptions(select, type);
				control.data('selectBox-options', options);
				
				switch( type ) {
					case 'inline':
						control.append(options);
						break;
					case 'dropdown':
						control.find('.selectBox-label').text( $(select).find('OPTION:selected').text() || '\u00A0' );
						$("BODY").append(options);
						break;
				}
				
			};
			
			
			var disableSelection = function(selector) {
				$(selector)
					.css('MozUserSelect', 'none')
					.bind('selectstart', function(event) {
						event.preventDefault();
					});
			};
			
			
			//
			// Public methods
			//
			
			
			switch( method ) {
				
				case 'control':
					return $(this).data('selectBox-control');
					break;
				
				case 'settings':
					if( !data ) return $(this).data('selectBox-settings');
					$(this).each( function() {
						$(this).data('selectBox-settings', $.extend(true, $(this).data('selectBox-settings'), data));
					});
					break;
				
				case 'options':
					$(this).each( function() {
						setOptions(this, data);
					});
					break;
				
				case 'value':
					if( !data ) return $(this).val();
					$(this).each( function() {
						setValue(this, data);
					});
					break;
				
				case 'enable':
					$(this).each( function() {
						enable(this);
					});
					break;
				
				case 'disable':
					$(this).each( function() {
						disable(this);
					});
					break;
				
				case 'destroy':
					$(this).each( function() {
						destroy(this);
					});
					break;
				
				default:
					$(this).each( function() {
						init(this, method);
					});
					break;
				
			}
			
			return $(this);
			
		}
		
	});
	
})(jQuery);;
(function ($) {
  $(document).ready(function() {
  /**
   * - O' behold, sitebuilders' customizations to the current theme -
   * (This project has been in it's most active state from 06/2011 to 08/2011)
   * 
   * NOTES:
   * 1. Most of the code is somewhat documented while some is not
   * TODO: improve documentation
   * 2. Most of the code does some strange yet ugly hacks
   * TODO: find a better way to obtain the same results : preferably by using php
   * 3. Most of the stuff could be moved into separate functions to make the code cleaner
   * TODO: clean up the code, so some things could be done with functions
   * 4. One important thing is that window.onload event is being triggered with some height adjusting stuff.
   *    That event is mainly used because there is a lot of page height measuring being done and it seems that webkit 
   *    browsers add the images to the dom only at the window onload event. So the page is at it's full height
   *    at that event when using webkit browsers.
   * TODO: there are some things in the window onload event that are pretty messed up and should be cleaned up
   *
   */
    // Do some browser checking
    var good_browser = true;
    var equal_heights_browser = true;
    if ($.browser.msie == true) {
      var version = $.browser.version;
      if (version == '7.0' || version == '8.0' || version == '6.0') {
        good_browser = false;
      }
    }
    if ($.browser.webkit == true) {
      equal_heights_browser = false;
    }

  
  // Go back link code
  var go_back_link = $('.js .go-back-link-wrapper');
  if (go_back_link.length > 0) {
      go_back_link.show().addClass('jquery-modified');
      $('a', go_back_link).click(function (event) {
          event.preventDefault();
          history.back();
      });
  }
  
  // Check the status of the page: edit mode or view mode
  $('body').not('.page-node-edit, .page-node-add').addClass('normal-mode jquery-modified');
  $('body').not('.normal-mode').addClass('node-edit-mode jquery-modified');
    
  $('.node-type-event .go-back-link-wrapper').addClass('should-be-moved');
  $('#content .region-content').append($('.go-back-link-wrapper.should-be-moved'));
    // Apply jQuery UI selectmenu to select elements
    // We are currently excluding some browser versions here: IE6, IE7 and IE8
    if (good_browser == true) {
      // This thing should work in FF, Opera, Safari, Chrome and IE9
      $('.view-products-listing select, select.form-select').not('.node-edit-mode select.form-select').selectBox();
    }
    
    // Move feeds icon on news block page next to h1 element
    var news_feed_icon = $('.block .view-news-view div.feed-icon');
    if (news_feed_icon.length > 0) {
      $('h1').after(news_feed_icon);
    }
	
	// Set equal heights to frontpage small liftup blocks
	//$('#content, body.page-node-edit #content.equals, body.page-node-add #content.equals').css('overflow','visible');
    
    // We cannot use equal heights in webkit browsers in document ready event - the images have not yet been loaded here
    // We are using window onload event for webkit browsers
    if (equal_heights_browser == true) {
    	$('body').addClass('equal-heights-browser');
		$('#frontpage-smaller-liftups .block').equalHeights(225).addClass('jquery-modified');
		$('.normal-mode #main .equals').equalHeights(450);
    	$('#main .region-sidebar-second .section.equals').css('overflow','visible');
    	$('#main .region-sidebar-first  .section.equals').css('overflow','visible');
    	$('#content, body.page-node-edit #content.equals, body.page-node-add #content.equals').css('overflow','visible');
    } else {
    	$('body').addClass('webkit-browser');
    }
	
	/// Alter the search box a bit: use the placeholder plugin to enable placeholder functionality
	// Try to fetch translated version of the word 'Search'
	var search_text = Drupal.t('Search');
	
	// Add a placeholder text to search box input element and trigger the placeholder plugin
	// Set blankSubmit to true so the search form would not submit the word "Search"
	$('.block-search input:text').addClass('jquery-modified').attr('placeholder', search_text).placeholder(
	  {
	    'blankSubmit' : true
	  }
	);
    
    // Identify a form as a contact form
    var webform_form = $('form.webform-client-form');
    var form_type_input = $('input[name="submitted[form_type]"]', webform_form);
    form_type_input.each( function () {
    	if ($(this).attr('value') == 'contact') {
			var parent_form = $(this).parent(webform_form);
			// We have found a form which type is "contact"
			// - Add some nifty classes to the form and the fieldsets etc (wherever needed)
			// - Add a wild RESET BUTTON! Mi gusto!
			parent_form.addClass('contact-form jquery-modified');
			$('fieldset', parent_form).each( function (i) {
				i++;
				$(this).addClass('jquery-modified fieldset-number-' + i);
			});
			// Manipulate the form actions div
			var actions = $('#edit-actions', parent_form);
			// Move it inside the last fieldset
			$('fieldset:last .fieldset-wrapper', parent_form).append(actions).addClass('jquery-modified');
			actions.addClass('jquery-modified');
			var str_clear = Drupal.t('Clear');
			// Add a reset button so the user cannot say "Y NO RESET BUTTON!" 
			$(actions).append('<input type="reset" value="' + str_clear + '" id="edit-reset" class="form-submit form-reset" />');
    	}
    });
    
	
	
    /** If nice menu has an active item somewhere make sure that the top level item also has active trail selector
     *  This might happen for example when viewing some item that is not in the menu but should have the correct context 
     *  visible in the main menu.
     *  This kind of modification is currently only needed when the nice menu is used in "down" mode and only in #navigation
     */
     
     $('#navigation ul.nice-menu.nice-menu-down > li.menuparent').each( function () {
       var active_item = $('ul > li a.active-trail', $(this));
       if (active_item.length > 0) {
         $('a:first', $(this)).addClass('jquery-modified active-trail active');
       }
     });
     
     // We have to add the dummy block in window onload event in webkit browsers
     if (equal_heights_browser == true) {
     /**
      * Fill the empty space in the second sidebar in certain circumstances:
      * - the content area is taller than the second sidebar
      *
      * The empty space should be filled with an empty block element that has a white background
      * (current specifications at 29.6.2011)
      */
      
      /// First we have to determine if a dummy block should be inserted
      /// This happens if the content area is taller than the second sidebar
      // We have to find the specific content area element and measure its height
      var content = $('#content');
      var content_height = content.height();

      // Then we have to find the sepcific sidebar element and measure its height
      // It might be safest if we calculated the total height of all blocks in the sidebar region
      var sidebar = $('.region-sidebar-second .section');
      var sidebar_height = 0;
      
      $('.block', sidebar).each( function () {
        var margin_bottom = parseInt($(this).css('margin-bottom'));
        var current_height = $(this).height();
        var total = current_height + margin_bottom;
        sidebar_height += total;
      });

      // Calculate the difference
      var difference = content_height - sidebar_height;

      // If the content area is taller than the sidebar we must insert the dummy block
      if (difference > 0) {
        // Create the block element with proper classes and inject it to the end of the sidebar container
        // It should be at the same level than the other blocks, and probably even have same classes than the other blocks
        sidebar.append('<div class="block block-dummy"></div>');
        
        // After the block has been created we need to move the 'last' class to it from the originally last element
        $('.block.last', sidebar).removeClass('last').addClass('jquery-modified old-last');

        // It should be noted that the new dummy block height should be negated by the amount of margin bottom that the new old-last block has
        difference -= parseInt($('.old-last').css('margin-bottom'));

        // Adjust the height and classes of the dummy block
        $('.block-dummy').css('height', difference + 'px').addClass('last jquery-modified new-last');
      } 

     /*
     * // End of dummy block code
     */
     }
     /**
      * When viewing contacts with google map and locations:
      * - move locations header and locations content inside a specific wrapper on page
      * - this is done by jquery because it's a fast way to do it and javascript is needed anyway when viewing google maps
      * - and currently the location module does not contain a proper way to override those things in the theme
      * Specifications in layout files at 30.6.2011
      */
     
     // Find out if we are in a page that needs alteration
     var node_type = $('.node-type-contact-info-page');
     if (node_type.length > 0) {
       
       // Find out if required elements are present on the page
       // - the locations content and/or the locations header
       // - the target wrapper that should finally have the locations prepended
       var target = $('.locations-wrapper');
       var locations = $('.location-locations-wrapper');
       
       if (target.length > 0 && locations.length > 0) {
         // Move the certain elements
         target.prepend(locations);
         var locations_header = $('.location-locations-header');
         target.prepend(locations_header);
         // Finish up styling etc if needed
         target.addClass('jquery-modified');
         locations.addClass('jquery-modified');
         locations_header.addClass('jquery-modified');
       }
     
     }
     /*
     * // End of location moving code
     */
     
     /**
      * When viewing events move the event date group before the event location info
      * - there is currently no way to do that by using proper theme functions
      * - 22.8.2011
      */
     var node_type = $('.node-type-event');
     if (node_type.length > 0) {
     	
     	// Do modifications only if the event contains the location information
     	// and if the event contains the event date information
     	var locations = $('.location-locations-wrapper');
     	var dates = $('.group-event-dates');
     	if (locations.length > 0 && dates.length > 0) {
     	  // Prepend the dates wrapper to the node content
     	  // and add some describing classes to the modified elements
     	  $('.node-event .content').prepend(dates).addClass('jquery-modified');
     	  dates.addClass('jquery-modified');
     	}
     }
     /**
      * End of fixing the event page with locations
      */ 
      
      
     /**
      * A simple script for handling go back links
      */
      
      // Match a go back link
      $('a.go-back-link').click(function (event) {
        // Prevent default action
        event.preventDefault();
        
        // Take the user one step back in history
        history.back();
      });
            
      /*
      * // End of go back links
      */
     
	var str_all = Drupal.t('All');
	$('ul.country-list').prepend('<li class="country-item first active"><div class="country-title"><span id="country-item" class="country-link">' + str_all + '</span></div></li>');
	$('.country-filter .country-title').click( function () {
		var country = $('.country-link', $(this)).attr("id");
		var parent = $(this).parent('.country-item');
		$('.country-filter .country-item').removeClass('active');
		parent.addClass('active');
		$('.view-sales-network .country-item').each( function () {
			if ($(this).hasClass(country) == false) {
				$(this).hide().removeClass('active-item');
			} else {
				$(this).show().addClass('active-item');
			}
		});
	});

  }); // End of (document).ready()
  // We are triggering the equal heights for webkit browsers here
  // The images have not yet been loaded on document ready event so we have to trigger some stuff on window onload
  // These should be in functions but are not.
    window.onload = function() {
    
    	if ($('body').hasClass('webkit-browser') == true) {
			$('#frontpage-smaller-liftups .block').equalHeights(225).addClass('jquery-modified');
			$('.normal-mode #main .equals').equalHeights(450);
			$('#main .region-sidebar-second .section.equals').css('overflow','visible');
			$('#main .region-sidebar-first  .section.equals').css('overflow','visible');
			$('#content, body.page-node-edit #content.equals, body.page-node-add #content.equals').css('overflow','visible');
			
		 /**
		  * Fill the empty space in the second sidebar in certain circumstances:
		  * - the content area is taller than the second sidebar
		  *
		  * The empty space should be filled with an empty block element that has a white background
		  * (current specifications at 29.6.2011)
		  */
		  
		  /// First we have to determine if a dummy block should be inserted
		  /// This happens if the content area is taller than the second sidebar
		  // We have to find the specific content area element and measure its height
		  var content = $('#content');
		  var content_height = content.height();
	
		  // Then we have to find the sepcific sidebar element and measure its height
		  // It might be safest if we calculated the total height of all blocks in the sidebar region
		  var sidebar = $('.region-sidebar-second .section');
		  var sidebar_height = 0;
		  
		  $('.block', sidebar).each( function () {
			var margin_bottom = parseInt($(this).css('margin-bottom'));
			var current_height = $(this).height();
			var total = current_height + margin_bottom;
			sidebar_height += total;
		  });
	
		  // Calculate the difference
		  var difference = content_height - sidebar_height;
	
		  // If the content area is taller than the sidebar we must insert the dummy block
		  if (difference > 0) {
			// Create the block element with proper classes and inject it to the end of the sidebar container
			// It should be at the same level than the other blocks, and probably even have same classes than the other blocks
			sidebar.append('<div class="block block-dummy"></div>');
			
			// After the block has been created we need to move the 'last' class to it from the originally last element
			$('.block.last', sidebar).removeClass('last').addClass('jquery-modified old-last');
	
			// It should be noted that the new dummy block height should be negated by the amount of margin bottom that the new old-last block has
			difference -= parseInt($('.old-last').css('margin-bottom'));
	
			// Adjust the height and classes of the dummy block
			$('.block-dummy').css('height', difference + 'px').addClass('last jquery-modified new-last');
		  } 
	
		 /*
		 * // End of dummy block code
		 */
		}
		/**
		 * Fix the footer height
		 * Case: Sometimes the page wrapper is shorter than the body element. Then we should add more 'red' to the footer
		 * and extend the height of the footer element so it would fill the gap between the page wrapper and the body element.
		 * We have to calculate the difference between page wrapper and body and add that difference to the current footer height
		 * -> this should also function when window is resized.
		 * -> this should also work backwards so the footer should get shorter when the window is resized smaller
		 * TODO: Put these things in a function
		 */ 
		 var b_height = $('body').height();
		 var p_height = $('#page-wrapper').height();
		 var f_height = $('#footer').height();
		 var difference = b_height - p_height;
		 // Increase the height of the footer if needed
		 if (difference > 0) {
			f_height += difference;
			$('#footer').css('height', f_height + 'px');
		 }
		 $(window).resize(function() {
		 	// Reset the height at first
			 $('#footer').css('height', 'auto');
			 var b_height = $('body').height();
			 var p_height = $('#page-wrapper').height();
			 var f_height = $('#footer').height();
			 var difference = b_height - p_height;
			 // Increase the height of the footer if needed
			 if (difference > 0) {
				f_height += difference;
				$('#footer').css('height', f_height + 'px');
			 }
		 });
         
  	}
})(jQuery); // End of $
;

