﻿

/*********************************************************/
/********                On Load                  ********/
/*********************************************************/

$(function () {
	$('.HomeMenuItem').hover(
		function () { ShowSubMenu(this) },
		function () { HideSubMenu(this) }
	);
	$('.HomeMenuItem').click(
		function () { ShowSubMenu(this) }
	);
	InitRollOverButtons();
	MakeTabsMultiline();

	$("#CountrySelector").hover(
		function () { $("#CountrySelectorDropDown").show(); },
		function () { $("#CountrySelectorDropDown").hide(); }
	);

	StretchLeftColumn();

	$('.Captcha').click(function () {
		var originalUrl = new String(this.src);
		var pos = originalUrl.indexOf("&d=");
		if (pos >= 0) {
			originalUrl = originalUrl.substring(0, pos);
		}
		var d = new Date();
		this.src = originalUrl + "&d=" + d.getTime();
	});
});


/*********************************************************/
/********            Initialization               ********/
/*********************************************************/

function InitializeRefineResults() {
	$('body').append('<span class="DoorResultTooltip"></span>');
	$(".Thumb")
		.mouseover(ShowDoorResultToolTip)
		.mousemove(MoveDoorResultToolTip)
		.mouseleave(HideDoorResultToolTip);
	InitializeTaxonomy();
}

function InitializeTaxonomy(callBack) {
	$('.auto-collapse').each(function () { AutoCollapse(this) })
	$('.ExpandCollapse').click(function () { ExpandCollapse(this) });

	$('.TaxonomyWithImage')
		.mouseover(ShowTaxonomyImage)
		.mousemove(MoveTaxonomyImage)
		.mouseleave(HideTaxonomyImage);

	$(':checkbox').click(function () {
		RefreshTaxonomySearchResults();
		if (callBack)
			callBack();
	});

	$('.ButtonClearAll').click(function () {
		$(':checkbox').attr('checked', false);
		RefreshTaxonomySearchResults();
		if (callBack)
			callBack();
	});

	if ($(':checked').length > 0) {
		RefreshTaxonomySearchResults();
		if (callBack)
			callBack();
	}

}

function InitializeProductPage() {
	if ($(".HeaderImage").length > 1) {
		ShowProductPicture($("ul.ThumbnailImages li:first"));
	} else {
		$("ul.ThumbnailImages").hide();
		$(".HeaderImage").show();
	}
	ShowTabContent($("ul.Tabs li:first"));
	ActivateProductClicks();
}



function InitializeImageGallery() {
	ShowGalleryPicture($('#GalleryThumbnails li:first'));

	$('#GalleryThumbnails img').mouseenter(function () { ShowGalleryPicture($(this).parent().parent()); });

	var thumbSize = 77;
	var scrollno = 7;
	var width = $('#GalleryThumbnails li:visible').length * thumbSize;

	if ($('#GalleryThumbnails').width() < width)
		$('#GalleryThumbnails').width(width);

	$('#GalleryLeft').click(function () { SlideGalleryPages($('#GalleryThumbnails li.active').prevAll(':visible'), scrollno, true); });
	$('#GalleryRight').click(function () { SlideGalleryPages($('#GalleryThumbnails li.active').nextAll(':visible'), scrollno, true); });

	$('#GalleryFirst').click(function () { SlideGalleryTo($('#GalleryThumbnails li.active').prevAll(':visible').last(), true); });
	$('#GalleryLast').click(function () { SlideGalleryTo($('#GalleryThumbnails li.active').nextAll(':visible').last(), true); });

	$('#GalleryPrev').click(function () { SlideGalleryPages($('#GalleryThumbnails li.active').prevAll(':visible'), 1, false); });
	$('#GalleryNext').click(function () { SlideGalleryPages($('#GalleryThumbnails li.active').nextAll(':visible'), 1, false); });


	InitializeTaxonomy(ImageGalleryRefreshCallBack);

}

function ActivateProductClicks() {
	$("ul.Tabs li").click(function () { return ShowTabContent($(this)); });

	$("ul.ThumbnailImages li").hover(
		function () {
			$(this).find('img').css({ 'opacity': '0.8' });
			ShowProductPicture($(this));
		},
		function () {
			$(this).find('img').css({ 'opacity': '1' });
		}
	);

	$("ul.ThumbnailImages li").click(function () {
		return ShowProductPicture($(this));
	});
}

