function nav_overs(id){
	$('#'+id+' li').hover(function() {
	var itm = $(this).attr('id');
	var pos = $('#'+itm).position();
	var posLeft = pos.left + 2;
	$('#'+itm+'-over').css('left', posLeft);
	$('#'+itm+'-over').fadeIn(0, function(){ if(jQuery.browser.msie) { $(this).get(0).style.removeAttribute('filter'); } });
	$('#'+itm+'-over').addClass('shadow');
	});	
}

function activeNav(id){
	var pos = $('#'+id).position();
	var posLeft = pos.left + 2;
	$('#'+id+'-over').css('left', posLeft);
	$('#'+id+'-over').fadeIn(0, function(){ if(jQuery.browser.msie) { $(this).get(0).style.removeAttribute('filter'); } });
	$('#'+id+'-over').addClass('shadow');
	
}

function icon_overs(id,h,spd){
	$('#'+id+' li').hover(function() {
	$(this).children('.link a').animate({ marginTop: -h }, spd);
	}, function() {
	$(this).children('.link a').animate({ marginTop: -0 }, spd);          
	});	
}


function formEvents(){
	//get all forms on page
	var allforms = document.getElementsByTagName('form');
	
	//loop through forms
	for(i=0;i<allforms.length;i++){
		
		//get all input tags in current form
		var thisform = allforms[i].getElementsByTagName('input');
		
		//loop through those inputs
		for(j=0;j<thisform.length;j++){
			//qualify that the input is a text input, and has a title, and isn't being excluded by using the 'noevents' class
			if(thisform[j].title && thisform[j].title != '' && thisform[j].type != 'image' && thisform[j].type != 'button' && thisform[j].type != 'submit' && thisform[i].className != 'noevents'){
				//assign the title to the value
				thisform[j].value = thisform[j].title;
				//events that will remove/replace default values into fields
				thisform[j].onfocus = function(){if(this.title == this.value){this.value = '';}}
				thisform[j].onblur = function(){if(this.value == ''){this.value = this.title;}}
			}
		}
	}
}


timer = null;

function fadeInOpts(id){
	if(timer) clearTimeout(timer);
	$('.navover.link').hide();
	$('.navoverpanel').hide();
	// Removed for click event $('.jumpopts').not(id+'opts').fadeOut('fast');
	// Removed for click event $('.jump').not(id).removeClass('over');
	$(id+'opts').fadeIn(0, function(){ if(jQuery.browser.msie) { $(this).get(0).style.removeAttribute('filter'); } });
	$(id).addClass('over');
}

function fadeOutOpts(id){
	timer = setTimeout("doFade('"+id+"')",100);
}

function doFade(id){
	$(id+'opts').hide();
	$(id).removeClass('over');
}



function showPanel(id){
	if(timer) clearTimeout(timer);
	$('.jumpopts').fadeOut('fast');
	$('.jump').removeClass('over');
	$('.navover.link').not(id).hide();
	$('.navoverpanel').not(id+'-panel').hide();
	$(id).fadeIn(0, function(){ if(jQuery.browser.msie) { $(this).get(0).style.removeAttribute('filter'); } });
	$(id).addClass('shadow');
	$(id+'-panel').fadeIn(0, function(){ if(jQuery.browser.msie) { $(this).get(0).style.removeAttribute('filter'); } });
	$(id+'-panel').addClass('shadow');

}

function removePanel(id){
	var navitemname = id+'-panel';
	timer = setTimeout("doFadePanel('"+id+"','"+navitemname+"')",100);
}

function doFadePanel(id,navid){
	if($(id).attr('class') != 'navover shadow act'){
	 	$(id).hide();
	}
	$(navid).hide();
}
		

function setWidth(id){
	var wdt = $(id).width();
	$(id).css('width', wdt );

}

function gallery_jump(id,nm){
	$('#'+id).cycle(nm);
	$('#'+id).cycle('pause');
}

function setHeight(currElement, nextElement, opts, isForward){
	//var hgt = $(this).css('height');
	var hgt = $(this).height();
	var nm = $(this).attr('id');
	$('#servicescycle').css('height', hgt+'px');
	$('#educationcycle').css('height', hgt+'px');
	$('.cyclelist li a').removeClass('act');
	$('#'+nm+'_link').addClass('act');	
}

function checkHeight(){
	var edhgt = $('#educationcycle').css('height');
	var svhgt = $('#servicescycle').css('height');
	if(edhgt == 'auto' || edhgt == '0'){ alert('height problem'); }
}

function Start(page) {
	OpenWin = this.open(page, "CtrlWindow", "width=362,height=272,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,top=1,left=1");
}

function popUpPage(pg,w,h,scr,t,l) {
	OpenWin = this.open(pg, "CtrlWindow", "width="+w+",height="+h+",toolbar=no,menubar=no,location=no,scrollbars="+scr+",resizable=yes,top="+t+",left="+l);
}


function readMore(cls){
	$('.'+cls).click(function() {
		var id = $(this).attr('id');
		if($('#'+id+'-text').is(":visible") == false){
			$('#'+id+'-text').show();
		} else {
			$('#'+id+'-text').hide();
		}
	});	
}


function changeSrc(currElement, nextElement, opts, isForward){
	$('#heronav a img').attr('src','im/heronav_pager_off.png');
	$('#heronav a.activeSlide img').attr('src','im/heronav_pager.png');
}

$(document).ready(function(){
	$('.navover').hide();
	$('.jumpopts').hide();
	$('.navoverpanel').hide();
	
	icon_overs('followicons',24,0);
	formEvents();
	nav_overs('nav');
	
	// Removed for click event - group below added $('.jump').hover(function(){ fadeInOpts('#'+this.id); },function (){ fadeOutOpts('#'+this.id); });
	$('#wantbtn').toggle(function(){ fadeInOpts('#'+this.id); $('#wantbtn').addClass('forceover'); },function (){ fadeOutOpts('#'+this.id); $('#wantbtn').removeClass('forceover'); });
	$('#findbtn').toggle(function(){ fadeInOpts('#'+this.id); $('#findbtn').addClass('forceover'); },function (){ fadeOutOpts('#'+this.id); $('#findbtn').removeClass('forceover'); });
	$('#wantbtnopts').hide();
	$('#findbtnopts').hide();
	
	$('.navover').hover(function(){ showPanel('#'+this.id); });
	
	$('.navoverpanel').hover(function(){var navitem = $('.navoverpanel').index(this) + 2; showPanel('#nav'+navitem+'-over'); $('#heroes').cycle('pause'); },function (){ var navitem = $('.navoverpanel').index(this) + 2; removePanel('#nav'+navitem+'-over'); $('#heroes').cycle('resume');});
	$('.navover').hover(function(){ showPanel('#'+this.id); $('#heroes').cycle('pause');},function (){ removePanel('#'+this.id); $('#heroes').cycle('resume');});

	$('#heroes').cycle({ 
		fx:     'fade',  
		timeout: 24000,
		after: changeSrc,
		pager:  '#heronav', 
		pagerAnchorBuilder: function(idx, slide){ 
			return '<a href="#"><img class="png fl" src="im/heronav_pager_off.png" width="13" height="13" /></a>'; 
		}
	});
	
	$('#find select').focus(function(){ fadeInOpts('#findbtnopts'); });
	readMore('showmore');

});

