window.onresize = resizeCheck;
window.onload = init;
function getRemoteCust() {
	var argv = getRemoteCust.arguments;
	var pageName = argv[0];
	var theXML = argv[2];
	httpRequest = getXmlHttpRequestObject();
	httpRequest.open('Post',pageName , false);
	httpRequest.send(theXML);
	return httpRequest.responseText;
}
          
function getxml(value) {
	return '<Arg type="String">' + value + '</Arg>';
}

function getPage(value) {
	alert(value);
}

function MyXml() {
	this.xml=xml
}

function xml(functionName,xml){
	return '<Xml><FunctionName>'+functionName+'</FunctionName>'+ xml + '</Xml>';
}
          
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest(); //Not IE
	} 
	else if(window.ActiveXObject) {
		 return new ActiveXObject("Microsoft.XMLHTTP"); //IE
   } 
}    
          
          
// various variables needed for the filebrowser to work
var ie5 = document.all && document.getElementById;
var ns6 = document.getElementById && !document.all;
if (ie5 || ns6) {
	document.onclick = unPopContext;
}
var browser=navigator.userAgent.toLowerCase();
var browserVersion=navigator.appVersion;
var ie6=(browser.indexOf('msie')!=-1 && browser.indexOf('msie 7')==-1);
var ie5real=(browser.indexOf('msie 5')!=-1);

var contextType=0;
var activeFile;
var addImageForNews;
var uploadActive=false;
var docHeight;
var galleryLoaded=false;

var viewportwidth;
var viewportheight;
 
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
 if (typeof window.innerWidth != 'undefined') {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
 }
 
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
 }
 
 // older versions of IE
 
 else
 {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
 }

function init () {
	resizeCheck();
	if (document.getElementById('cmeLibraryBrowser')) {
		pngCheck(document.getElementById('cmeLibraryBrowser'));
		if (ie6 || ie5) {
			document.getElementById('cmeLibraryBrowser').style.width='550px';
		}
		if (browser.indexOf('msie 7')==-1) {
			document.getElementById('interfaceContainer').style.width='100%';
		}
	}
	activateContextMenus();
}


function showContext() {
	return popContext(tempX,tempY);
}

function resizeCheck() {
	checkHeight();
	checkGalleryPos();
	//if the user is in the middle of renaming a file, then the new file name must be submitted upon resize
	if (document.getElementById('renameField')) {
		if (document.getElementById('renameField').style.display=='block') {
			renameSubmit();
		}
	}
}

function checkHeight() {
	if (!window.innerHeight) {
		docHeight=viewportheight;
		if (document.getElementById('cmeLibraryBrowser')) {
			var cme=document.getElementById('cme');
			var interfaceContainer=document.getElementById('interfaceContainer');
			var cmeLibraryBrowserFileList=document.getElementById('cmeLibraryBrowserFileList');
			cme.style.height=document.body.offsetHeight;
			cme.style.width=document.body.offsetWidth;
			interfaceContainer.style.width='';
			if (document.body.offsetWidth-cmeLibraryBrowserFileList.offsetWidth<=100) {
				//alert(cmeLibraryBrowserFileList.offsetWidth);
				interfaceContainer.style.width='100%';
			}
		}
	} else {
		docHeight=viewportheight;
	}
}

