/*

	  __                            
	 /              /      /        
	(___  ___  ___    ___ (___  ___ 
		)|    |   )| |   )|    |___ 
	 __/ |__  |    | |__/ |__   __/ 
					 |        
					 
	JavaScript functions.

*/

/*

	Show/Hide
	
*/
function show(element) {
	document.getElementById(element).style.display = "none";
	document.getElementById(element+"-hidden").style.display = "";
}

function hide(element) {
	document.getElementById(element).style.display = "";
	document.getElementById(element+"-hidden").style.display = "none";
}

/* 
	
	Show/Hide comment info
	
*/
function ShowInfo() {
	document.getElementById("comment-author").style.display = "";
	document.getElementById("showinfo").style.display = "none";
	document.getElementById("hideinfo").style.display = "";
}

function HideInfo() {
	document.getElementById("comment-author").style.display = "none";
	document.getElementById("showinfo").style.display = "";
	document.getElementById("hideinfo").style.display = "none";
}

/* 

	Show/Hide formatting info
	
*/
formattingOpen = false;
function toggleFormatting() {
	if (formattingOpen == false) {
		document.getElementById("tags-allowed").style.display = "";
		formattingOpen = true;
	} else {
		document.getElementById("tags-allowed").style.display = "none";
		formattingOpen = false;
	}
}

/* 

	Quote comment
	
*/
function addQuote(comment,quote){
	/*
	
		Derived from Alex King's JS Quicktags code (http://www.alexking.org/)
		Released under LGPL license
		
	*/
	
	// IE support
	if (document.selection) {
		comment.focus();
		sel = document.selection.createRange();
		sel.text = quote;
		comment.focus();
	}
	// Mozilla support
	else if (comment.selectionStart || comment.selectionStart == '0') {
		var startPos = comment.selectionStart;
		var endPos = comment.selectionEnd;
		var cursorPos = endPos;
		var scrollTop = comment.scrollTop;
		if (startPos != endPos) {
			comment.value = comment.value.substring(0, startPos)
			              + quote
			              + comment.value.substring(endPos, comment.value.length);
			cursorPos = startPos + quote.length
		}
		else {
			comment.value = comment.value.substring(0, startPos) 
				              + quote
				              + comment.value.substring(endPos, comment.value.length);
			cursorPos = startPos + quote.length;
		}
		comment.focus();
		comment.selectionStart = cursorPos;
		comment.selectionEnd = cursorPos;
		comment.scrollTop = scrollTop;
	}
	else {
		comment.value += quote;
	}
	
	// If Live Preview Plugin is installed, refresh preview
	try {
		ReloadTextDiv();
	}
	catch ( e ) {
	}	
}
function quote(postid, author, commentarea, commentID, textile) {
	var posttext = '';
	if (window.getSelection){
		posttext = window.getSelection();
	}
	else if (document.getSelection){
		posttext = document.getSelection();
	}
	else if (document.selection){
		posttext = document.selection.createRange().text;
	}
	else {
		return true;
	}
	
	if (posttext==''){
		
		// quote entire comment as html
		var posttext = document.getElementById(commentID).innerHTML;
		var posttext = posttext.replace(/	/g, "");
		var posttext = posttext.replace(/<p>/g, "\n");
		var posttext = posttext.replace(/<\/\s*p>/g, "");
		var posttext = posttext.replace(/<br>/g, "")

		// remove nested blockquotes
		var posttext = posttext.replace(/<blockquote>[^>]*<\/\s*blockquote>/g, "");
		var posttext = posttext.replace(/<blockquote>[^>]*<\/\s*blockquote>/g, "");

		var quote='<blockquote>\n'+posttext+'</blockquote>\n\n';

		var comment=document.getElementById(commentarea);
		addQuote(comment,quote);
		
	} else {
		
		// quote selection a html or textile
		if (textile) {
			var quote='bq. '+posttext+'\n\n';
		} else {
			var quote='<blockquote>\n\n'+posttext+'\n\n</blockquote>\n';
		}
		var comment=document.getElementById(commentarea);
		addQuote(comment,quote);
		
	}
	return false;
}

// Set Flash Quality
function setQuality(theMovie, quality) {

	theMovie.SetVariable("_quality", quality);

}

// Toggle Flash Size
function toggleSize(theMovie, scale, width, height) {
	scaleFactor = 1.5;

	largeWidth = scaleFactor * width;
	largeHeight = scaleFactor * height;
	
	if (scale == true) { 
		theMovie.style.width = largeWidth + "px";
		theMovie.style.height = largeHeight + "px";
	} else {
		theMovie.style.width = width + "px";
		theMovie.style.height = height + "px";
	}
}
/*function toggleSize(theMovie, scale, width, height) {
	top.AR = width / height;

	largeWidth = "100%";
	largeHeight = document.body.clientWidth / top.AR;
	
	if (scale == true) { 
		top.isScaled = theMovie;
		theMovie.style.width = largeWidth;
		theMovie.style.height = largeHeight + "px";
		
		// zoom
		theMovie.style.position = "absolute";
		theMovie.style.left = "0";
		theMovie.style.top = "0";
		document.getElementById("gamecontrols").style.position = "absolute";
		document.getElementById("gamecontrols").style.top = largeHeight + "px";
	} else {
		top.isScaled = false;
		theMovie.style.width = width + "px";
		theMovie.style.height = height + "px";

		// unzoom
		theMovie.style.position = "";
		document.getElementById("gamecontrols").style.position = "";
	}
}
window.onresize = function () {
	if (top.isScaled != undefined) {
		top.isScaled.style.height = document.body.clientWidth / top.AR + "px";
		document.getElementById("gamecontrols").style.top = document.body.clientWidth / top.AR + "px";
	}
}*/


// frameblast
function frameBlast() {

	function checkMango() {
		try {
			if (top.document.location.href.split("http://newmango/")[1] != undefined) {
				return true;
			} else {
				return false;
			}
		}
		catch( ee ) {
			return false;
		}

	}
	function checkSporkle() {
		try {
			if (top.document.location.href.split("http://sporkle.com/")[1] != undefined || top.document.location.href.split("http://www.sporkle.com/")[1] != undefined || top.document.location.href.split("http://sporkle.dk/")[1] != undefined || top.document.location.href.split("http://www.sporkle.dk/")[1] != undefined) {
				return true;
			} else {
				return false;
			}
		}
		catch( ee ) {
			return false;
		}
	}
	if (checkMango() || checkSporkle()) {
		// fine
	} else {
		l1 = "This game doesn't belong to the site you're viewing it with. Please play it on www.sporkle.com, where it's freely available.";
//		l2 = "<a href='"+document.location.href+"' target='_top'>Play this game at Sporkle now</a>";
		l2 = "<a href='http://www.sporkle.com/games/' target='_top'>Play this game at Sporkle now</a>";
		alert(l1);
		document.getElementById("flashcontent").innerHTML = l2;
	}
		
}
//window.onload = frameBlast;
addEvent(window, 'load', frameBlast)









/* Event Listener by Scott Andrew - http://scottandrew.com, edited by Mark Wubben
----------------------*/
function addEvent(obj, evType, fn){
	if(obj.addEventListener){
		obj.addEventListener(evType, fn, false); 
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent('on'+evType, fn);
		return r;
	} else {
		return false;
	}
}
// usage: addEvent(window, 'load', functionname);