//This script and all code within are the exclusive property of Concraption.com and its developers.
//Unauthorized use or duplication of any part of this script is strictly forbidden.

//AJAX Core
function HttpClient(method,async,xmlhttp,result) {
	this.requestType = method;
	this.isAsync = async;
	this.xmlhttp = xmlhttp;
	this.requestResult = result;
} //end HttpClient
HttpClient.prototype = {
	callback:false,
	onSend:false,
	onLoad:false,
	onError:function(error) {
		alert(error.message);
	}/*onError:function(error)*/,
	init:function() {
		try {
			this.xmlhttp = new XMLHttpRequest();
		} catch (e) {
			var XMLHTTP_IDS = new Array('MSXML2.XMLHTTP.5.0','MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','Microsoft.XMLHTTP');
			var success = false;
			for (var i = 0; i < XMLHTTP_IDS.length && !success; i++) {
				try {
					this.xmlhttp = new ActiveXObject(XMLHTTP_IDS[i]);
					success = true;
				} catch (e) {}
			} //end var i = 0; i < XMLHTTP_IDS.length && !success; i++ FOR
			if (!success) {
				throw new Error('Unable to create XMLHttpRequest.');
			} //end !success IF
		} //end try/catch
	} /*end init:function()*/,
	makeRequest:function(url,payload) {
		if (!this.xmlhttp) {
			this.init();
		} //end !this.xmlhttp IF
		this.xmlhttp.open(this.requestType,url,this.isAsync);
		var self = this;
		if (this.callback != false) {
			this.xmlhttp.onreadystatechange = function() {self._readyStateChangeCallback();}
		} //end this.callback != false IF
		if (this.requestType == "POST") {
			this.xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
		} //end this.requestType == "POST" IF
		this.xmlhttp.send(payload);
		if (!this.isAsync) {
			return this.xmlhttp.responseText;
		} //end !this.isAsync IF
	} /*end makeRequest:function(url,payload)*/,
	_readyStateChangeCallback:function() {
		switch(this.xmlhttp.readyState) {
			case 2:
				if (this.onSend != false) {
					this.onSend();
				} //end this.onSend != false IF
			break;
			case 4:
				if (this.onLoad != false) {
					this.onLoad();
				} //end this.onLoad != false IF
				if (this.xmlhttp.status == 200) {
					if (this.requestResult == 'XML') {
						this.callback(this.xmlhttp.responseXML);
					} else {
						this.callback(this.xmlhttp.responseText);
					} //end this.requestResult == 'XML' IF
				} else {
					this.onError(new Error('HTTP Error Making Request: ['+this.xmlhttp.status+'] '+this.xmlhttp.statusText));
				} //end this.xmlhttp.status == 200 IF
			break;
		} //end this.xmlhttp.readyState SWITCH
	} //end _readyStateChangeCallback:function()
} //end HttpClient.prototype

//DOM Core
function emptyElement(target) {
	while (target.hasChildNodes()) {
		target.removeChild(target.firstChild);
	} //end target.hasChildNodes WHILE
} //end emptyElement

//Track mouse movements
var mouseX = 0;
var mouseY = 0;
function trackMouse(e) {
	if (document.all) {
		mouseX = event.clientX + document.body.scrollLeft;
		mouseY = event.clientY + document.body.scrollTop;
	} else {
		mouseX = e.pageX;
		mouseY = e.pageY;
	} //end document.all IF
	return true;
} //end trackMouse
document.onmousemove = trackMouse;

//Track screen size
var screenW = 0;
var screenH = 0;
function trackScreen() {
	if (self.innerWidth) {
		screenW = self.innerWidth;		
		screenH = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		screenW = document.documentElement.clientWidth;
		screenH = document.documentElement.clientHeight;
	} else if (document.body) {
		screenW = document.body.clientWidth;
		screenH = document.body.clientHeight;
	} //end self.innerWidth || (document.documentElement && document.documentElement.clientWidth) || document.body IFs
} //end trackScreen
trackScreen();
window.onresize = trackScreen;

