
///////////////////////////////////////////////////////////////////////
//     This fade library was designed by Erik Arvidsson for WebFX    //
//                                                                   //
//     For more info and examples see: http://webfx.eae.net          //
//     or contact Erik at http://webfx.eae.net/contact.html#erik     //
//                                                                   //
//     Feel free to use this code as lomg as this disclaimer is      //
//     intact.                                                       //
///////////////////////////////////////////////////////////////////////


var __fadeArray = new Array();    // Needed to keep track of wich elements are animating

//////////////////  fade  ////////////////////////////////////////////////////////////
//                                                                                  //
//   parameter: fadeIn                                                              //
// description: A boolean value. If true the element fades in, otherwise fades out  //
//              The steps and msec are optional. If not provided the default        //
//              values are used. Opacity is optional and specifies the start/end    //
//              opacity values. onfinish is used when the fadein/out has finished   // 
//              and is called (so pass in a function name)                          //
//////////////////////////////////////////////////////////////////////////////////////

function Fade(el, fadeIn, steps, msec, opacity, onfinish)
{
    if (steps    == null)  steps   = 4;
    if (msec     == null)  msec    = 25;
    if (opacity  == null)  opacity = 100;
    if (onfinish == null)  onfinish = '';

    if (el.fadeIndex == null) {
        el.fadeIndex = __fadeArray.length;
    }

    __fadeArray[el.fadeIndex] = el;

    if (el.style.visibility == "hidden") {
        el.style.display  = 'block';
        el.fadeStepNumber = 0;
    } else {
        el.fadeStepNumber = steps;
    }

    if (fadeIn) {
        el.style.filter = "Alpha(Opacity=0)";
        el.style.MozOpacity = '0';
    } else {
        el.style.filter = "Alpha(Opacity=" + opacity + ")";
        el.style.MozOpacity = opacity / 100;
    }

    window.setTimeout("RepeatFade(" + fadeIn + "," + el.fadeIndex + "," + steps + "," + msec + ", " + opacity + ", '" + onfinish + "')", msec);
}

