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

function loadEvents(){
	imgHover('contact','gif');
	imgHover('submit','jpg');
	if($('employee')!=null){imgHover('employee','gif')}
	if($('client')!=null){
		imgHover('client','gif');
		$('client').parentNode.href="javascript:showlogin()";
	}
	if($('peoplesoft')!=null){imgHover('peoplesoft','gif')}
	if($('sharepoint')!=null){imgHover('sharepoint','gif')}
	var a=new Array();
	var i=$('s');
	i.onmouseover=function(){this.className='searchover'}
	i.onmouseout=function(){this.className='search'}
	i.onfocus=function(){this.value=''}
	i.onblur=function(){if(this.value==''){this.value='Search...'}}
	var h=$('ddh');
	h.onmouseover=function(){dd.mu(1)}
	h.onmouseout=function(){dd.mu(-1)}
	var c=$('ddc');
	c.onmouseover=function(){dd.ch()}
	c.onmouseout=function(){dd.mu(-1)}
	if($('home')!=null){imgHover('home','gif')}
	if($('about')!=null){imgHover('about','gif')}
	if($('services')!=null){imgHover('services','gif')}
	if($('clients')!=null){imgHover('clients','gif')}
	if($('testimonials')!=null){initTestimonials()}
}

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

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

var dd=function(){
	var s=10; var t=15;
	return{
		mu:function(d){
			var h=$('ddh'); var c=$('ddc'); clearInterval(c.timer);
			if(d==1){
				clearTimeout(h.timer); if(c.maxh&&c.maxh<=c.offsetHeight){return}
				else if(!c.maxh){c.style.display='block'; c.style.height='auto'; c.maxh=c.offsetHeight; c.style.height='0px'}
				c.timer=setInterval(function(){dd.sl(c,1)},t)}
			else{h.timer=setTimeout(function(){dd.cl(c)},50)}
			h.className='hover';
		},
		cl:function(c){c.timer=setInterval(function(){dd.sl(c,-1)},t); $('ddh').className=''},
		ch:function(){
			var h=$('ddh'); var c=$('ddc'); clearTimeout(h.timer); clearInterval(c.timer);
			if(c.offsetHeight<c.maxh){c.timer=setInterval(function(){dd.sl(c,1)},t)}
		},
		sl:function(c,d){
			var currh=c.offsetHeight; var dist;
			if(d==1){dist=(Math.round((c.maxh-currh)/s))}else{dist=(Math.round(currh/s))}
			if(dist<=1&&d==1){dist=1}
			c.style.height=currh+(dist*d)+'px'; c.style.opacity=currh/c.maxh; c.style.filter='alpha(opacity='+(currh*100/c.maxh)+')';
			if((currh<6&&d!=1)||(currh>(c.maxh-2)&&d==1)){
				clearInterval(c.timer); 
				if(d!=1){c.style.height='0px'}
				else{c.style.opacity=1; c.style.filter='alpha(opacity=100)'}
			}
		}
};}();

var slider=function(){
	var array=[]; var speed=5; var timer=10;
	return{
		init:function(t,c){
			var s,ds,l,i,y;
			s=$(t); ds=s.getElementsByTagName('div'); l=ds.length; i=y=0;
			for(i=0;i<l;i++){
				var d,did; d=ds[i]; did=d.id; dn=did.replace('-content','');
				if(did.indexOf("header")!=-1){
					y++; d.onclick=new Function("slider.process(this)")}
				else if(did.indexOf("content")!=-1){
					array.push(dn); d.maxh=d.offsetHeight; hr=$(dn+'-header');
					if(c!=y){d.style.height='0px'; d.style.display='none'; hr.className+=' contracted'}
					else{d.style.display='block'; hr.className+=' expanded'}
				} 
			}
		},
		process:function(d){
			var cl,i; cl=array.length; i=0;
			for(i;i<cl;i++){
				var s,h,c,cd;
				s=array[i]; h=$(s+'-header');
				c=s+'-content'; cd=$(c); clearInterval(cd.timer); cn=h.className;
				if(h==d&&cd.style.display=='none'){
					cd.style.display='block'; this.islide(c,1); h.className=cn.replace('contracted','expanded')
                                   }else if(cd.style.display=='block'){this.islide(c,-1); h.className=cn.replace('expanded','contracted')}
			}
		},
		islide:function(i,d){var c,m; c=$(i); m=c.maxh; c.direction=d; c.timer=setInterval("slider.slide('"+i +"')",timer)},
		slide:function(i){
			var c,m,h,dist; c=$(i); m=c.maxh; h=c.offsetHeight;
			dist=(c.direction==1)?Math.round((m-h)/speed):Math.round(h/speed);
			if(dist<=1){dist=1}
			c.style.height=h+(dist*c.direction)+'px'; c.style.opacity=h/c.maxh; c.style.filter='alpha(opacity='+(h*100/c.maxh)+')';
			if(h<2&&c.direction!=1){
				c.style.display='none'; clearInterval(c.timer); c.style.opacity=0; c.style.filter='alpha(opacity=0)'
			}else if(h>(m-2)&&c.direction==1){clearInterval(c.timer); c.style.opacity=1; c.style.filter='alpha(opacity=100)'}
		}
};}();

