function Querystring(qs) {    // optionally pass a querystring to parse
    this.params = {};

    if (qs == null) qs = location.search.substring(1, location.search.length);
    if (qs.length == 0) return;

    // Turn <plus> back to <space>
    qs = qs.replace(/\+/g, ' ');
    var args = qs.split('&'); // parse out name/value pairs separated via &

    // split out each name=value pair
    for (var i = 0; i < args.length; i++) {
        var pair = args[i].split('=');
        var name = decodeURIComponent(pair[0]);
        var value = (pair.length == 2) ? decodeURIComponent(pair[1]) : "";
        this.params[name] = value;
    }
}

Querystring.prototype.get = function(key, default_)
   {
           var value = this.params[key];
           return (value != null) ? value : default_;
   }

   Querystring.prototype.contains = function(key)
   {
           var value = this.params[key];
           return (value != null);
   }

/*
	===========
	= Cookies =
	===========
*/
HISTORY.cookies = {                                                                         
	timeoutDays : 30, // Duration of the cookie in days.

	// Cookie setter.
	set : function (name, value) {
		var expirationDate = new Date();
		expirationDate.setDate(expirationDate.getDate() + this.timeoutDays);
		document.cookie = name + "=" + escape(value) + ";expires=" + expirationDate.toGMTString();
	},

	// Cookie getter.
	get : function (name) {
		var start, end;
		if (document.cookie.length > 0) {
			start = document.cookie.indexOf(name + "=");
			if (start != -1) {
				start = start + name.length + 1;
				end = document.cookie.indexOf(";",start);
				if (end == -1) {
					end = document.cookie.length;
				}
				return unescape(document.cookie.substring(start,end));
			}
		}
		return false;
	},

    setTimeOutDays : function (days) {
        this.timeoutDays = days;
    }
};