//////////////////////////////////////////////////////////////////////////////////////
//  Used to iterate the fading                                                      //
//////////////////////////////////////////////////////////////////////////////////////
function RepeatFade(fadeIn, index, steps, msec, opacity, onfinish)
{
    el = __fadeArray[index];

    c = el.fadeStepNumber;
    if (el.fadeTimer != null) {
        window.clearTimeout(el.fadeTimer);
    }

    if (c == 0 && !fadeIn) {            // Done fading out!
        el.style.visibility = "hidden"; // If the platform doesn't support filter it will hide anyway
        el.style.display    = "none"; // If the platform doesn't support filter it will hide anyway

        if (onfinish) {
            eval(onfinish + "()");
        }
        return;

    } else if (c == steps && fadeIn) {    // Done fading in!
        el.style.filter = "Alpha(Opacity=" + opacity + ")";
        el.style.MozOpacity = opacity / 100;
        el.style.visibility = "visible";

        if (onfinish) {
            eval(onfinish + "()");
        }
        return;

    } else {
        fadeIn ? c++ : c--;
        el.style.visibility = "visible";
        el.style.filter = "Alpha(Opacity=" + opacity*c/steps + ")";
        el.style.MozOpacity = (opacity / 100) * c/steps;

        el.fadeStepNumber = c;
        el.fadeTimer = window.setTimeout("RepeatFade(" + fadeIn + "," + index + "," + steps + "," + msec + ", " + opacity + ", '" + onfinish + "' )", msec);
    }
}
/**
    * o------------------------------------------------------------------------------o
    * | This package is licensed under the Phpguru license 2008. A quick summary is  |
    * | that the code is free to use for non-commercial purposes. For commercial     |
    * | purposes of any kind there is a small license fee to pay. You can read more  |
    * | at:                                                                          |
    * |                  http://www.phpguru.org/static/license.html                  |
    * o------------------------------------------------------------------------------o
    *
    * © Copyright 2008 Richard Heyes
    */
    
    /**
    * Create the ModalDialog object
    */
    ModalDialog = {};

    /**
    * Shows a modal dialog
    * 
    * @param string contentID ID of content layer to use HTML of
    * @param int    width     Width of dialog
    */
    function ModalDialog_Show(contentID, width, offset)
    {
			var _offset=offset || 100;
        /**
        * Hide all selects so they don't show through the ModalDialog layer
        */
        if (document.all) {
            var selectObjs = document.getElementsByTagName('select');
    
            for (var i=0; i<selectObjs.length; ++i) {
                if (!selectObjs[i].md_nohide) {
                    selectObjs[i].md_vis = selectObjs[i].style.visibility;
                    selectObjs[i].style.visibility = 'hidden';
                }
            }
        }
        
        /**
        * Create the background layer if necessary
        */
        var dialogBg = document.getElementById('modalBg');
        
        if (!dialogBg) {
            var bgDiv = document.createElement('div');
            bgDiv.id = 'modalBg';
            bgDiv.className = 'modalBg';
            bgDiv.style.opacity =1;
        
            document.body.appendChild(bgDiv);
            
            var dialogBg = document.getElementById('modalBg');
            ModalDialog.background = dialogBg;
        }
        
        
        /**
        * Create the shadow layer
        */
        if(1==0){
          var dialogShadow = document.getElementById('modalShadow');
          
          if (!dialogShadow) {
              var shadowDiv = document.createElement('div');
              shadowDiv.id = 'modalShadow';
              shadowDiv.className = 'modalShadow';
              
              document.body.appendChild(shadowDiv);
              
              var dialogShadow = document.getElementById('modalShadow');
          }
        }
        // Show the dialog
        var dialog = document.getElementById(contentID);
        dialog.style.visibility = 'hidden';
        dialog.style.width = width + 'px';
        
//        dialogShadow.style.visibility = 'visible';
//        dialogShadow.style.width = dialog.offsetWidth + 'px';
//        dialogShadow.style.height = dialog.offsetHeight + 'px';
    
        /**
        * Insert the header into the dialog
        */
        var dialogHeader = document.createElement('div');
        dialogHeader.id = 'dialogHeader';
        dialogHeader.className = 'modalDialogHeader';
        dialog.appendChild(dialogHeader);
        dialogHeader = document.getElementById('dialogHeader');
    
        Fade(dialogBg, false, null, null, 70);
        Fade(dialog, true, null, null, 100);
//        Fade(dialogShadow, true, null, null, 50, 'ModalDialog_FinishFade');
        
        
        // Moz stuff
        if (!document.all) {
            dialogBg.style.width  = document.body.scrollWidth + 'px';
            dialogBg.style.height = document.body.scrollHeight + 'px';

            dialog.style.left = document.body.offsetWidth / 2 - width / 2 + 'px';
            
            dialogHeader.style.width = (dialog.offsetWidth - 2) + 'px';
            dialogHeader.style.paddingTop = '5px';

//            dialogShadow.style.left = (document.body.offsetWidth / 2 - width / 2) + 4 + 'px';
        
        // IE stuff
        } else {
            dialogHeader.style.width = dialog.offsetWidth + 'px';
            dialogBg.style.width = document.body.scrollWidth + 5;
        }
        // this is run for all browsers
        var _top = parseInt($j(document).scrollTop()) + _offset;
        dialog.style.top = _top+'px';
//        dialogShadow.style.top  = parseInt(dialog.style.top) + 4;
        
        /**
        * When the window is resized, reposition the dialog
        */
//        window.onresize = ModalDialog.Reposition;
//        window.onscroll = ModalDialog.Reposition;
        
        // Set visible dialog var
        ModalDialog.dialog = dialog;
//        ModalDialog.shadow = dialogShadow;
    }
    
    
    /**
    * Closes a modal dialog
    */
    function ModalDialog_Close()
    {
        var dialogBg     = ModalDialog.background;
        var dialog       = ModalDialog.dialog;
//        var dialogShadow = ModalDialog.shadow;
    
        
        // Lose the dialog header
        dialog.removeChild(document.getElementById('dialogHeader'));
    
        // Hide stuff
        dialogBg.style.MozOpacity = 0;
        dialogBg.style.visibility = 'hidden';
        
        dialog.style.MozOpacity = 0;
        dialog.style.visibility = 'hidden';
//        dialogShadow.style.visibility = 'hidden';
        
        
        __visibleDialog = null;
        
        /**
        * Unhide all selects
        */
        var selectObjs = document.getElementsByTagName('select');
        
        for (var i=0; i<selectObjs.length; ++i) {
            if (!selectObjs[i].md_nohide) {
                selectObjs[i].style.visibility = selectObjs[i].md_vis;
            }
        }
    }
    
    function ModalDialog_FinishFade()
    {
        if(1==0){
          var shadow  = ModalDialog.shadow;
          var visible = ModalDialog.dialog;
      
          shadow.style.width = visible.offsetWidth;
          shadow.style.height = visible.offsetHeight;
          shadow.style.filter = 'Alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius=2)';
        }
    }

    /**
    * Repositions the dialod after a resize or scroll event
    */
    ModalDialog.Reposition = function ()
    {
        var dialog = ModalDialog.dialog;
//        var shadow = ModalDialog.shadow;

//        var _top = parseInt($j(document).scrollTop()) + parseInt($j(window).height() / 2) - parseInt(dialog.offsetHeight);
        // Reposition in the vertical center
//        dialog.style.top  = _top;
//        shadow.style.top = parseInt(dialog.style.top) + 4;

        // Reposition in the horizontal centre
        dialog.style.left  = document.body.scrollLeft + (document.body.clientWidth / 2) - (dialog.offsetLeft / 2);
        //shadow.style.left = parseInt(dialog.style.left) + 4;
    }
    
    /**
    * Assign the objects functions
    */
    ModalDialog.Show = ModalDialog_Show;
    ModalDialog.Close = ModalDialog_Close;

