/* ********* WEBSITES ********* */

function headerBits(controllerObj, domObj) {

	this.domObj = domObj;

	this.controllerObj = controllerObj;

	this.isDisplayed = false;

	this.init = function () {

		this.displayPanel = $(this.domObj.getElementsByTagName('div')[0]);

		this.displayPanelsSetup();

		this.controllerObj.newObj(this);

		this.CachedActivateHandler = this.ActivateHandler.bindAsEventListener(this);

		Event.observe(this.domObj, 'mouseover', this.CachedActivateHandler);

		return true;

	}

	this.ActivateHandler = function () {

		if(!this.isDisplayed) {

			Event.stopObserving(this.domObj, 'mouseover', this.CachedActivateHandler);


			controllerObj.currentObj = this;

			controllerObj.setCanClose(true);

			controllerObj.clearUp(this);


			this.CachedOutHandler = this.outHandler.bindAsEventListener(this);

			Event.observe(this.domObj, 'mouseout', this.CachedOutHandler);

			this.CachedOverHandler = this.overHandler.bindAsEventListener(this);

			Event.observe(this.domObj, 'mouseover', this.CachedOverHandler);

			this.displayScript();

		}


	}

	this.overHandler = function () {

		controllerObj.setCanClose(false);

	}

	this.outHandler = function () {

		controllerObj.setCanClose(true);

	}

	this.clearUp = function () {

		//alert('clear Standup');

		this.hideScript();

		Event.observe(this.domObj, 'mouseover', this.CachedActivateHandler);

	}

	this.displayScript = function () {

		this.isDisplayed = true;

		//this.domObj.style.background = 'url(images/websites_on.gif) 0% 0% no-repeat';

		//Effect.Appear(this.displayPanel, { duration: 0.2, queue:'front' });

		$(this.displayPanel).show();


	}

	this.hideScript = function () {

		this.isDisplayed = false;

		//this.domObj.style.background = 'url(images/websites_off.gif) 0% 0% no-repeat';

		//Effect.Fade(this.displayPanel, { duration: 0.2, queue:'end' });

		$(this.displayPanel).hide();

	}

	this.displayPanelsSetup = function () {

		this.displayPanel.style.left = (10 + this.domObj.offsetWidth) + 'px';

		this.displayPanel.style.top = (33) + 'px';

	}

	this.init();

}



/* ********* IMPRO ********* */


function improBits(controllerObj, domObj) {

	this.domObj = domObj;

	this.controllerObj = controllerObj;

	this.isDisplayed = false;


	this.init = function () {

		this.displayPanelLeft = $(this.domObj.getElementsByTagName('div')[0]);

		this.displayPanelRight = $('improMenuRight');

		this.displayPanelsSetup();


		this.controllerObj.newObj(this);

		this.CachedActivateHandler = this.ActivateHandler.bindAsEventListener(this);

		Event.observe(this.domObj, 'mouseover', this.CachedActivateHandler);

		return true;

	}

	this.ActivateHandler = function () {

		//alert('Show Improv');

		if(!this.isDisplayed) {

			Event.stopObserving(this.domObj, 'mouseover', this.CachedActivateHandler);

			controllerObj.currentObj = this;

			controllerObj.setCanClose(true);

			controllerObj.clearUp(this);


			this.CachedOutHandler = this.outHandler.bindAsEventListener(this);

			Event.observe(this.domObj, 'mouseout', this.CachedOutHandler);

			this.CachedOverHandler = this.overHandler.bindAsEventListener(this);

			Event.observe(this.domObj, 'mouseover', this.CachedOverHandler);

			this.displayScript();

		}

	}

	this.overHandler = function () {

		//alert('over');

		controllerObj.setCanClose(false);

	}

	this.outHandler = function () {

		//alert('out');

		controllerObj.setCanClose(true);

	}

	this.clearUp = function () {

		//alert('clear Improv');

		this.hideScript();

		Event.observe(this.domObj, 'mouseover', this.CachedActivateHandler);

	}

	this.displayScript = function () {

		this.isDisplayed = true;

		this.domObj.style.background = 'url(images/improv_on.jpg) 50% 0% no-repeat';

		//Effect.BlindDown(this.displayPanelRight, { duration: 0.5, queue:'front' });
		
		//Effect.BlindDown(this.displayPanelLeft, { duration: 0.5, queue:'front' });

		$(this.displayPanelLeft).show();

		$(this.displayPanelRight).show();

	}

	this.hideScript = function () {

		this.isDisplayed = false;

		this.domObj.style.background = 'url(images/improv_off.jpg) 50% 0% no-repeat';

		//Effect.BlindUp(this.displayPanelLeft, { duration: 0.5, queue:'end' });

		//Effect.BlindUp(this.displayPanelRight, { duration: 0.5, queue:'end' });

		$(this.displayPanelLeft).hide();

		$(this.displayPanelRight).hide();

	}

	this.displayPanelsSetup = function () {

		this.displayPanelLeft.style.left = (143 - this.domObj.offsetWidth) + 'px';

		this.displayPanelLeft.style.top = '10px';

		this.displayPanelRight.style.left = (this.domObj.offsetWidth - 50) + 'px';

		this.displayPanelRight.style.top = '10px';


	}


	this.init();

}

/* ********* STANDUP ********* */


