/*
	+-------------------------------------------------------------------------------------------------------+
   	 | 		Copyright 2006-2007 Kahiloa Solutions et Communication											|
   	 | 		Nikon Europe Project / Nikon Widgets Core Javascript 											|
   	 |		Version 1.0  																					|
   	 | 		Last Update 05.01.2007																			|
   	+-------------------------------------------------------------------------------------------------------+ 
*/

/*
 +------------------------------------------------------------------------------+
 |		CLASS : Overlay	- version 1.0				   						|
 +------------------------------------------------------------------------------+ 
*/	 	
 
var Overlay = Class.create();
Overlay.prototype = {

	initialize: function(idOverlay, idBox) {
		this.idOverlay = idOverlay;
		this.idBox = idBox;
		this.box = $(this.idBox);
		this.boxWidth = this.box.style.width;		
		this.options = Object.extend({
   				duration: 0.01,
				alpha: 0.9,
				classname: "div_overlay",
				bgcolor: "#000000",
				box_X: 50,
				box_Y: 50,
				destroy: false
	  	 	}, arguments[2] || {});
		
		this.pageScroll = getPageScroll();
		this.pageSize = getPageSize();
    	
		var tbody = document.getElementsByTagName("body")[0];
		this.overlay = document.createElement("div");
  		this.overlay.id = this.idOverlay;
		this.overlay.className = this.options.classname;
		
		this.overlay.style.display = 'none';		
		this.overlay.style.position = 'absolute';
		this.overlay.style.top = '0px';
		this.overlay.style.left = '0px';
		this.overlay.style.width = '100%';
		this.overlay.style.backgroundColor = this.options.bgcolor;				
		tbody.appendChild(this.overlay);
					
	  	this.box.style.display = 'none'; 			
		if(this.options.destroy) { this.overlay.onclick = this.destroy.bind(this); } 
		else{ this.overlay.onclick = this.close.bind(this); }
	},
	
	openCenter: function() {			
		var top =(this.pageSize[3]/2) - (Element.getHeight(this.box)/2);
		var left =(this.pageSize[2]/2) - (Element.getWidth(this.box)/2); 	
		//alert(top+" , "+left);	
		this.open(top, left);
	},
		
	open: function(top,left) {				
		this.resize();	
		$(this.idOverlay).style.height = (this.pageSize[1]+1000)+'px';	
		//window.onscroll = this.resize.bind(this);
		//window.onresize = this.resize.bind(this);					
		if(this.options.duration>0) {
			new Effect.Appear(this.idOverlay, { duration: this.options.duration, from: 0.0, to: this.options.alpha });
		}	
		else {
			Element.setOpacity(this.idOverlay,this.options.alpha);
			Element.show(this.idOverlay);
		}					
		$(this.idBox).style.top = (this.pageScroll[1]+top)+"px";
		$(this.idBox).style.left = left+'px';		
		
		if(this.options.duration!=0) {
			new Effect.Appear(this.idBox, { duration: this.options.duration, from: 0.0, to: 1.0 });
		}	
		else {
			Element.show(this.idBox);
		}			
	},
	
	close: function() {
   	 	new Effect.Fade(this.idOverlay, { duration: this.options.duration});
   	 	new Effect.Fade(this.idBox, { duration: this.options.duration});
	},
	
	destroy: function() {
		this.close();
		Element.remove(this.idBox);
		Element.remove(this.overlay);
	},
	
	resize: function() {		
		//alert(this.pageScroll[0]);
		$(this.idOverlay).style.width = '100%';
	}		
}

/*
 * @object Flash 
 */
var Flash = {
	/*
	 * @method have
	 * Check if browser have flash player
	 */
	have: function(){		
		if( navigator.mimeTypes.length > 0 ) {
			return navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin != null;
		}
		else if(window.ActiveXObject) {
			try {
				new ActiveXObject( "ShockwaveFlash.ShockwaveFlash" );
				return true;
			}
			catch( oError ){
				return false;
			}
		}
		else{
			return false;
		}			
	},
	
	/*
	 * @method getMovieByName
	 * @param {Object} Name
	 */
	getMovieByName: function(Name) {
		if (navigator.appName.indexOf("Microsoft") != -1) {
        	return window.document[Name];
   		}
   		else {
       		return document[Name];
   		}
	}
}


