var overlay;
function overlayinit(func){

		document.write('<div id=overlay style="position: absolute; left: 0px; top: 0px; height: 400px; width: 400px;float:left;filter:alpha(opacity=0);moz-opacity:0;opacity:0;display:none"></div>');    
		
		overlay = document.getElementById('overlay');
		overlay.style.backgroundColor = "#999999"; 
		
		var arrayPageSize = getpgSize();
		
		overlay.style.width = arrayPageSize[0]+'px';
		overlay.style.height = arrayPageSize[1]+'px';
		
		var obj=document.getElementById('overlay');
		obj.style.backgroundColor = "#000000"; 
		obj.style.width= arrayPageSize[0]+'px';
		obj.style.height= arrayPageSize[1]+2000+'px';
		
		overlay.onclick = function() {
		   var obj=document.getElementById('overlay');
		   
		   if(obj.style.Opacityvalue>0 || obj.style.opacity>0){
		   	if(func){
		   		  var f=eval(func);
		   	    f();
		   	    try{
		   	      callpicture(0);
		   	    }catch(err) {
						}
		   	}else{
			      callpicture(0); 
			  }
			  
			  
		   }
		}


}



function bgstart(){
	  hideSelectBoxes();
    //new Effect.Appear('overlay', { duration: 0.2, from: 0.0, to: 0.8 });
    /*
    var obj=document.getElementById('overlay');
    obj.style.filter="Alpha(Opacity=70)"; 
    obj.style.opacity =0.7;
    if(overlay.style){
		    overlay.style.filter="Alpha(Opacity=70)"; 
		    overlay.style.opacity =0.7;
		}
    */
    var obj=document.getElementById('overlay');
	
    //obj.style.display='block'; 
	
    change_opacity('overlay',0.0,0.6);
	
    //obj.onclick = function() { callpicture(0); }

}


function bgend(){
	  
		//new Effect.Fade('overlay', { duration: 0.2});
		showSelectBoxes();
		change_opacity('overlay',0.6,0.0);
		/*
    var obj=document.getElementById('overlay');
    obj.style.filter="Alpha(Opacity=10)"; 
    obj.style.opacity =0.1;
    if(overlay.style){
		    overlay.style.filter="Alpha(Opacity=10)"; 
		    overlay.style.opacity =0.1;
		}*/
}


var timeopacity;

function change_opacity(item,v1,v2){
	  
    var obj=document.getElementById(item);
	  //if(v2>v1)v1=eval(v1+0.1);
	  //else v1=eval(v1-0.1);
	 
	  if(v2>v1)v1=Math.round(v1*10)/10.0+Math.round(0.2*10)/10.0;
	  else v1=Math.round(v1*10)/10.0-Math.round(0.2*10)/10.0;
	  v1=Math.round(v1*10)/10.0;
	  
	  
	  
	  if(typeof(timeopacity)!="undefined"){
	  	   clearInterval(timeopacity);
	  }    
    
    if (eval(document.getElementById(item)))	
		if(overlay.style.filter){ // for IE
			 obj.style.filter="Alpha(Opacity="+v1*100+")";
		    if(v1>0)obj.style.display='block';
		    else obj.style.display='none';		
		}else{ // for Firefox
			 overlay.style.opacity =v1;
		    overlay.style.Opacityvalue =v1;
		    if(v1>0)overlay.style.display='block';
		    else overlay.style.display='none';		
		}
    // if(overlay.style){
		    // overlay.style.opacity =v1;
		    // overlay.style.Opacityvalue =v1;
		    // if(v1>0)overlay.style.display='block';
		    // else overlay.style.display='none';
		// }else{
		    // obj.style.filter="Alpha(Opacity="+v1*100+")";
		    // if(v1>0)obj.style.display='block';
		    // else obj.style.display='none';
		// }
		
		//alert('v1='+v1+' v2='+v2);
	  if(v1==v2){
	  	   if(typeof(timeopacity)!="undefined")clearInterval(timeopacity);
	  	   
	  	   obj.style.Opacityvalue=v1;
	  	   
	  	   //alert('now value='+obj.style.Opacityvalue);	
	  	   return;
	  }
		
		timeopacity=setInterval("change_opacity('"+item+"',"+v1+","+v2+")",80);
		
}



function getpgSize(){
	
	var xScroll, yScroll;
	
	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;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	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;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}









