$(document).ready(function() {
	
	doMainNav();
	
	$(window).bind("resize", function(evt) {
		
		var vpW = $(this).width();
		var vpH = $(this).height();
		
		//console.info("Viewport Width: "+vpW+"\nViewport Height: "+vpH);
	});
	
	
});




/* UTILITY FUNCTIONS */

/* openBrWindow() */
// @param array features: [status, toolbar, location, menubar, directories, resizable, scrollbars, height, width]
function openBrWindow(theURL, winName, features) {
	window.open(theURL, winName, features);
}

// getQueryString() 
// @returns value of requested querystring key, or default value if key is null
function getQueryString(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];
	}
}

// setQueryString()
// @sets the current querystring values
function setQueryString(str) {
	var qs = "?"+str;
	var href = window.location.href
	href = href.replace(/\?.*$/, "");
	window.location.href = href+qs;
}

// setQueryHash()
// @sets the current querystring hash value
function setQueryHash(str) {
	var current_hash = location.hash.replace(/\?.*$/, '');
	if (current_hash) {
		current_hash.replace(/^#/, '');
	}
	parent.location.hash = "#"+str;
}




/* DEEP LINKING */
// Our plugin will be defined within an immediately executed method.
(
	function( $ ){
		// Default to the current location.
		var strLocation = window.location.href;
		var strHash = window.location.hash;
		var strPrevLocation = "";
		var strPrevHash = "";

		// This is how often we will be checkint for changes on the location.
		var intIntervalTime = 100;

		// This method removes the pound from the hash.
		var fnCleanHash = function(strHash){
			return(strHash.substring(1, strHash.length));
		}

		// This will be the method that we use to check changes in the window location.
		var fnCheckLocation = function(){
			// Check to see if the location has changed.
			if (strLocation != window.location.href){

				// Store the new and previous locations.
				strPrevLocation = strLocation;
				strPrevHash = strHash;
				strLocation = window.location.href;
				strHash = window.location.hash;

				// The location has changed. Trigger a change event on the location object,
				// passing in the current and previous location values.
				$(window.location).trigger("change", {
					currentHref: strLocation,
					currentHash: fnCleanHash(strHash),
					previousHref: strPrevLocation,
					previousHash: fnCleanHash(strPrevHash)
				});

			}
		}

		// Set an interval to check the location changes.
		setInterval(fnCheckLocation, intIntervalTime);
	}
)(jQuery);