/*
 +----------------------------------------------------------------------------------+
  |		CLASS: FlashTag - version 1.0													|
 +----------------------------------------------------------------------------------+ 
*/

var FlashTag = Class.create();
FlashTag.prototype = {
	
	/*
	 * Initialize
	 */
	initialize: function(src, width, height){
	    this.src       = src;
	    this.width     = width;
	    this.height    = height;
		
		this.options = Object.extend({
   			id: null,
			version: '7,0,14,0',
			bgcolor: 'AAABA5',
			flashVars: null
	  	}, arguments[3] || {});				
	},
	
	/*
	 * @maethod getContent
	 * Get the Flash tag as a string. 
	 */
	getContent: function(){		
		var flashTag = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
	    if (this.options.id != null){
			flashTag += 'id="'+this.options.id+'" ';
	   	}
		flashTag += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+this.options.version+'" ';
	    flashTag += 'width="'+this.width+'" ';
	    flashTag += 'height="'+this.height+'">\n';
	    flashTag += '<param name="movie" value="'+this.src+'"/>\n';
	    flashTag += '<param name="quality" value="high"/>\n';
		flashTag += '<param name="wmode" value="transparent" />\n';
		flashTag += '<param name="allowscriptaccess" value="always" />';
	    flashTag += '<param name="bgcolor" value="#'+this.options.bgcolor+'"/>\n';
	    if (this.options.flashVars != null){
			flashTag += '<param name="flashvars" value="'+this.options.flashVars+'"/>\n';
	    }					
	    flashTag += '<embed src="'+this.src+'" ';
	    flashTag += 'quality="high" '; 
	    flashTag += 'bgcolor="#'+this.options.bgcolor+'" ';
		flashTag += 'allowscriptaccess="always" ';
	    flashTag += 'width="'+this.width+'" ';
	    flashTag += 'height="'+this.height+'" ';
	    flashTag += 'type="application/x-shockwave-flash" ';
	    if (this.options.flashVars != null){
	    	flashTag += 'flashvars="'+this.options.flashVars+'" ';
			flashTag += 'cswLiveConnect="true" ';
			flashTag += 'play="false" ';
	    }
		if (this.options.id != null){
			flashTag += 'name="'+this.options.id+'" ';
	    }
	    flashTag += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';
	    flashTag += '</embed>\n';
		flashTag += '</object>\n';
		
	    return flashTag;
	},

	/*
	 * @method write
	 * Write the Flash tag out.
	 */
	write: function(){
	    document.write(this.getContent());
	},
	
	/*
	 * @method get 
	 * Get the Flash tag. 
	 */
	get: function(){
		return this.getContent();
	}
}


/*
 * Class TabView 
 */
var TabView = Class.create();
TabView.prototype = {
	initialize: function(tabs) {
				
		this.tabs = tabs;				
		this.options = Object.extend({
			navId: 'tabView',
   			selectClassName: 'selected',
			saveKey: 'nbv.tabview.select',
			defaultOpen: 0 
	  	}, arguments[1] || {});
		
		this.currentView = null;
		
		this.activeTabs();	
		$(this.options.navId).show();
		
		if(Cookies.get(this.options.saveKey) != null) {		
			var memoryView = Number(Cookies.get(this.options.saveKey));			
			this.changeView(memoryView);
		}
		else {
			this.changeView(this.options.defaultOpen);
		}			
	},
	
	activeTabs: function() {
		for(var i=0; i<this.tabs.length; i++) {
			$(this.tabs[i].idTab).onclick = this.changeView.bind(this, i);
		}
	},
	
	changeView: function(viewIndex) {		
		if(viewIndex != this.currentView) {			
			
			if(this.currentView != null) {											
				this._closeView(this.currentView);
			}
			else {
				if(viewIndex != this.options.defaultOpen) {
					this._closeView(this.options.defaultOpen);
				}
			}
			this._openView(viewIndex);			
			this._saveView(viewIndex);					
			return false; 
		}
		
		resizeBgkLeftMenu();
		
	},
	
	_openView: function(viewIndex) {
		$(this.tabs[viewIndex].idTab).addClassName(this.options.selectClassName);
		$(this.tabs[viewIndex].idView).show();
	},
	
	_closeView: function(viewIndex) {
		$(this.tabs[viewIndex].idTab).removeClassName(this.options.selectClassName);
		$(this.tabs[viewIndex].idView).hide();
	},
	
	_saveView:function(viewIndex) {
		this.currentView = viewIndex;					
		Cookies.set(this.options.saveKey, this.currentView.toString(), 365);
	}
	
}