function popContext(x,y) {
	var contextMenu=document.getElementById('contextMenu');
	contextMenu.style.display='inline';
	contextMenu.style.left=x+'px';
	contextMenu.style.top=y+'px';
	switch (contextType) {
		case 0:
			//pops the contextmenu for right clicks outside a folder or a file
			//this context menu will include the following options:
			//1. Upload file
			//2. Create a new folder
			//3. (if Cut/Copy has been selected on a file/folder) Paste
			contextMenu.innerHTML=document.getElementById('OnboardcontextMenu').innerHTML;
//			contextMenu.innerHTML='<ul><li><a href="javascript:showUploadForm();">Upload file</a></li><li><a href="javascript:CreateFolder();">Create folder</a></li><li><a href="javascript:PasteFolder()">Paste</a></li></ul>';
			return false;
		case 1:
			//pops the contextmenu for right clicks on folders or files
			//this context menu will include the following options
			//1.Cut
			//2.Rename
			//3.Delete
//				if (addImageForNews) {
//			
//				contextMenu.innerHTML+='<li><a href="javascript:sendPicturePath(activeFile.childNodes[2].value);">'+translateUseImageForNews+'</a></li>';
//		
//			}
//			contextMenu.innerHTML='<ul><li><a href="javascript:cutFolder()">Cut</a></li><li><a href="javascript:renameFile();">Rename</a></li><li><a href="javascript:DeleteFolder()">Delete</a></li></ul>';
			contextMenu.innerHTML=document.getElementById('OnFilescontextMenu').innerHTML;
			return false;
	}
	document.getElementById('uploadField').style.display='none';
}
function unPopContext() {
	if (document.getElementById('contextMenu')) {
		document.getElementById('contextMenu').style.display='none';
		if (!uploadActive) {
			document.getElementById('uploadField').style.display='none';
		}
	}
}
function activateContextMenus() {
	if (document.getElementById('cmeLibraryBrowserFileList')) {
		fileCollection=document.getElementById('cmeLibraryBrowserFileList').getElementsByTagName('a');
		for (i=0;i<fileCollection.length;i++) {
			fileCollection[i].onmouseover=function() {
				switchContextType(1);
				setActiveFile(this);
			}
			fileCollection[i].onmouseout=function() {
				switchContextType(0);
			}
		}
	}
}
function switchContextType(bool) {
	contextType=bool;
}

function setActiveFile(obj) {
	activeFile=obj;
}

function sendPicturePath(path) {
	tempPath=path.replace("\\","\/");
	document.getElementById('picturePreview').src=tempPath;
	closed();
}

function renameFile(language) {
	var renameField=document.getElementById('renameField');
	renameField.style.display='block';
	//document.getElementById('cme').style.width='100%';
	var interfaceContainer=document.getElementById('interfaceContainer');
	interfaceContainer.onscroll=checkScroll;
	//alert(interfaceContainer.scrollTop);
	renameField.style.top=((findPos(activeFile)[1]+46)-interfaceContainer.scrollTop)+"px";
	renameField.style.left=(findPos(activeFile)[0])+"px";
	document.form1.rename.value=activeFile.childNodes[1].nodeValue;
	document.form1.rename.focus();
	document.form1.rename.onblur = function() {
		renameSubmit(language);
		interfaceContainer.onscroll=null;
	}
}
function checkScroll() {
	var interfaceContainer=document.getElementById('interfaceContainer');
	if (document.getElementById('renameField')) {
		if (document.getElementById('renameField').style.display=='block') {
			document.getElementById('renameField').style.top=(findPos(activeFile)[1]+46-document.getElementById('interfaceContainer').scrollTop)+"px";
		}
	}
}
function renameSubmit(language) {
	//submit the value of the rename textarea any way you like
	xsldoc="configuration\\Layout\\System\\DocumentLibrary.xsl";
    var value=document.getElementById('Current').value;
	valueToSubmit=document.form1.rename.value;
	//hide the renamefield
	var renameField=document.getElementById('renameField');
	renameField.style.display='none';
	//---document.getElementById('cme').style.width='auto';
	var oldvalue = activeFile.childNodes[2].value;
	var  ToXml=new MyXml();
    var theXML = ToXml.xml("RenameFolder",getxml(oldvalue)+getxml(valueToSubmit)+getxml(xsldoc)+getxml(language));
    <!--calling getRemotecust method to get values from xml file-->
    co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);     
    document.getElementById("cme").innerHTML= co;
    getmenu();
}

function newFolderRename(newFolderName) {
	fileCollection=document.getElementById('cmeLibraryBrowser').getElementsByTagName('a');
	for (i=0;i<fileCollection.length;i++) {
		if (fileCollection[i].childNodes[1].nodeValue==newFolderName) {
			activeFile=fileCollection[i];
			renameFile();
		}
	}
}

