////////////////////////////////////////////////////////////////////////////
//
// © PMP CONCEPT 2007 :: FENETRE DE DIALOGUE
//
////////////////////////////////////////////////////////////////////////////
//$('body').append('<div id="pmpdial"></div>');
$(document).ready(function(){
	pmpdial = {
		message: null,
		index:0,
		
		init: function (template) {
			this.racine = $('script[src$="pmpdial.js"]').attr('src').replace('pmpdial.js', '');
			this.closeButton = false;
			
		},
		open: function (dialog) {
			// add padding to the buttons in firefox/mozilla
			if ($.browser.mozilla) {
				$('#pmpdial-container .pmpdial-button').css({
					'padding-bottom': '2px'
				});
			}
			// input field font size
			if ($.browser.safari) {
				$('#pmpdial-container .pmpdial-input').css({
					'font-size': '.9em'
				});
			}
			
			// dynamically determine height
			var h = 500;
			/*if ($('#pmpdial-subject').length) {
				h += 26;
			}
			if ($('#pmpdial-cc').length) {
				h += 22;
			}*/
			
			
			//$('.op_c')
			var title = $('#pmpdial-container .pmpdial-title').html();
			//$('#pmpdial-container .pmpdial-title').html('Loading...');
			dialog.overlay.fadeIn(200, function () {
				dialog.container.fadeIn(200, function () {
					dialog.data.fadeIn(200, function () {
						/*$('#pmpdial-container .pmpdial-content').animate({
							height: h
						}, function () {
							
						});*/
						
					});
					//alert($('.op_c').height());
					//$('.op_c').css('width', ($('#noborder').width()+20)+'px');
					/*var w = $('#noborder').width()-10;
					var h = $('#noborder').height()+30;
					$('#noborder').width(w);
					$('.op_c').height(h);*/
					//alert($('.op_c').height());
				});
			});
		},
		show: function (template, params) {
			this.index++;
			
			id = 'pmpdial'+this.index;
						
			if(!template)
				template = this.racine+'_templates/default.php';
			
			$.get(template, params,  function(data){
				
				//$(data).modal({
				$(data).modal({
					overlayId: 'pmpdial-overlay',
					containerId: 'pmpdial-container',
					onOpen: pmpdial.open,
					//onShow: pmpdial.show,
					onClose: pmpdial.close,
					overlayClose:true
				});
			});
		},
		close: function (dialog) {
			
			$.modal.close();
			/*$('#pmpdial-container').animate({
				height: 40
			}, function () {
				dialog.data.fadeOut(200, function () {
					dialog.container.fadeOut(200, function () {
						dialog.overlay.fadeOut(200, function () {
							$.modal.close();
						});
					});
				});
			});*/
		}
	};

	pmpdial.init();
});

/*
// definition du message a afficher
function message(txt)
{
	window.parent.showLayer(txt);
}

// afficher la fentre
function showLayer(content){
	// calcul de la taille de la fenetre de navigation
	size = truebody().scrollHeight;
	size2 = $(window).height();
	// insertion du texte a afficher
	document.getElementById('outerImageContainer').innerHTML = content;
	// definition du style pour le fond noir transparent
	document.getElementById('overlay').className="overlayoff";
	// hauteur du fond noir
	document.getElementById('overlay').style.height= size + "px";
	document.getElementById('overlay').style.width= truebody().scrollWidth + "px";
	// centrage de la fenetre
	//larg = document.getElementById('outerImageContainer').offsetWidth;
	//document.getElementById('outerImageContainer').style.marginLeft = -(larg/2) + "px";
	centerScreen("outerImageContainer");
	
	// masque les éléments bug IE
	hideElementsByTagName('SELECT');
	
	// afichage general
	document.getElementById('popup_layer').style.visibility="visible";	
}

// masquer la fenetre
function hideLayer(){
		// cache general
		document.getElementById('popup_layer').style.visibility="hidden";
		// retour sur l'ancien style
		document.getElementById('overlay').className="overlay";
		// effacement du contenue du bloc
		document.getElementById('outerImageContainer').innerHTML= null;
		
		// affiche les éléments bug IE
		showElementsByTagName('SELECT');
}

//
function truebody(){
	//return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	return document.documentElement ? document.documentElement : document.body;
}

// bloc message
if (document.getElementById || document.all){
	document.write('<div id="popup_layer"><div id="overlay" class="overlay"></div><div id="lightbox"><div id="outerImageContainer"></div></div></div>')
}

function centerScreen(id) 
{
	var obj = document.getElementById(id);
	if(obj)
	{
		offsetx = window.pageXOffset ? pageYOffset : (truebody().scrollLeft ? truebody().scrollLeft : 0);
		offsety = window.pageYOffset ? pageYOffset : (truebody().scrollTop ? truebody().scrollTop : 0);
		
		obj.style.left=(((( window.innerWidth ? window.innerWidth : truebody().clientWidth) - obj.offsetWidth)/2) + offsetx) + "px";
		obj.style.top=(((( window.innerHeight ? window.innerHeight : truebody().clientHeight) - obj.offsetHeight)/2) + offsety) + "px";
	}
}


function refreshStyle()
{
	
	//modifie la taille du fond
	document.getElementById('overlay').style.height= truebody().scrollHeight + "px";
	document.getElementById('overlay').style.width= truebody().scrollWidth + "px";
		
	// centre la fenetre à l'écran si le popup est affiché
	if(document.getElementById('popup_layer') && document.getElementById('popup_layer').style.visibility=="visible")
	{
		centerScreen("outerImageContainer");
	}
}

function hideElementsByTagName(tagname,id)
{
	if(tagname==null)
		return;
	
	var elements = document.getElementsByTagName(tagname);
	
	for (i = 0; i < elements.length; i++)
		elements[i].style.visibility = 'hidden';
}


function showElementsByTagName(tagname)
{
	if(tagname==null)
		return;
	
	var elements = document.getElementsByTagName(tagname);
	
	for (i = 0; i < elements.length; i++)
		elements[i].style.visibility = 'visible';
}

window.onscroll = refreshStyle;
window.onresize = refreshStyle;
*/

