// FBI 2007

var Position = {
        cumulativeOffset: function(element) {
            var valueT = 0, valueL = 0;
            do {
                valueT += element.offsetTop  || 0;
                valueL += element.offsetLeft || 0;
                element = element.offsetParent;
            } while (element);
        return [valueL, valueT];
    }
};

var objSize = {
   getPageSize: function() {
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {  
      xScroll = document.body.scrollWidth;
      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
      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;
    }  
    var pageHeight, pageWidth;

    // 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: pageWidth ,pageHeight: pageHeight , windowWidth: windowWidth, windowHeight: windowHeight};
  },
  
  rPx: function(value) {
		return value.substring(0, value.length-2);
  },
  
  resetObjPos: function(posID, resID, left, top, vis) {
   //    pos[0] = left;          pos[1] = top;
   var pos = Position.cumulativeOffset($(posID));
   $(resID).style.left = (pos[0] + left)+'px';
   $(resID).style.top  = (pos[1] + top)+'px';
   $(resID).style.visibility = vis;
  },
  
  hover: function(id, path) {
   var p = "url("+path+")";
   $(id).setStyle({backgroundImage:p });
  }
};

var clsPageResize = Class.create();
clsPageResize.prototype = {
    initialize: function() {
		this.mTdRob  = 220;
		this.mTab    = 25;
		
		this.objPS   = 0; // objSize.getPageSize();
		this.pHeight = 0; // objPS.windowHeight;
		this.pWidth  = 0; // objPS.widnowWidth;
	},
	
	resize: function() {
		var napol = 0;
		if(cPRead.FName == 'Katalog')
		   napol = 300;
		else
		   napol = 250;
        
	    this.objPS = objSize.getPageSize();
		this.pHeight = this.objPS.windowHeight;
		this.pWidth  = this.objPS.windowWidth;
		
		Element.setStyle('content', {height: (this.pHeight)+'px'} );
		Element.setStyle('content', {width: (this.pWidth)+'px'} );
		Element.setStyle('header', {width: (this.pWidth)+'px'} );
		Element.setStyle('subheader', {width: (this.pWidth)+'px'} );
		
		Element.setStyle('main', {height: (this.pHeight-157)+'px'} );
		Element.setStyle('main', {width : (this.pWidth)+'px'} );
		
		Element.setStyle('left_side', {width : (this.pWidth - (napol+25))+'px'} );
		Element.setStyle('left_side', {height: (this.pHeight-157)+'px'} );
		
		Element.setStyle('right_side', {width : (napol)+'px'} );
		Element.setStyle('right_side', {height: (this.pHeight-157)+'px'} );
		
		if(cPRead.FName == 'Nastavitve') {
		   var lSideW = objSize.rPx($('left_side').style.width);
		   var lSideH = objSize.rPx($('left_side').style.height);
		   
		   $('nastavitve').style.width  = (lSideW-12)+'px';
		   $('nastavitve').style.height = (lSideH-130)+'px';
		   
		   objSize.resetObjPos('myMenu', 'nastavitve', 1, 57, 'visible');
		   objSize.resetObjPos('myMenu', 'robS', 50, 42, 'visible');
		   
		   $('robS').style.height = '15px';
		   $('robS').style.width  = (lSideW-61)+'px';
		   
		   smf.shwUsrCom('visible');
		   if(cPRead.s_chmod == 'CA') {
		       $('adm').style.visibility = 'visible';
			   objSize.resetObjPos('myMenu', 'adm', 25, -150, 'visible');
			   $('adm').onclick = new Function("smf.shwAdmCom('visible'); cPRead.ajxGetFile('../adm_Index', '', 'nastavitve', 'Administratorske moznosti');");
		   }
		}
		else if(cPRead.FName == "Doma") {
			//alert("doma!");
			Element.setStyle('novosti', {height:(this.pHeight-242)+'px'});
			cPRead.ajxGetSqlNovosti(0, 2);
			
			cPRead.muvNov = 0;
			cPRead.posNov = 1;
			smf.showNNav();
		}
		else if(cPRead.FName == "Pregled loga") {
 		   log_start.show_users();
		}
		else if(cPRead.FName == 'Aktivacija uporabnika') {
		   cPRead.ajxGetUsersActivation();
		}
	}
}
