var activated=null;

function form_submit(frm){
	var frm=$.id(frm).submit();
}

function nospam(d,a){
	window.location='mailto:'+a+'@'+d+'?subject=contact from donely.com';
}

function addStrokes(){

	var headings=$.id('main-content').getElementsByTagName('H2');

	for(var i=0;i<headings.length;i++)
		{
		var n=Math.floor(Math.random()*5)+1;
		var t=headings[i].offsetTop;
		ElementHandler.putAfter(headings[i], {tag: 'IMG', id: 'stroke-'+i, src: 'http://www.donely.com/grfx/stroke-'+n+'.jpg', className: 'stroke', title: '', alt: 'graphical element'});

		var stroke=$.id('stroke-'+i);
		stroke.style.top=t+35+'px';
		stroke.style.visibility='visible';
		}
}

function activate(m,off){

		if(typeof m=='object')
			m=this;
		else
			m=$.id(m);

		var rate=8;
		var h=m.oldHeight;

		if(off==true)
			{
			changeDim(m.id,3,18,rate/2,'px','hidden');
			changeDim(m.id,5,0,rate*(25/(h-18))+1,'px','hidden');

			m.activated=false;
			}
		else
			if(typeof m.activated=='undefined' || m.activated==false)
				{
				changeDim(m.id,3,h,rate,'px','hidden');
				changeDim(m.id,5,-25,rate*(25/(h-18))+1,'px','hidden');

				m.activated=true;
				
				if(activated)
					activate(activated,true);

				activated=m.id;
				}
	}

function handleMenus(){
	
//	var menus=$.className('menu');
//
//	for(var i=0;i<menus.length;i++)
//		{
//		var menu=menus[i];
//		menu.oldHeight=menu.offsetHeight;
//	
//		menu.style.height='18px';
//		menu.style.overflow='hidden';
//
//		var h2=menu.getElementsByTagName('H2');
//		h2=h2[0];
//
//		h2.innerHTML='<a href="#" onclick="this.blur()" class="top">'+h2.innerHTML+'</a>';
//
//		var a=menu.getElementsByTagName('A');
//
//		if(typeof menu.activated=='undefined' || menu.activated==false)
//			EventUtils.addEventListener(menu,'click',activate);
//		}
}

function init(){

//	addStrokes();
	handleMenus();
}

var dimensions=new Array('top','left','width','height','marginLeft','marginTop');

function animLS(lyr,dim,target,step,mode,overflow){

	obj=document.getElementById(lyr);

	real=obj.lsReal[dim];
	delta=Math.sqrt(Math.abs(target-real))*0.0125;

	step=obj.sig[dim]*10;

	new_dim=obj.lsReal[dim];
	obj.lsReal[dim]=real+(obj.step[dim]*step*delta);

	var d=dimensions[dim];

	if((new_dim>=target && obj.sig[dim]>0) || (new_dim<=target && obj.sig[dim]<0))
		{
		target=target+''+mode;
		obj.style[d]=target;
		clearInterval(obj.lsInterval[dim]);
		obj.lsInterval[dim]=0;

		if(overflow!='off')
			obj.style.overflow=overflow;
		return;
		}
	else
		{
		new_dim=new_dim+''+mode;
		obj.style[d]=new_dim;
		}
}

function changeDim(lyr,dim,target,step,mode,overflow){

	obj=$.id(lyr);

	if(obj.lsReal==null)
		{
		w_w=document.body.clientWidth;
		w_h=document.body.clientHeight;

		obj.step=new Array();
		obj.sig=new Array();
		obj.lsReal=new Array();
		obj.lsInterval=new Array();
		}

	if(obj.lsInterval[dim]!=0)
		{
		clearInterval(obj.lsInterval[dim]);
		obj.lsInterval[dim]=0;
		}

	switch(dim)
		{
		case 0:
			obj.lsReal[0]=(!parseInt(obj.offsetTop))?0:parseInt(obj.offsetTop);
			break;
		case 1:
			obj.lsReal[1]=(mode=='%')?((parseInt(obj.offsetLeft)/w_w)*100):parseInt(obj.offsetLeft);
			break;
		case 2:
			obj.lsReal[2]=(mode=='%')?((parseInt(obj.offsetWidth)/w_w)*100):parseInt(obj.offsetWidth);
			break;
		case 3:
			obj.lsReal[3]=(mode=='%')?((parseInt(obj.offsetHeight)/w_h)*100):parseInt(obj.offsetHeight);
			break;
		case 4:
			obj.lsReal[4]=parseInt(obj.style.marginLeft);
			break;
		case 5:
			obj.lsReal[5]=(!parseInt(obj.style.marginTop))?0:parseInt(obj.style.marginTop);
			break;
		}

	obj.step[dim]=step;
	obj.sig[dim]=((target-obj.lsReal[dim])>0)?1:-1;

	obj.lsInterval[dim]=setInterval("animLS('"+lyr+"',"+dim+","+target+","+step+",'"+mode+"','"+overflow+"')",30);
}