//Fade Core
function fade(target,direction) {
	targetElement = target;
	dir = direction;
	o = (dir == "out" ? 1 : 0);
	if (document.all) {
		o = (o == 1 ? 100 : 0);
		targetElement.style.filter="alpha(opacity="+o+")";
		timer = setInterval("fadeIE()",30);
	} else if (document.getElementById && !document.all) {
		timer = setInterval("fadeGecko()",30);
	} //end document.all || (document.getElementById && !document.all) IFs
} //end fade
function fadeGecko() {
	target = targetElement;
	direction = dir;
	if (o <= 1.05 && direction == "in") {
		target.style.MozOpacity = o;
		target.style.KhtmlOpacity = o;
		target.style.opacity = o;
		o += 0.05;
	} else if (o >= -0.05 && direction == "out") {
		target.style.MozOpacity = o;
		target.style.KhtmlOpacity = o;
		target.style.opacity = o;
		o -= 0.05;
	} else {
		clearInterval(timer);
		if (direction == "out") {
			emptyElement(target);
		} //end direction IF
	} //end (o < 1 && direction == "in") && (o > 0 && direction == "out") IFs
} //end fadeGecko
function fadeIE() {
	target = targetElement;
	direction = dir;
	if (o <= 120 && direction == "in") {
		target.filters.alpha.opacity = o;
		o += 20;
	} else if (o >= -20 && direction == "out") {
		target.filters.alpha.opacity = o;
		o -= 20;
	} else {
		clearInterval(timer);
		if (direction == "out") {
			emptyElement(target);
		} //end direction IF
	} //end (o < 100 && direction == "in") || (o > 0 && direction == "out") IFs
} //end fadeIE

//Feedback functions
function buildFeedbackForm(section,theme) {
	var target = document.getElementById("leave_feedback");
	emptyElement(target);
	var left = document.createElement("div");
	left.setAttribute("style","float:left;");
	var title = document.createElement("img");
	title.setAttribute("src","title.php?theme="+theme+"&text=Leave Feedback&size=32");
	title.setAttribute("alt","Leave Feedback");
	left.appendChild(title);
	target.appendChild(left);
	var right = document.createElement("p");
	right.setAttribute("style","float:right;");
	var closeBox = document.createElement("img");
	closeBox.setAttribute("src","close.php?theme="+theme);
	closeBox.setAttribute("alt","Hide Form");
	closeBox.setAttribute("title","Hide Form");
	closeBox.setAttribute("onclick","destroyFeedbackForm();");
	right.appendChild(closeBox);
	target.appendChild(right);
	var form = document.createElement("p");
	form.appendChild(document.createTextNode("Name: "));
	var name = document.createElement("input");
	name.setAttribute("id","name");
	name.setAttribute("type","text");
	name.setAttribute("size","30");
	name.setAttribute("maxlength","30");
	form.appendChild(name);
	form.appendChild(document.createElement("br"));
	form.appendChild(document.createElement("br"));
	form.appendChild(document.createTextNode("Feedback:"));
	form.appendChild(document.createElement("br"));
	var feedback = document.createElement("textarea");
	feedback.setAttribute("id","body");
	feedback.setAttribute("cols","70");
	feedback.setAttribute("rows","7");
	feedback.setAttribute("wrap","virtual");
	form.appendChild(feedback);
	form.appendChild(document.createElement("br"));
	form.appendChild(document.createElement("br"));
	var button = document.createElement("input");
	button.setAttribute("type","submit");
	button.setAttribute("onclick","leaveFeedback('"+section+"');");
	button.setAttribute("value","Leave Feedback");
	form.appendChild(button);
	target.appendChild(form);
	
	//Position form
	target.style.left = mouseX;
	target.style.top = mouseY;
} //end buildFeedbackForm
function destroyFeedbackForm() {
	var target = document.getElementById("leave_feedback");
	emptyElement(target);
} //end destroyFeedbackForm
function leaveFeedback(section) {
	var http = new HttpClient("POST",true,false,"XML");
	http.callback = function(xmlDoc) {
		//Update feedback status
		var target = document.getElementById("leave_feedback_status");
		emptyElement(target);
		if (xmlDoc.getElementsByTagName("error").length > 0) {
			var errorHeader = document.createElement("p");
			errorHeader.setAttribute("class","error");
			errorHeader.appendChild(document.createTextNode("Your feedback could not be added because of the following errors:"));
			target.appendChild(errorHeader);
			var errorList = document.createElement("ul");
			errorList.setAttribute("class","error");
			var errors = xmlDoc.getElementsByTagName("error");
			for (i = 0; i < errors.length; i++) {
				var error = document.createElement("li");
				error.appendChild(document.createTextNode(errors[i].firstChild.data));
				errorList.appendChild(error);
			} //end i = 0; i < errors.length; i++ FOR
			target.appendChild(errorList);
		} else {
			var success = document.createElement("p");
			success.setAttribute("class","success");
			success.appendChild(document.createTextNode("Your feedback was successfully added."));
			target.appendChild(success);
			destroyFeedbackForm();
		} //end xmlDoc.getElementsByTagName("error").length > 0 IF
		
		//Display feedback
		if (xmlDoc.getElementsByTagName("posts").length > 0) {
			var target = document.getElementById("feedback");
			emptyElement(target);
			var posts = xmlDoc.getElementsByTagName("post");
			//Update feedback counter
			var counterTarget = document.getElementById("feedback_counter");
			emptyElement(counterTarget);
			counterTarget.appendChild(document.createTextNode(posts.length));
			for (i = 0; i < posts.length; i++) {
				var post = document.createElement("p");
				post.setAttribute("class","small");
				var header = document.createElement("span");
				header.setAttribute("class","bold");
				header.appendChild(document.createTextNode("Feedback - Posted "+posts[i].getAttribute("date")+" by "+posts[i].getAttribute("by")));
				post.appendChild(header);
				post.appendChild(document.createElement("br"));
				var lines = posts[i].firstChild.data.split("::BR::");
				for (i = 0; i < lines.length; i++) {
					post.appendChild(document.createTextNode(lines[i]));
					post.appendChild(document.createElement("br"));
				} //end i = 0; i < lines.length; i++ FOR
				target.appendChild(post);
			} //end i = 0; i < posts.length; i++ FOR
		} //end xmlDoc.getElementsByTagName("posts").length > 0 IF
	} //end http.callback = function(xmlDoc)
	var payload = "section="+section+"&name="+document.getElementById("name").value+"&body="+document.getElementById("body").value;
	http.makeRequest("feedback.php",payload);
} //end leaveFeedback