/*
 * Class Pager
 */
var Pager = Class.create();
Pager.prototype = {
	
	initialize: function(itemsJSON, idTable) {		
		this._JSON = itemsJSON;
		this._items;
		this._table = idTable;	

		this.options = Object.extend({
			ajax: false,
			mode: "thumbnail",
			template: '<a href="#{url}">#{title}</a>',
			idPrev: "btn_prev",
			idNext: "btn_next",
			separatorChar: "|",
			idPagesNumber: "span_pages_number",
			nbPageNumberDisplay: 2,
			itemsPerLine: 1,
			linesPerPage: 15					
	  	 }, arguments[2] || {});
		 		 
		 this._currentPage = 1;
		 this._count = 0;
		 this._countLines = 0;
		 this._countPages = 0;
		 this._pagesNav;
		 this._syntax = /(^|.|\r|\n)(\<%=\s*(\w+)\s*%\>)/;
		 this._tpl = new Template(this.options.template, this._syntax);
		 
		 if(this.options.ajax==true) {
		 	new Ajax.Request(this._JSON, {
			  onSuccess: this._onItemsLoaded.bind(this),
			  onFailure: this._onItemsFailure.bind(this)
			});
		 }
		 else {
		 	this._items = eval('('+ this._JSON +')');
		 	this._initItems();
		 }									
	},
	
	_onItemsLoaded: function(xhr) {	
		//alert(xhr.responseText);	
		this._items = eval('('+xhr.responseText+')');
		this._initItems();
	},
	
	_onItemsFailure: function(xhr) {
		alert("Data can't be loaded... please reload this page.");
	},
	
	_initItems: function() {				
		this._count = this._items.length;				
		this._itemsPerPage = this.options.itemsPerLine*this.options.linesPerPage;				
		this._countLines = Math.round(this._count/this.options.itemsPerLine);		
		this._countPages = Math.round(this._countLines/this.options.linesPerPage);		
		//alert("Nombre d'items total: "+ this._count +"\n"+ "Nombre de lignes total: "+this._countLines +"\n"+ "Nombre d'Items par page: "+this._itemsPerPage +"\n"+ "Nombre de Pages: "+this._countPages);		
		this._pagesNav = new Array(this._countPages);		
				
		this._initNav();
		this._updateLines(0);
	},
		
	next: function() {
		this.changePage(this._currentPage+1);
		return false;
	},	
	prev: function() {
		this.changePage(this._currentPage-1);
		return false;
	},
	
	changePage: function(pageNumber) {	
		if(pageNumber != this._currentPage) {		
			if (pageNumber == 1) { 
				this._activeButton(this.options.idPrev,'prev',false);
			}
			else { 
				this._activeButton(this.options.idPrev,'prev',true); 
			}
			if (pageNumber == this._countPages) {
				this._activeButton(this.options.idNext,'next',false); 
			}
			else { 
				this._activeButton(this.options.idNext,'next',true); 
			}			
			this._pagesNav[this._currentPage].className='';			
			this._pagesNav[pageNumber].className='selected';			
			
			var firstItem = (pageNumber-1)*this._itemsPerPage;			
						 										
			this._updateLines(firstItem);												
			this._currentPage = pageNumber;
		}	
		return false;	
	},
	
	_initNav: function() {		
		var i, strNav;
		//var spanPageNumber = new Array(this._countPages);
		var spanPageNumber = new Array();
		//var spanSepar = new Array(this._countPages-1);
		var spanSepar = new Array();
				
		if(this._countPages > 1) {			
			this._activeButton(this.options.idNext,'next',true);					
		}	
		
		for(i=1; i<=this._countPages; i++) {			
			// add <span><a>1</a></span>
			this._addPageNumber(i, spanPageNumber);						
			if(i != this._countPages) {
				// add separator <span>|</span>		
				this._addSeparator(i, spanSepar);										
			}	
			this._pagesNav[i].onclick = this.changePage.bind(this, i);			
		}
	},
	
	_addPageNumber: function(i, spanPageNumber) {								
		this._pagesNav[i] = document.createElement('a');						
		if(i==1) { this._pagesNav[i].className='selected'; }
		this._pagesNav[i].innerHTML = i;
		$(this.options.idPagesNumber).appendChild(this._pagesNav[i]);
	},
	
	_addSeparator: function(i, spanSepar) {
		spanSepar[i] = document.createElement('span');
		spanSepar[i].innerHTML = this.options.separatorChar;
		$(this.options.idPagesNumber).appendChild(spanSepar[i]);
	},
	
	_updateLines: function(itemStart) {		
		var i, j;
		var strLines = '';		
		var __itemNumber = itemStart;
				
		for(i=0; i < this.options.linesPerPage; i++) {	
			if($(this._table).rows[i]) {
				$(this._table).deleteRow(i);	
			}			
			var row = $(this._table).insertRow(i);					
			for(j=0; j<this.options.itemsPerLine; j++) {				
				var cell = row.insertCell(j);
				if(this._items[__itemNumber] != null) {
					cell.innerHTML = this._tpl.evaluate(this._items[__itemNumber]);
				}
				__itemNumber++;
			}
		}		
	},	
	
	_activeButton: function(idButton, callback, active) {
		if(active==false) {
   	 		$(idButton).onclick = function inactive(){ return false; };
			$(idButton).className = "disable";   	 			
   	 	}
   	 	else {   	 										
			if(arguments[3]) {var params = arguments[3]}
			else {params = "";}
			$(idButton).onclick = eval("this." + callback + ".bind(this," + arguments[3] + ");");
			$(idButton).className = "enable";
		}
	}
}

