/*
The code in this file or document and its designs, methods, data, know-how and all other related elements are the property of LUXSON ltd © Copyright 2009-2010 and/or may contain code operated under third party licence(s); unauthorised use is therefore prohibited, including (without limitation) copying, editing, adapting, reverse engineering or any other similar or related action, in part or in full. Separate rights may also exist for LUXSON and/or client and/or third party content and/or services. For licensing information please contact LUXSON ltd.
*/

function SilkDeLux(b, m){

	var butN = b;
	var menN = m;
	
	var butA = new Array();
	var menA = new Array();
	var menWA = new Array();
	var tA = new Array();
	
	var tInt = new Array();
	
	var tO = new Array();
	
	var silkyActive = false;
	
	function silkDeLuxObj(){
		var arrTemp = document.getElementsByTagName('div');
		for(var i = 0; i < arrTemp.length; i++){
			if(arrTemp[i].className == butN){
				butA.push(arrTemp[i]);
			}
			if(arrTemp[i].className == menN){
				
				menA.push(arrTemp[i]);
			}
		}
	}
	
	
	function silkDeLuxBuild(){
		
		silkDeLuxObj();
		
		for(var j = 0; j < menA.length; j++){
			
			var o = menA[j].parentNode;
			
			var w = document.createElement('div');
			o.insertBefore(w, menA[j]);
			
			w.appendChild(menA[j]);
			
			tA.push(w.scrollHeight);
			w.style.height = '0px';
			w.style.position = 'relative';
			
			tO.push(false);
			var th = menA[j].scrollHeight;
			menA[j].style.position = 'absolute';
			menA[j].style.bottom = '0px';
			w.style.overflow = 'hidden';
			w.style.display = 'none';
			menWA.push(w);
			tInt.push(new Number());
			
		}
		
		for(var i = 0; i < butA.length; i++){
			var ti = i;
			if(window.addEventListener){
				butA[i].addEventListener('click', function(){silkDeLuxClick(this)}, false);	
			}else if(window.attachEvent){
				butA[i].attachEvent("onclick", function(){silkDeLuxClick(this)});
			}else{
				alert("error: add/attach event");
			}
		}
		
	}
	
	function silkDeLuxClick(obj){
		
		var n;
		
		for(var i = 0; i < butA.length; i++){
			if(obj == butA[i]){
				n = i;	
			}
		}
				
		clearInterval(tInt[n]);
		menWA[n].style.display = 'block';
			
		var tP;
		var tHeight;
		
		if(tO[n] == false){
			tO[n] = true;
			tHeight = tA[n];
			silkDeLuxCustomFunction('open');
		}else{
			tO[n] = false;
			tHeight = 0;
			silkDeLuxCustomFunction('close');
		}
		
		var tch = Number(menWA[n].style.height.substr(0, menWA[n].style.height.length-2));
		var pivD = (tHeight-tch)/2;
		var pivP = tch+((tHeight-tch)/2);
		
		var segs = 20;
		var upd = 0;
		
		this.updateMove = function(){
			if(upd >= segs){
				menWA[n].style.height = tHeight+'px';
				clearInterval(tInt[n]);
			}else{
				menWA[n].style.height = (pivP+(Math.cos(Math.PI+((Math.PI/segs)*upd)))*pivD)+'px';
			}
			upd++;
		}
		tInt[n] = setInterval("this.updateMove()", 30);
		
	}
	
	function silkDeLuxCustomFunction(t){
		if(t == 'open'){
			document.getElementById("menuText").innerHTML = "Hide Menu";
			document.getElementById("menuArrow").innerHTML = "&#9650;";
		}else{
			document.getElementById("menuText").innerHTML = "Menu";
			document.getElementById("menuArrow").innerHTML = "&#9660;";
		}
	}
	
	function addLoadEvent(func) { 
	  var oldonload = window.onload; 
	  if (typeof window.onload != 'function') { 
		window.onload = func; 
	  } else { 
		window.onload = function() { 
		  if (oldonload) { 
			oldonload(); 
	  	} 
	  	func(); 
		} 
	  } 
	} 
	addLoadEvent(silkDeLuxBuild);
	
}

var silkDeLux = new SilkDeLux('menuButton', 'menuHolder');
