var bkDrpW = 1200,
	bkDrpH = 595;

function getSize(way) {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) { //Non-IE    
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode'    
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible    
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	switch (way) {
		case 'w':
			return myWidth;
			break;
		case 'h':
			return myHeight;
			break;
	}
}

function sizeBg() {
	if (document.compatMode && document.compatMode != "BackCompat") { theHeight = document.documentElement.clientHeight; theWidth = document.documentElement.clientWidth;}
		else { theHeight = document.body.clientHeight; theWidth = document.body.clientWidth;}
	var brsW = getSize('w'), brsH = getSize('h'),
		bkDrpImg = document.getElementById('bakimg'),
		proT = document.getElementById('photo_rotator'),
		proTi = document.getElementById('prImg').style, 
		jumbler = 0,
		perC=brsW / bkDrpW;
//		testbox = document.getElementById("testbox");
	if (perC<1) perC=1;
	if (perC >= 1) { 
		proT.style.width=664*perC+"px"; 
		proT.style.height=364*perC+"px"; 
		proT.style.left = 240 * perC+"px"; 
		jumbler = 258*perC; 
//		if (jumbler < 258 ) { jumbler = 258;  }
//		if ((proT.offsetHeight+proT.offsetTop) > theHeight) { jumbler = (theHeight-proT.offsetHeight)-50;  }
		proT.style.top = jumbler+"px";
//		testbox.innerHTML=theHeight+" | "+(proT.offsetHeight+proT.offsetTop);
		//if ((proT.offsetHeight+proT.offsetTop) > theHeight) { proT.style.top = 258*perC+"px"; } else { proT.style.bottom = "0px";  }
		proTi.height=proT.offsetHeight+"px";
	}
	bkDrpImg.width=perC*bkDrpW;
}

function sizeCont(){
    if(document.getElementById){
		if (document.compatMode && document.compatMode != "BackCompat") { theHeight = document.documentElement.clientHeight; theWidth = document.documentElement.clientWidth;}
		else { theHeight = document.body.clientHeight; theWidth = document.body.clientWidth;}
		var conttop = document.getElementById("contareaX"),
		mcont = document.getElementById("main_content"),
		ncont = document.getElementById("sidebar"); 
//		testbox = document.getElementById("testbox");
		if  (theWidth >= 1000) {
			conttop.style.overflow = "auto";
			conttop.style.height = theHeight - 258 + "px";
		} else {
			if (ncont.offsetHeight > mcont.offsetHeight) {
			  sizer=ncont.offsetHeight+10;
			} else {
			  sizer=mcont.offsetHeight+10;
			}
			if (theHeight > (sizer+258)) sizer=theHeight - 258;
			conttop.style.height = sizer+"px"; 
			conttop.style.overflow = "visible";
		}
//		setTimeout("sizeCont()",10);
    }
}

function sizeContHm(){
    if(document.getElementById){
		if (document.compatMode && document.compatMode != "BackCompat") { theHeight = document.documentElement.clientHeight; theWidth = document.documentElement.clientWidth;}
		else { theHeight = document.body.clientWidth; theWidth = document.body.clientWidth;}
		var proT2 = document.getElementById('photo_rotator').style,
		conttop = document.getElementById("contareaX"),
		ncont = document.getElementById("sidebar");
//		testbox = document.getElementById("testbox");

			if ((ncont.offsetHeight+258) > (parseInt(proT2.height)+parseInt(proT2.top))) {
			  sizer=ncont.offsetHeight+10;
			} else {
			  sizer=(parseInt(proT2.height)+parseInt(proT2.top))-258+20;
			} 
			if ((theHeight-258) > sizer) sizer=theHeight-258;
//			testbox.innerHTML=ncont.offsetHeight+"< jncont .offsetHeight<br />"+parseInt(proT2.height)+"< jproT2 .height<br />"+parseInt(proT2.top)+"< jproT2 .top<br />"+(parseInt(proT2.height)+parseInt(proT2.top))+"< total<br />"+sizer+"< jsizer<br />"+theHeight+"< jtheHeight";
			conttop.style.height = sizer+"px"; 
			conttop.style.overflow = "visible";
    }
}

function FadeIn(id, lvl)
{
  if (!lvl) lvl1=0;
  var element=document.getElementById(id);
  if (element.timer) window.clearTimeout(element.timer); 
  var startMS = (new Date()).getTime();
  element.timer = window.setTimeout("ChangeOpacity('" + id + "',1000," + startMS + ",lvl1,100)",1);
}

function FadeOut(id, lvl)
{
  if (!lvl) lvl2=100;
  var element=document.getElementById(id);
  if (element.timer) window.clearTimeout(element.timer); 
  var startMS = (new Date()).getTime();
  element.timer = window.setTimeout("ChangeOpacity('" + id + "',1000," + startMS + ",lvl2,0)",1);
}

function ChangeOpacity(id,msDuration,msStart,fromO,toO)
{
  var element=document.getElementById(id);
  var opacity = element.style.opacity * 100;
  var msNow = (new Date()).getTime();  
  opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
  if (opacity<0) {
    SetOpacity(element,0);
  } else if (opacity>100) {
    SetOpacity(element,100); 
  } else {
       SetOpacity(element,opacity);
	element.timer = window.setTimeout("ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")",1);
  }  
}

function SetOpacity(object,opacityPct)
{

  object.style.filter = 'alpha(opacity=' + opacityPct + ')';   // IE.
  object.style.MozOpacity = opacityPct/100;   // Old mozilla and firefox
  object.style.opacity = opacityPct/100;  // Everything else.
}