function MakeTabsMultiline() {
	$("ul.Tabs li:has(br)").each(function () {
		var $tab = $(this).parent();
		$tab.addClass("TabsMultiline");
		$tab.find("li a:has(br)").addClass("Multiline");
	});
}

function InitializeQuickDealerLocator($textBox, $link, siteSection) {
	var originalValue = $textBox.val();
	$textBox.TextBoxWithHint().OnEnterKey(function () { return GoToDealerLocator($textBox, $link, originalValue, siteSection); });
	$link.unbind('click').click(function () { return GoToDealerLocator($textBox, $link, originalValue, siteSection); });
}

function InitializeSearchThisSite($textBox) {
	var originalValue = $textBox.val();
	$textBox.TextBoxWithHint()
		.blur(function () { return SearchThisSite($textBox, originalValue); })
		.OnEnterKey(function () { return SearchThisSite($textBox, originalValue); });
}

function FAQShowAll() {
	$(".FAQEntry").show();
	$(".BottomLink").hide();
}

function FAQSearch(text) {
	SearchAndHighlight($(".FAQEntry"), $(".FAQEntry"), text);
}

function LexiconSearch(text) {
	SearchAndHighlight($(".LexiconEntry"), $(".LexiconEntry, .LexiconGroup"), text);
}

function InitializeFAQ() {

	$(".FAQEntry").slice(20).hide();

	$("#txtSearch").change(function () {
		FAQSearch($(this).val());
	});

	var searchQuery = queryString["s"];
	if (searchQuery) {
		$("#txtSearch").val(searchQuery);
		FAQSearch(searchQuery);
	}

	$(".ClearSearch").click(function (e) {
		$("#txtSearch").val("");
		FAQSearch("");
		e.preventDefault();
	});

}


function InitializeLexique() {

	$("#txtSearch").change(function () {
		LexiconSearch($(this).val());
	});

	var searchQuery = queryString["s"];
	if (searchQuery) {
		$("#txtSearch").val(searchQuery);
		LexiconSearch(searchQuery);
	}

	$(".ClearSearch").click(function (e) {
		$("#txtSearch").val("");
		LexiconSearch("");
		e.preventDefault();
	});

}


/*********************************************************/
/********                Helpers                  ********/
/*********************************************************/


function InitRollOverButtons() {
	$('img.rollOverButton, input[type=image].rollOverButton').hover(
		function () { PictureRollover($(this), 'src-mouse-in'); },
		function () { PictureRollover($(this), 'src-mouse-out'); }
	);
	$('div.rollOverButton').hover(
		function () { DivRollover($(this), 'src-mouse-in'); },
		function () { DivRollover($(this), 'src-mouse-out'); }
	);
}

function DivRollover($div, attribute) {
	$div.find('img').each(function () {
		PictureRollover($(this), attribute);
	});
}

function PictureRollover($img, attribute) {
	var src = $img.attr(attribute);
	if (src && src != "")
		$img.attr('src', src);
}

function ProductTab(text) {
	var anchor = $("ul.Tabs li a:contains(" + text + ")")
	if (anchor != null) {
		var tab = anchor.parent();
		if (tab != null)
			ShowTabContent(tab);
	}
}

function ProductTabNo(index) {
	var tab = $("ul.Tabs li:eq(" + (index - 1) + ")")
	if (tab != null)
		ShowTabContent(tab);
}

function SetButtonPicture($target, $source) {
	var imgOut = $source.attr('img-out');
	var imgIn = $source.attr('img-in');
	var alt = $source.text();
	if (imgOut != '') {
		if (imgIn != '') {
			$target.html($("<img/>", { "class": "rollOverButton", "src": imgOut, "src-mouse-out": imgOut, "src-mouse-in": imgIn, "alt": alt }));
			InitRollOverButtons();
		} else {
			$target.html($("<img/>", { "class": "rollOverButton", "src": imgOut, "alt": alt }));
		}
	}
}


function ShowSubMenu(menu) {
	$('.HomeMenuItem').removeClass('ActiveMenuItem');
	$(menu).addClass('ActiveMenuItem');
	$('.HomeSubmenuItem').hide();
	clearTimeout($('.HomeSubmenuItem', menu).attr('timeoutID'));
	$('.HomeSubmenuItem', menu).show();
}