function showUploadForm() {
	var uploadField=document.getElementById('uploadField');
	uploadField.style.top=(document.body.offsetHeight/2)-50+"px";
	uploadField.style.left=(document.body.offsetWidth/2)-125+"px";
	uploadField.onmouseover=function() {
		uploadActive=true;
	}
	uploadField.onmouseout=function() {
		uploadActive=false;
	}
	uploadField.style.display='block';
}

function postfile(fileName) {
	if(window.ActiveXObject) {
		fso = new ActiveXObject( 'Scripting.FileSystemObject' );
		f = fso.GetFile( fileName );
		var	fileSize = f.size;
		var	Name = f.Name;
		var xmlSOAP = new ActiveXObject("MSXML2.DOMDocument");
		xmlSOAP.loadXML('<?xml version="1.0" encoding="utf-8"?>'+
		'<soap:Envelope xmlns:xsi="<A href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</A>" '+
		'xmlns:xsd="<A href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</A>" xmlns:soap="<A href="http://schemas.xmlsoap.org/soap/envelope/">http://schemas.xmlsoap.org/soap/envelope/</A>"> '+
		 '<soap:Body>'+
		  '<UploadData xmlns="<A href="http://tempuri.org/">http://tempuri.org/</A>" >'+
		'<fileName>'+this.Name+'</fileName>'+
		'<fileSize>'+this.fileSize+'</fileSize>'+
		'<file></file>'+
		  '</UploadData>'+
		 '</soap:Body>'+
		'</soap:Envelope>');
		var adoStream = new ActiveXObject("ADODB.Stream");
		// create a new node and set binary content
		var fileNode = xmlSOAP.selectSingleNode("//file");
		fileNode.dataType = "bin.base64";
		// open stream object and read source file
		if (adoStream.State != 1 ) {
			adoStream.Type = 1;  // 1=adTypeBinary 
			adoStream.Open(); 
			adoStream.LoadFromFile(fileName);
		}
		
		adoStream.Position = offset;
		// store file content into XML node
		fileNode.nodeTypedValue = adoStream.Read(length);//adoStream.Read(-1); // -1=adReadAll
		if (adoStream.EOS) {
			//Close Stream
			adoStream.Close();
		}
	} else {  
		// open the local file
		var file = Components.classes["@mozilla.org/file/local;1"]
			.createInstance(Components.interfaces.nsILocalFile);
		file.initWithPath( fileName );		
		stream = Components.classes["@mozilla.org/network/file-input-stream;1"]
			.createInstance(Components.interfaces.nsIFileInputStream);
		stream.init(file,	0x01, 00004, null);
		var bstream =  Components.classes["@mozilla.org/network/buffered-input-stream;1"]
			.getService();
		bstream.QueryInterface(Components.interfaces.nsIBufferedInputStream);
		bstream.init(stream, 1000);
		bstream.QueryInterface(Components.interfaces.nsIInputStream);
		binary = Components.classes["@mozilla.org/binaryinputstream;1"]
			.createInstance(Components.interfaces.nsIBinaryInputStream);
		binary.setInputStream (stream);
	   
		// start AJAX file upload in 1 second
		window.setTimeout("ajax_upload()", 1000);
	}
}
		
function ajax_upload() {
	// request more permissions
	try {
		netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
	} catch (e) {
		alert("Permission to read file was denied.");
	}
	
	http_request = false;
	http_request = new XMLHttpRequest();
	if (!http_request) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}
	// prepare the MIME POST data
	var boundaryString = 'capitano';
	var boundary = '--' + boundaryString;
	var requestbody = boundary + '\n' 
	+ 'Content-Disposition: form-data; name="mytext"' + '\n' 
	+ '\n' 
	+ mytext + '\n' 
	+ '\n' 
	+ boundary + '\n' 
	+ 'Content-Disposition: form-data; name="myfile"; filename="' 
		+ filename + '"' + '\n' 
	+ 'Content-Type: application/octet-stream' + '\n' 
	+ '\n'
	+ escape(binary.readBytes(binary.available()))
	+ '\n'
	+ boundary;
	
	document.getElementById('sizespan').innerHTML = 
		"requestbody.length=" + requestbody.length;
	
	// do the AJAX request
	http_request.onreadystatechange = requestdone;
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "multipart/form-data; \
		boundary=\"" + boundaryString + "\"");
	http_request.setRequestHeader("Connection", "close");
	http_request.setRequestHeader("Content-length", requestbody.length);
	http_request.send(requestbody);
}
function getKey(keyStroke) {
	if (keyStroke) {
		keyCode=keyStroke.which.toString();
		
		if (keyCode==0) {
		//	closed();
		}		
	}
}
document.onkeypress = getKey;
//  End -->