/*
	==================
	= jQuery Plugins =
	==================
	Make sure $ is protected.
*/
(function($){
	/*
		labelHide
		---------
		Loops through a result set and for each result, takes the value of any
		associated label, applies it as the value of the result, and hides the label.
	*/
	$.fn.labelHide = function (value) {
		this.each(function () {

			var obj, id, label;
			obj = $(this);
			id = obj.attr("id");
			label = $("label[for='"+id+"']");

			if (id.length > 0 && label.length > 0) {
				if (value) {
					obj.val(label.text());
				}
				label.hide();
			}
		});
		return this;
	}

	/*
		Clear Defaults
		--------------
		This function loops through a result set and for each result,
		it clears the default value onfocus and restores the default
		if the value is empty onblur.
	*/
	$.fn.clearDefault = function (str_default) {
		return this.each(function () {

			var obj = $(this),
				obj_val = obj.val();

			if (obj_val.length === 0) {

				obj.val(str_default);

				obj.focus(function () {
					if (obj.val() == str_default) {
						obj.val("");
					}
				});

				obj.blur(function () {
					if (obj.val() == "") {
						obj.val(str_default);
					}
				});
			}
		});
	}

	/*
		Submit Replace
		--------------
		When applied to a form, this plugin will find any submit
		button and replace it with an anchor.
	*/
	$.fn.submitReplace = function (klass) {
		 this.each(function () {
		 	var form, btn;
			form = $(this);
			btn  = form.find(':submit');

			btn.hide().after('<a href="#">'+btn.val()+'</a>');

			if (klass.length) {
				btn.next().addClass(klass);
			}

			btn.next().click(function (e) {
				e.preventDefault();
				form.submit();
			});

		});
		return this;
	}

	/*
		Match Columns
		-------------
		This function loops through a result set and for each result,
		it matches the height of the longest result.
	*/
	$.fn.matchColumns = function () {
		var height_tar = 0;

		this.each(function () {
			height_obj = $(this).outerHeight();
			height_tar = Math.max(height_tar, height_obj);
		});

		this.each(function () {
			var pad_top = parseInt($(this).css("padding-top"));
			var pad_bot = parseInt($(this).css("padding-bottom"));
			var bor_top = parseInt($(this).css("border-top-width"));
			var bor_bot = parseInt($(this).css("border-bottom-width"));

			var offset = pad_top + pad_bot + bor_top + bor_bot;

			// fix for ie6
			if ($.browser.msie && $.browser.version == 6) {
				$(this).css({"height": (height_tar - offset) + "px"});
			}
			else {
				$(this).css({"min-height": (height_tar - offset) + "px"});
			}
		});
		return this;
	}

	/*
		Alternate
		---------
		Iterates through a set of given objects and applies 'odd' or 'even'
		class to each element
	*/
	$.fn.alternate = function () {
		var i = 0;
		this.each(function () {
			(i % 2 == 0) ? $(this).addClass('odd') : $(this).addClass('even');
			i++;
		});
		return this;
	}

	/*
		Font Resizer
		------------
	*/
	$.fn.fontResizer = function () {
		return this.each(function () {
			var fontSizeSet = false;
			var resizerCookie = HISTORY.cookies.get('resizer');

			// Validate cookied value against array...
			for (var i = 0; i < HISTORY.font_sizes.length; i++) {
				if (HISTORY.font_sizes[i] == resizerCookie) {
					HISTORY.body.addClass(resizerCookie);
					fontSizeSet = true;
				}
			}

			if (!fontSizeSet) {
				HISTORY.body.addClass(HISTORY.font_sizes[0]);
			}

			$(this).click(function (e) {
				e.preventDefault();
				for (var i = 0; i < HISTORY.font_sizes.length; i++) {
					if (HISTORY.body.hasClass(HISTORY.font_sizes[i])) {
						var next = (i + 1 > HISTORY.font_sizes.length - 1) ? 0 : i + 1;
						HISTORY.body.removeClass(HISTORY.font_sizes[i]).addClass(HISTORY.font_sizes[next]);
						HISTORY.cookies.set('resizer',HISTORY.font_sizes[next]);
						break;
					}
				}
			});
		});
	}

	/*
		Switchers
		---------
	*/
	$.fn.switchers = function () {
		return this.each(function () {
			var link_a, link_b, list_a, list_b;

			link_a = $('.category-head p a:eq(0)',this);
			link_b = $('.category-head p a:eq(1)',this);
			list_a = $('ul:eq(0)',this);
			list_b = $('ul:eq(1)',this);

			link_a.addClass('selected');
			list_b.hide();

			link_a.click(function (e) {

				e.preventDefault();

				list_b.fadeOut('fast', function () {
					link_b.removeClass('selected');

					list_a.fadeIn('fast', function () {
						link_a.addClass('selected');
					});
				});

			});

			link_b.click(function (e) {

				e.preventDefault();
				link_a.removeClass('selected');

				list_a.fadeOut('fast',function () {
					link_a.removeClass('selected');

					list_b.fadeIn('fast',function () {
						link_b.addClass('selected');
					});
				});

			});
		});
	}

	/*
		UL Select List
		--------------
		This function loops through a result set and for each result,
		creates a fake element similar to a select box.  Only applies
		to <ul>s with links in the <li>s.
	*/
	$.fn.ulSelectList = function () {
		this.each(function () {

			if ($.browser.msie && $.browser.version < 8) { // IE6/7 get a select box instead of the fancy fake dropdown.
				var obj, select;

				obj = $(this);
				obj.hide().after('<select></select>');
				select = obj.next();

				// Make copies of the links inside the new select element.
				$('a',obj).each(function () {
					obj = $(this);
					if (obj.parent().hasClass('selected')) {
						select.append('<option selected="selected" value="selected">'+obj.text()+'</option>');
					}
					else {
						select.append('<option value="'+obj.attr('href')+'">'+obj.text()+'</option>');
					}
				});

				// On change, the select options redirect the user as if they
				// had clicked a link in the fake select.
				select.change(function () {
					if ($(this).val() != 'selected') {
						window.location = $(this).val();
					}
				});
			} else {

				// Initial setup of the fake select.
				var ul = $(this);
				ul.wrap('<div class="fake-select inactive"></div>');
				var div = ul.parent();
				div.append('<a class="trigger" href="#"></a>');
				$('li.selected',ul).siblings().hide();

				// The trigger toggles the reveal/collapse functions.
				$('a.trigger',div).click(function (e) {
					e.preventDefault();
					if (div.hasClass('inactive')) {
						reveal();
					}
					else {
						collapse();
					}
				});

				// When you click on the selected item, which is hard-coded
				// into the template, do not do anything - simply collapse
				// the fake select box.
				$('li.selected a',ul).click(function (e) {
					e.preventDefault();
					if (div.hasClass('inactive')) {
						reveal();
					}
					else {
						collapse();
					}
				});

				// Set a timer so that when you mouseout of the fake select,
				// it will wait 2 seconds and then collapse itself.
				var timer = false;
				div.hover(function () {
					if (timer) {
						clearTimeout(timer);
					}
				},function () {
					if (div.hasClass('active'))	{
						timer = setTimeout(collapse,1000);
					}
				});

				// Reveals the fake select options.
				function reveal() {
					div.removeClass('inactive').addClass('active');
					$('li',ul).slideDown(100);
				}

				// Collapses the fake select options.
				function collapse() {
					div.removeClass('active').addClass('inactive');
					$('li:not(.selected)',ul).slideUp(100);
				}
			} // else
		}); // each
		return this;
	}

	/*
		Browser offset fix
		------------------
		Intended to fix background centering issue. On browser resize, detects for odd number
		pixels (most browsers). If so, applies css offset for the given property.
	*/
	$.fn.browserOffsetFix = function (property, offset) {
		var obj, ver, ie6, ie7, ff3, saf4, prop_val;
		obj  = $(this);
		ver  = $.browser.version;
		ie6  = ($.browser.msie && ver < 7);
		ie7  = ($.browser.msie && ver == 7);
		ff3  = ($.browser.mozilla && ver.split('.')[2] == 0);
		saf4 = ($.browser.safari && ver.split('.')[0] >= 528);
		prop_val = Number(obj.css(property).replace('px',''));

		// init fix on browser load
		propertyFix();

		// fix on resize
		$(window).resize(propertyFix);

		function propertyFix() {
			// Determine if the viewport has an odd width.
			var odd_width = $(window).width() % 2 ? true : false;
			// Add the offset to the given property in these cases.
			if ((ie6 && odd_width) || (ie7 && odd_width) || (saf4 && odd_width)) {
				obj.css(property, prop_val + offset + "px");
			}
			// Subtract the offset from the given property in these cases.
			else if (ff3 && odd_width) {
				obj.css(property, prop_val - offset + "px");
			}
			// Otherwise, restore original value.
			else {
				obj.css(property, prop_val + "px");
			}
		} // propertyFix()
	} // browserOffsetFix()

	/*
		Open New Modular Windows
		------------------------
	*/
	$.fn.newWindow = function (width, height, scrollbars, name) {
		this.each(function () {
			name   = (name == null) ? "main" : name;
			width  = (width == null) ? "490" : width;
			height = (height == null) ? "600" : height;
			scrollbars = (scrollbars == null) ? 0 : scrollbars;

			$(this).click(function (e) {
				e.preventDefault();
				window.open($(this).attr('href'), name, 'width=' + width + ',height=' + height + ',scrollbars=' + scrollbars + ',resizeable=1,menubar=0');
			});
		});
		return this;
	}

})(jQuery);

jQuery(function ($) {	
					$('ul.showsSub, ul.videosSub, ul.featuresSub').hide();

					$('.nav ul li.shows, ul.showsSub').hover(function() {$('ul.showsSub').show();}, function () {$('ul.showsSub').hide();});
					$('.nav ul li.videos, ul.videosSub').hover(function() {$('ul.videosSub').show();}, function () {$('ul.videosSub').hide();});
					$('.nav ul li.features, ul.featuresSub').hover(function() {$('ul.featuresSub').show();}, function () {$('ul.featuresSub').hide();});
				});



