
// gets screen width
function get_window_width(value) {
  
  if( typeof( window.innerWidth ) == 'number' ) {
	  return window.innerWidth;
	} else if( document.documentElement && document.documentElement.clientWidth ) {
	  return document.documentElement.clientWidth;
	} else if( document.body && document.body.clientWidth ) {
	  return document.body.clientWidth;
  }
  return value;

}

 
// gets screen height
function get_window_height(value) {
  
  if( typeof( window.innerHeight ) == 'number' ) {
	  return window.innerHeight;
	} else if( document.documentElement && document.documentElement.clientHeight ) {
	  return document.documentElement.clientHeight;
	} else if( document.body && document.body.clientHeight ) {
	  return document.body.clientHeight;
  }
  return value;

}

 function _get_screen_parameters() {
 	var ratio = 1.66;
  var securityMargin = 0;
  var lowResolution = "La seva pantalla no té prou resolució; és possible que alguns elements no es visualitzin correctament. Canvïi a una resolució 1024 x 768 o superior.";		
 	var availHeight, availWidth;
	
	availWidth = self.screen.availWidth;
	availHeight = self.screen.availHeight;
	
	//real maximized window size
	if (self.innerWidth) {
		availWidth = availWidth + self.innerWidth - self.outerWidth;
		availHeight = availHeight + self.innerHeight - self.outerHeight;
	}
	//as two last lines don't work in IE, we make an approach
  else {
	  availHeight = availHeight - 150;
  }
	
	if(availWidth < availHeight * ratio) { //width is the limitant
		if(availWidth < minWidth - securityMargin) {
			alert (lowResolution);
			width = minWidth - securityMargin;
		} else if (availWidth < maxWidth) {
			width = availWidth - securityMargin;
		} else {
			width = maxWidth;
		}
	}

	else { //height is the limitant
		if(availHeight < (minHeight - securityMargin/ratio)) {
			alert (lowResolution);
			width = minHeight*ratio - securityMargin/ratio;
		} else if (availHeight < maxHeight + (securityMargin/ratio)) {
			width = availHeight*ratio - (securityMargin/ratio);
		} else {
			width = maxHeight*ratio;
		}
	}
			
	var wh = new Array  
	wh[0]= width;
	wh[1]= width/ratio; //height
	return wh;

}

function _centerweb(mode, wWindow) {
	switch(mode) {
		case "full":
		  return 0;	  
		break;
		case "fixed_screen":
		  return parseInt((self.screen.availWidth - wWindow) / 2);
		break;
		case "fixed_height":
		  return parseInt((get_window_width() - wWindow) / 2);
	  break;
	  default:
	    return 0;
  }
}

function _calculate(mode, minWidth, maxWidth, minHeight, maxHeight) {
 	
switch(mode) {
	case "full":
	  wWindow = get_window_width();
	  hWindow = get_window_height();
	  //if (!correction) correction = 28;  
	  //hWindow += ( 2 * hGap - correction);
	  //wWindow += ( 3 * wGap - correction);	  
	break;
	case "fixed_screen":
	  var arraySizes = _get_screen_parameters();
	  wWindow = arraySizes[0];
	  hWindow = arraySizes[1];
	break;
	case "fixed_height":

	  lowResolution = "La seva pantalla no té prou resolució; és possible que alguns elements no es visualitzin correctament. Canvïi a una resolució 1024 x 768 o superior.";		
	  wWindow = get_window_width();
	  hWindow = get_window_height();
	  
	  //if (!correction) correction = 28;  
	  //hWindow += ( 2 * hGap - correction);
	  //wWindow += ( 3 * wGap - correction);
	  // calculate page metrics
	  if (wWindow > maxWidth) wWindow = maxWidth;
	  if (wWindow < minWidth) wWindow = minWidth;
    if (hWindow > maxHeight) hWindow = maxHeight;
    if (hWindow < minHeight) hWindow = minHeight;
   break;

default:
alert("mode '" + mode + "' no implementat a la interfície");
}
	var wh = new Array  
	wh[0]= wWindow;
	wh[1]= hWindow;
	return wh;
}