if(!YAHOO.Mevia){ YAHOO.namespace("Mevia"); }

YAHOO.Mevia.InteractionLightBox = function(postlink_id, updateSendBoxSection, headerTitle, width, height, onClose,
		showCloseButton)
{
	var end=function(){
		jQuery.fancybox.close();
	};
	
	var boxWidth = 640;
	if (width) {
		boxWidth = width;
	}
	
	var boxHeight = 'auto';
	var autoDimensions = true;
	if (height) {
		boxHeight = height;
		autoDimensions = false;
	}
	
	// retrieve viewport
	var viewportHeight = jQuery(window).height();
	if (boxHeight == 'auto' || boxHeight > viewportHeight) {
		boxHeight = viewportHeight - 40;
	};
	
	var panelCfg = {
		'autoDimensions' : autoDimensions,
		'autoScale' : true,
		'centerOnScroll' : true,
		'enableEscapeButton' : false,
		'hideOnOverlayClick' : false,
		'height' : boxHeight,
		'padding' : 5,
		'showCloseButton' : showCloseButton,
		'title' : headerTitle,
		'titlePosition' : 'inside',
		'width' : boxWidth
	}

	if (onClose) {
		panelCfg.onClosed = onClose;
	};

	this.end = end;
 	this.plink = getCustomTag(postlink_id);
	this.plink.request.setOnSuccess(function(o)
	{
		var json = jQuery.parseJSON(o.responseText);
		for (key in json) {
			if (key != "default") {
				updateSendBoxSection = key;
				lightboxContent = json[key];
				break;
			};
		}
		panelCfg.content = "<div id='" + updateSendBoxSection + "'>" + lightboxContent + "</div>";
		panelCfg.onComplete = function()
		{
			var current_section = new Section(updateSendBoxSection);
			current_section.setURLParams('');
			current_section.request.setStaticParam("sectionid", updateSendBoxSection);
			addCustomTag('section', updateSendBoxSection, current_section);
			
			// YAHOO.plugin.Dispatcher.process( YAHOO.util.Dom.get(updateSendBoxSection), lightboxContent);
			// jQuery.fancybox.center();
		}
		jQuery.fancybox(panelCfg);
		// setTimeout('jQuery.fancybox.center()', 500);
	});
			  
	this.plink.doPost();
};

YAHOO.Mevia.ActionBox = function(postlink_id, updateSendBoxSection, attachTo, attachEvent, container)
{
	
	if (YAHOO.Mevia.actionContextMenu == null) {
		YAHOO.Mevia.actionContextMenu = new YAHOO.widget.Panel("actionContextMenu", 	            	            	            
		{
			visible				:	false,
			zindex				:	4,
			close				:	true,
			draggable			: 	false
		});

		YAHOO.Mevia.actionContextMenu.end = function()
		{
			YAHOO.Mevia.actionContextMenu.destroy();
		};
	};
	
	var postlink = getCustomTag(postlink_id);
	postlink.request.setOnSuccess(function(o)
	{
		YAHOO.Mevia.actionContextMenu.hide();
		var json = eval("("+o.responseText+")");
		YAHOO.Mevia.actionContextMenu.setBody("chargement du menu");
		YAHOO.Mevia.actionContextMenu.setHeader("");
		YAHOO.Mevia.actionContextMenu.render(YAHOO.util.Dom.get(container));
		// console.log(container);
		// console.log(YAHOO.util.Dom.get(container));
		
		// removing the old listeners, running the destroyer rules, and setting the loading message
		YAHOO.plugin.Dispatcher.process ( YAHOO.Mevia.actionContextMenu.body, "chargement du menu" );
		/* loading the content */
		YAHOO.plugin.Dispatcher.process( YAHOO.Mevia.actionContextMenu.body, json[updateSendBoxSection]);
		// displaying the panel
		YAHOO.Mevia.actionContextMenu.cfg.setProperty('context',[attachTo, 'tl', 'bl']);
		YAHOO.Mevia.actionContextMenu.show();
	});
	
	YAHOO.util.Event.addListener(attachTo, 'click', function()
	{
		postlink.doPost();
	});
}


// YAHOO.Mevia.confirmLightBox = function(message)
// {   
//     var handleYes = function()
// 	{ 
// 	    this.hide(); 
// 	}; 
// 	
// 	var handleNo = function()
// 	{ 
// 	    this.hide(); 
// 	};
// 	
// 	YAHOO.Mevia.confirmLightBox =  new YAHOO.widget.SimpleDialog("confirmLightBox",  
// 	{
// 		width				:	"300px", 
// 		fixedcenter			: 	true, 
// 		zindex				: 	4, 
// 		modal				: 	true, 
// 		visible				: 	false, 
// 		draggable			: 	false, 
// 		close				: 	true, 
// 		text				: 	"Do you want to continue?", 
// 		icon				: 	YAHOO.widget.SimpleDialog.ICON_HELP, 
// 		constraintoviewport	: 	true, 
// 		buttons				: 	[ {
// 			text		: 	"Yes",
// 			handler		: 	handleYes,
// 			isDefault	: 	true
// 		}, 
// 		{
// 			text	: 	"No",
// 			handler	: 	handleNo
// 		}] 
// 	}); 
// 	YAHOO.Mevia.confirmLightBox.setHeader(message);
// 	YAHOO.Mevia.confirmLightBox.setBody(message);
// 	YAHOO.Mevia.confirmLightBox.render(document.body);	
// 	YAHOO.Mevia.confirmLightBox.show();
// };
