window.addEvent('domready', function(){
	// Cheating for image replacement of h4#advantageIcon becuase of overlap bug for sifr and css drop down menu      
	
	if ($('advantageIcon')) {
		$('advantageIcon').setHTML('<img src="/images/h3_advantage.gif" alt="The Accellent Advantage" width="215" height="24" style="margin-left:-25px;" />');
	}
	
	//Top Tab
	
	//select the button
	var button1 = $('button1');
	//select the content element
	var content1 = $('newsletterWrap');
	// select the button
	var openTab = $$('.openTab');
	//The height transition we attach to 'newsletterWrap'
	var b1Toggle = new Fx.Style('newsletterWrap', 'height',{duration: 500});
	
	if (content1) {
		//add an onclick event listener to button1
		/*button1.addEvent('click', function(){
		  //toggle height transition (hide-show)
		  if(content1.getStyle('height').toInt() > 0){
			//hide
		  b1Toggle.start(0);
		  }else{
			//show
			b1Toggle.start(c1Height);
		  }
		  
		  //toggle classname button1 <-> button1 button1t
		  button1.toggleClass('button1t');
		  return false;
		});*/
		
		// after submit tab should stay open
		if (content1.hasClass('open')) {
			content1.setStyle('height', c1Height);
		}
		
		
		// Add open button function from feature section
		openTab.each(function(el) {
			el.addEvent('click', function() {
				if (content1.getStyle('height').toInt() > 0) {
					b1Toggle.start(0);
					window.scrollTo(0, 0);
				} else {
					b1Toggle.start(c1Height);
					window.scrollTo(0, 0);
				}
				
				//toggle classname button1 <-> button1 button1t
				//button1.toggleClass('button1t');
				return false;
			});
			// disable original a link destination
			el.getElements('a').setProperty("href", "#");
		});
		
		//set css display:block for the contentElements
		content1.setStyle('display','block');
		
		//get the scrollSize of the contentElements
		var c1Height = content1.getSize().scrollSize.y;
		
		// disable original a link destination
		//var link_path = button1.getElements('a');
		//link_path.setProperty("href", "#");
	}

	new SmoothScroll({
		transition:Fx.Transitions.Quart.easeInOut,
		duration: 800
	});
	
	// Human Body: Spot Blink
	var periodical;
	
	var blinkFunc = function () {
		$$('.humanspot').each(function(bf) {
			var blinkFx = new Fx.Styles(bf, {duration: 2000,  transition: Fx.Transitions.linear});
			
			blinkFx.start( {
				/*'width': [15, 11],
				'height': [15, 11],
				'top': [0, 2],
				'left': [0, 2],*/
				'opacity': [1, 0.5]
			}).chain(function() {
			
				blinkFx.start.delay(2000, this, {
					/*'width': [11, 15],
					'height': [11, 15],
					'top': [2, 0],
					'left': [2, 0],*/
					'opacity': [0.5, 1]		  
				});
			});
		})
	}
	
	blinkFunc();
	
	blinkFunc.periodical(6000);
	
	
	// Human Body: Tooltip	
	var bubbles = $$('#rightCol ul#humanBody li dl.bubbletips');
	
	bubbles.setStyle('opacity', 0);
	
	$$('.hotspot').each(function(spots, index) {
		
		spots.addEvent('click', function() {
			bubbles.each(function(el, index2) {
				var bubbleFx = new Fx.Style(el, 'opacity', {duration: 500, transition: Fx.Transitions.linear});
				if (index == index2) {
					el.setStyle('display', 'block');
					bubbleFx.start(0, 1);
				} else {
					el.setStyle('display', 'none');
					bubbleFx.start(1, 0);
				}
				
				el.addEvent('mouseleave', function() {
					delayFunc = function() { 
						bubbleFx.start(1,0);
					}.delay(3000);
					afterFunc = function () {
						el.setStyle('display', 'none');
					}.delay(3500);
				});
				
			});
											
		});
	
		spots.addEvent('mouseenter', function() {
			this.setStyle('cursor', 'pointer');
		});
	});
	
	
	// 2nd level drop down effect
	/*
	var submenu = $$('#menu ul li ul li.text');
	submenu.setStyle('opacity', 0.95);
	*/
	
	var list = $$('#menu ul li ul li.text a');
	list.each(function(element) {
	 	
		var fx = new Fx.Styles(element, {duration:180, wait:false});
	 
		element.addEvent('mouseenter', function(){
			fx.start({
				'background-color': '#4d84c4',
				'color': '#fff'
			});
		});
	 
		element.addEvent('mouseleave', function(){
			fx.start({
				'background-color': '#fff',
				'color': '#000'
			});
		});
	 
	});
	
	// fix bug for safari
	var list2 = list.getParent().getParent().getParent();
	
	list2.each(function(list2El) {
		list2El.addEvent('mouseenter', function() {
			list.each(function(list1El) {
				list1El.setStyles({
					'background-color': '#fff',
					'color': '#000'
				});
			});
		});
	});
	
	
	//Strategic Focus Page Scroll 
	var scrollBox = new Fx.Scroll('scrollBox', {
		wait: false,
		duration: 300,
		transition: Fx.Transitions.Quad.easeInOut
	});
	
	var pageId = 1;
	var pageNum = 4;
	
	if ($('btnNext') && $('btnPrev')) {
	
		$('btnNext').addEvent('click', function(event) {
			event = new Event(event).stop();
			if (pageId == 1) {
				scrollBox.toElement('sPage2');
				pageId++;
			} else if (pageId < pageNum) {
				scrollBox.toElement('sPage' + (pageId+1));
				pageId++;
			} else {
				scrollBox.toElement('sPage1');
				pageId = 1;
			}
			myChangeMarker ();
		});
		
		$('btnPrev').addEvent('click', function(event) {
			event = new Event(event).stop();
			if (pageId == 1) {
				scrollBox.toElement('sPage4');
				pageId = pageNum;
			} else if (pageId < pageNum) {
				scrollBox.toElement('sPage' + (pageId-1));
				pageId--;
			} else {
				scrollBox.toElement('sPage3');
				pageId--;
			}
			myChangeMarker ();
		});
		
		 
		$('btnPage1').addEvent('click', function(event) {
			event = new Event(event).stop();
			scrollBox.toElement('sPage1');
			pageId = 1;
			myChangeMarker ();
		});
		 
		$('btnPage2').addEvent('click', function(event) {
			event = new Event(event).stop();
			scrollBox.toElement('sPage2');
			pageId = 2;
			myChangeMarker ();
		});
		 
		$('btnPage3').addEvent('click', function(event) {
			event = new Event(event).stop();
			scrollBox.toElement('sPage3');
			pageId = 3;
			myChangeMarker ();
		});
		 
		$('btnPage4').addEvent('click', function(event) {
			event = new Event(event).stop();
			scrollBox.toElement('sPage4');
			pageId = 4;
			myChangeMarker ();
		});
		
		myChangeMarker ();
	}
	function myChangeMarker(){
		//$('btnPage' + pageId).getParent().setStyle('background-position', 'top left');
		if (pageId == 1) {
			$('btnPage1').getParent().setStyle('background-position', 'top left');
			$('btnPage2').getParent().setStyle('background-position', 'bottom left');
			$('btnPage3').getParent().setStyle('background-position', 'bottom left');
			$('btnPage4').getParent().setStyle('background-position', 'bottom left');
		} else if (pageId == 2) { 
			$('btnPage1').getParent().setStyle('background-position', 'bottom left');
			$('btnPage2').getParent().setStyle('background-position', 'top left');
			$('btnPage3').getParent().setStyle('background-position', 'bottom left');
			$('btnPage4').getParent().setStyle('background-position', 'bottom left');
		} else if (pageId == 3) { 
			$('btnPage1').getParent().setStyle('background-position', 'bottom left');
			$('btnPage2').getParent().setStyle('background-position', 'bottom left');
			$('btnPage3').getParent().setStyle('background-position', 'top left');
			$('btnPage4').getParent().setStyle('background-position', 'bottom left');
		} else {
			$('btnPage1').getParent().setStyle('background-position', 'bottom left');
			$('btnPage2').getParent().setStyle('background-position', 'bottom left');
			$('btnPage3').getParent().setStyle('background-position', 'bottom left');
			$('btnPage4').getParent().setStyle('background-position', 'top left');
		}
	}
	
});