function HideSubMenu(menu) {
	$(menu).removeClass('ActiveMenuItem');
	var subMenu = $('.HomeSubmenuItem', menu).first();
	var id = setTimeout(function () { subMenu.hide(); }, 200);
	$('.HomeSubmenuItem', menu).attr('timeoutID', id);
}

function allImagesLoaded() {
	var complete = true;
	$('img').each(function () {
		if (this.complete == false)
			complete = false;
	});
	return complete;
}
var initialLeftMenuHeight = 0;
var retryWhenImagesLoaded = 10;
function StretchLeftColumn() {

	if (retryWhenImagesLoaded > 0 && !allImagesLoaded()) {
		retryWhenImagesLoaded--;
		setTimeout(arguments.callee, 100);
	}

	if (initialLeftMenuHeight == 0)
		initialLeftMenuHeight = $('#LeftMenuContent').height();
	else
		$('#LeftMenuContent').css('height', initialLeftMenuHeight);

	var totalHeight = $('#LeftColumn').height();
	var header = $('#LeftMenuTop').height();
	var footer = $('#LeftMenuBottom').height();
	var newHeight = totalHeight - header - footer;

	if (newHeight > initialLeftMenuHeight)
		$('#LeftMenuContent').css('height', newHeight);
}

function ShowDoorResultToolTip() {
	$('.DoorResultTooltip').html($('img', this).attr('alt')).show();
	var path = $('img', this).attr('picture-src');
	$(this).parent().parent().find('.ProductPicture').attr('src', path);
	$(this).parent().find('.Thumb').removeClass('ActiveThumb');
	$(this).addClass('ActiveThumb');
}

function HideDoorResultToolTip() {
	$('.DoorResultTooltip').hide();
}

function MoveDoorResultToolTip(mouse) {
	$('.DoorResultTooltip').css({ left: mouse.pageX - 5, top: mouse.pageY + 20 });
}

function Expand(checkbox) {
	$(checkbox).attr('src', '/garaga/images/collapse.png');
	$(checkbox).parent().parent().find('ul').find('li').show();
}
function Collapse(checkbox) {
	$(checkbox).attr('src', '/garaga/images/Expand.png');
	$(checkbox).parent().parent().find('ul').find('li').hide();
}

function AutoCollapse(checkbox) {
	if ($(checkbox).parent().parent().find('ul').find('li').find(':checked').length == 0)
		Collapse(checkbox);
}


function ExpandCollapse(checkbox) {
	var src = $(checkbox).attr('src').toLowerCase();
	if (src.indexOf('collapse.png') >= 0) {
		Collapse(checkbox);
	} else {
		Expand(checkbox);
	}
}

function ShowTaxonomyImage() {
	$(this).find('.TaxonomyImage').show();
}

function MoveTaxonomyImage(mouse) {
	var $ToolTip = $(this).find('.TaxonomyImage');
	$ToolTip.css({ left: mouse.pageX - $(this).offset().left + 25, top: mouse.pageY - 20 });
}

function HideTaxonomyImage() {
	$(this).find('.TaxonomyImage').hide();
}

function ReturnFalse() {
	return false;
}


function SlideGalleryPages($nextThumbs, scrollAmount, animate) {

	if ($nextThumbs.length < scrollAmount)
		scrollAmount = $nextThumbs.length;


	SlideGalleryTo($nextThumbs.eq(scrollAmount - 1), animate);
}

function SlideGalleryTo($selectedThumb, animate) {

	if (!$selectedThumb || $selectedThumb.length == 0)
		return;

	var negativeOffset = $selectedThumb.position().left * -1;

	if (animate) {
		$('#GalleryPicture').css('opacity', '0.7');
		$('#GalleryThumbnails').animate({ 'left': negativeOffset + 'px' }, 500, 'swing', function () {
			ShowGalleryPicture($selectedThumb);
			$('#GalleryPicture').css('opacity', '1');
		});
	} else {

		$('#GalleryThumbnails').animate({ 'left': negativeOffset + 'px' }, 100, 'swing', function () {
			ShowGalleryPicture($selectedThumb);
		});
	}
}


