
var siam_rules = {
	'div#flashMessage' : function(el) {
		new Effect.Highlight(el, {startcolor:'#1FAFFF', endcolor:'#000000', duration: 5.0});
	},
	'a.imagelist' : function(e1) {
		initBox('divoverlay');
		var theObject = $(e1.id);
		theObject.onclick = function(e) {
			
			deldivhtml = '<span style="color:black;">Loading Image list ...</span>';
			new Ajax.Updater('divoverlay',WR + '/admin/imagelist/', {asynchronous:true, evalScripts:true});
			
			showBox(e,500,400,deldivhtml);
			return false;
			
		}
	},
	'a.imageaddlist' : function(e1) {
		initBox('divoverlay');
		var theObject = $(e1.id);
		theObject.onclick = function(e) {
			var albumid = $F('albumid');
			deldivhtml = '<span style="color:black;">Loading Image list ...</span>';
			new Ajax.Updater('divoverlay',WR + '/admin/imageaddlist/' + albumid + '/', {asynchronous:true, evalScripts:true});
			
			showBox(e,500,400,deldivhtml);
			return false;
			
		}
	}
}

Behaviour.register(siam_rules);


function initBox(divname) {
		// 'divoverlay'
	if (!document.getElementById(divname)) {
		var objBody = document.getElementsByTagName("body").item(0);
		
		var divOverlay = document.createElement("div");
		divOverlay.setAttribute('id',divname);
		divOverlay.style.display = 'none';
		divOverlay.style.position = 'absolute';
		divOverlay.style.top = '0';
		divOverlay.style.left = '0';
		divOverlay.style.zIndex = '500';
		//divOverlay.style.width = '140px';
		//divOverlay.style.height = '90px';
		objBody.insertBefore(divOverlay, objBody.firstChild);
	}
}

function showBox(e, divWidth, divHeight, theInnerHtml) {
	_showBox(e, divWidth, divHeight, theInnerHtml, 'divoverlay', 0.5, 15, 15);
}

function _showBox(e, divWidth, divHeight, theInnerHtml, whichDiv, dur, x_offset, y_offset) {
	initBox('divoverlay');
	
	var objDivOverlay = $(whichDiv);
	
	if (!e) var e = window.event;
	var left = Event.pointerX(e);
	var top = Event.pointerY(e);
		// Check to be sure it doesn't run off the page
	var windowWidth = 1024;
	if (typeof window.innerWidth!='undefined') {
			windowWidth = window.innerWidth;
	}
	else {
		if (document.documentElement && typeof document.documentElement.clientWidth!='undefined' && document.documentElement.clientWidth!=0) {
				windowWidth = document.documentElement.clientWidth;
		} 
		else {
			if (document.body && typeof document.body.clientWidth!='undefined') {
				windowWidth = document.body.clientWidth;
			}
		}	
	}
	if ((left + parseInt(divWidth) + 10) > windowWidth) {
		left = left - parseInt(divWidth);
	}
	
	left = left + x_offset;
	top = top + y_offset;
	
	objDivOverlay.style.top = top + 'px';
	objDivOverlay.style.left = left + 'px';
	objDivOverlay.style.width = divWidth + 'px';
	if (divHeight != 'auto') {
		objDivOverlay.style.height = divHeight + 'px';
	}

	objDivOverlay.innerHTML = theInnerHtml;
	
	Effect.Appear(objDivOverlay, { duration: dur,  queue: {position:'front', scope: 'floating_div', limit:1} });
}


function hideBox() {
	_hideBox('divoverlay', 0.5);
}

	
function _hideBox(whichDiv, dur) {
	var objDivOverlay = $(whichDiv);
	Effect.Fade(objDivOverlay, { duration: dur,  queue: {position:'end', scope: 'floating_div', limit:1} });
}

