/* --------------------------------------------

	main.js
	* Loads init(s) for application

------------------------------------------------*/
window.addEvent('domready', function(){
	// init all functions required on dom load
	init();
	
});

//Function to init the Application, call when app first loads
function init(){
	addEventHandlers();
	//alert("Event Handlers Loaded...");
	
	//add global form validators
	var dropLoginChk = new FormCheck('preheaderLoginForm',{
				errorsLocation: '3'
			});
}

//function to handle all event handlers for items on page after domready
function addEventHandlers()
{
	/* ===================================================
	* Event Handlers for drop-down login panel
	* ==================================================== */
	$('loginLink').addEvent('click', function(e)
		{
			e.stop();
			$('preheaderLoginContent').toggleClass('hide');
		}
	);

	//modal event listeners
	$('modalCloseButton').addEvents({
		click: function(e){
			closeModal(e);
			e.stop();
		}
	});
	
}


/* -----------------------------------------------
function for adding modal box
*/
function openModal(x, y, w, title, urlToOpen)
{
	var mLeft = x;
	var mTop = y;
	var mWidth  = w;
	
	$('modalDiv').setStyles({
		left: mLeft,
		top: mTop,
		width: mWidth
	});
	
	$('modalTitle').innerHTML = title;
	
	var urlRequest = new Request.HTML({
		url: urlToOpen,
		method: 'get',
		update: 'modalContent',
		evalScripts: true, /* this is the default */
		onComplete: function(){
			//console.log('ajax complete!')
			//remove spinner!
			}
	}).send();
	
	//$('modalContentIFrame').src = url;
	//$('modalContentIFrame').setStyle('height', '475px');
	$('modalDiv').toggleClass('hide');
		
}

/*=====================================
function to close the modal
*/
function closeModal(e){
	$('modalDiv').toggleClass('hide');
	
}