window.addEvent('domready',function() {
		$$('a').each(function(item) {
			var href = item.getProperty('href');
			if(href != null && href.search(/.pdf/) != -1) {
				var img = new Element('img',{'src':'/graphics/pdf-small-wide.gif','styles':{'border':'none'}});
				item.grab(img,'top');
			}
			if(href != null && href.search(/.dwg/) != -1) {
				var img = new Element('img',{'src':'/graphics/dwg-small-wide.gif','styles':{'border':'none'}});
				item.grab(img,'top');
			}
		});	
		if($$('.target-blank')) {

         $$('.target-blank').each(function(item) {
					item.addEvent('click',function(e) {
							e.preventDefault();
							window.open(item.getProperty('href'));
					});
			});
		}
		if($('query')) {
			var search = $('query');
			search.addEvent('focus',function() {
				if(this.value == 'Search') { this.set('value',''); }
				this.setStyle('color','#000000');
			});
			search.addEvent('blur',function() {
				if(!this.value) { this.set('value','Search'); }
				this.setStyle('color','#ccc');
			});
		}
		if($('contact_us_box')) {
			var cform = $('contact_box_form');
			var cdiv = $('contact_box_wrapper');
			var csubmit = $('contact_box_submit');
			$$('input.contact-box').addEvent('focus',function() {
				this.value = '';
				this.setStyle('color','#555');
			});
			$('question').addEvent('focus',function() {
				this.value = '';
				this.setStyle('color','#555');		
			});
			var contactRequest = new Request.HTML({
						url:'/includes/headers/contact.php',
						onSuccess:function(t,e,h,j) {
							if(h.indexOf('Please')== -1) {
								cdiv.set('html',h);
							}
						}
					});
			csubmit.addEvent('click',function(e) {
					e.stop();
					contactRequest.post(cform);
			});

		}
		
		
		//enewsletter signup
		if($('enews-form')) {
			var form = $('enews-form');
			var submit = $('enews-submit');
			var input = $('eNews_box');
			input.addEvent('focus',function() {
					if(this.value == 'Email Address...') {
						this.value = '';
						this.setStyle('color','#555555');
					}
			});
			var enewsRequest = new Request.HTML({
					url:'/includes/enews.php',
					onSuccess:function(t,e,h,j) {
						if(h.indexOf('valid')== -1) {
							form.getParent('div').set('html',h);
						}
						else {
							alert(h);	
						}
					}
			});
			submit.addEvent('click',function(e) {
					e.stop();
					enewsRequest.post(form);
			});
		}
		
		if($('power-now-slides')) {
			
            //power now home page main-promo animation
			//settings
			var btns = $$('#slide-tabs li');
			var total = 5;
			var images = $$('.homepage-slideshow-images-item');
			var index = 0;
			var showInterval = 4000;
			var fadeSpeed = 500;
			var interval;
			//periodicals
			var start = function() {
				interval = (function() {
						var n = (function() { var next = index + 1; return next < total ? next : 0; })();
					btns[n].fireEvent('animate');
				}).periodical(showInterval);
			};
			//actions
			btns.each(function(btn,i) {
				var originalZIndex = btn.getStyle('z-index');
				//tab clicks
				btn.addEvent('animate',function(e) {
					if(interval) $clear(interval);
					if(e) e.stop();
					if(index != i) {
						//fade outs
						btns[index].removeClass('selected').setStyle('z-index',originalZIndex).fireEvent('mouseleave');
						$$(images[index]).set('tween',{duration:5000});
						$$(images[index]).fade('out');
						//fade ins
						btns[index = i].addClass('selected').fireEvent('mouseenter');
						$$(images[index]).fade('in');
					}
					start();
				});
				//opacity
                if(i != 0) { $$(images[i]).setStyle('opacity',0); }
				//mousein,mouseout
				$$(images[i]).addEvents({
					mouseenter: function() {
						$clear(interval);
					},
					mouseleave: function() {
						start();
					}
				});
				
			});
			//go
			start();
           	
        }
        if($('critical-slide-wrapper')) {
        	$('critical-left').getElement('a').addEvent('click',function(e) {e.preventDefault();});
        	$('critical-right').getElement('a').addEvent('click',function(e) {e.preventDefault();});
        	$$('.handle').getElements('a').each(function(item){item.addEvent('click',function(e) { e.preventDefault();});});
        	var nS1 = new noobSlide({
				box: $('critical-slide-wrapper'),
				items: [0,1,2,3,4],
				size: 940,
				autoPlay: true,
				addButtons: {
					previous: $('critical-left'),
					next: $('critical-right')
				},
				handles: $$('.handle'),
				onWalk: function(currentItem,currentHandle){
					this.handles.removeClass('selected');
					currentHandle.addClass('selected');
				}
			});	
        }
        if($('power-slide-wrapper')) {
        	$('critical-left').getElement('a').addEvent('click',function(e) {e.preventDefault();});
        	$('critical-right').getElement('a').addEvent('click',function(e) {e.preventDefault();});
        	$$('.handle').getElements('a').each(function(item){item.addEvent('click',function(e) { e.preventDefault();});});
        	var nS1 = new noobSlide({
				box: $('power-slide-wrapper'),
				items: [0,1,2,3,4],
				size: 940,
				autoPlay: true,
				addButtons: {
					previous: $('critical-left'),
					next: $('critical-right')
				},
				handles: $$('.handle'),
				onWalk: function(currentItem,currentHandle){
					this.handles.removeClass('selected');
					currentHandle.addClass('selected');
				}
			});	
        }
        
		//Critical home page logo slides
		if($('brand_container')) {
			$('logo-previous').addEvent('click',function(e) { e.preventDefault();});
			$('logo-next').addEvent('click',function(e) { e.preventDefault();});
			var nS2 = new noobSlide({
				box:$('brand_wrapper'),
				items: [0,1,2,3],
				size:840,
				autoPlay:false,
				addButtons: {
					previous: $('logo-previous'),
					next: $('logo-next')
				}
			});
		}
		//google custom search
		var search_input = $('search-input');
		if(search_input.value != '') {
			search_input.setStyle('background','none');	
		}
		search_input.addEvent('click',function() {
			this.setStyle('background','none');	
		});
		$('search-link').addEvent('click', function(e) {
			e.stop();
			$('cse-search-box').submit();
		});
		//Photo Gallery
			if($('page_photo_gallery')) {
				$('photo-previous').addEvent('click',function(e) { e.preventDefault();});
				$('photo-next').addEvent('click',function(e) { e.preventDefault();});
				var nS3 = new noobSlide({
					box:$('photo_wrapper'),
					items: [0,1],
					size:608,
					autoPlay:false,
					addButtons: {
						previous: $('photo-previous'),
						next: $('photo-next')
					}
				});
			}	
			if($('battery_box')) {
				var cform = $('contact_box_form');
				var cdiv = $('contact_box_wrapper');
				var csubmit = $('contact_box_submit');
				var cmsg = $('thank-you');
				var cerror = $('error');
			
				$$('input.contact-box').addEvent('focus',function() {
					this.value = '';
					this.setStyle('color','#555');
				});
				$('question').addEvent('focus',function() {
					this.value = '';
					this.setStyle('color','#555');		
				});
				var quoteRequest = new Request.HTML({
					url:'/includes/contact-pop.php',
					evalScripts:true,
					onSuccess:function(t,e,h,j) {
						if(h == 'Succeeded') {
							cdiv.addClass('hide');
							cmsg.removeClass('hide');
							if(!cerror.hasClass('hide')) { cerror.addClass('hide'); }
							
						}
						else {
							if(cdiv.hasClass('hide')) { cdiv.removeClass('hide'); }							if(cerror.hasClass('hide')) { cerror.removeClass('hide'); }
						}
					}
				});
				csubmit.addEvent('click',function(e) {
					e.stop();
					quoteRequest.post(cform);
				});
				

		
			}
			
		
});

/*  DO MOUSEOVERS 
function mo(state,image)
{
	var src = image.src, ext = src.substring(src.lastIndexOf('.'),src.length);
	image.src = state ? src.replace(ext,'-mo' + ext) : src.replace('-mo' + ext,ext); return;
}
 */
/*  GET AN ELEMENT  
if(typeof $ != 'function') { function $(element) { return document.getElementById(element); } }
*/

