function opacity(id, opacStart, opacEnd, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	if(opacStart >= opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
		document.getElementById(id).style.display = 'none';	
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
	if (opacity == 0) {
		document.getElementById(id).style.display = 'none';	
	}
}

function opacityOff1(id, opacStart, opacEnd, millisec) {
	opacityOff('overlay', 500);
}



var timer = 0;
var fadeIn = true;
var fadeOut = false;
var opac = 0;
var speed = 0;
var timer1;
var timer2;
var i = 0;
// fade - step of fade 1..50
var fade = 5;


function opacityOff(id, millisec) {
	clearInterval(timer1);
	i = document.getElementById(id).style.opacity;
	var m = Number(i)*100;
	if (Number(document.getElementById(id).style.opacity) < 0) {
		changeOpac(0, id);
	}
	function down() {
		if (Number(document.getElementById(id).style.opacity) > 0) {			
			changeOpac(m, id);
			m = m - fade;
		} else {
			clearInterval(timer2);
			document.getElementById(id).style.display = 'none';
			changeOpac(0, id);
		}			
	}	
	timer2=setInterval(down, 10);
}

function opacityOn(id, millisec) {
	clearInterval(timer2);	
	document.getElementById(id).style.display = 'block';
	i = document.getElementById(id).style.opacity;
	var k = Number(i);
		function up() {
			if (Number(document.getElementById(id).style.opacity) < 1) {
				changeOpac(k, id);
					k += fade;
			} else {
				clearInterval(timer1);
				changeOpac(100, id);
			}			
		}	
	timer1=setInterval(up, 10);
}


//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.curropacity = opacity;
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
	if (opacity < 0) {
		document.getElementById(id).style.display = 'none';		
		//alert('off');
	}
		if (opacity >= 100) {
		document.getElementById(id).style.display = 'block';
		//alert('on');
	}
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}



function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	//make image transparent
	changeOpac(0, imageid);
	//make new image
	document.getElementById(imageid).src = imagefile;
	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}



function currentOpac(id, opacEnd, millisec) {
	var currentOpac = 100;
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}
	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}



function selectCode(tid) 
{
	tid.focus();
	tid.select();
};
function show(name, sfs) 
{
	hideObjects();
	document.getElementById('overlay').style.display = 'block';
	document.getElementById('niWg').style.display = 'block';
	document.getElementById('code').focus();
	document.getElementById('code').select();
	scroll(0,0);
	

	
}

function hideObjects()
{
	var hideEmbedCssText1 = ' select {display: none;}';
     insertStyle(hideEmbedCssText1); 
	opacity('overlay', 0, 50, 500);
	opacity('niWg', 0, 100, 500);
	scroll(0,0);
	
function xClientHeight()
{
  var v=0,d=document,w=window;
  if((!d.compatMode || d.compatMode == 'CSS1Compat') && !w.opera && d.documentElement && d.documentElement.clientHeight)
    {v=d.documentElement.clientHeight;}
  else if(d.body && d.body.clientHeight)
    {v=d.body.clientHeight;}
  else if(xDef(w.innerWidth,w.innerHeight,d.width)) {
    v=w.innerHeight;
    if(d.width>w.innerWidth) v-=16;
  }
  return v;
}

function xClientWidth()
{
  var v=0,d=document,w=window;
  if((!d.compatMode || d.compatMode == 'CSS1Compat') && !w.opera && d.documentElement && d.documentElement.clientWidth)
    {v=d.documentElement.clientWidth;}
  else if(d.body && d.body.clientWidth)
    {v=d.body.clientWidth;}
  else if(xDef(w.innerWidth,w.innerHeight,d.height)) {
    v=w.innerWidth;
    if(d.height>w.innerHeight) v-=16;
  }
  return v;
}

		
		
		var client_width = xClientWidth();
		var client_height = xClientHeight();
		var top = client_height/2 - 290;
		document.getElementById('overlay').style.width = client_width + 'px';
		document.getElementById('overlay').style.height = client_height + 'px';	
		document.getElementById('niWg').style.top = top + 'px';
//		alert(document.getElementById('overlay').style.height);	
	window.onresize = function() {
		var client_width = xClientWidth();
		var client_height = xClientHeight();	
		var top = client_height/2 - 290;

		document.getElementById('overlay').style.width = client_width + 'px';
		document.getElementById('overlay').style.height = client_height + 'px';
		document.getElementById('niWg').style.top = top + 'px';
	}
}



function showObjects()
{

//	opacityOff('overlay', 50, 0, 1000);
	opacityOff1();
	document.getElementById('niWg').style.display = 'none';	
	
	clearStyle(hStyle);
	var hideEmbedCssText = 'select { }';
	insertStyle( hideEmbedCssText);		
}
function insertStyle ( styleText) 
{ 
	var style = document.createElement('style')
	style.type = 'text/css';
	try 
	{
 		style.appendChild( document.createTextNode( styleText ) );
 	}
 	catch(e) 
 	{ 
 		style.styleSheet.cssText = styleText;
 	}
	 var head = document.getElementsByTagName('head')[0];
	 if (!head) 
	 {
	     head = document.createElement('head');
	     document.body.parentNode.insertBefore(head, document.body);
  	 }
    hStyle = style;
    head.appendChild(style);
}
function clearStyle(style) 
{
    if (style.parentNode) style.parentNode.removeChild(style);
}




