/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function getWindowSize(){
    var windowWidth, windowHeight;

    if (self.innerHeight) {	// all except Explorer
        if(document.documentElement.clientWidth){
            windowWidth = document.documentElement.clientWidth;
        } else {
            windowWidth = self.innerWidth;
        }
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }
     return [windowWidth, windowHeight];
}
function getPageSize() {

    var pageHeight, pageWidth;
    var xScroll=0, yScroll=0;

    if (window.innerHeight && window.scrollMaxY) {
        xScroll = window.innerWidth + window.scrollMaxX;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;

    if (self.innerHeight) {	// all except Explorer
        if(document.documentElement.clientWidth){
            windowWidth = document.documentElement.clientWidth;
        } else {
            windowWidth = self.innerWidth;
        }
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }

    return [pageWidth,pageHeight];
}

var inviewEditors = new Array();
inviewEditors[0] = "login";
inviewEditors[1] = "contacts";
inviewEditors[2] = "fiscals";
inviewEditors[3] = "activities";
inviewEditors[4] = "attachments";
inviewEditors[5] = "schedule";
inviewEditors[6] = "gallery";
inviewEditors[7] = "products";
inviewEditors[8] = "title";
inviewEditors[9] = "product";
inviewEditors[10] = "theme";
inviewEditors[11] = "meta";
inviewEditors[12] = "help";

function SetupInviewEditor(section){
    var arrayPageSize = getPageSize();
    var arrayWindowSize = getWindowSize();
    var panel=document.getElementById("editoverlay");
    panel.style.width = arrayPageSize[0] + 'px';
    panel.style.height = arrayPageSize[1] + 'px';

    
    for (i=0;i<inviewEditors.length;i++){//hide previously used editors
        try {
          document.getElementById("editor_"+inviewEditors[i]).style.display="none";
        } catch(err) {  }
    }
    try {
        var editor=document.getElementById("editor_"+section);
        //if(section=='login') alert(editor.style.display);
        editor.style.display="block";

        var box=document.getElementById("editbox");
        /*var eLEFT=(arrayWindowSize[0]-500)/2;
        eLEFT=~~eLEFT;
        //alert(eLEFT);
        //box.style.left=eLEFT;//(arrayWindowSize[0]-500)/2;
        //alert(box.style);*/
        box.style.top=(arrayWindowSize[1]-box.style.height)/2-200;
       // $('editbox').setStyle({ left: eLEFT})
       
        //box.style.setExpression("top", "document.body.scrollTop + 150 + 'px'");

        currentEditor=section;

        $('editoverlay').appear({ duration: 1.0, from: 0, to: 0.6 });
        $('editbox').appear({ duration: 1.0, from: 0, to: 1.0 });
    } catch(err) { }
}
function CloseInviewEditor(){
    CloseInviewEditor(false);
}
function CloseInviewEditor(dorefresh){
    $('editoverlay').fade({ duration: 1.0, from: 0.6, to: 0 });
    $('editbox').fade({ duration: 1.0, from: 1, to: 0 });
    if(dorefresh){
        location.reload(true);
    }
}
var currentEditor="";
//document.observe('body:loaded', SetupInContextEditor());