$(document).ready(function(){
	
	// Fancy tool-tip
	$('#swatchThumbnails img').tooltip({
		delay: 0,
		track: true,
		showURL: false
	});
	
	// Hide all instances of .tabPanel, except for the very first one.
	$('.tabPanel:not(:first)').hide();
	
	// When someone clicks on the More Info link, show the More Info panel
	$('#tabLinkMoreInfo a').click(function(){
		$('.tabPanel:visible').hide();
		$('#moreInfo').show();
		return false;
	});
	
	// When someone clicks on the Commercials link, show the Commercials panel
	$('#tabLinkCommercials a').click(function(){
		$('.tabPanel:visible').hide();
		$('#productCommercials').show();
		return false;
	});
	
	// When someone clicks on the Send to Friend link, show the Send to Friend panel
	$('#tabLinkSendFriend a').click(function(){
		$('.tabPanel:visible').hide();
		$('#sendFriend').show();
		return false;
	});

});

location.querystring = (function() {
    // The return is a collection of key/value pairs
    var queryStringDictionary = {};
    // Gets the query string, starts with '?'
    var querystring = decodeURI(location.search);
    // document.location.search is empty if no query string
    if (!querystring) {
        return {};
    }
    // Remove the '?' via substring(1)
    querystring = querystring.substring(1);
    // '&' seperates key/value pairs
    var pairs = querystring.split("&");
    // Load the key/values of the return collection
    for (var i = 0; i < pairs.length; i++) {
        var keyValuePair = pairs[i].split("=");
        queryStringDictionary[keyValuePair[0]]
                = keyValuePair[1];
    }
    // toString() returns the key/value pairs concatenated
    queryStringDictionary.toString = function() {
        if (queryStringDictionary.length == 0) {
            return "";
        }
        var toString = "?";
        for (var key in queryStringDictionary) {
            toString += key + "=" +
                queryStringDictionary[key];
        }
        return toString;
    };
    // Return the key/value dictionary
    return queryStringDictionary;
})();


// This is how to call it in your script
// (If "q" isn't there, val is undefined):
//var val = location.querystring["q"];

// This is how to roll out all of them:
//for (var key in location.querystring) {
//    alert(key + "=" + location.querystring[key]);
//}

// this is how to get the whole thing (incl. the ?):
//alert(window.location.querystring.toString());

