
var RedBox = {

    showInline: function(id){
    
        this.showOverlay();
        new Effect.Appear('RB_window', {
            duration: 0.4,
            queue: 'end'
        });
        //Element.scrollTo('RB_window');
        this.cloneWindowContents(id);
    },
    
    loading: function(){
        this.showOverlay();
        Element.show('RB_loading');
        this.setWindowPosition();
    },
    
    hide_loading: function(){
        Element.hide('RB_loading');
        new Effect.Fade('RB_overlay', {
            duration: 0.4
        });
    },
    
    addHiddenContent: function(id){
        this.removeChildrenFromNode($('RB_window'));
        this.moveChildren($(id), $('RB_window'));
        Element.hide('RB_loading');
        new Effect.Appear('RB_window', {
            duration: 0.4,
            queue: 'end'
        });
        // Element.scrollTo('RB_window');
        this.setWindowPosition();
    },
    
    addHiddenContentPreview: function(id){
        this.showOverlay();
        this.removeChildrenFromNode($('RB_window'));
        this.moveChildrenForPreview(id, $('RB_window'));
        Element.hide('RB_loading');
        new Effect.Appear('RB_window', {
            duration: 0.4,
            queue: 'end'
        });
        //Element.scrollTo('RB_window');
        this.setWindowPosition();
    },
    
	addHiddenContentPreviewReq: function(source){
		this.showOverlay();
        this.removeChildrenFromNode($('RB_window'));
        this.moveChildrenForPreviewReq(source, $('RB_window'));
        Element.hide('RB_loading');
        new Effect.Appear('RB_window', {
            duration: 0.4,
            queue: 'end'
        });
        this.setWindowPosition();
    },
	
    close: function(){
        new Effect.Fade('RB_window', {
            duration: 0.4
        });
        new Effect.Fade('RB_overlay', {
            duration: 0.4
        });
    },
    
    showOverlay: function(){
        if ($('RB_redbox')) {
            Element.update('RB_redbox', "");
            new Insertion.Top($('RB_redbox'), '<div id="RB_window" style="display: none;"></div><div id="RB_overlay" style="display: none;"></div>');
        }
        else {
            new Insertion.Bottom(document.body, '<div id="RB_redbox" align="center"><div id="RB_window" style="display: none;"></div><div id="RB_overlay" style="display: none;"></div></div>');
        }
        new Insertion.Top('RB_overlay', '<div id="RB_loading" style="display: none"></div>');
        
        this.setOverlaySize();
        new Effect.Appear('RB_overlay', {
            duration: 0.4,
            to: 0.6,
            queue: 'end'
        });
    },
    
    setOverlaySize: function(){
        if (window.innerHeight && window.scrollMaxY) {
            yScroll = window.innerHeight + window.scrollMaxY;
        }
        else 
            if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
                yScroll = document.body.scrollHeight;
            }
            else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
                yScroll = document.body.offsetHeight;
            }
        $("RB_overlay").style['height'] = yScroll + "px";
    },
    
    setWindowPosition: function(){
        var pagesize = this.getPageSize();
        $("RB_window").style['width'] = 'auto';
        $("RB_window").style['height'] = 'auto';
        
        var dimensions = Element.getDimensions($("RB_window"));
        var width = dimensions.width;
        var height = dimensions.height;
//		alert("$('for_redbox')-->"+$('for_redbox'));
//		alert("view--->"+view)
//        if ($('for_redbox') && view != '') {
//            if (getInternetExplorerVersion() > 1.0 && getInternetExplorerVersion() <= 7.0) {
//                $("RB_window").style['left'] = ((pagesize[0] - width) / 8) + "px";
//            }
//            else {
//                $("RB_window").style['left'] = ((pagesize[0] - width) / 2) + "px";
//            }
//        }
//        else {
            if (getInternetExplorerVersion() > 1.0 && getInternetExplorerVersion() <= 7.0 && $('for_redbox')&& view != '') {
                $("RB_window").style['left'] = ((pagesize[0] - width) / 8) + "px";
            }
            else {
                $("RB_window").style['left'] = ((pagesize[0] - width) / 2) + "px";
            }
//        }
        if (((pagesize[1] - height) / 2) < 0) {
            $("RB_window").style['top'] = "20px";
            original_top = "20px";
        }
        else {
            //          $("RB_window").style['top'] = ((pagesize[1] - height) / 2) + "px";
            original_top = ((pagesize[1] - height) / 2) + "px";//changed to get original top position of pop-up to set after each scroll---Pooja
            //changed for IE6 issue
                var scrOfY = getScrollXY();////to open pop-up always on center even after page scrolls to last--pooja
                if (scrOfY) 
                    $("RB_window").style['top'] = parseInt(original_top) + scrOfY + "px";
                else 
                    $("RB_window").style['top'] = original_top;
                
            
        }
        
    },
    
    
    getPageSize: function(){//alert("8");
        var de = document.documentElement;
        var w = window.innerWidth || self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
        var h = window.innerHeight || self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;
        arrayPageSize = new Array(w, h)
        return arrayPageSize;
    },
    
    removeChildrenFromNode: function(node){
        while (node.hasChildNodes()) {
            node.removeChild(node.firstChild);
        }
    },
    
    moveChildren: function(source, destination){
        while (source.hasChildNodes()) {
            destination.appendChild(source.firstChild);
        }
    },
    
    moveChildrenForPreview: function(source, destination){
        destination.innerHTML = source.innerHTML;
    },
    
	moveChildrenForPreviewReq: function(source, destination){
        destination.innerHTML = source;
    },
    
    cloneWindowContents: function(id){
        var content = $(id).cloneNode(true);
        content.style['display'] = 'block';
        $('RB_window').appendChild(content);
        
        this.setWindowPosition();
    }
    
}
