/*------------------------------------------------------------------------------

     By: Tim Oram
   File: header-2.0.js
Purpose: Handles the login, bookmark and homepage popups.
Created: January 3, 2008; Updated: January 7, 2006
Company: Statusfirm Dynamic Media Incorporated
Copyright 2008; All Rights Reserved
-------------------------------------------------------------------------------*/


function classHeaderPopups() {
	
	
	/* the last popup shown */
	this.last_id = null;
	
	/* functions */
	this.initEvents = initEvents;
	this.hidePopUp = hidePopUp;
	this.showPopUp = showPopUp;
	
	this.popupsList = new Array('login','bookmark','homepage');
	
	/* save this to self cause the current this is lost when scope changes */ 
	var self = this;
	
	$(document).ready(function(){self.initEvents()});
}

function initEvents(){
	var self = this;
	
	//$('#header .login').bind('click', function(){self.showPopUp('login');});
	for(var i=0; i < self.popupsList.length; i++) {
		var id = self.popupsList[i];
		$('#header .' + id).bind('click', function(e){self.showPopUp(e)});
		$('#popups .' + self.popupsList[i] + ' .close').bind('click', function(e){self.hidePopUp(e)});
	}
}

function showPopUp(e){
	id = e.target.className;
	old = this.last_id;
	/*console.dir(e);/**/
	
	this.hidePopUp();
	if(old != id){
		corr = $('#header .' + id).offset();
		dtop = (corr.top + $('#header .' + id).height() - 0) + 'px';
		dleft = (corr.left - 2) + 'px';
		//console.log('(x,y) => (' + dleft + ',' + dtop + ')');
		$('#popups .' + id).css({left:dleft, top:dtop});
		$('#popups .' + id).show(200);
		this.last_id = id;
	}
	else{
		this.last_id = null;
	}
}

function hidePopUp(){
	if(this.last_id != null){
		$('#popups .' + this.last_id).hide(100);
		this.last_id = null;
	}
}

myHeaderPopups = new classHeaderPopups();

