/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
 *	Copyright 2007 BOSS Logics, a division of Set Your Site, Inc.
 *	
 *	USE OR MANIPULATION OF THIS CODE IS PROHIBITED WITHOUT EXPRESS WRITTEN PERMISSION.
 *
 * 	Any use of the code written here-in belongs to the developer
 * 	and is hereby the owner.  If used, one must have strict
 * 	approval by the developer of the code written here-in.
 *
 * 	The developer may at anytime change, modify, add, or delete
 * 	any content contained within. 
 *	
 * 	This content may not be used on any server 12outside of the boss32.com maintained 
 *	servers.  Any such use will be considered a copyright infringement and will be 
 *	prosecuted to the full extent of the law.
 *
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 
var hatDir = '/i/layout/pgs/home/hats';
function switchHat(targObj) {
	var type = targObj.className;
	var hat = $('hat');
	if(type==hat.className) return;		// prevent double click

	targObj.className = hat.className;
	targObj.src = hatDir+'/'+hat.className+'.png';

	/* alpha tween */
	var alpha_tw = new Tween(hat, 'alpha', '', 1, 0, .2, true);
	alpha_tw.onstop = function() { 
		if(type!=hat.className) {
			hat.className = type;
			hat.src = '/i/layout/pgs/home/hats/'+type+'.png';
		}
		new Tween(hat, 'alpha', '', 0, 1, .2, true);
	}
	/* end alpha tween */

	/* vertical tween */
	var vert_tw = new Tween(hat, 'marginTop', 'out.strong', 0, -30, .2, true);
	vert_tw.onstop = function() { 
		new Tween(hat, 'marginTop', 'out.strong', -30, 0, .3, true);
	}
	/* end vert tween */

	var dir = (Math.floor(Math.random()*2));

	/* rotate tween */
	var rotate_tw = new Tween(hat, 'rotate', '', 0, -15*(dir?1:-1), .2, true);
	rotate_tw.onstop = function() { 
		new Tween(hat, 'rotate', '', -15*(dir?1:-1), 0, .3, true);
	}
	/* end rotate tween */

	/* shift left tween */
	var shiftLeft_tw = new Tween(hat, 'marginLeft', '', 0, -30*(dir?1:-1), .2, true);
	shiftLeft_tw.onstop = function() { 
		new Tween(hat, 'marginLeft', '', -30*(dir?1:-1), 0, .3, true);
	}
	/* end shift left tween */
}
var lastPopMonkey = false;
function setPopupMonkey(monkey, quick) {
	if(!monkey && lastPopMonkey)	monkey = lastPopMonkey;
	lastPopMonkey = monkey;

	var numberPositions = 5;
	var delayRange = Array(3, 6);

	var upPos = rand(0, 25);
	var downPos = 190;
	monkey.timer;

	// hide at new position
	var pos = rand(0, numberPositions)+1;
	monkey.className = "hiding position"+pos;

	// raise up
	monkey.up = function() {
		monkey.twIn = new Tween(monkey, 'marginTop', 'strong.out', downPos, upPos, rand(.2,.5, true), true);
		monkey.twIn.onstop = function() {
			var t = rand(2,5);
			monkey.timer = setTimeout(monkey.down, t*1000);
		}
	}
	monkey.down = function(quick) {
		monkey.twOut = new Tween(monkey, 'marginTop', 'strong.out', upPos, downPos, quick?.1:rand(.5,1, true), true);
		monkey.twOut.onstop = function() {
			//monkey.timer = setTimeout(function() { setPopupMonkey(monkey, quick) }, quick?(.1*1000):rand(2,5)*1000);
			setPopupMonkey(monkey, quick);
		}
	}
	monkey.onmouseover = function() {
		if(monkey.timer) clearTimeout(monkey.timer);
		if(monkey.twOut)	monkey.twOut.stop(false,true);
		if(monkey.twIn)		monkey.twIn.stop(false,true);
		monkey.down(true);
	}
	var t = rand(delayRange[0], delayRange[1]);
	monkey.timer = setTimeout(monkey.up, quick?.1*1000:t*1000);
}

