	/*
		Name: com_aol_music_sns_signin.js
		$LastChangedDate: 2009-01-07 13:44:51 -0500 (Wed, 07 Jan 2009) $
		$Rev: 34712 $
		Modified by Jay Smith
		/////////////////////
		dependencies:
		2. moo-12-all.js
		/////////////////////
		
		DESCRIPTION:
		see "$get() for mootools - reading get variables" located at:
		http://webfreak.no/wp/2007/09/05/get-for-mootools-a-way-to-read-get-variables-with-javascript-in-mootools/
	*/

	//see http://cass-hacks.com/articles/code/js_url_encode_decode/
	if( typeof com === "undefined" ) { var com = {}; }
	if( typeof com.aol === "undefined" ) { com.aol = {}; }
	if( typeof com.aol.music === "undefined" ) { com.aol.music = {}; }
	if( typeof com.aol.music.utilities === "undefined" ) { com.aol.music.utilities = {}; }
	com.aol.music.utilities.URLEncode = function(clearString) {
 	  var output = '';
 	  var x = 0;
 	  clearString = clearString.toString();
 	  var regex = /(^[a-zA-Z0-9_.]*)/;
 	  while (x < clearString.length) {
 	    var match = regex.exec(clearString.substr(x));
 	    if (match != null && match.length > 1 && match[1] != '') {
 	    	output += match[1];
 	      x += match[1].length;
 	    } else {
 	      if (clearString[x] == ' ')
 	        output += '+';
 	      else {
 	        var charCode = clearString.charCodeAt(x);
 	        var hexVal = charCode.toString(16);
 	        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
 	      }
 	      x++;
 	    }
 	  }
 	  return output;
 	}


	com.aol.music.utilities.URLDecode = function(encodedString) {
 	  var output = encodedString;
 	  var binVal, thisString;
 	  var myregexp = /(%[^%]{2})/;
 	  while ((match = myregexp.exec(output)) != null
 	             && match.length > 1
 	             && match[1] != '') {
 	    binVal = parseInt(match[1].substr(1),16);
 	    thisString = String.fromCharCode(binVal);
 	    output = output.replace(match[1], thisString);
 	  }
 	  return output;
 	}
 	
	
	//TODO: Move these functions into a reusable mootools URL utilities class. TBD
	function $get(key, url) {
		if (arguments.length < 2)
			url = com.aol.music.utilities.URLDecode(location.href);
		if (arguments.length > 0 && key != "") {
			if (key == "#") {
				var regex = new RegExp("[#]([^$]*)");
			} else if (key == "?") {
				var regex = new RegExp("[?]([^#$]*)");
			} else {
				var regex = new RegExp("[?&]" + key + "=([^&#]*)");
			}
			var results = regex.exec(url);
			return (results == null) ? "" : results[1];
		} else {
			url = url.split("?");
			var results = {};
			if (url.length > 1) {
				url = url[1].split("#");
				if (url.length > 1)
					results["hash"] = url[1];
				url[0].split("&").each( function(item, index) {
					item = item.split("=");
					results[item[0]] = item[1];
				});
			}
			return results;
		}
	}
 	
 	/*
	 	Jay Smith
		
		Description: 
		signin_initializer generates a signin() method which can be used in links. Redirects the
		user to the /signin page passing the last visited url.
		
		USAGE EXAMPLE:
		<a href="/signin" onclick="signin(); return false;" title="Sign In / Register" class="snsBttnnew">
	    	Sign In / Register
	    </a>
	    
	    REMARKS:
	    For links, onclick must call signin() and return false to prevent the browser from trying to go
	    directly to /signin in the href, hence ==>   href="/signin" onclick="signin(); 
	    The href, although not used will act as a fall-back feature when javascript is disabled.
	*/
	(function signin_initializer(){
		if(!window.signin) {
			var last_visited_url =  "/signin?siteState=" + encodeURIComponent("OrigUrl=" + window.location.href);
			window.signin = function(prompt_user) {
				if(prompt_user) {
					if(confirm("Please signin to continue.\nWould you like to signin now?")) { 
						window.location = last_visited_url;
					}
				}
				else window.location = last_visited_url;
				return false;
			}
		}
	})();