function pngCheck(where) {
	//a script to fix IE6-'s incapabilities of showing transparent PNGs
	if (ie6 || ie5) {
		imgCollection=where.getElementsByTagName('img');
		//imgCollection=document.getElementById('cmeLibraryBrowser').getElementsByTagName('img');
		for (i=0;i<imgCollection.length;i++) {
			thisURL=imgCollection[i].src;
			imgCollection[i].style.filter='progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+thisURL+'\',sizingMethod=\'scale\')';
			imgCollection[i].src='/Style/CMEimages/transparent.gif';
		}
		
	}
}


if (!ie5) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
function getMouseXY(e) {
	if (document.getElementById('fader')) {
		if (ie5) { // grab the x-y pos.s if browser is IE
			tempX = event.clientX;
			tempY = event.clientY;
		} else {  // grab the x-y pos.s if browser is NS
			tempX = e.pageX;
			tempY = e.pageY;
		}  
		if (tempX < 0){tempX = 0;}
		if (tempY < 0){tempY = 0;}  
		return true;
	}
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function cutFolder() {
	var name =activeFile.childNodes[1].nodeValue;
	var value=activeFile.childNodes[2].value;
	var  ToXml=new MyXml();
    var theXML = ToXml.xml("CutFolder",getxml(value)+getxml(name));
    <!--calling getRemotecust method to get values from xml file-->
    co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML); 
}

function PasteFolder(language) {
	 var xsldoc="configuration\\Layout\\System\\DocumentLibrary.xsl";     
     var value=document.getElementById('Current').value;
	 var  ToXml=new MyXml();
     var theXML = ToXml.xml("PasteFolder",getxml(value)+getxml(xsldoc)+getxml(language));
    
     co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML); 
     document.getElementById("cme").innerHTML= co; 
	 addFileTypeIcons();
     getmenu();
}

function DeleteFolder(language) {
     xsldoc="configuration\\Layout\\System\\DocumentLibrary.xsl";
	 var value=document.getElementById('Current').value;         
     var name =activeFile.childNodes[2].value;
	 var  ToXml=new MyXml();
     var theXML = ToXml.xml("DeleteFolder",getxml(name)+getxml(xsldoc)+getxml(language));
//     <!--calling getRemotecust method to get values from xml file-->
     co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);
     document.getElementById("cme").innerHTML= co;  
	 addFileTypeIcons();
     getmenu();
 }


function CreateFolder(language,CurrentFolder) {
	var value=document.getElementById('Current').value;
	xsldoc="configuration\\Layout\\System\\DocumentLibrary.xsl";
	var  ToXml=new MyXml();	
	var theXML = ToXml.xml("CreateFolder",getxml(value)+getxml(xsldoc)+getxml(language)+getxml(CurrentFolder));
	//     <!--calling getRemotecust method to get values from xml file-->
	co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML); 
	document.getElementById("cme").innerHTML= co; 
	addFileTypeIcons();
	getmenu();
}

function GetDocumentLibrary(current, forNews,language) {
	xsldoc="configuration\\Layout\\System\\DocumentLibrary.xsl";
	var  ToXml=new MyXml();
	var theXML = ToXml.xml("GetFilesAndFolder",getxml(current)+getxml(xsldoc)+getxml(forNews)+getxml(language));
	//     <!--calling getRemotecust method to get values from xml file-->
	co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);
	
	//begin: animation script inserted by Rasmus
	if (document.getElementById('cme').innerHTML.length==0) {
		//alert(document.getElementById('cme').innerHTML.length);
		var opacity = new Opacity(document.getElementById("cme"));
		opacity.setOpacity(0);
		opacity.FadeIn();
	}
	var cme=document.getElementById('cme');
	cme.style.zIndex='200';
	addImageForNews=forNews;
	//end: animation script inserted by Rasmus
	document.getElementById("cme").innerHTML= co;
	getmenu();
	contextType=0;
	/*document.getElementById('cme').style.width='100%';
	document.getElementById('cme').style.height='100%';*/
	addFileTypeIcons();
	return false;
}
  