function BuildTaxonomy(groups, taxIds) {
	var group = $(this).attr('name');
	var taxId = $(this).attr('value');

	var i = $.inArray(group, groups);
	if (i == -1) {
		i = groups.length;
		groups[i] = group;
	}

	if (taxIds[i] && taxIds[i] != null && taxIds[i].length > 0)
		taxIds[i] += ", ." + taxId;
	else
		taxIds[i] = "." + taxId;
}

function ShowOrHide(doorResult, groups, taxIds) {
	for (i = 0; i < groups.length; i++) {
		if (!$(doorResult).is(taxIds[i]))
			$(doorResult).removeClass("ShowThisDoor");
	}
}


function CreateTaxonomyGroup(groups, group) {
	var i = $.inArray(group, groups);
	if (i == -1) {
		i = groups.length;
		groups[i] = group;
	}
	return groups;
}

function CreateTaxonomyList(taxIds, taxId, i) {
	if (taxIds[i] && taxIds[i] != null && taxIds[i].length > 0)
		taxIds[i] += ", ." + taxId;
	else
		taxIds[i] = "." + taxId;
	return taxIds;
}

function GoToDealerLocator($textBox, $link, originalValue, siteSection) {
	var search = $textBox.val();
	var url = $link.attr('href') + '?s=' + siteSection;
	if (search != originalValue)
		url = url + '&q=' + search;
	location.href = url;
	return false;
}

function SearchThisSite($textBox, originalValue) {
	var search = $textBox.val();
	if (search == originalValue)
		search = "";
	location.href = $textBox.attr('data-search-page') + '?searchText=' + search;
	return false;
}

/*********************************************************/
/********            Feature specific             ********/
/*********************************************************/

function RefreshTaxonomySearchResults() {
	var groups = [];
	var taxIds = [];

	$(":checkbox:checked'").each(function () {
		groups = CreateTaxonomyGroup(groups, $(this).attr('name'));
		var i = $.inArray($(this).attr('name'), groups);
		taxIds = CreateTaxonomyList(taxIds, $(this).attr('value'), i);
	});

	$('.DoorResult')
		.hide()
		.addClass("ShowThisDoor")
		.each(function () { ShowOrHide(this, groups, taxIds); });

	$('.ShowThisDoor').show();

}

function ImageGalleryRefreshCallBack() {
	$('#GalleryContent').show();
	if ($('#GalleryThumbnails').position().left != 0) {
		$('#GalleryThumbnails').animate({ 'left': '0px' }, 500, 'swing', function () {
			ShowGalleryPicture($('#GalleryThumbnails li:visible').first());
		});
	} else {
		ShowGalleryPicture($('#GalleryThumbnails li:visible').first());
	}
}

function ShowTabContent(tab) {
	$("ul.Tabs li").removeClass("active");
	tab.addClass("active");
	$(".Tab").hide();
	var activeTab = tab.find("a").attr("href");
	$(activeTab).show(); //fadeIn();
	StretchLeftColumn();
	return false;
}

function ShowProductPicture(thumb) {
	$("ul.ThumbnailImages li").removeClass("active");
	thumb.addClass("active");
	$(".HeaderImage").hide();
	var activeImage = thumb.find("a").attr("href");
	$(activeImage).show(); //fadeIn();
	return false;
}


