/**
 * Smack the Pixie! - In-Game Javascript functions
 *
 * @author      	 Chris Macdonald <chris@cdmweb.co.uk>
 * @copyright   	 2006 Chris Macdonald
 * @compatibility  PHP 4.2.3 and onwards, register_globals OFF
*/

window.name = 'main';

var aySound = new Array();

function preloadSounds(wh) {
	
	if (arguments.callee.done)
		return;
	
	if (wh=="offer") {
		aySound[0] = "sounds/smack.wav";
		aySound[1] = "sounds/ahhh.wav";
//		aySound[2] = "sounds/44mag.wav";
//		aySound[3] = "sounds/muuu.wav";
//		aySound[4] = "sounds/24theme.wav";
//		aySound[5] = "sounds/tick.wav";
	}
	if (wh=="openbox") {
		aySound[2] = "sounds/boo.wav";
		aySound[3] = "sounds/applause.wav";
	}
	if (wh=="bonus") {

		aySound[6] = "sounds/congrats.wav";
	}
	
	arguments.callee.done = true;
}

function pixieOver(pixie) {
	
	extra = pixie + '_extra';
	
	document.all[pixie].innerHTML = '<img src=images/bankers/' + pixie + '/thinking.gif border=0 onMouseOut=\"pixieOut(\'' + pixie + '\')\" style=\"cursor: hand\" alt=\"Click to view this banker`s profile\">';
//	document.all[extra].innerHTML = pixie;
}

function pixieOut(pixie) {
	
	extra = pixie + '_extra';
	
	document.all[pixie].innerHTML = '<img src=images/bankers/' + pixie + '/neutral.gif border=0 onMouseOver=\"pixieOver(\'' + pixie + '\')\" style=\"cursor: hand\">';

}

var highlightbehavior="TD"

var ns6=document.getElementById&&!document.all
var ie=document.all

function changeto(e,highlightcolor){
	source=ie? event.srcElement : e.target
	if (source.tagName=="TABLE")
		return
	while(source.tagName!=highlightbehavior && source.tagName!="HTML")
		source=ns6? source.parentNode : source.parentElement
	if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
		source.style.backgroundColor=highlightcolor
}

function contains_ns6(master, slave) { //check if slave is contained by master
	while (slave.parentNode)
	if ((slave = slave.parentNode) == master)
		return true;
	
	return false;
}