function GetParent(current, forNews,language) {
	xsldoc="configuration\\Layout\\System\\DocumentLibrary.xsl";
	var  ToXml=new MyXml();
	var theXML = ToXml.xml("GetParentFolder",getxml(current)+getxml(xsldoc)+getxml(forNews)+getxml(language));
	//     <!--calling getRemotecust method to get values from xml file-->
	co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);
	//begin: animation script inserted by Rasmus
	if (document.getElementById('cme').innerHTML.length==0) {
		//alert(document.getElementById('cme').innerHTML.length);
		var opacity = new Opacity(document.getElementById("cme"));
		opacity.setOpacity(0);
		opacity.FadeIn();
	}
	addImageForNews=forNews;
	//end: animation script inserted by Rasmus
	document.getElementById("cme").innerHTML= co; 
	getmenu();
	addFileTypeIcons();
	contextType=0;
	return false;
}
  
function GetGallery(folderName) {
	folderName="/Documents and images/Gallery/"+folderName;
	xsldoc="configuration\\Layout\\System\\ImageGallery.xsl";
	var  ToXml=new MyXml();
	var theXML = ToXml.xml("GetGallery",getxml(folderName)+getxml(xsldoc));
	//     <!--calling getRemotecust method to get values from xml file-->
	co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);    
	document.getElementById("gallery").innerHTML= co;
}
	
function GetGalleryImages(folderName,picturename) {
	xsldoc="configuration\\Layout\\System\\DisplayGalleryImages.xsl";
	var  ToXml=new MyXml();
	var theXML = ToXml.xml("GetGalleryImages",getxml(folderName)+getxml(picturename)+getxml(xsldoc));
	//<!--calling getRemotecust method to get values from xml file-->
	co = getRemoteCust("/RemotFunctionPage.aspx", "doStuf", theXML);          
	document.getElementById("cme").innerHTML= co;
	var galleryContainer=document.getElementById('galleryContainer');
	var galleryTable=document.getElementById('galleryTable');
	var standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body;
	galleryContainer.style.visibility='hidden';
	pngCheck(document.getElementById('tl'));
	var cme=document.getElementById('cme');
	if (ie5 && !galleryLoaded) {
		galleryLoaded=true;
		cme.style.height=standardbody.offsetHeight;
		cme.style.width=standardbody.offsetWidth;
		cme.style.top=0;
		cme.style.left=0;
	} else {
		cme.style.width='100%';
		cme.style.height='100%';
	}
	cme.style.zIndex='20';
	if (ie6) {
		document.getElementById('fader').style.position='absolute';
		document.getElementById('fader').style.height=standardbody.offsetHeight;
		document.getElementById('galleryContainer').style.position='absolute';
		standardbody.scroll='no';
		standardbody.style.overflow='hidden';
	}
	if (ie5real) {
		document.getElementById('cme').style.top=standardbody.scrollTop;
	}
	var mainPicture=document.getElementById('mainPicture');
	mainPicture.onload = function() {
		galleryHeightCheck(mainPicture);
		checkGalleryPos();
		checkHeight();
		galleryContainer.style.visibility='visible';
	}
	document.getElementById('fader').style.top=0;
}
function checkGalleryPos() {
	if (document.getElementById('galleryContainer')) {
		var galleryContainer=document.getElementById('galleryContainer');
		var galleryTable=document.getElementById('galleryTable');
		galleryContainer.style.top=((docHeight/2)-(galleryTable.offsetHeight/2))+"px";
		//alert(document.getElementById('cme').offsetTop);
	}
}
function galleryHeightCheck() {
	var mainPicture=document.getElementById('mainPicture');
	var picturesContainer=document.getElementById('picturesContainer');
	if (mainPicture.width)	{
		picturesContainer.style.width=(mainPicture.width)+"px";
	}
	lis=document.getElementById('pictures').getElementsByTagName('li');
	liAmount=lis.length;
	document.getElementById('pictures').style.width=((liAmount*67)+15)+"px";
	for (i=0;i<liAmount;i++) {
		if (lis[i].firstChild.className=='active') {
			picturesContainer.scrollLeft=(lis[i].offsetLeft-(mainPicture.width/2))+(lis[i].firstChild.offsetWidth/2);
		}
	}	
}
function getmenu() { 
	checkHeight();
	pngCheck(document.getElementById('cmeLibraryBrowser'));
	if (ie6) {
		document.getElementById('cmeLibraryBrowser').style.width='550px';
	}
	if (browser.indexOf('msie 7')==-1) {
		document.getElementById('interfaceContainer').style.width='100%';
	}
	activateContextMenus();
}
function closed() {
	galleryLoaded=false;
	document.getElementById("cme").innerHTML= "";
	var standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body;
	standardbody.scroll='auto';
	standardbody.style.overflow='auto';
	document.getElementById('cme').style.width='auto';
	var cme=document.getElementById('cme');
	cme.style.zIndex='-1';
}

