/*
	MonxTools for MooTools v1.00
	by Robert Slootjes - MediaMonks, www.mediamonks.com
	Copyright 2007
*/

/************************************************************************************************************
 *	
 *	showMonxBox
 *	
 *  usage:
 *	onclick="showMonxBox('http://www.url-to-iframe.com/', '800', '600');"
 *
************************************************************************************************************/
function showMonxBox(strUrl, intWidth, intHeight, strTitle, blnDisableClose)
{
	new Fx.Style($('ufoverlay') , 'opacity').start(0, 1);
	new Fx.Style($('ufoverlay1') , 'opacity').start(0, 0.75);
	var intPageWidth			= getWidth();
	var intPageHeight			= getHeight();
	var intPageScrollHeight		= getScrollHeight();
	
	intCloseHeight = 27;
	
	objDivContent = new Element('div');
	objDivContent.setProperty('id', 'overlay-page');
	objDivContent.setStyle('position', 'relative');
	objDivContent.setStyle('width', intWidth + 'px');
	
	if(blnDisableClose != false)
	{
		objDivContent.setStyle('height', (parseInt(intHeight) + parseInt(intCloseHeight)) + 'px');
	}
	else
	{
		objDivContent.setStyle('height', intHeight + 'px');
	}
	
	
	objDivContent.setStyle('left', ((intPageWidth / 2) - (intWidth / 2)) + 'px');
	objDivContent.setStyle('top', ((intPageScrollHeight / 2) - (intHeight / 2)) + 'px');
	objDivContent.setStyle('background-color', '#FFFFFF');
	objDivContent.setStyle('border', '1px solid #0F2235');
	objDivContent.injectInside($('ufoverlay'));
	
	
	if(blnDisableClose != false)
	{
		objHeader = new Element('div');
		objHeader.setStyle('position', 'relative');
		objHeader.setStyle('width', (intWidth - 10) + 'px');
		objHeader.setStyle('height', intCloseHeight + 'px');
		objHeader.setStyle('background-image', 'url(images/monxbog_bg.gif)');
		objHeader.setStyle('color', '#6A4139');
		objHeader.setStyle('padding', '10px 0px 0px 10px');
		
		objHeader.injectInside(objDivContent);
		
		objTitle = new Element('span');
		objTitle.setStyle('font-family', 'Georgia');
		objTitle.setStyle('font-size', '16px');
		objTitle.setStyle('font-weight', 'bold');
		objTitle.appendText(strTitle);
		objTitle.injectInside(objHeader);
		
		objImage = new Element('img');
		objImage.setProperty('src', 'images/monxbox_close.gif');
		objImage.setStyle('cursor', 'pointer');
		objImage.setStyle('position', 'absolute');
		objImage.setStyle('top', '0px');
		objImage.setStyle('right', '3px');
		objImage.addEvent('click', function(){closemonxbox()});
		objImage.injectInside(objHeader);

	}
	
	objIframe = new Element('iframe');
	objIframe.setProperty('src', strUrl);
	objIframe.setProperty('frameborder', '0');
	objIframe.setStyle('width', intWidth + 'px');
	objIframe.setStyle('height', intHeight + 'px');
	objIframe.setStyle('border', 'none');
	objIframe.injectInside(objDivContent);
	
}

function closemonxbox()
{
	new Fx.Style($('ufoverlay'), 'opacity', {duration:500, onComplete: function(){ $('overlay-page').remove() } }).start(1, 0);
	new Fx.Style($('ufoverlay1') , 'opacity').start(0.75, 0);
}