function ShowGalleryPicture($item) {
	var $header = $('#GalleryMenu');

	$('#GalleryThumbnails li').removeClass("active");
	if ($item.length > 0) {
		$('#NoPictureFound').hide();

		var $link = $item.find('.LinkPicture');

		$item.addClass("active");

		$('#GalleryPicture a').attr("href", $link.attr('href')).html($("<img/>", { "src": $link.attr('href'), "alt": $link.find('img').attr('alt') }));
		$('#GalleryClickToZoom a').attr('href', $link.attr('href'));

		$header.html("")
				.append("<div id=\"DoorName\">" + $link.find('img').attr('alt') + "</div>")
				.append($item.find('.DoorSpecs').clone());

		$('#GalleryIndex').html(($item.prevAll(':visible').length + 1) + " / " + ($item.siblings(':visible').length + 1));

		var $googleMapInfo = $item.find('.DoorSpecs');
		var $testimonial = $item.find('.Testimonial');

		if ($googleMapInfo.attr('data-Latitude') != "" || $testimonial.length > 0) {
			$('#ImageGallery').css("height", "635px");
		} else if ($('#DealerDetails').length > 0) {
			// Dealer Locator Detail Page (tabs) = -25px
			$('#ImageGallery').css("height", "410px");
		} else {
			$('#ImageGallery').css("height", "435px");
		}


		if ($googleMapInfo.attr('data-Latitude') != "") {
			$('#GalleryGoogleMap')
				.attr("data-Latitude", $googleMapInfo.attr("data-Latitude"))
				.attr("data-Longitude", $googleMapInfo.attr("data-Longitude"))
				.attr("data-ZoomLevel", $googleMapInfo.attr("data-ZoomLevel"))
				.ShowGoogleMap();
		}

		if ($testimonial.length > 0) {
			$('#GalleryTestimonial span').html($testimonial.html());
			$('#GalleryTestimonial').show();
		} else {
			$('#GalleryTestimonial span').html("");
			$('#GalleryTestimonial').hide();
		}

		var $getAQuote = $item.find('.LinkGetAQuote');
		var $learnMore = $item.find('.LinkLearnMore');

		if ($getAQuote != null)
			$header.append($getAQuote.clone());

		if ($learnMore != null)
			$header.append($learnMore.clone());

		SetButtonPicture($header.find(".LinkGetAQuote"), $getAQuote);
		SetButtonPicture($header.find(".LinkLearnMore"), $learnMore);


	} else {
		$('#GalleryContent').hide();
		$('#NoPictureFound').show();

	}

}


/*********************************************************/
/********         HomePage Rotating Banner        ********/
/*********************************************************/

var selectingBanner = false;
var timerID = 0;

function RotateBannerItem() {
	if (selectingBanner == false) {
		var $active = $('.RotatingBannerItem:visible');
		if ($active.length > 0) {
			var $next = $active.next('.RotatingBannerItem');
			if ($next.length == 0) {
				$next = $('.RotatingBannerItem:hidden').first();
			}
			ShowBannerItem($next);
		}
	}
}

function ActivateBannerLinks() {
	selectingBanner = false;
	$('.InactiveBannerItem').click(function () {
		selectingBanner = true;
		StopBannerTimer();
		var index = $(this).attr('itemNo');
		var $next = $('.RotatingBannerItem').eq(index);
		ShowBannerItem($next);
		StartBannerTimer();
	});
}

function ShowBannerItem($next) {
	var $active = $('.RotatingBannerItem:visible');
	if ($active.length > 0) {
		$('.InactiveBannerItem').unbind('click');
		$active.find('.BannerText').hide();
		$next.show()
			.css({ 'opacity': '0.0', 'z-index': '11' })
			.animate({ 'opacity': '1.0' }, 1000, function () {
				$active.hide();
				$next.find('.BannerText').show();
				$next.css({ 'opacity': '', 'z-index': '10' });
				ActivateBannerLinks();
			});

	}
}


function StopBannerTimer() {
	clearInterval(timerID);
}
function StartBannerTimer() {
	timerID = setInterval("RotateBannerItem()", 4000);
}

function SetupBanner() {
	$('.RotatingBannerLinks').each(function (LinkIndex) {
		var links = "";
		$('.RotatingBannerItem').each(function (ItemIndex) {
			var cssClass = (LinkIndex == ItemIndex ? 'ActiveBannerItem' : 'InactiveBannerItem');
			links = links + '<div class="' + cssClass + '" itemNo="' + ItemIndex + '">' + (ItemIndex + 1) + '</div>';
		});
		$(this).html(links);
	});

	$('.RotatingBannerItem').first().show();
	ActivateBannerLinks();
	StartBannerTimer();
}



/*********************************************************/
/********            jQuery Extensions            ********/
/*********************************************************/

