﻿/*
 * Flutschi Window
 *
 * Copyright (c) 2009-01-24   
 * David Oliveira | david.oliveira@zenn.pt
 * 
 * Depends:
 *	jQuery v1.3
 *
 * Notes: To Close Window from URL target, call parent.FlutschiWindowClose();
 *
 */

function FlutschiWindow(/*String*/ URL, /*Number*/ Width, /*Number*/ Height) 
{
    var fwImagesPath = 'images/';
    var modalWidth = Number(Width) + 20;
    var modalHeight = Number(Height);
    var modalPositionTop = (Number(jQuery(window).height()) - Number(modalHeight)) / 2;
    if (modalPositionTop < 0) modalPositionTop = 0;
    var modalPositionLeft = (Number(jQuery(window).width()) - Number(modalWidth)) / 2;
    if (modalPositionLeft < 0) modalPositionLeft = 0;

    jQuery('body').append('<div id="fwOverlay" style="position: absolute; top:0px; left:0px; z-index: 5; width: 100%; height:100%; filter: Alpha(Opacity=60); -moz-opacity:0.6; opacity: 0.6; background-color:#85BBEF;"></div>');
    if (modalHeight > jQuery('#fwOverlay').height())
        jQuery('#fwOverlay').height(modalHeight + 45);

    var html = '<div id="fwModal" style="display:none; position:absolute; top:' + modalPositionTop + 'px; left:' + modalPositionLeft + 'px; z-index:1000; width:' + modalWidth + 'px;">';
    html += '<div style="position:relative; display:block; height:25px;">';
    html += '<div style="position:absolute; left:0px; top:0px;"><img src="' + fwImagesPath + 'fw-left-top.gif" /></div>';
    html += '<div style="margin:0px 10px 0px 10px; background:url(' + fwImagesPath + 'fw-right-middle.gif); text-align:right;"><span id="fwBtnClose" style="cursor:pointer;"><img src="' + fwImagesPath + 'fw-btn-close.gif" alt=""></span></div>';
    html += '<div style="position:absolute; right:0px; top:0px;"><img src="' + fwImagesPath + 'fw-right-top.gif" /></div>';
    html += '</div>';


    html += '<div style="position:relative; display:block; margin-top:-2px;">';
    html += '<div style="position:absolute; left:0px; top:0px; width:7px; height:' + modalHeight + 'px; background-image:url(' + fwImagesPath + 'fw-frame-left.gif);"></div>';
    html += '<div style="margin:-2px 7px 0px 7px; height:' + modalHeight + 'px; background-color:#FFFFFF;">';
    html += '<iframe width="' + Width + '" height="' + Height + '"  frameborder="0" marginwidth="0" marginheight="0" scrolling="NO" src="' + URL + '"></iframe>';
    html += '</div>';
    html += '<div style="position:absolute; right:0px; top:0px; width:7px; height:' + modalHeight + 'px; background-image:url(' + fwImagesPath + 'fw-frame-right.gif);"></div>';
    html += '</div>';

    html += '<div style="position:relative; display:block; height:7px;">';
    html += '<div style="position:absolute; left:0px; top:0px;"><img src="' + fwImagesPath + 'fw-bottom-left-c.gif" style="vertical-align:top;" /></div>';
    html += '<div style="margin:0px 7px 0px 7px; background-image:url(' + fwImagesPath + 'fw-bottom-middle.gif); height:7px;">&nbsp;</div>';
    html += '<div style="position:absolute; right:0px; top:0px;"><img src="' + fwImagesPath + 'fw-bottom-right-c.gif" style="vertical-align:top;" /></div>';
    html += '</div>';

    html += '</div>';
    jQuery('body').append(html);

    jQuery('#fwBtnClose').click(FlutschiWindowClose);
    scroll(0, 0);
    document.documentElement.style.overflow = "hidden";
    jQuery('#fwModal').toggle('slow');
    
}

function FlutschiWindowClose() {
    jQuery('#fwOverlay').remove();
    jQuery('#fwModal').toggle('slow', function() {
        jQuery('#fwModal').remove();
        document.documentElement.style.overflow = "auto";        
    });    
}

function FlutschiWindowCloseAndRedirect(/*String*/ URL) {
	FlutschiWindowClose();
	window.location = URL;
}

function FlutschiWindowCloseAndRefresh() {
    //FlutschiWindowClose();
    window.location.reload(true);
}