/*
 +----------------------------------------------------------------------------------+
 |		CLASS: NWParser - version 1.0												|
 +----------------------------------------------------------------------------------+ 
*/	
var NwdParser = Class.create();
NwdParser.prototype = {
	
	/*
	 * @method initialize (public)
	 * @param {Object} nw 
	 * @return none
	 * 
	 * Type of elements :
	 * <string>
	 * <number>
	 * <boolean>
	 * <file>
	 * <data> 
	 * 
	 */
	initialize: function(nwd) {
		this.nwd = nwd;
		this.errors = 'NWParser Errors : \n';
		this.itemNodes = this.nwd.getElementsByTagName("item");
		this.options = Object.extend({
			fallback: true
	  	 }, arguments[1] || {});
		
		if(this.options.fallback==true) {
			this.globalNode = this.nwd.getElementsByTagName("global")[0];
		}
		this.nullValue = '--';
	},
	
	/*
	 * @method getItem (public)
	 * @param {Number} itemId
	 */
	getItem: function(itemId) {
		try{
			// fallback on item
			var i = this.itemNodes[itemId];
			if(i==null && this.options.fallback==true) {
				i = this.globalNode;
			}
			if(i==null) {
				this._setError('Error[getItem]: item '+itemId+' not found');
			}
			return i;
		}catch(e){
			this._setError('Error[getItem]: '+e.message);
		}	
	},		
	
	/*
	 * @method getItemByName (public)
	 * @param {String} itemName
	 */
	getItemByName: function(itemName) {
		try{
			for(var x=0; x<this.itemNodes.length; x++){
				if(this.itemNodes[x].getAttribute("name")==itemName) {
					return this.itemNodes[x];
				}
				else {
					if(this.options.fallback==true) { 
						return this.globalNode; 
					}
					else return false;
				}
			}
		}catch(e){
			this._setError('Error[getItemByName]: '+e.message);
		}	
	},
	
	/*
	 * @method getElementsOfSection (public)
	 * @param {String} sectionName
	 * @param {Number} ItemId
	 * @fallback {Boolean}
	 * @return {Array} return an Indexed Array or false
	 */
	getElementsOfSection: function(sectionName, itemNode) {
		try{			
			var sectionNode;
			sectionNode = this._getSectionNode(sectionName, itemNode);
			// fallback			
			if(!sectionNode) {
				sectionNode = this._getSectionNode(sectionName, this.globalNode);
			}
			if(!sectionNode) {
				return false;		
			}
			else {
				var els = this._getElementNodes(sectionNode, "index");
				return els;
			}			
		}catch(e){
			this._setError('Error[getElementsOfSection]: '+e.message);
		}
	},
	
	
	/*
	 * @method getElementsOfSectionByName (public)
	 * @param {String} sectionName
	 * @param {Number} ItemId
	 * @fallback {Boolean}
	 * @return {Array} return an Named Indexed Array
	 */
	getElementsOfSectionByName: function(sectionName, itemNode) {
		try{			
			var sectionNode;
			sectionNode = this._getSectionNode(sectionName, itemNode);
			
			// fallback
			if(!sectionNode && this.options.fallback==true) {
				sectionNode = this._getSectionNode(sectionName, this.globalNode);
			}
			// no fallback
			if(!sectionNode) {
				return false;		
			}
			else {
				var els = this._getElementNodes(sectionNode, "name");				
				return els;
			}
		}catch(e){
			this._setError('Error[getElementsOfSectionByName]: '+e.message);
		}
	},
	
	/*
	 * @method _getSectionNode (private)
	 * @param {String} sectionName
	 * @param {XMLNode} itemNode
	 * @return {XMLNode} return the item's section node OR FALSE
	 */
	_getSectionNode: function(sectionName, itemNode) {
		try{
			var sectionNode;
			if(!itemNode) { return false; }
			else {
				// if <item> have <section> nodes
				if(itemNode.hasChildNodes()==true){
					var sections = getChildsElement(itemNode);				
					for(var x=0; x<sections.length; x++){
						if(sections[x].getAttribute("name")==sectionName) {
							sectionNode = sections[x];
						}
					}				
					if(sectionNode==null) {
						return false;
					}
					else {
						return sectionNode;
					}
				}
				else {				
					return false;
				}
			}
		}catch(e){
			this._setError('Error[_getSectionNode]: '+e.message);
		}
	},
	
	/*
	 * @method _getElementNodes (private)
	 * @param {XMLNode} sectionNode
	 * @param {String} by
	 */
	_getElementNodes: function(sectionNode, by){
		try{			
			var elementNodes = getChildsElement(sectionNode);
			if(elementNodes) {
				var es = new Array();
				//alert(elementNodes.length);
				// by name
				if(by=="name") {
					for(var x=0; x < elementNodes.length; x++) {
						var el = elementNodes[x];
						var name = el.getAttribute("name");										
						es[name] = {
							type: el.tagName,
							name: el.getAttribute("name"),
							title: el.getAttribute("title"),
							value: this._getValue(el)
						};
					}					
				}
				else {
					for(var x=0; x < elementNodes.length; x++) {
						var el = elementNodes[x];
						es[x] = {
							type: el.tagName,
							name: el.getAttribute("name"),
							title: el.getAttribute("title"),
							value: this._getValue(el)
						};
					}
				}
				return es;
			}
			else {
				return false;
			}
			
		}
		catch(e){
			this._setError('Error[_getElementNodes]: '+e.message);
		}
	},
	
	/*
	 * @method _getValue (private)
	 * @param {XMLNode} node
	 * @return {String} the value or attribute("value") of the node
	 * 
	 */
	_getValue: function(node){
		try{
			var value;
			if(node.tagName=="data"){
				var value = getFirstElement(node)
				value = value.data;
			}
			else if(!node.getAttribute("value")){
				if(node.firstChild) {
					value = node.firstChild.nodeValue;
				}
				else {
					value = this.nullValue;
				}
			}
			else{
				value = node.getAttribute("value");
			}
			return value;
		}catch(e){
			this._setError('Error[getElementsOfSection]: '+e.message);
		}
	},
	
	/*
	 * @method setError (private)
	 * @param {String} Message
	 */
	_setError: function(Message){
		if(Browser.ff) { 
			//console.log('NwdParser Error: %d', Message);
		}
		else{
			this.errors += Message+'\n';
			window.status = this.errors;
		}
	}
	
}