var tooltip=function(){
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 100;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				tt.style.top = '-200px';
				tt.style.left = '-300px';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();

var testimonials = new Array();
var xml, testtimer, length;
var current = -1;

function initTestimonials(){
	var json = {"testimonials": [
		{"testimonial":"Summit has been great to work with. They are very professional and deliver their promises. We maintained our project schedule and yet were able to flex as business changes occurred. Great group!","signature":"Ralph Forsythe, Alfa Insurance"},
		{"testimonial":"Summit only brings in the most highly seasoned Information Technology staff that have managed or implemented innumerable complex PeopleSoft solutions.","signature":"Doug Dean, Childrens Health Systems"},
		{"testimonial":"Summit has always been there for us when we needed assistance... before, during, and after the upgrades.","signature":"Brad McCann, Alfa Insurance"}
	]};
	var jsoncontent = eval(json);
	length = jsoncontent.testimonials.length;
	for(var i=0; i < length; i++){
		testimonials.push("<p>\"" + jsoncontent.testimonials[i].testimonial + "\"</p><em> - " + jsoncontent.testimonials[i].signature + "</em>");
	}
	rotateTestimonials();
	setInterval(rotateTestimonials, 10000);
}

function rotateTestimonials(){
	var h = $('holder');
	if(current < (length - 1)){
		current = current + 1;
	}else{
		current = 0;
	}
	h.style.opacity = 0;
	h.style.filter = 'alpha(opacity=0)';
	h.innerHTML = testimonials[current];
	testtimer = setInterval(function(){fadeOut(h)}, 35);
}

function fadeOut(h){
	var a = parseFloat(h.style.opacity);
	if(a < 1){
		var na = a + .05;
		h.style.opacity = na;
		h.style.filter = 'alpha(opacity=' + (na*100) + ')';
	}else{
		clearInterval(testtimer);
	}
}

function pageWidth(){return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null}

function pageHeight(){return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null}

function topPosition(){return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0}

function leftPosition(){return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0}

function showlogin(){
	var login,loginheader,loginclose,logintitle,logincontent,loginmask;
	if(!$('login')){
		login=document.createElement('div');
		login.id='login';
		loginheader=document.createElement('div');
		loginheader.id='login-header';
		logintitle=document.createElement('div');
		logintitle.id='login-title';
		loginclose=document.createElement('div');
		loginclose.id='login-close'
		logincontent=document.createElement('div');
		logincontent.id='login-content';
		loginmask=document.createElement('div');
		loginmask.id='login-mask';
		document.body.appendChild(loginmask);
		document.body.appendChild(login);
		login.appendChild(loginheader);
		loginheader.appendChild(logintitle);
		loginheader.appendChild(loginclose);
		login.appendChild(logincontent);;
		loginclose.setAttribute('onclick','hidelogin()');
		loginclose.onclick=hidelogin;
	}else{
		login=$('login');
		loginheader=$('login-header');
		logintitle=$('login-title');
		loginclose=$('login-close');
		logincontent=$('login-content');
		loginmask=$('login-mask');
		loginmask.style.visibility="visible";
		login.style.visibility="visible";
	}
	logincontent.className='divider';
	login.style.opacity=0;
	login.style.filter='alpha(opacity=0)';
	login.alpha=0;
	var width=pageWidth();
	var height=pageHeight();
	var left=leftPosition();
	var top=topPosition();
	var loginwidth=login.offsetWidth;
	var loginheight=login.offsetHeight;
	var topposition=top+(height/4);
	var leftposition=left+(width/2)-(loginwidth/2);
	login.style.top=topposition+'px';
	login.style.left=leftposition+'px';
	var title='Choose Your Destination';
	logintitle.innerHTML=title;
	var message="<img src='http://static.summitsti.com/icon_pa.gif' onclick='window.location=\"https://www.autotask.net/ClientPortal/Login.aspx?ci=2544\"' /><img src='http://static.summitsti.com/icon_cp.gif' onclick='showform(); $(\"login-title\").innerHTML=\"Enter Your Login\"' />";
	logincontent.innerHTML=message;
	var content=$('wrapper');
	loginmask.style.height=content.offsetHeight+'px';
	login.timer=setInterval('fadelogin(true)',5);
}

function hidelogin(){
	var login=$('login');
	clearInterval(login.timer);
	login.timer=setInterval("fadelogin(false)",5);
}

function fadelogin(flag){
	var l=$('login');
	var v=(flag)?l.alpha+10:l.alpha-10;
	l.alpha=v;
	l.style.opacity=(v/100);
	l.style.filter='alpha(opacity='+v+')';
	if(v>=99){
		clearInterval(l.timer);
		l.timer=null;
	}else if(v<=1){
		l.style.visibility='hidden';
		$('login-mask').style.visibility='hidden';
		clearInterval(l.timer);
	}
}

function showform(){
	var c=$('login-content');
	c.className='';
	var i="<form id='redirect' name='redirect' action='http://www.summitsti.com/redirect/' method='post'>";
	i+="<input type='text' name='email' class='textbox' value='' />";
	i+=" <input type='submit' value='GO' />";
	i+="</form>";
	c.innerHTML=i;
}