function $(i){return document.getElementById(i)}

function imgHover(n,x){
	var e=$(n), p='http://static.tourathens.com/', s=p+n+'_hover.'+x;
	e.onmouseover=function(){this.src=s};
	e.onmouseout=function(){this.src=p+n+'.'+x};
	preLoad(s);
}

function preLoad(s){if(document.images){var o=new Image();o.src=s}}

function map(){
	window.open("../map/", "Directions", config="height=390, width=570, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no");
}

function showCategories(i){
	var l=document.getElementById('memberlist');
	var h=l.getElementsByTagName('span'), s=l.getElementsByTagName('ul');
	if(h[i].className=='expand'){
		s[i].style.display='block';
		h[i].className='collapse';
	}else{
		s[i].style.display='none';
		h[i].className='expand';
	}
}

function loadEvents(){
	if($('home')!=null){imgHover('home','jpg')}
	if($('events_attractions')!=null){imgHover('events_attractions','jpg')}
	if($('member_directory')!=null){imgHover('member_directory','jpg')}
	if($('attorneys_staff')!=null){imgHover('attorneys_staff','jpg')}
	if($('about_us')!=null){imgHover('about_us','jpg')}
	if($('contact_us')!=null){imgHover('contact_us','jpg')}
	if($('calendar')!=null){imgHover('calendar','jpg')}
	if($('local_jobs')!=null){imgHover('local_jobs','jpg')}
	if($('links')){
		accordion=new TINY.accordion.slider('accordion');
		accordion.init('links','h2',0,-1,'reverse');
	}
	dropdown=new TINY.dropdown.menu('dropdown');
	dropdown.init('ddnav','menuhover',1);
}

function getCategories(d,s){
	var i=d.selectedIndex, v=d.options[i].value, t='sub'+d.id+'_holder',
	r='http://tourathens.com/wp-content/themes/chamber/sub-categories.php?id='+v+'&name=sub'+d.id;
	if(s){r+='&sel='+s}
	xmlRequest(r,t);
	updateValues()
}

function xmlRequest(r,t){
	var x;
	try{x=new ActiveXObject("Microsoft.XMLHTTP")}
	catch(e){x=new XMLHttpRequest()}
	x.onreadystatechange=function(){
		if(x.readyState==4){document.getElementById(t).innerHTML=x.responseText}
	}
	x.open("GET",r,true);
	x.send(null)
}

function updateValues(){
	var c=$('class1'), i=c.selectedIndex, v=c.options[i].value, base=0, voters=0;
	if(v=='297'||v=='312'){
		base=120;		
		voters=1;
	}else if(v=='90'){
		base=90;
		voters=1;
	}else{
		var emp=$('employees'), pt=$('part_time'), empv, ptv=0;
		if(emp.value==''){
			emp.value=1;
		}
		if(pt.value==''){
			pt.value=0;
		}
		empv=emp.value;
		if(pt.value>0){
			ptv=Math.floor(pt.value/2);
		}
		var tot=parseInt(empv)+parseInt(ptv);
		if(tot<4){
			base=180;
			voters=1;
		}else if(tot<7){
			base=200;
			voters=1;
		}else if(tot<11){
			base=225;
			voters=1;
		}else if(tot<20){
			base=265;
			voters=1;
		}else if(tot<30){
			base=325;
			voters=2;
		}else if(tot<50){
			base=415;
			voters=2;
		}else if(tot<70){
			base=505;
			voters=2;
		}else if(tot<100){
			base=595;
			voters=3;
		}else{
			base=595+((tot-100)*1.4);
			voters=Math.floor(base/200);
		}
	}
	$('votes').value=voters;
	$('dues').value='$'+(base+25);
}

function printEvents(){
  var popup = window.open('', 'Events', 'height=400, width=600, location=0, menubar=0, status=0');
  var temp = popup.document;
  var content = document.getElementById('eventsentry').innerHTML;
  temp.write('<html><head><title>Tourism Events - Print View</title>');
  temp.write('<link rel="stylesheet" href="http://tourathens.com/wp-content/themes/chamber/style.css" />');
  temp.write('</head><body onload="window.print()" style="background:#fff; padding:10px">');
  temp.write(content);
  temp.write('</body></html>');
  temp.close();
}

var TINY={};

function T$(i){return document.getElementById(i)}
function T$$(e,p){return p.getElementsByTagName(e)}

TINY.accordion=function(){
	function slider(n){this.n=n; this.a=[]}
	slider.prototype.init=function(t,e,m,o,k){
		var a=T$(t), i=s=0, n=a.childNodes, l=n.length; this.s=k||0; this.m=m||0;
		for(i;i<l;i++){
			var v=n[i];
			if(v.nodeType!=3){
				this.a[s]={}; this.a[s].h=h=T$$(e,v)[0]; this.a[s].c=c=T$$('ul',v)[0]; h.onclick=new Function(this.n+'.pr(0,'+s+')');
				if(o==s){h.className=this.s; c.style.height='auto'; c.d=1}else{c.style.height=0; c.d=-1} s++
			}
		}
		this.l=s
	};
	slider.prototype.pr=function(f,d){
		for(var i=0;i<this.l;i++){
			var h=this.a[i].h, c=this.a[i].c, k=c.style.height; k=k=='auto'?1:parseInt(k); clearInterval(c.t);
			if((k!=1&&c.d==-1)&&(f==1||i==d)){
				c.style.height=''; c.m=c.offsetHeight; c.style.height=k+'px'; c.d=1; h.className=this.s; su(c,1)
			}else if(k>0&&(f==-1||this.m||i==d)){
				c.d=-1; h.className=''; su(c,-1)
			}
		}
	};
	function su(c){c.t=setInterval(function(){sl(c)},20)};
	function sl(c){
		var h=c.offsetHeight, d=c.d==1?c.m-h:h; c.style.height=h+(Math.ceil(d/5)*c.d)+'px';
		c.style.opacity=h/c.m; c.style.filter='alpha(opacity='+h*100/c.m+')';
		if((c.d==1&&h>=c.m)||(c.d!=1&&h==1)){if(c.d==1){c.style.height='auto'} clearInterval(c.t)}
	};
	return{slider:slider}
}();

TINY.dropdown=function(){
	function menu(n){this.n=n; this.h=[]; this.c=[]; this.z=99}
	menu.prototype.init=function(p,c,f){
		this.m=c; var w=T$(p), s=T$$('ul',w), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',1)');
			h.onmouseout=new Function(this.n+'.st('+i+')')
		}
	};
	menu.prototype.st=function(x,z){
		var c=this.c[x], h=this.h[x], p=T$$('a',h)[0];
		c.style.display=z?'block':'none'
	};
	return{menu:menu}
}();

TINY.style=function(){
	return{
		value:function(e,p){
			e=typeof e=='object'?e:T$(e);
			return e.currentStyle?e.currentStyle[p]:document.defaultView.getComputedStyle(e,null).getPropertyValue(p)
		}
	}
}();

window.onload=loadEvents;