﻿window.addEvent('domready', function(){
	if($$('.inner .progress').length>0){ feedRotator() }
	if($$('.sq .inner').length>0){ sq_accordian() }
	if($$('.feedbackform input').length>0){
		resetHoverThing($$('.feedbackform input'))
		resetHoverThing($$('.feedbackform textarea'))
	}
	if($$('.documents input').length>0){
		resetHoverThing($$('.documents input'))
	}
	if($$('#fnav').length>0){
		addLinkylink($('fnav'))
	}
	
});

function addLinkylink(obj){
	var newli = new Element('li', {'class': 'newli'}).injectInside(obj);
	newli.set('html', '<a href="javascript:window.print()">Print</a>')
}

function resetHoverThing(arr){
	arr.each(function(el, i){ 
		el.defVal = el.value
		/* console.log('--> '+el+' '+el.defVal) */
		if(el.hasClass('subbut')){}
		else{
			el.addEvents({
				'focus': function(){
					if(el.value==el.defVal){ el.value = "" }
				},
				'blur': function(){
					if(el.value==""){ el.value = el.defVal }
				}
			});
		}
	});
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Accordian setup

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

function sq_accordian(){
	//var acc = new Accordion($$('.sq h2'), $$('.sq .inner'), { alwaysHide: false, show:1 });
	//$$('.sq h2').each(function(el, i){ el.addEvents({ 'mouseover': function(){ acc.display(i); } }); });
}

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Feed Rotator

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
var feedItems = new Array();
var count = 0;
var tempHTML;
var contHgt;
var myWrappers = [];
var myHeight

function feedRotator(){
	$$('.inner').each(function(el, i){ 
		if(i==3){
			el.setStyles({'position':'relative', 'overflow':'hidden','background':'none','height':'150px'});
			tempHTML = el.get('html');
			el.set('html','');
			contHgt = el.getStyle('height');
			
			var wrapper = new Element('div',{'class':'wrapper'}).inject(el,'inside').setStyle('position','absolute');
			wrapper.set('html',tempHTML);
			
			var clone = $(wrapper).clone().inject($(wrapper),'after');
			
			myHeight = wrapper.getStyle('height');
			
			var myHider = new Element('div', {'class': 'hider'});
			myHider.wraps($(el));
		};
		//console.log(tempHTML);
		//console.log(contHgt);
	});
	crossFade();
	
	console.log('hgf')
};

function crossFade(){
	//install looping timer to scroll news
	var myTimer = beginScroll.periodical(40);
	
	$$('.inner .wrapper').each(function(el, i){ 
		//console.log('found wrapper');
		myWrappers.push(el);
		el.setStyle('top',i*myHeight.toInt());
		
		el.addEvents({
			'mouseover': function(){
				myTimer = $clear(myTimer);
				//console.log('over');
			},
			'mouseout': function(){
				 myTimer = beginScroll.periodical(40);
				 //console.log('out');
			}
		},this);
	},this);
};

function beginScroll(){
	myWrappers[0].setStyle('top',myWrappers[0].getStyle('top').toInt()-1);
	myWrappers[1].setStyle('top',myWrappers[1].getStyle('top').toInt()-1);
	
	//console.log((myHeight.toInt()*-1)+(contHgt.toInt()));
	if(myWrappers[1].getStyle('top').toInt() <= (myHeight.toInt()*-1)+(contHgt.toInt())){
		//console.log('triggered loop');
		myWrappers[0].setStyle('top',(myHeight.toInt()*-1)+(contHgt.toInt()));
		myWrappers[1].setStyle('top',contHgt);
	};
};