function createMonxBox()
{
	var objBogus	= new Element('div');
	objBogus.setProperty('id', 'ufoverlay1');
	objBogus.setStyle('position', 'absolute');
	objBogus.setStyle('left', '0px');
	objBogus.setStyle('width', '100%');
	objBogus.setStyle('height', getScrollHeight() + 'px');
	objBogus.setStyle('top', '0px');
	objBogus.setStyle('opacity', '0');
	objBogus.setStyle('z-index', '5');
	objBogus.setStyle('background-color', '#0F2235');
	objBogus.injectInside(document.body);
	
	var objDivMain	= new Element('div');
	objDivMain.setProperty('id', 'ufoverlay');
	objDivMain.setStyle('position', 'absolute');
	objDivMain.setStyle('left', '0px');
	objDivMain.setStyle('width', '100%');
	objDivMain.setStyle('height', getScrollHeight() + 'px');
	objDivMain.setStyle('top', '0px');
	objDivMain.setStyle('opacity', '0');
	objDivMain.setStyle('z-index', '15');
	objDivMain.injectInside(document.body);
}



/************************************************************************************************************
 *	
 *	designCheckbox
 *	
 *  usage:
 *	designCheckbox('CheckboxId', 'check.png', 'delete.png' );
 *
************************************************************************************************************/
function designCheckbox(strInputClass, strCheckedImage, strUncheckedImage)
{
	a = 1;
	$$('input.' + strInputClass).each(function(item)
	{
		item.setStyle('display', 'none');
		item.setProperty('id', strInputClass + '_' + a);
		domImage = new Element('img');
		domImage.a = a;
		if(item.checked == true)
		{
			domImage.src = strCheckedImage;
		}
		else
		{
			domImage.src = strUncheckedImage;
		}
		domImage.setProperty('id', strInputClass + '_image_' + a);
		domImage.addEvent('click', function(){ designCheckboxHandler(this.a, strInputClass, strCheckedImage, strUncheckedImage) })
		domImage.setStyle('cursor', 'pointer');
		domImage.injectAfter(item);
		a++;
	}
	);
}

function designCheckboxHandler(intElement, strInputClass, strCheckedImage, strUncheckedImage)
	{
		if($(strInputClass + '_' + intElement).checked == true)
		{
			// make false
			$(strInputClass + '_image_' + intElement).src	= strUncheckedImage;
			$(strInputClass + '_' + intElement).checked = false;
			$(strInputClass + '_' + intElement).defaultChecked = false;
		}
		else
		{
			// make true
			$(strInputClass + '_image_' + intElement).src	= strCheckedImage;
			$(strInputClass + '_' + intElement).checked = true;
			$(strInputClass + '_' + intElement).defaultChecked = true;
		}
	}

/************************************************************************************************************
 *	
 *	designRadioButton
 *	
 *  usage:
 *	designRadioButton('radioButtonClass', 'check.png', 'delete.png' );
 *
************************************************************************************************************/
function designRadioButton(strInputClass, strCheckedImage, strUncheckedImage)
{
	a = 1;
	$$('input.' + strInputClass).each(function(item)
	{
		item.setStyle('display', 'none');
		item.setProperty('id', strInputClass + '_' + a);
		domImage = new Element('img');
		domImage.a = a;
		if(item.getProperty('selected') == 'selected')
		{
			domImage.src = strCheckedImage;
			item.checked = true;
		}
		else
		{
			domImage.src = strUncheckedImage;
		}
		domImage.setProperty('id', strInputClass + '_image_' + a);
		domImage.addEvent('click', function(){ designRadioButtonHandler(this.a, strInputClass, strCheckedImage, strUncheckedImage) })
		domImage.setStyle('cursor', 'pointer');
		domImage.injectAfter(item);
		a++;
	}
	);
}

function designRadioButtonHandler(intElement, strInputClass, strCheckedImage, strUncheckedImage)
{
	a = 1;
	$$('input.' + strInputClass).each(function(item)
	{
		item.checked = 'false';
		$(strInputClass + '_image_' + a).src = strUncheckedImage;
		a++;
	}
	);
	$(strInputClass + '_image_' + intElement).src = strCheckedImage;
	$(strInputClass + '_' + intElement).checked = true;
	$(strInputClass + '_' + intElement).defaultChecked = true;
}


// autostart monxbox
window.addEvent('domready', function() {createMonxBox()});