// JavaScript Document

window.addEvent('domready', function() {
	
	// Position of current Nav Point
	var curNavPos = 0;
	
	// get toggler with a.current
	$$('#mainnav li.toggler').each( function(element, index){
		if(element.getFirst('a').hasClass('current')){
				curNavPos = index;
		}
		// for IE 6&7
		element.getFirst('a').setAttribute('href', 'javascript:;');
	});
	
	//create Accordion instance
	function resetAcc(){
		navAccordion.display.delay(500, navAccordion, curNavPos);
	}
	
	var resetTimer;
	
	$('mainnav').addEvent('mouseleave' , function(){
			resetTimer = resetAcc.delay(500);									 
	});
	
	var navAccordion = new Accordion($('mainnav'), 'li.toggler', 'ul.element', {
		show: curNavPos,
		duration : 'long',
		transition: Fx.Transitions.Cubic.easeOut,
		onActive: function(toggler, element){
			toggler.setStyle('color', '#ff6600');
		},
		onBackground: function(toggler, element){
			toggler.setStyle('color', '#000000');
		}
	});
	
	// Make the acc effect on mouseover
	/*
	navAccordion.togglers.each(function(toggler){
	toggler.addEvent('mouseover',function(){
		this.fireEvent('click');
		});
	});
	*/
	
	//create Accordion instance for infotext div
	var infoAccordion = new Accordion($('infoText'), 'h3.toggler', 'div.element', {
		opacity: false,
		show: 1000,
		duration : 600,
		transition: Fx.Transitions.Cubic.easeOut
	});
	
	//create Accordion instance
	var subnavAccordion = new Accordion($('subNav'), 'li.tog', 'ul.el', {
		opacity: false,
		show: 0,
		duration : 600,
		transition: Fx.Transitions.Cubic.easeOut,
		onActive: function(tog, el){
			tog.setStyle('color', '#ff6600');
			el.setStyle('color', '#000000');
		},
		onBackground: function(tog, el){
			tog.setStyle('color', '#000000');
		}
	
	});
	
	var addinfoAccordion = new Accordion($('addInfo'), 'h4.togg', 'ul.ele', {
		opacity: false,
		duration : 600,
		transition: Fx.Transitions.Cubic.easeOut
	});
	
	if(Browser.Engine.trident4== true){
		window.addEvent('resize', function() {
			var size;
			window.getScrollSize().y >= $('mainWrapper').getSize().y ? size = window.getScrollSize() : size = $('mainWrapper').getScrollSize() ;

			$('topShadow').setStyle('width', window.getSize().x);
			$('leftShadow').setStyle('height', size.y );
			$('rightShadow').setStyle('height', size.y );
			//$('top').setStyle('width', window.getScrollSize().x);
			//$('top').setStyle('height', window.getScrollSize().y );
			//alert("The element is "+size.x+" pixels wide and "+size.y+"pixels high.");
		});
		
		window.fireEvent('resize');
	}
	

	$$('#picRows a img').each(function(e){
		$picsrc = e.getProperty('src').replace(/\.jpg/, "_SW.jpg");
		e.getParent('a').setStyle('background-image', 'url('+$picsrc+')' );
		//alert($picsrc);
	});
	$$('#picRows a img').set('tween', {duration: 1300});
	$$('#picRows a img').fade(.01);	
	$$('#picRows a img').addEvent('mouseover' , function(){
				this.fade('in');
	});
	$$('#picRows a img').addEvent('mouseout' , function(){
				this.fade(.01);										 
	});
	
/* newsbox */ 
	$$('#news a img').each(function(e){
		$picsrc = e.getProperty('src').replace(/\.jpg/, "_SW.jpg");
		e.getParent('a').setStyle('background-image', 'url('+$picsrc+')' );
	//	alert($picsrc);
	});
	$$('#news a img').set('tween', {duration: 1300});
	$$('#news a img').fade(.01);
	$$('#news a img').addEvent('mouseover' , function(){
				this.fade('in');
	});
	$$('#news a img').addEvent('mouseout' , function(){
				this.fade(.01);										 
	});
 
 /* home large image */
	$$('#conHead a img').each(function(e){
		$picsrc = e.getProperty('src').replace(/\.jpg/, "_SW.jpg");
		e.getParent('a').setStyle('background-image', 'url('+$picsrc+')' );
	//	alert($picsrc);
	});
	$$('#conHead a img').set('tween', {duration: 1300});
	$$('#conHead a img').fade(.01);
	$$('#conHead a img').addEvent('mouseover' , function(){
				this.fade('in');
	});
	$$('#conHead a img').addEvent('mouseout' , function(){
				this.fade(.01);										 
	});	

/* teaser pics */
	$$('#teaser3col a img').each(function(e){
		$picsrc = e.getProperty('src').replace(/\.jpg/, "_SW.jpg");
		e.getParent('a').setStyle('background-image', 'url('+$picsrc+')' );
	//	alert($picsrc);
	});
	$$('#teaser3col a img').set('tween', {duration: 1300});
	$$('#teaser3col a img').fade(.01);
	$$('#teaser3col a img').addEvent('mouseover' , function(){
				this.fade('in');
	});
	$$('#teaser3col a img').addEvent('mouseout' , function(){
				this.fade(.01);										 
	});	
});