//set up the mouse events for the navs
function attachFadeHandlersNav(containerId)
{
	container=$(containerId);
	container.onmouseover=function(nsEvent)
	{
		var el;
		if (nsEvent!=undefined)	 el=nsEvent.target;
		else el=event.srcElement;
  		if (el.tagName=='A'){
  			var vId = el.id + "_out";
			if(Fade.Instances[vId]){
				Fade.Instances[vId].stop();
			}

  			vId = el.id + "_over";
   			if(!Fade.Instances[vId]){
   				if(!el.style.color){
   					el.style.color = '#dddddd';
   				}

   				Fade.Instances[vId]= new Fade(el.id,'#dddddd','#ffcc00',200, vId);
   			}

   			var vColor = el.style.color;
			if(vColor.indexOf("rgb") >= 0){
				vColor = vColor.match(/\d{1,3}[,|)]/g);
				var hr = hex(vColor[0].substr(0, vColor[0].length-1));
				var hg = hex(vColor[1].substr(0, vColor[1].length-1));
				var hb = hex(vColor[2].substr(0, vColor[2].length-1));
				vColor = "#" + hr + hg + hb;
			}

			Fade.Instances[vId].startColor = HexToRGB(vColor);
			Fade.Instances[vId].start();
  		}
	}

	container.onmouseout=function(nsEvent)
	{
		var el;
		if (nsEvent!=undefined)	 el=nsEvent.target;
		else el=event.srcElement;
   		if (el.tagName=='A'){
   			var vId = el.id + "_over";
			if(Fade.Instances[vId]){
				Fade.Instances[vId].stop();
			}
			
   			vId = el.id + "_out";
   			if(!Fade.Instances[vId]){
   				if(!el.style.color){
   					el.style.color = '#ffcc00';
   				}
   				Fade.Instances[vId]= new Fade(el.id,'#ffcc00','#dddddd',500, vId);
   			}

			var vColor = el.style.color;
			if(vColor.indexOf("rgb") >= 0){
				vColor = vColor.match(/\d{1,3}[,|)]/g);
				var hr = hex(vColor[0].substr(0, vColor[0].length-1));
				var hg = hex(vColor[1].substr(0, vColor[1].length-1));
				var hb = hex(vColor[2].substr(0, vColor[2].length-1));
				vColor = "#" + hr + hg + hb;
			}

			Fade.Instances[vId].startColor = HexToRGB(vColor);
			Fade.Instances[vId].start();
   		}
	}

}

function attachFadeHandlersNav1(containerId)
{
	container=$(containerId);
	container.onmouseover=function(nsEvent)
	{
		
		
		var el;
		if (nsEvent!=undefined)	 el=nsEvent.target;
		else el=event.srcElement;
 
  		if (el.tagName=='A')
  		{
  			var vId = el.parentNode.id + "_out";
			if(Fade.Instances[vId]){
				Fade.Instances[vId].stop();
			}
		
  			vId = el.parentNode.id + "_over";
  			if(!Fade.Instances[vId]){
  				el.parentNode.style.backgroundColor = '#64615F';
  				Fade.Instances[vId]= new Fade(el.parentNode.id,'#64615F','#000000',800, vId);
 				Fade.Instances[vId].setColor=function(element,color){
 					element.style.backgroundColor=color;
 				};
			}
			
			var vBgColor = el.parentNode.style.backgroundColor;
			
			if(vBgColor.indexOf("rgb") >= 0){
				vBgColor = vBgColor.match(/\d{1,3}[,|)]/g);
				var hr = hex(vBgColor[0].substr(0, vBgColor[0].length-1));
				var hg = hex(vBgColor[1].substr(0, vBgColor[1].length-1));
				var hb = hex(vBgColor[2].substr(0, vBgColor[2].length-1));
				vBgColor = "#"+hr+hg+hb;
			}
//alert(vBgColor)
			Fade.Instances[vId].startColor = HexToRGB(vBgColor);
			Fade.Instances[vId].start();
		}

	}

	container.onmouseout=function(nsEvent)
	{
		var el;
		if (nsEvent!=undefined)	 el=nsEvent.target;
		else el=event.srcElement;
 
		
  		if (el.tagName=='A')
  		{
  			var vId = el.parentNode.id + "_over";
  			if(Fade.Instances[vId]){
				Fade.Instances[vId].stop();
			}
			
  			vId = el.parentNode.id + "_out";
  			if(!Fade.Instances[vId]){
  				el.parentNode.style.backgroundColor = '#000000';
 				Fade.Instances[vId]= new Fade(el.parentNode.id,'#000000','#64615F',500, vId);
 				Fade.Instances[vId].setColor=function(element,color){
 					element.style.backgroundColor=color;
 				};
			}
			
			var vBgColor = el.parentNode.style.backgroundColor;
			if(vBgColor.indexOf("rgb") >= 0){
				vBgColor = vBgColor.match(/\d{1,3}[,|)]/g);
				var hr = hex(vBgColor[0].substr(0, vBgColor[0].length-1));
				var hg = hex(vBgColor[1].substr(0, vBgColor[1].length-1));
				var hb = hex(vBgColor[2].substr(0, vBgColor[2].length-1));
				vBgColor = "#"+hr+hg+hb;
			}

			Fade.Instances[vId].startColor = HexToRGB(vBgColor);
			Fade.Instances[vId].start();
		}

	}

}