function standupBits(controllerObj, domObj) {

	this.domObj = domObj;

	this.controllerObj = controllerObj;

	this.isDisplayed = false;

	this.init = function () {

		this.displayPanel = $(this.domObj.getElementsByTagName('div')[0]);

		this.displayPanelsSetup();

		this.controllerObj.newObj(this);

		this.CachedActivateHandler = this.ActivateHandler.bindAsEventListener(this);

		Event.observe(this.domObj, 'mouseover', this.CachedActivateHandler);

		return true;

	}

	this.ActivateHandler = function () {

		if(!this.isDisplayed) {

			Event.stopObserving(this.domObj, 'mouseover', this.CachedActivateHandler);

			controllerObj.currentObj = this;

			controllerObj.setCanClose(true);

			controllerObj.clearUp(this);


			this.CachedOutHandler = this.outHandler.bindAsEventListener(this);

			Event.observe(this.domObj, 'mouseout', this.CachedOutHandler);

			this.CachedOverHandler = this.overHandler.bindAsEventListener(this);

			Event.observe(this.domObj, 'mouseover', this.CachedOverHandler);

			this.displayScript();

		}


	}

	this.overHandler = function () {

		controllerObj.setCanClose(false);

	}

	this.outHandler = function () {

		controllerObj.setCanClose(true);

	}

	this.clearUp = function () {

		//alert('clear Standup');

		this.hideScript();

		Event.observe(this.domObj, 'mouseover', this.CachedActivateHandler);

	}

	this.displayScript = function () {

		this.isDisplayed = true;

		this.domObj.style.background = 'url(images/stand_up_on.gif) 0% 0% no-repeat';

		//Effect.Appear(this.displayPanel, { duration: 0.4, queue:'front' });

		$(this.displayPanel).show();

	}

	this.hideScript = function () {

		this.isDisplayed = false;

		this.domObj.style.background = 'url(images/stand_up_off.gif) 0% 0% no-repeat';

		//Effect.DropOut(this.displayPanel, { duration: 0.2, queue:'end' });

		$(this.displayPanel).hide();

	}

	this.displayPanelsSetup = function () {

		this.displayPanel.style.left = '10px';

		this.displayPanel.style.top = (37 - (this.domObj.offsetHeight)) + 'px';

	}

	this.init();

}


/* ********* WEBSITES ********* */

function websitesBits(controllerObj, domObj) {

	this.domObj = domObj;

	this.controllerObj = controllerObj;

	this.isDisplayed = false;

	this.init = function () {

		this.displayPanel = $(this.domObj.getElementsByTagName('div')[0]);

		this.displayPanelsSetup();

		this.controllerObj.newObj(this);

		this.CachedActivateHandler = this.ActivateHandler.bindAsEventListener(this);

		Event.observe(this.domObj, 'mouseover', this.CachedActivateHandler);

		return true;

	}

	this.ActivateHandler = function () {

		if(!this.isDisplayed) {

			Event.stopObserving(this.domObj, 'mouseover', this.CachedActivateHandler);


			controllerObj.currentObj = this;

			controllerObj.setCanClose(true);

			controllerObj.clearUp(this);


			this.CachedOutHandler = this.outHandler.bindAsEventListener(this);

			Event.observe(this.domObj, 'mouseout', this.CachedOutHandler);

			this.CachedOverHandler = this.overHandler.bindAsEventListener(this);

			Event.observe(this.domObj, 'mouseover', this.CachedOverHandler);

			this.displayScript();

		}


	}

	this.overHandler = function () {

		controllerObj.setCanClose(false);

	}

	this.outHandler = function () {

		controllerObj.setCanClose(true);

	}

	this.clearUp = function () {

		//alert('clear Standup');

		this.hideScript();

		Event.observe(this.domObj, 'mouseover', this.CachedActivateHandler);

	}

	this.displayScript = function () {

		this.isDisplayed = true;

		this.domObj.style.background = 'url(images/websites_on.gif) 0% 0% no-repeat';

		//Effect.Appear(this.displayPanel, { duration: 0.2, queue:'front' });

		$(this.displayPanel).show();


	}

	this.hideScript = function () {

		this.isDisplayed = false;

		this.domObj.style.background = 'url(images/websites_off.gif) 0% 0% no-repeat';

		//Effect.Fade(this.displayPanel, { duration: 0.2, queue:'end' });

		$(this.displayPanel).hide();

	}

	this.displayPanelsSetup = function () {

		this.displayPanel.style.left = this.domObj.offsetWidth + 'px';

		this.displayPanel.style.top = '0px';

	}

	this.init();

}



/* ********* INTERACTION HANDLER ********* */

function interactionHandler() {

	this.objList = [];

	this.currentObj = false;

	this.canClose = false;

	this.init = function () {

		Event.observe(document, 'click', this.clearUp);

		return true;

	}

	this.setCanClose = function (val) {

		this.canClose = val;

		//alert('canClose' + this.canClose);

	}.bind(this);

	this.newObj = function (obj) {

		this.objList.push(obj);

	}.bind(this);

	this.clearUp = function (skipObj) {

		//alert(this.currentObj + ' : ' + this.canClose)

		if(this.currentObj && this.canClose) {

			/* Check if is the current obj */

			for(var i = 0; i < this.objList.length; i++) {
				if(this.objList[i] != skipObj) {
					this.objList[i].clearUp();
				}
			}

		}

	}.bind(this);

	this.init();

}
