function getQueryVariable(variable) {
	var query = document.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
		  return pair[1];
		}
	} 
	//alert('Query Variable ' + variable + ' not found');
}


function emailCheck(str) {

	var at = "@";
	var dot = ".";
	var lat = str.indexOf(at);
	var lstr = str.length;
	var ldot = str.indexOf(dot);
	
	if (str.indexOf(at) == -1)
	   return false;
	if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr)
	   return false;
	if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr)
		return false;
	 if (str.indexOf(at, (lat + 1)) != -1)
		return false;
	 if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot)
		return false;
	 if (str.indexOf(dot,(lat + 2)) == -1)
		return false;
	 if (str.indexOf(" ") != -1)
		return false;
		
	 return true
	 
}




//dropdown menu fixer...for IE, of course
function IEdropdownFix() {
	if(document.all && document.getElementById) {
		navRoot = document.getElementById("nav").firstChild;
		for(i = 0; i < navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if(node.nodeName == "LI") {
				node.onmouseover = function() {
					this.className += " over";
				}
				node.onmouseout = function() {
					this.className = this.className.replace(" over", "");
				}
			}
		}
	}
}



function debuggerStuff() {

	try {
		loadFirebugConsole();
	}
	catch(e) {
		//make IE behave
		console = new Object;
		console.log = function() {} ;
	}
	
}



function linkOpener() {
	return;

	var allAnchors = $(document.body).getElements("a");
	allAnchors.each(function(item) {
		
		if(item.href == "") //some non-href link...maybe javascript
			return;
		
		var localLink = item.href.contains("jksmusic.com"); //production box
		
		if(localLink) {
			//console.log("leave me alone");
		}
		else {
			//console.log("open new window");
			//item.target = "_blank";
		}

	});
	
}




function mediaplayer(myObj) {

/*
window.addEvent("domready", function() {

	var myFileSettings = 
		{
			file:"/resources/webinars/mob-marketing/trailer-280x210.flv",
			poster:"/resources/webinars/mob-marketing/poster-280x210.png",
			width:280,
			height:230,
			replaceElement:"trailer"
		}
		
	var myPlayer = new mediaplayer(myFileSettings);
	myPlayer.setAutostart(true);
	myPlayer.render();

});
*/

	this.playerSpecs = 
		{
			pathToPlayer:"/includes/js/mediaplayer/player.swf",
			version:"9.0.115",
			controllerHeight:20
		}

	this.flashvars = 
		{
			file:myObj.file, 
			image:myObj.poster, 
			fullscreen:true,
			autostart:false,
			skin:"/includes/js/mediaplayer/skins/simple.swf"
		}
		
	this.params = 
		{
			wmode:"transparent", 
			allowfullscreen:true,
			allowscriptaccess:"always"
		}
		
	this.attributes =
		{
			name:myObj.replaceElement
		}
		
	this.setFullscreen = function(trueFalse) {
			this.flashvars.fullscreen = trueFalse;
			this.params.allowfullscreen = trueFalse;
		}
	
	this.setAutostart = function(trueFalse) {
			this.flashvars.autostart = trueFalse;
		}
	
	this.render = function() {
			
			var height = myObj.height + this.playerSpecs.controllerHeight;
	
			if($(myObj.replaceElement)) {
				swfobject.embedSWF(this.playerSpecs.pathToPlayer, myObj.replaceElement, myObj.width, height, this.playerSpecs.version, false, this.flashvars, this.params, this.attributes);
			}
		}
}

function playerReady(obj) {
	//console.log(obj);
	player = $(obj["id"]);
	
	if(preloadFirstFile) {
		loadFirstFile();
	}
	
	return;
	
//	//load up the first one
//	var plElements = $("playlist").getChildren();
//	
//	plElements[0].addClass("playlistActive");
//	
//	if(plElements.length == 1) {
//		plElements[0].addClass("hide");
//	}
//	
//	var script = plElements[0].get("onclick");
//	script.replace('"', '');
//	eval(script);
//	
//	loadedFlag = true;
};

//var loadedFlag;

function playfirst() {
	//load up the first one
	var theFirst = $("playlist0");
	
	theFirst.addClass("playlistActive");
	$("playFirstBox").setStyle("display", "none");
	var file = new String;
	file = theFirst.get("theFile");
	
	player.sendEvent("LOAD", file);
	player.sendEvent("PLAY");
}


function loadFirstFile() {
	var plElements = $("playlist").getChildren();
	var file = plElements[0].get("onclick");
	file = file.replace("play('", "");
	file = file.replace("', this)", "");
	
	player.sendEvent("LOAD", file);
}

function play(file, li) {
	if(file) {
		player.sendEvent("LOAD", file);
		player.sendEvent("PLAY");
		
//		if(!loadedFlag) {
//		 	player.sendEvent("STOP");
//		}
//		else {
			var lastOne = $$(".playlistActive");
			for(var x = 0; x < lastOne.length; x++) {
			  lastOne[x].removeClass("playlistActive");	
			}
			
			li = $(li);
			li.addClass("playlistActive");
//		}
//		loadedFlag = true;
	}
}



function autoFill() {
	var now = new Date;
	var rightNow = now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
	
	setFieldValue("email", "brian@doubleforte.net");
	setFieldValue("name", "Brian Test " + rightNow);
	setFieldValue("city", "San Jose");
	setFieldValue("state", "CA");
	setFieldValue("country", "United States");
	setFieldValue("phone", "408-555-1234");
	setFieldValue("school", "School of Hard Knocks");
	setFieldValue("comments", "Some comments go here.");
	setFieldValue("referred_by", "yo mama");

}

function setFieldValue(field, newVal) {
	if($(field)) {
		$(field).value = newVal;
	}
}

function goToPayPal(item, price) {
	$("#item_name").val(item);
	$("#paypalAmount").val(price);
	$("#paypalForm").submit();
}