/*
 +----------------------------------------------------------------------------------+
  |		UTILS OBJECTS & FUNCTIONS - version 1.0				   						|
 +----------------------------------------------------------------------------------+ 
*/	


/*
 * Object: Browser
 */
var Browser = {
	name: navigator.appName.toLowerCase(),
	agent: navigator.userAgent.toLowerCase(),
	version: navigator.appVersion,
	os: navigator.platform,
	win: navigator.userAgent.indexOf("Win") != -1,
	mac: navigator.userAgent.indexOf("Mac") != -1,
	ie: navigator.userAgent.toLowerCase().indexOf("msie") != -1,
	ie4: navigator.userAgent.toLowerCase().indexOf("msie 4.") != -1,
	ie5: navigator.userAgent.toLowerCase().indexOf("msie 5.") != -1,
	ie6: navigator.userAgent.toLowerCase().indexOf("msie 6.") != -1,
	ie7: navigator.userAgent.toLowerCase().indexOf("msie 7.") != -1,
	ns: navigator.appName.toLowerCase().indexOf("netscape") != -1,
	moz: navigator.appName.toLowerCase().indexOf("netscape") != -1 && navigator.userAgent.toLowerCase().indexOf("gecko") != -1,
	ff: navigator.appName.toLowerCase().indexOf("netscape") != -1 && navigator.userAgent.toLowerCase().indexOf("firefox") != -1,
	safari: navigator.userAgent.toLowerCase().indexOf("safari") != -1,
	opera: navigator.userAgent.toLowerCase().indexOf("opera") != -1
};
/*
 * Object: Cookies
 * Cookies manager for all widgets
 */
 var Cookies = {
		set: function(name, value, daysToExpire) {
			var expire = '';
			var domain = 'locahost';
			var path = '/';
			if (daysToExpire != undefined) {
				var d = new Date();
				d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
				expire = '; expires=' + d.toGMTString();
			}
			return (document.cookie = escape(name) + '=' + escape(value || '') + expire + ';path='+path);
		},
				  
		get: function(name) {
			var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
			return (cookie ? unescape(cookie[2]) : null);
		},
				  
		erase: function(name) {
			var cookie = Cookie.get(name) || true;
			Cookie.set(name, '', -1);
			return cookie;
		},
		
		accept: function() {
			if (typeof navigator.cookieEnabled == 'boolean') {
				return navigator.cookieEnabled;
			}
		}
};