//

function mouseInElement(el,offsetX,offsetY)
{
var d= el.getDimensions();
var x=el.X();
var y=el.Y();

return (xMousePos>=x+offsetX &&
		yMousePos>=x+offsetY &&
		xMousePos<=el.width + offsetX &&
		yMousePos<=el.height + offsetY);

}

function Bobble(list,time)
{
	this.bobbleList=list;
	this.timeEach=time; 	 
	var utc=new Date();
	this.id=utc.getTime();
	this.index=0;
	Bobble.Instances[this.id] = this;
	this.start();
	

}

Bobble.prototype.start=function()
{
	this.startTime=new Date().getTime();
	this.interval=setInterval('Bobble.Instances[' + this.id + '].tween()',this.timeEach);
	//alert(this.interval);
	this.stopped=false;
}

Bobble.prototype.tween=function()
{
	//alert('run it');
		var el=$(this.bobbleList[this.index]) ;

	 if (this.index<this.bobbleList.length && el.animating!=true)
	 {
	 	el.style.display="inline";
		el.animating=true;
		//new Effect.Shake2(el);
		Fade.Instances[el.id]= new Fade(el.id,"#64615F","#DDDDDD",500, el.id);
		Fade.Instances[el.id].start();
		this.index++;
	 }
	 else
	 {
	 	clearInterval(this.interval);		
	 }
}



Bobble.Instances=new Array();

/* Effect to shake down the divs and what nots */
Effect.Shake2 = function(element) {

	var m1=new Effect.Move(element,{ x:  0, y: -10, duration: 0});
  var m2= new Effect.Move(element,{ x: 0, y: 10, duration: 0.3});

	m2.options.afterFinish=function(el)
	{
	  el.animating=false;
	 // alert(el.animating);
	}
}

/* BK MENU Core */
function DHTMLMenu(id)
 {
	this.baseID=id;
	this.currentMenu=null;
 }
 
 DHTMLMenu.prototype.hideCurrent=function()
 {
	if (this.currentMenu!=null)
	{
	 this.currentMenu.style.display="none";
	 /* start an animation */
	}
 }
 
 DHTMLMenu.prototype.showMenu=function (id)
 {
	this.hideCurrent();
	menuId=(this.baseID + '__ctl' + id + '_item');
	this.currentMenu=$(menuId);

	this.currentMenu.innerHTML=this.currentMenu.innerHTML;
	
	this.currentMenu.style.display="block";
	itemList=new Array();
	
	var item;
	var item2;
	var i=0;
	
	for (item=$(menuId + '__ctl' + i + '_link');
		 item!=undefined;
		 item=$(menuId + '__ctl' + ++i + '_link'))
	{
		item.style.color = '#dddddd';
		
		item2=$(menuId + '__ctl' + i + '_plus');
		item2.style.color = '#dddddd';
		
		item2.innerHTML=item2.innerHTML;
		item.innerHTML=item.innerHTML;
				
		item2.style.display="none";
		item.style.display="none";
		
		itemList.push(item2);
		itemList.push(item);
			
	} 
	
	//alert(itemList);
 	 new Bobble(itemList,50);
	
	
 }