function addFileTypeIcons() {
	var fileList=document.getElementById('cmeLibraryBrowserFileList');
	var files=fileList.getElementsByTagName('li');
	for (i=0;i<files.length;i++) {
		thisImage=files[i].getElementsByTagName('img')[0];
		thisFile =files[i].getElementsByTagName('input')[0].value;
		fileArray=thisFile.split(".");
		fileExtension=fileArray[fileArray.length-1];
		icon='';
		if (fileExtension.length<5) {
			switch (fileExtension) {
				case 'doc':
					icon='doc';
					break;
				case 'xls':
					icon='xls';
					break;
				case 'ppt':
					icon='ppt';
					break;
				case 'pdf':
					icon='pdf';
					break;
				case 'jpg':
					icon='img';
					break;
				case 'jpeg':
					icon='img';
					break;
				case 'gif':
					icon='img';
					break;
				case 'png':
					icon='img';
					break;
				case 'mov':
					icon='mov';
					break;
				case 'avi':
					icon='mov';
					break;
				case 'flv':
					icon='mov';
					break;	
			}
		}
		if (icon.length>0) {
			thisImage.src='/login/CSS/images/filetype-'+icon+'.png';
		}
		//alert(fileExtension);
	}
}
  //****** fade scripts inserted by Rasmus ********
function Opacity(id) {
	this.opacity = 0;
	this.style = id.style;
	this.timer = null;
}
			 
Opacity.prototype.setOpacity = function(value) {
	if(value == 0) {
		this.style.display = 'none';
	} else {
		this.style.display = 'block';
	}
   
	this.style.opacity = (value / 100);
	this.style.MozOpacity = (value / 100);
	this.style.KhtmlOpacity = (value / 100);
	this.style.filter = "alpha(opacity=" + value + ")";
}
			 
Opacity.prototype.Stop = function() {
	clearInterval(this.timer);
	if(this.opacity> 0) {
		this.setOpacity(100);
	}
}
			 
Opacity.prototype.FadeIn = function() {
	var _this = this;
   
	this.timer = window.setInterval(function() { _this.FadeInTimer(); }, 10);
}
 
Opacity.prototype.FadeInTimer = function() {
	if(this.opacity <100) {
		this.opacity = this.opacity + 20;
		this.setOpacity(this.opacity);
		return false;
	} else {
		clearInterval(this.timer);
		return true;
	}
}
 
Opacity.prototype.FadeOut = function() {
	var _this = this;
	this.timer = window.setInterval(function() { _this.FadeOutTimer(); }, 10);
}
 
Opacity.prototype.FadeOutTimer = function() {
	if(this.opacity> 0) {
		this.opacity = this.opacity-20;
		this.setOpacity(this.opacity);
		return false;
	} else {
		clearInterval(this.timer);
		return true;
	}
}