	/*
	
	Dialog Class
	
	# @Author	Maximiliano Canestro
	# @Email	maximiliano.canestro@gameloft.com
	# @Studio	Buenos Aires - Argentina
	# @Date		April 28º 2010
	
		Example to use:
		
			var dialog = new Dialog();
			dialog.create('http://new-staging.gameloft.org/minisites/glive/doc.php');		
			dialog.setTitle("The Title");
			dialog.setButtonCancel('Cancel');
			dialog.setButtonAccept(label, callback function);
			dialog.init();
	*/
	
	function DialogWeb(){
		
		var me 				= this;
		var ButtonCancel 	= false;
		var ButtonAccept 	= false;
		var TitleDialog		= false;
		var loadUrl;
		var isCreated		= false;
		
		// Method: initializator 
		this.create = function(url){
			this.createDialog(url);
		}
		
		this.init = function(){			
			$.get( this.loadUrl,
				function(data){
					$("#dialogContent").html(data);
					if(this.TitleDialog){
						$("#dialogTitle").html(this.TitleDialog);
					}else{
						$("#dialogTitle").html("&nbsp;");
					}
					me.showDialog();
				}
			);
		}
		
		this.showDialog = function(){
			var widthD = $(window).width() / 2;		
			var widthW = $("#dialogContent").first().width() / 2;
			
			$("#dialogWindowBox").css({
				top:	this.getPageScroll()[1] + (this.getPageHeight() / 10),
				left:	(widthD - widthW)
			});
			$("#dialogLoading").hide();
			
			if(this.ButtonCancel || this.ButtonAccept){
				$("#dialogButtons").show();
			}else{
				$("#dialogButtons").hide();
			}

			if(this.TitleDialog){
				$("#dialogTitle").html(this.TitleDialog);
				$("#dialogTitle").show();
			}

			$("#dialogWindowBox").show();
			$("#dialogContent").fadeIn();
		}
		
		
		this.closeBox = function(){
			$('#dialogWindowBox').slideUp('fast', function(){
				$("#dialogWindowBox").empty();
				$("#dialogWindowBox").remove();
				$("#windowOverlay").remove();
			});
			this.isCreated = false;			
		}
		
		this.setTitle = function(label){
			this.TitleDialog = label;
		}
		
		this.setBackgroundContent = function(color){
			$("#dialogContent").css({background: color});
		}
		
		this.setButtonCancel = function(label){
			this.ButtonCancel = true;
			$("#dialogButtonA").html(label);
			$("#dialogButtonA").show();
			$("#dialogButtonA").click(function(){
				me.closeBox();
			});			
		}
		
		this.setButtonAccept = function(label, callback){
			this.ButtonAccept = true;
			$("#dialogButtonB").html(label);
			$("#dialogButtonB").show();		
			$("#dialogButtonB").click(function(){
				call_user_func(callback);
			});
		}
		
		this.destroyButtonCancel = function(){
			$("#dialogButtonA").remove();	
		}
        
        this.destroyButtonAccept = function(){
			$("#dialogButtonB").remove();	
		}
		 
		this.createDialog = function(url){
			
			this.loadUrl = url;
			
			var windowOverlay = document.createElement("div");
			$(windowOverlay).attr("id","windowOverlay");
			$(windowOverlay).addClass("windowOverlayBox");
			$('body').append(windowOverlay);
			$(windowOverlay).css('opacity', 0.5);
			
			var dialogWindowBox = document.createElement("div");
			$(dialogWindowBox).attr("id","dialogWindowBox");
			$("body").append(dialogWindowBox); 
				
			var dialogWindowContainer = document.createElement("div");
			$(dialogWindowContainer).attr("id","dialogWindowContainer");
			$(dialogWindowBox).append(dialogWindowContainer);    
							
			var tableContent = document.createElement("table");
			$(dialogWindowContainer).append(tableContent);
			$(tableContent).attr("border","0");
			$(tableContent).attr("cellspacing","0");
			$(tableContent).attr("cellpadding","0");
			
			var tableTr1Content = document.createElement("tr");
			$(tableContent).append(tableTr1Content);

			var tableTr2Content = document.createElement("tr");
			$(tableContent).append(tableTr2Content);

			var tableTr3Content = document.createElement("tr");
			$(tableContent).append(tableTr3Content);

			var tableTd1Content = document.createElement("td");
			$(tableTr1Content).append(tableTd1Content);

			var tableTd2Content = document.createElement("td");
			$(tableTr2Content).append(tableTd2Content);

			var tableTd3Content = document.createElement("td");
			$(tableTr3Content).append(tableTd3Content);

			var dialogTitle = document.createElement("div");
			$(dialogTitle).attr("id","dialogTitle");
			$(tableTd1Content).append(dialogTitle);
			$(dialogTitle).hide();

			var dialogContent = document.createElement("div");
			$(dialogContent).attr("id","dialogContent");
			$(tableTd2Content).append(dialogContent);
			$(dialogContent).hide();
							
			var dialogButtons = document.createElement("div");
			$(dialogButtons).attr("id","dialogButtons");
			$(tableTd3Content).append(dialogButtons); 
			$(dialogButtons).hide();
			
			var dialogLoading = document.createElement("div");
			$(dialogLoading).attr("id","dialogLoading");
			$(dialogWindowContainer).append(dialogLoading);    
			
			var dialogLoadingText = document.createElement("div");
			$(dialogLoadingText).html(loading_text+"...");
			$(dialogLoading).append(dialogLoadingText); 
			
			var dialogLoadingImg = document.createElement("img");
			$(dialogLoadingImg).attr("src", URL_MEDIA + "images/dialogLoader.gif");
			$(dialogLoading).append(dialogLoadingImg); 
			
	
			var dialogButtonA = document.createElement("div");
			$(dialogButtonA).addClass("dialogButton");
			$(dialogButtonA).attr("id","dialogButtonA");
			$(dialogButtons).append(dialogButtonA);
			$(dialogButtonA).hide();
	
			var dialogButtonB = document.createElement("div");
			$(dialogButtonB).addClass("dialogButton");
			$(dialogButtonB).attr("id","dialogButtonB");
			$(dialogButtons).append(dialogButtonB);
			$(dialogButtonB).hide();
			
			var widthD = $(window).width() / 2;		
			var widthW = 200;		
			$("#dialogWindowBox").css({
				top:	this.getPageScroll()[1] + (this.getPageHeight() / 10),
				left:	(widthD - widthW)
			});
			
			$('#windowOverlay').click(function(){
				try{ $(document).trigger( me.closeBox() ) }catch(e){}
			});
		}
		
		this.getPageScroll = function() {
			var xScroll, yScroll;
			if (self.pageYOffset){
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop){
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body){
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;	
			}
			return new Array(xScroll,yScroll);
		}
	
		this.getPageHeight = function(){
			var windowHeight;
			if (self.innerHeight){
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight){
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body){
				windowHeight = document.body.clientHeight;
			}	
			return windowHeight;
		}
		
	} // End class