(function ($) {

	$.fn.TextBoxWithHint = function () {
		var dataAttribute = 'data-originalvalue';
		this.attr(dataAttribute, this.val())
					.focus(function () {
						if ($(this).val() == $(this).attr(dataAttribute))
							$(this).val('');
					}).blur(function () {
						if ($(this).val() == '')
							$(this).val($(this).attr(dataAttribute));
					});
		return this;
	}


	$.fn.OnEnterKey = function (actionCallback) {
		this.keypress(function (event) {
			var code = (event.keyCode ? event.keyCode : event.which);
			if (code == 13) {
				actionCallback($(this));
				event.preventDefault();
			}
		});
		return this;
	}

	$.fn.RotateBanner = function () {

		this.AfficherProchaineImage = function (imageSet) {
			return function () {
				var visible = imageSet.filter(':visible');
				var nextVisible = visible.next();
				if (nextVisible == null || nextVisible.length == 0)
					nextVisible = imageSet.first();

				nextVisible.show()
				.css({ 'opacity': '0.0', 'z-index': '11' })
				.animate({ 'opacity': '1.0' }, 1000, function () {
					visible.hide();
					nextVisible.css({ 'z-index': '10' });
				});

			}
		}

		this.css({
			'position': 'absolute',
			'top': '0px',
			'left': '0px'
		}).hide().first().show();

		if (this.length > 1)
			setInterval(this.AfficherProchaineImage(this), 4000);
		return this;
	}

	$.fn.ShowGoogleMap = function () {

		this.each(function () {
			var id = $(this).attr('id');
			var lat = $(this).attr('data-Latitude');
			var lng = $(this).attr('data-Longitude');
			var zm = $(this).attr('data-ZoomLevel');

			if (!zm || typeof (zm) == undefined || zm === "")
				zm = 12;
			else
				zm = parseInt(zm);

			var latLng = new google.maps.LatLng(lat, lng)

			var googleMap = new google.maps.Map(this, {
				zoom: zm,
				center: latLng,
				mapTypeId: google.maps.MapTypeId.ROADMAP,
				scrollwheel: false
			});



			mainMarker = new google.maps.Marker({
				position: latLng,
				map: googleMap,
				zIndex: 0,
				draggable: false
			});

			var divBulle = $(this).attr('data-Contenu');
			if (divBulle && divBulle != undefined && divBulle != '') {
				var contenuBulle = $(divBulle).html();
				if (contenuBulle != '') {
					var infowindow = new google.maps.InfoWindow({
						content: contenuBulle,
						disableAutoPan: false
					});

					mainMarker.window1 = infowindow;
					infowindow.open(googleMap, mainMarker);
				}
			}



		});

		return this;
	}

	/*

	highlight v3

	Highlights arbitrary terms.

	<http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html>

	MIT license.

	Johann Burkard
	<http://johannburkard.de>
	<mailto:jb@eaio.com>

	*/

	$.fn.highlight = function (pat) {
		function innerHighlight(node, pat) {
			var skip = 0;
			if (node.nodeType == 3) {
				var pos = node.data.toUpperCase().indexOf(pat);
				if (pos >= 0) {
					var spannode = document.createElement('span');
					spannode.className = 'highlight';
					var middlebit = node.splitText(pos);
					var endbit = middlebit.splitText(pat.length);
					var middleclone = middlebit.cloneNode(true);
					spannode.appendChild(middleclone);
					middlebit.parentNode.replaceChild(spannode, middlebit);
					skip = 1;
				}
			}
			else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) {
				for (var i = 0; i < node.childNodes.length; ++i) {
					i += innerHighlight(node.childNodes[i], pat);
				}
			}
			return skip;
		}
		this.each(function () {
			innerHighlight(this, pat.toUpperCase());
		});

		return this.find('.highlight');
	};

	$.fn.removeHighlight = function () {
		return this.find("span.highlight").each(function () {
			this.parentNode.firstChild.nodeName;
			with (this.parentNode) {
				replaceChild(this.firstChild, this);
				normalize();
			}
		}).end();
	};


})(jQuery);


function SearchAndHighlight($searchNodes, $showNodes, text) {
	if (text && text != '') {
		$showNodes.hide();
		$searchNodes
			.removeHighlight()
			.highlight(text)
			.parents().show();

		$(".AdditionalKeywords").hide();

	} else {
		$searchNodes.removeHighlight()
		$showNodes.show();
	}

	if ($showNodes.filter(":visible").length == 0) {
		$(".NoResultFound").show();
	} else {
		$(".NoResultFound").hide();
	}
}


var queryString = {};
(function () {
	var e,
        a = /\+/g,  // Regex for replacing addition symbol with a space
        r = /([^&=]+)=?([^&]*)/g,
        d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
        q = window.location.search.substring(1);

	while (e = r.exec(q))
		queryString[d(e[1])] = d(e[2]);
})();



