//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 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
	 
}



function displayAddys() {
	if (!document.getElementsByTagName && !document.createElement &&
		!document.createTextNode) return;
	var nodes = document.getElementsByTagName("span");
	for(var i=nodes.length-1;i>=0;i--) {
		if (nodes[i].className=="addy") {
			var at = / at /;
			var dot = / dot /g;
			var node = document.createElement("a");
			var address = nodes[i].firstChild.nodeValue;

			address = address.replace(at, "@");
			address = address.replace(dot, ".");

			address = address.replace(at, "@");
			address = address.replace(dot, ".");
			node.setAttribute("href", "mailto:"+address);
			node.appendChild(document.createTextNode(address));
			
			var prnt = nodes[i].parentNode;
			for(var j=0;j<prnt.childNodes.length;j++)
				if (prnt.childNodes[j] == nodes[i]) {
					if (!prnt.replaceChild) return;
					prnt.replaceChild(node, prnt.childNodes[j]);
					break;
				}
		}
	}
}



function linkOpener(testingServer) {
	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("baynote.com"); //production box
		var kentonLink = item.href.contains(testingServer); //testing box
		
		if(localLink || kentonLink) {
			//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",
			pathToPlayer:"/includes/js/NonverBlaster-hover/DocAndExample/NonverBlaster.swf",
			version:"9.0.115",
			//controllerHeight:20
			controllerHeight:0
		}

	this.flashvars = 
		{
			//file:myObj.file, 
			//image:myObj.poster, 
			//fullscreen:true,
			//autostart:false
			videoURL:myObj.file,
			teaserURL:myObj.poster,
			autoPlay:false,
			controlColour:0x777777
		}
		
	this.params = 
		{
			wmode:"transparent", 
			//allowfullscreen:true,
			allowfullscreen:false,
			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.flashvars.autoPlay = trueFalse;
		}
	
	this.render = function() {
			
			var height = myObj.height + this.playerSpecs.controllerHeight;
	
			if($(myObj.replaceElement)) {
				//console.log("here");
				//$(myObj.replaceElement).set("html", "hey!");
				//return;
				
				//get major flash version
				var thisMajorVersion = this.playerSpecs.version.split(".", 1);
				if(thisMajorVersion[0] > Browser.Plugins.Flash.version) {
					$(myObj.replaceElement).set("html", "Adobe Flash Player version " + this.playerSpecs.version + " or greater is required to load this asset. (You have version " + Browser.Plugins.Flash.version + ".) Please download the latest player at <a href=\"http://get.adobe.com/flashplayer/\">http://get.adobe.com/flashplayer/</a>");
				}
				else { //make it so
					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"]);
	//console.log(player.getConfig());
};


function addCheckAvailablityButton() {
	var el = $("addToCartButton");
	var theButton = new Element("img", 
		{
			"src":"/store/includes/languages/english/images/buttons/button-check-availability.png",
			"style":"display:inline;"
		}
	);
	
	var theLink = new Element("a",
		{
			"href":"/exclusivity/"
		}
	);
	
	theButton.inject(el);
	theLink.wraps(theButton);
	el.addClass("hideImages");
}