﻿var modalWindow = 
{   
    parent:"body",   
    windowId:null,   
    windowTitle:null,   
    windowCloseTxt:null, 
    content:null,   
    width:null,   
    height:null,     
    
    open:function()   
    {   
        var modal = "";   
        modal += "<div class=\"modal-overlay\"></div>";   
        modal += "<div id=\"" + this.windowId + "\" class=\"modal-window\" style=\"width:" + this.width + "px; height:" + this.height + "px; margin-left:-" + (this.width / 2) + "px;\">";   
        modal += "<div class=\"container-window\" style=\"background:url('_img/pixel.gif'); width:" + this.width + "px; height:" + this.height + "px;\">";  
        modal += "<div class=\"bar-window\"><div>" + this.windowTitle + "<a class=\"close-window\" title=\"" + this.windowCloseTxt + "\"></a></div></div>";  
        modal += "<div class=\"content-window\" style=\"height:" + (this.height - 37) + "px;\">" + this.content + "</div>";       
        modal += "<div class=\"bottom-window\"><div></div></div>"; 
        modal += "</div>";    
        modal += "</div>";           
        $(this.parent).append(modal);   
        
        //Fix ie6 overlay / png por gif
        if($.browser.msie() && $.browser.version.number() == 6)
        {
            $(".modal-overlay").css('height', $(document).height() + 'px');
            $('.bar-window').css('background', 'url("_img/windowTopLeft.gif") no-repeat top left');
            $('.bar-window div').css('background', 'url("_img/windowTopRight.gif") no-repeat top right');
            $('.bottom-window').css('background', 'url("_img/windowBotLeft.gif") no-repeat top left');
            $('.bottom-window div').css('background', 'url("_img/windowBotRight.gif") no-repeat top right');
            $('.close-window').ifixpng();
        }
        else
        {
            $(".container-window").dropShadow();
        }
                
        var windowHeight = $(window).height();
        var scrollTop = $(window).scrollTop();
        $(".modal-window").css('top', Math.round((windowHeight/2) - (this.height/2) + scrollTop) + 'px'); 
        
        $(".bar-window").mousedown(function() { addDragEvent($(".modal-window")); }); 
        $(".bar-window").mouseup(function() { deleteDragEvent($(".modal-window")); }); 
        $(".close-window").click(function() { modalWindow.close(); });   
        $(".modal-overlay").click(function() { modalWindow.close(); });   
    } ,   
    
    close:function()   
    {   
        $(".modal-window").remove();   
        $(".modal-overlay").remove();   
    }
};  

function addDragEvent(element)
{
    element.draggable
    (
        {
            zIndex: 	2005,
			ghosting:	true
		}
    );  
}

function deleteDragEvent(element)
{
    element.draggable
	(
	    { }
	);
}