function changeback(e,originalcolor){
	if (ie&&(event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")||source.tagName=="TABLE")
		return
	else if (ns6&&(contains_ns6(source, e.relatedTarget)||source.id=="ignore"))
		return
	if (ie&&event.toElement!=source||ns6&&e.relatedTarget!=source)
		source.style.backgroundColor=originalcolor
}

function boxOver(boxid) {
	
	window.color = window.document.all[boxid].style.background;
	window.document.all[boxid].bgColor = color;
	
}

function boxOut(boxid) {
	
	window.document.all[boxid].bgColor = 'lightgreen';
}

function BoxSound(sound) {
	
	if (stop!=1) {
		
		playSound(sound);
	}
	stop = 1;
}

function amount(amount,type,sound,info) {
	
	document.all.amount.innerHTML = amount;
	
	if (type=="offer") {
		setInterval('drawOptions(\"offer\")',1000);
		document.all.offer_info.innerHTML = info;
	}
	if (type=="open") {
		drawOptions('open');
	}
}

function pixieReaction(which) {
	
	if (document["pixie"].src == dazed.src || document["pixie"].src == smack.src)
		return;
	
	if (which=="deal") {
		document["pixie"].src = deal.src;
	}
	else if (which=="nodeal") {
		document["pixie"].src = nodeal.src;
	}
	else if (which=="neutral") {
		document["pixie"].src = neutral.src;
	}
	return;
}

var stopsound;

function SmackSound() {
		
	if (stopsound!=1)
		playSound(1);
	
	stopsound = 1;
}

var stopsoundagain;

function ShotSound() {
		
	if (stopsoundagain!=1)
		playSound(2);
	
	stopsoundagain = 1;
}

var stopthissound;

function CrySound() {
		
	if (stopthissound!=1)
		playSound(3);
	
	stopthissound = 1;
}

function SmackPixie() {
	
//	var special;
//	
//	special = Math.round(10*Math.random());
//	
//	special=3;
//	
//	if (special==1) { // Kiefer Sutherland
//		
//		if (sound=='on') 
//			playSound(4);
//	
//		SpecialKiefer();
//		return;
//	}
	
	if (sound=='on') {
		playSound(0);
		setInterval('SmackSound()',500);
	}
	
	document.all.option1.innerHTML = '<b></b>';
	document["pixie"].src = smack.src;
	document.all.option2.innerHTML = '<a href=\"play.php\"><img border=0 src=images/continue.gif></a>';
	
	setInterval('Daze()', 1000);
	
}

var KieferDone;

function SpecialKiefer() {	

		document.all.option1.innerHTML = '<b></b>';
		document["pixie"].src = thinking.src;
		document.all.option2.innerHTML = '<b></b>';
		setTimeout('SpecialKieferSecond()',4000);
}

function SpecialKieferSecond() {
	
	document.all.option2.innerHTML = '<img src=images/other/jack_bauer.gif width=182>';
	setInterval('SpecialKieferShot()', 3000);
}


var stopthis;

function SpecialKieferShot() {
	
	if (stopthis!=1) {
	
		if (sound=='on') {
			
			playSound(2);
			setInterval('SmackSound()',1000);
			setInterval('ShotSound()',2000);
			setInterval('CrySound()',3000);
		}
	
		document["pixie"].src = shot.src;
		setInterval('SpecialKieferEnd()', 6000);
		stopthis = 1;
	}
}

function SpecialKieferEnd() {
	
	if (KieferDone!=1) {
		
		if (sound=='on')
			playSound(5);
				
		document.all.option2.innerHTML = '<a href=\"play.php\"><img border=0 src=images/24continue.gif></a>';
		KieferDone = 1;
	}
}

var stop;

function Daze() {
		
	document["pixie"].src = dazed.src;
	
//	setInterval('do_continue()', 5000);
	
}

function do_continue() {

	window.open('play.php', 'main');
}

function drawOptions(type) {

	if (type=="offer" && document.all.option1.innerHTML=='' && document.all.option2.innerHTML=='') {
		
		document.all.option1.innerHTML = '<a href=\"play.php?deal=true\" onMouseOut=\"pixieReaction(\'neutral\')\" onMouseOver=\"pixieReaction(\'deal\')\"><img src=images/deal.gif width=160 height=50 border=0></a>';
		document.all.option2.innerHTML = '<a style=\"cursor: pointer\" onClick=\"SmackPixie()\" onMouseOut=\"pixieReaction(\'neutral\')\" onMouseOver=\"pixieReaction(\'nodeal\')\"><img src=images/no_deal.gif width=186 height=50 border=0></a>';
		document["pixie"].src = neutral.src;

//	if (document.all.pixie.innerHTML!='<img src=' + neutral.src + '>')
//			document.all.pixie.innerHTML = '<img src=' + neutral.src + '>';
	}
	if (type=="open" && document.all.technique.innerHTML=='') {
		document.all.technique.innerHTML = '<center><table><tr><td align=center><a href=\"play.php?continue=1&boxid=true\"><img border=0 src=\"images/continue.gif\" width=200 height=50></a> </td></tr></table>';
	}
}

function doBlink() {
	
	textToblink = '?'
	
	if (document.all.amount.innerHTML == '') {
		document.all.amount.innerHTML = textToblink;
	}
	
	else if (document.all.amount.innerHTML == textToblink) {
		document.all.amount.innerHTML = '';
	}
	
	else
		return;
	
		setTimeout('doBlink()',450);
}

//Sequential fly-in text script- by JavaScriptKit.com
//For this script and 400+ more, visit http://www.javascriptkit.com
//This notice must stay intact for use

var pausebetweenmsg=0 //customize pause in miliseconds between each message showing up (3000=3 seconds)
var glidespeed=50 //customize glide speed in pixels per frame.

var curobjindex=0

function actualstyle(el, cssproperty){
	if (el.currentStyle)
		return el.currentStyle[cssproperty]
	else if (window.getComputedStyle){
		var elstyle=window.getComputedStyle(el, "")
		return elstyle.getPropertyValue(cssproperty)
	}
}

function collectElementbyClass(){
var classname="glidetext"
glidearray=new Array()
var inc=0
var alltags=document.all? document.all : document.getElementsByTagName("*")
for (i=0; i<alltags.length; i++){
if (alltags[i].className==classname)
glidearray[inc++]=alltags[i]
}
if (glidearray.length>0)
onebyoneglide();
}

var countbonus = 1;
var tcountbonus;
var tcurobjindex = curobjindex;

function onebyoneglide(){

if (curobjindex<glidearray.length) {

	glidetimer=setInterval("glideroutine()",50)
	countbonus++;
}

}

var backupcurobjindex = 0;

function glideroutine(){

if (parseInt(actualstyle(glidearray[curobjindex], "left"))<0)
	glidearray[curobjindex].style.left=parseInt(actualstyle(glidearray[curobjindex], "left"))+50
else  {

	glidearray[curobjindex].style.left=0
	if (sound=='on' && stopall!=1)
		playSound(6);
	
	backupcurobjindex = curobjindex;
	
	clearInterval(glidetimer)
	
	if (stopall!=1)
		setTimeout("doflyoff()", 2500);
	
}
}

function doflyoff() {
	
	timer=setInterval("flyoff()", 50);
	
}

var stopall = 0;

function flyoff() {
	
	if (parseInt(actualstyle(glidearray[backupcurobjindex], "left"))<750)
		glidearray[backupcurobjindex].style.left=parseInt(actualstyle(glidearray[backupcurobjindex], "left"))+50
	else {
		clearInterval(timer)
		tcurobjindex = (tcurobjindex+1);
	
		tcountbonus = (countbonus-1);
		
		if (tcurobjindex<glidearray.length) {
		
			glidearray[curobjindex].style.left='-750px';
			document.getElementById("bonus" + tcountbonus).innerHTML = document.getElementById("bonus" + countbonus).innerHTML;
			setTimeout("onebyoneglide()", pausebetweenmsg)
		}
		else if (stopall!=1) {
		
			glidearray[curobjindex].style.left='-750px';
			document.getElementById("bonus1").innerHTML = defaultmess;
			setTimeout("onebyoneglide()", pausebetweenmsg)
			stopall = 1;
		}
	}
}

if (window.addEventListener)
	window.addEventListener("load", collectElementbyClass, false)
else if (window.attachEvent)
	window.attachEvent("onload", collectElementbyClass)
else if (document.getElementById)
	window.onload=collectElementbyClass