//Films functions
function showFilm(id,media,theme) {
	var target = document.getElementById("film");
	emptyElement(target);
	var containerWidth = 0;
	switch (media) {
		case "flv":
			containerWidth = 620;
			var flashvars = new Array("file=http://www.concraption.com/films/"+id+".flv","width=600","height=470","location=http://www.concraption.com/films/player.swf","showdigits=false","bufferlength=3","type=flv","usekeys=false");
			var movie = document.createElement("object");
			movie.setAttribute("classid","clsid:D27CDB6E-AE6D-11cf-96B8-444553540000");
			movie.setAttribute("width","600");
			movie.setAttribute("height","470");
			var movieParam = document.createElement("param");
			movieParam.setAttribute("name","movie");
			movieParam.setAttribute("value","films/player.swf");
			movie.appendChild(movieParam);
			var allowfullscreenParam = document.createElement("param");
			allowfullscreenParam.setAttribute("name","allowfullscreen");
			allowfullscreenParam.setAttribute("value","true");
			movie.appendChild(allowfullscreenParam);
			var flashvarsParam = document.createElement("param");
			flashvarsParam.setAttribute("name","flashvars");
			flashvarsParam.setAttribute("value",flashvars.join("&"));
			movie.appendChild(flashvarsParam);
			var embed = document.createElement("embed");
			embed.setAttribute("type","application/x-shockwave-flash");
			embed.setAttribute("src","films/player.swf");
			embed.setAttribute("width","600");
			embed.setAttribute("width","470");
			embed.setAttribute("allowfullscreen","true");
			embed.setAttribute("flashvars",flashvars.join("&"));
			movie.appendChild(embed);
		break;
		case "swf":
			containerWidth = 570;
			var movie = document.createElement("object");
			movie.setAttribute("classid","clsid:D27CDB6E-AE6D-11cf-96B8-444553540000");
			movie.setAttribute("width","550");
			movie.setAttribute("height","400");
			var movieParam = document.createElement("param");
			movieParam.setAttribute("name","movie");
			movieParam.setAttribute("value","films/player.swf");
			movie.appendChild(movieParam);
			var loopParam = document.createElement("param");
			loopParam.setAttribute("name","loop");
			loopParam.setAttribute("value","false");
			movie.appendChild(loopParam);
			var menuParam = document.createElement("param");
			menuParam.setAttribute("name","menu");
			menuParam.setAttribute("value","false");
			movie.appendChild(menuParam);
			var qualityParam = document.createElement("param");
			qualityParam.setAttribute("name","quality");
			qualityParam.setAttribute("value","high");
			movie.appendChild(qualityParam);
			var bgcolorParam = document.createElement("param");
			bgcolorParam.setAttribute("name","bgcolor");
			bgcolorParam.setAttribute("value","films/player.swf");
			movie.appendChild(bgcolorParam);
			var embed = document.createElement("embed");
			embed.setAttribute("type","application/x-shockwave-flash");
			embed.setAttribute("src","films/"+id+".swf");
			embed.setAttribute("width","550");
			embed.setAttribute("width","400");
			embed.setAttribute("loop","false");
			embed.setAttribute("menu","false");
			embed.setAttribute("quality","high");
			embed.setAttribute("bgcolor","#000000");
			movie.appendChild(embed);
		break;
		case "qth":
		case "qtm":
			containerWidth = 340;
			var movie = document.createElement("object");
			movie.setAttribute("classid","clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B");
			movie.setAttribute("codebase","http://www.apple.com/qtactivex/qtplugin.cab");
			movie.setAttribute("width","320");
			movie.setAttribute("height","256");
			movie.setAttribute("align","center");
			var srcParam = document.createElement("param");
			srcParam.setAttribute("name","src");
			srcParam.setAttribute("value","films/"+id+"-"+media+".mov");
			movie.appendChild(srcParam);
			var autoplayParam = document.createElement("param");
			autoplayParam.setAttribute("name","autoplay");
			autoplayParam.setAttribute("value","true");
			movie.appendChild(autoplayParam);
			var controllerParam = document.createElement("param");
			controllerParam.setAttribute("name","controller");
			controllerParam.setAttribute("value","true");
			movie.appendChild(controllerParam);
			var embed = document.createElement("embed");
			embed.setAttribute("bgcolor","#FFFFFF");
			embed.setAttribute("width","320");
			embed.setAttribute("height","256");
			embed.setAttribute("src","films/"+id+"-"+media+".mov");
			embed.setAttribute("pluginspage","http://www.apple.com/quicktime/download/");
			embed.setAttribute("type","video/quicktime");
			embed.setAttribute("autoplay","true");
			embed.setAttribute("controller","true");
			embed.setAttribute("align","center");
			movie.appendChild(embed);
		break;
		case "wm":
			containerWidth = 340;
			var movie = document.createElement("object");
			movie.setAttribute("classid","clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6");
			movie.setAttribute("codebase","http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=10");
			movie.setAttribute("width","320");
			movie.setAttribute("height","285");
			movie.setAttribute("standby","Your movie is loading...");
			movie.setAttribute("type","application/x-oleobject");
			movie.setAttribute("align","center");
			var filenameParam = document.createElement("param");
			filenameParam.setAttribute("name","filename");
			filenameParam.setAttribute("value","films/"+id+".wmv");
			movie.appendChild(filenameParam);
			var autostartParam = document.createElement("param");
			autostartParam.setAttribute("name","autostart");
			autostartParam.setAttribute("value","true");
			movie.appendChild(autostartParam);
			var showcontrolsParam = document.createElement("param");
			showcontrolsParam.setAttribute("name","showcontrols");
			showcontrolsParam.setAttribute("value","true");
			movie.appendChild(showcontrolsParam);
			var showstatusbarParam = document.createElement("param");
			showstatusbarParam.setAttribute("name","showstatusbar");
			showstatusbarParam.setAttribute("value","false");
			movie.appendChild(showstatusbarParam);
			var autorewindParam = document.createElement("param");
			autorewindParam.setAttribute("name","autorewind");
			autorewindParam.setAttribute("value","true");
			movie.appendChild(autorewindParam);
			var autosizeParam = document.createElement("param");
			autosizeParam.setAttribute("name","autosize");
			autosizeParam.setAttribute("value","true");
			movie.appendChild(autosizeParam);
			var showdisplayParam = document.createElement("param");
			showdisplayParam.setAttribute("name","showdisplay");
			showdisplayParam.setAttribute("value","false");
			movie.appendChild(showdisplayParam);
			var volumeParam = document.createElement("param");
			volumeParam.setAttribute("name","volume");
			volumeParam.setAttribute("value","0");
			movie.appendChild(volumeParam);
			var allowchangedisplaysizeParam = document.createElement("param");
			allowchangedisplaysizeParam.setAttribute("name","allowchangedisplaysize");
			allowchangedisplaysizeParam.setAttribute("value","false");
			movie.appendChild(allowchangedisplaysizeParam);
			var embed = document.createElement("embed");
			embed.setAttribute("src","films/"+id+".wmv");
			embed.setAttribute("width","320");
			embed.setAttribute("height","285");
			embed.setAttribute("type","application/x-mplayer2");
			embed.setAttribute("align","center");
			embed.setAttribute("autostart","1");
			embed.setAttribute("showcontrols","1");
			embed.setAttribute("showstatusbar","0");
			embed.setAttribute("autorewind","1");
			embed.setAttribute("autosize","1");
			embed.setAttribute("showdisplay","0");
			embed.setAttribute("volume","0");
			embed.setAttribute("allowchangedisplaysize","0");
			movie.appendChild(embed);
		break;
		default:
			var movie = document.createElement("p");
			movie.setAttribute("class","error");
			movie.appendChild(document.createTextNode("An error occurred while attempting to load your movie. If this error persits, please contact Concraption.com Support."));
	} //end media SWITCH
	var container = document.createElement("div");
	container.setAttribute("style","width:"+containerWidth+"px;");
	var closeContainer = document.createElement("div");
	closeContainer.setAttribute("style","float:right;");
	var closeButton = document.createElement("img");
	closeButton.setAttribute("src","close.php?theme="+theme);
	closeButton.setAttribute("alt","Close Layer");
	closeButton.setAttribute("title","Close Layer");
	closeButton.setAttribute("onclick","hideFilm();");
	closeContainer.appendChild(closeButton);
	container.appendChild(closeContainer);
	var movieContainer = document.createElement("div");
	movieContainer.setAttribute("style","clear:right;");
	movieContainer.appendChild(movie);
	container.appendChild(movieContainer);
	target.appendChild(container);
	
	//Position film and fade in
	target.style.left = mouseX+"px";
	target.style.top = mouseY+"px";
	fade(target,"in");
} //end showFilm
function hideFilm() {
	var target = document.getElementById("film");
	fade(target,"out");
} //end hideFilm

/* CODE BELOW THIS LINE HAS NOT BEEN OPTIMIZED */

//Misc functions
function setVisibility(of,to) {
	document.getElementById(of).style.display = (to ? "block" : "none");
} //end setVisibility
function insertCode(code,into) {
	var target = document.getElementById(into);
	target.value += code;
	target.focus();
} //end insertCode
function insertLink(into,from) {
	var theURL = document.getElementById(from+"_url");
	var theText = document.getElementById(from+"_text");
	insertCode(":-!"+theURL.value+"!-!"+(theText.value.length == 0 ? theURL.value : theText.value)+"!-:",into);
	setVisibility(from,false);
	theURL.value = "http://";
	theText.value = "";
} //end insertLink
function upload(section,into) {
	window.open("upload.php?s="+section+"&i="+into,"upload","screenX=350,screenY=200,width=400,height=180,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=1,toolbar=0")
} //end upload
function insertUpload(code,into) {
	var target = opener.document.getElementById(into);
	target.value += code;
	window.close();
	target.focus();
} //end insertUpload
function selectElement(element) {
	document.getElementById(element).checked = true;
} //end selectElement