/*
* @method _getChildsElement
* @param {XMLNode} node
* @return {Array} return array of childnodes whitout textnodes OR FALSE
*/
function getChildsElement(node) {			
	if(node.hasChildNodes()===true){
		var c = node.childNodes;
		var nc = new Array();
		for(var x=0; x<c.length; x++){
			if(c[x].nodeType == 1) {
				nc.push(c[x]);
			}
		} 
		return nc;
	}
	else {
		return false;
	}
}
	
/*
* @method _getFirstElement
* @param {XMLNode} node
* @return {XMLNode} return the first Element node 
*/
function getFirstElement(node) {
	if(node.firstChild.nodeType==1 || node.firstChild.nodeType==4) {
		return node.firstChild;	
	}
	else {
		return node.firstChild.nextSibling;
	} 
} 

/*
* @method _getFlashMovieObject
* @param {XMLNode} node
* @return {XMLNode} return the first Element node 
*/
function _getFlashMovieObject(movieName) {
  if (window.document[movieName]) {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1) {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

/*
* @method toogle2Divs
* @param {HTMLObject} btn
* @param {String} idToOpen
* @param {String} idToClose
* @options {Object}
* 		- {String} open
* 		- {String} close
*/
function toggle2Divs(btn, idToOpen, idToClose) {	
	var options = Object.extend({
			open: "open",
			close: "close"
 		 	}, arguments[3] || {});
	
	var isInput = false;		
	if(btn.tagName.toLowerCase()=="input") {isInput=true;}
	if(Element.visible(idToClose)) {
		Element.hide(idToClose); 
		Element.show(idToOpen);
		if(isInput) { btn.value = options.open; }
		else { btn.innerHTML = options.open; }		
	}
	else {
		Element.hide(idToOpen);
		Element.show(idToClose);
		if(isInput) { btn.value = options.close; }
		else { btn.innerHTML = options.close; } 		
	}
	var leftcol = $('menu').getHeight()+21;
	var rightcol = $('div_rightcol').getHeight();
	if(leftcol>rightcol) 		
		$('div_greyleftmiddle').style.height = (leftcol-rightcol)+"px";
	else
		$('div_greyleftmiddle').style.height = (rightcol-leftcol)+"px";
}

/*
 * Function: getPageScroll
 * Returns: array with x,y page scroll values.
 */
function getPageScroll(){
	var xScroll;
	var yScroll;
	
	if (self.pageXOffset) {		
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollLeft){	 // Explorer 6 Strict
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		xScroll = document.body.scrollLeft;
	}
	
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
}

/*
 * Function:  getPageSize
 * Returns:  array with page width, height and window width, height
 */
function getPageSize(){	
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		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;
	if (self.innerHeight) {	// all except Explorer
		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;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight); 
	return arrayPageSize;
}


