﻿// JScript File

LB_WIDTH = 640;
LB_HEIGHT = 500;
var curwin = "";

var reloadpage = false;
function init_tiny()
{
    
    tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
		plugins : "filemanager, imagemanager, advimage, safari,style,advlink,emotions,iespell,inlinepopups,media,searchreplace,contextmenu,paste,directionality,noneditable,visualchars,nonbreaking,xhtmlxtras",

		// Theme options
		theme_advanced_buttons1 : "bold,italic,underline,|,styleselect,fontselect,fontsizeselect,|,sub,sup",
		theme_advanced_buttons2 : "cut,copy,paste,|,search,replace,|,bullist,numlist,|,undo,redo,|,link,unlink,anchor,image,code,charmap,iespell,nonbreaking",
		theme_advanced_buttons3 : "",
		theme_advanced_buttons4 : "",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,
        
		// Example content CSS (should be your site CSS)
		//content_css : "/assets/styles/MudStyle2.css",

		editor_deselector : "mceNoEditor",
        
        extended_valid_elements : "script[type],object[width|height|classid|codebase],param[name|value],embed[src|type|width|height|flashvars|wmode]"
        
		// Replace values for the template plugin
		
	});
	
}	
function LB_showWindow(win){ 
    
    init_tiny();
    
    curwin = win;
    
    var overlay = $(curwin+'_overlay');
    var container = $('MasterOverlayContent');
    if( !container.hasChild(overlay) )
    {
        var ov = overlay.clone(true, true);
        overlay.destroy();
        container.grab(ov);
        overlay = $(curwin+'_window');
        ov = overlay.clone(true, true);
        overlay.destroy();
        container.grab(ov);
    
    }
    
    LB_overlaySize();
    $(curwin+'_overlay').tween('opacity', 0, 0.6);
    $(curwin+"_overlay").onclick = LB_remove;
    window.onscroll = LB_position;
    window.onresize = LB_position;
    $(curwin+"_closeWindowButton").onclick = LB_remove;
    
    LB_position();
}


function LB_remove(){
    //$(curwin+"_overlay").onclick = null;
    document.onkeyup = null;
    document.onkeydown = null;
    
    if ($(curwin+'_closeWindowButton')) 
        $(curwin+"_closeWindowButton").onclick = null;
    
    $(curwin+'_window').setStyles({
        "visibility": 'hidden',
        "display": 'none'
    });
    
    $(curwin+'_overlay').setStyles({
        "visibility": 'hidden',
        "display": 'none'
    });
    
    //$(curwin+'_overlay').set('tween', {
    //    duration: 400,
     //   onComplete: function(){
     //       
     //   }
    //});
    //$(curwin+'_overlay').tween('opacity', 0.6, 0);
    
    
    
    window.onscroll = null;
    window.onresize = null;
    
    
    if( reloadpage)
        window.location = window.location;
    
    return false;
}

function LB_position(){
    
    $(curwin+'_window').setStyles({
            "display": 'block'
        });
    
    
    LB_HEIGHT = parseInt($(curwin+'_window').getStyle("height"));
    LB_WIDTH = parseInt($(curwin+'_window').getStyle("width"))
    
    if( LB_WIDTH < 400 )
    {
        LB_WIDTH = 400;    
    }
    else if(LB_WIDTH > 725)
    {
        LB_WIDTH = 725;
    }
   
    //no one seems to get the size right.... just use this
    LB_WIDTH = 736;
    
    
    if( isIE6 )
    {
        $(curwin+'_window').setStyles({
            "height":window.getHeight()-50+'px', 
            "left": '0px',
            "visibility": 'visible',
            "display": 'block',
            "top": '25px',
            "width": LB_WIDTH+'px',
            "position": 'absolute'
        
        });
        
    }
    else
    {
        $(curwin+'_window').setStyles({
            "height":window.getHeight()-50+'px', 
            "left": (window.getScrollLeft() + (window.getWidth() - LB_WIDTH) / 2) + 'px',
            "visibility": 'visible',
            "display": 'block',
            "top": '25px',
            "width": LB_WIDTH+'px',
            "position": 'fixed'
        
        });
    }
    
}


function LB_overlaySize(){
    // we have to set this to 0px before so we can reduce the size / width of the overflow onresize 
    
    $(curwin+"_overlay").setStyles({
        "height": '0px',
        "width": '0px'
    });
    
    if( isIE6 )
    {
        $(curwin+"_overlay").setStyles({
            "height": window.getScrollHeight() + 'px',
            "width": window.getScrollWidth() + 'px',
            "position": 'absolute',
            "visibility": 'visible',
            "display": 'block',
            "top": '0',
            "left": '0',
            "background-color": '#c0c0c0'
        });
    }
    else
    {
        $(curwin+"_overlay").setStyles({
            "height": window.getScrollHeight() + 'px',
            "width": window.getScrollWidth() + 'px',
            "position": 'fixed',
            "visibility": 'visible',
            "display": 'block',
            "top": '0',
            "left": '0',
            "background-color": '#c0c0c0'
        });
    }
}
