(function($) {
	var methods = {
		init: function() {
			// Header toggle buttons
			$("a.toggle").click(function(evt) {
				evt.preventDefault();
				methods.toggleHeader();
			});
			
			$("#header-expand-fld").stop().height(0);
			
			// Dotted lines on global footer links
			$("ul.global li a").each(function(i, el) {
				var linkW = $(el).width();
				var elipses = $("<span class='elipses'></span>").html("&rsaquo;");
				elipses.css({
					"display":"block",
					"float":"left",
					"width":$(el).parent().width() - (linkW + 10),
					"height":"100%",
					"text-align":"right",
					"border-bottom":"1px dotted #c9cacd"
				});
				$(el).append(elipses);
			});
		},
		
		// Toggle header to reveal contact form
		toggleHeader: function() {
			var expand = $("#header-expand-fld");
			var defaultHeight = 0;
			var expandHeight = 550;
			if (expand.hasClass("open")) {
				expand.stop().animate({
					height: defaultHeight
				}, 700, "easeOutExpo", function() {
					$("#dropdown-thankyou").hide();
					$("#dropdown-form").show();	
				});
			} else {
				expand.stop().animate({
					height: expandHeight
				}, 700, "easeOutExpo");
			}
			expand.toggleClass("open");
		},
		
		setCookie:function(name, value, days) {
			var exdate=new Date();
			exdate.setDate(exdate.getDate() + days);
			var cValue=escape(value) + ((days==null) ? "" : "; expires="+exdate.toUTCString());
			document.cookie=name+"="+cValue;
		},
		
		getCookie:function(cName) {
			var i,x,y,cookies=document.cookie.split(";");
			for(i=0;i<cookies.length;i++) {
				x=cookies[i].substr(0,cookies[i].indexOf("="));
				y=cookies[i].substr(cookies[i].indexOf("=")+1);
				x=x.replace(/^\s+|\s+$/g,"");
				if (x==cName) {
					return unescape(y);
				}
			}
		},
		
		getQueryValue: function (key, _default) {
			if (_default==null) _default=""; 
			key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
			var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
			var qs = regex.exec(window.location.href);
			if(qs == null) {
				return _default;
			} else {
				return qs[1];
			}
		},

		// Match height of specified elements
		matchHeight: function(matchChild, matchParent) {
			var parent = $(matchParent);
			parent.each(function() {
				var matches = $(this).find(matchChild);
				var tallest = 0;
				matches.each(function(i, el) {
					if ($(this).height() > tallest) {
						tallest = $(this).height();
					}
				})
				matches.height(tallest);
			});
		},

		// Center floated content inside specified element
		centerFloat: function(content, alignType) {
			var cnt = $(content);
			var diff = cnt.parent().width() - cnt.width();
			if (alignType == "padding") {
				cnt.css({
					"width": cnt.width(),
					"float": "left",
					"padding-left": Math.floor(diff * 0.5),
					"padding-right": Math.floor(diff * 0.5)
				});
			} else if (alignType == "margin") {
				cnt.css({
					"width": cnt.width(),
					"float": "left",
					"margin-left": Math.floor(diff * 0.5),
					"margin-right": Math.floor(diff * 0.5)
				});
			} else {
				return;
			}
		}
	}

	$.fn.common = function(method) {
		if (methods[method]) {
			return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
		} else if (typeof method === 'object' || !method) {
			return methods.init.apply(this, arguments);
		} else {
			$.error('The method "' + method + '" does not exist in jQuery.common');
		}
	};
	
})(jQuery);
