$(document).ready(function(){
	//  MAIN MODULES & CONTENT MENU
	$("div span.body").wrapInner("<span><span></span></span>");
	$("div.hmodule").wrapInner("<span class=\"contain\"></span>");
	$("div.hmodule2").wrapInner("<span class=\"contain\"></span>");
	$("div.hmodule3").wrapInner("<span class=\"contain\"></span>");
	$("div span.hm_body").wrapInner("<span></span>");
	
	
	//  WEBSITE SURVEY POPUP
	$("#sitesurvey").click(function(e){e.preventDefault();
		window.open('http://www.westernintech.com/sitesurvey', 'SiteSurvey', 'width=850,height=550,scrollbars=yes');
	});
	
	
	//  LIGHTBOX
	$(".lightbox").lightBox();
	
	
	//  CONTACT FADE AND AJAX SWITCH
	$('.contactlink').click(function(e){h = $(this).attr('href');e.preventDefault();
		$('#t1').fadeOut(300, function(){$('#t1').load(h,function(){$(this).fadeIn(300);});});
	});
	
	
	//  ZEBRA STRIPING
	$(".stripe tr:even").addClass("alt");
	
	
	//  TIMEAGO STAMPS
	$("abbr[class*=timeago]").timeago();
	
	
	//  SEARCH BAR FUNCTIONS	
	$("form#kb").submit(function(){$("form#kb input").replaceAttr("value",/[;'"--"]/,"");});
	$("form#kb").submit(function(){l = $("form#kb input").val().length;if(l > 50){alert("Oops!\nYour search query seems to be too long, please try a shorter query");return false;}else{return true;}});

	
	//  IE 6 SUPERFISH MENUS
	if(document.all){$("#nav li").hoverClass("sfhover");}
	
	
	W_Carousel();
	
	
	$("a.rkb").trunk({cutoff:45});
	
	

	$('.opc_cat li a').click(function(e) {
		e.preventDefault();
		$(this).next().slideToggle('fast');
	});
});


// WIT "Trunk" - (truncate function)
jQuery.fn.trunk=function(a){var b={cutoff:40,backoff:10};var c=jQuery.extend(b,a);var d=c.cutoff-c.backoff;var s;return this.each(function(){var t=$(this).text();if(t.length>c.cutoff){s=t.substr(0,d)+'... '+t.substr(t.length-c.backoff,t.length)}else{s=t}$(this).text(s)});return this};


// WIT "Carousel" - (homepage feature rotator)
function W_Carousel(){active_id=0;timer=7000;construction=function(){start_events();start_prep();start_timer();return this};start_prep=function(){var urls=["http://www.westernintech.com/company/witadvantage","http://www.westernintech.com/powergen","http://www.westernintech.com/company/witadvantage","http://www.westernintech.com/company/witadvantage"];var imgs=["main_engineering_manufacturing.jpg","main_power_generation.jpg","main_custom_manifolds.jpg","main_power_unit.jpg"];$.each(imgs,function(i){var u=$.grep(urls,function(n,uidx){return(uidx==i)});$(".imgs").append("<a href=\""+u+"\"><img src=\"http://www.westernintech.com/images/"+this+"\" width=\"601\" height=\"245\" class=\"mi_img\"></a>")});$(".mi_img").hide().filter(".mi_img:eq("+active_id+")").show();$(".crsl_btn:eq("+active_id+")").addClass("crsl_btn_on");$(".crsl_btn > .a").hide().filter(".crsl_btn > .a:eq("+active_id+")").show();$(".crsl_btn > .text").vAlign()};start_timer=function(){a_t=setTimeout("adv_next()",timer)};adv_next=function(){if(active_id<3){active_id=active_id+1}else{active_id=0}change_image();change_btn();return start_timer()};start_events=function(){$(".crsl_btn").bind("click",function(){active_id=$(".crsl_btn").index(this);change_image();change_btn();clearTimeout(a_t)}).bind("mouseover",function(){$(this).addClass("crsl_btn_hover")}).bind("mouseout",function(){$(this).removeClass("crsl_btn_hover")})};change_image=function(){$(".mi_img:visible").hide();$(".mi_img:eq("+active_id+")").show()};change_btn=function(){$(".crsl_btn_on").removeClass("crsl_btn_on");$(".crsl_btn:eq("+active_id+")").addClass("crsl_btn_on");$(".crsl_btn > .a").hide().filter(".crsl_btn:eq("+active_id+") > .a").show()};return construction()};


// jQuery - "vAlign"
(function($){$.fn.vAlign=function(){return this.each(function(i){var ah=$(this).height();var ph=$(this).parent().height();var mh=(ph-ah)/2;$(this).css('padding-top',mh)})}})(jQuery);


//jQuery - "Lightbox"
(function($){$.fn.lightBox=function(j){j=jQuery.extend({overlayBgColor:'#000',overlayOpacity:0.8,fixedNavigation:false,imageLoading:'http://www.westernintech.com/images/lightbox/lightbox-ico-loading.gif',imageBtnPrev:'http://www.westernintech.com/images/lightbox/lightbox-btn-prev.gif',imageBtnNext:'http://www.westernintech.com/images/lightbox/lightbox-btn-next.gif',imageBtnClose:'http://www.westernintech.com/images/lightbox/lightbox-btn-close.png',imageBlank:'http://www.westernintech.com/images/lightbox/lightbox-blank.gif',containerBorderSize:10,containerResizeSpeed:400,txtImage:'Image',txtOf:'of',keyToClose:'c',keyToPrev:'p',keyToNext:'n',imageArray:[],activeImage:0},j);var k=this;function _initialize(){_start(this,k);return false}function _start(a,b){$('embed, object, select').css({'visibility':'hidden'});_set_interface();j.imageArray.length=0;j.activeImage=0;if(b.length==1){j.imageArray.push(new Array(a.getAttribute('href'),a.getAttribute('title')))}else{for(var i=0;i<b.length;i++){j.imageArray.push(new Array(b[i].getAttribute('href'),b[i].getAttribute('title')))}}while(j.imageArray[j.activeImage][0]!=a.getAttribute('href')){j.activeImage++}_set_image_to_view()}function _set_interface(){$('body').append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-image-box"><div id="lightbox-container-image"><img id="lightbox-image"><div style="" id="lightbox-nav"><a href="#" id="lightbox-nav-btnPrev"></a><a href="#" id="lightbox-nav-btnNext"></a></div><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"><img src="'+j.imageLoading+'"></a></div></div></div><div id="lightbox-container-image-data-box"><div id="lightbox-container-image-data"><div id="lightbox-image-details"><span id="lightbox-image-details-caption"></span><span id="lightbox-image-details-currentNumber"></span></div><div id="lightbox-secNav"><a href="#" id="lightbox-secNav-btnClose"><img src="'+j.imageBtnClose+'"></a></div></div></div></div>');var c=___getPageSize();$('#jquery-overlay').css({backgroundColor:j.overlayBgColor,opacity:j.overlayOpacity,width:c[0],height:c[1]}).fadeIn();var d=___getPageScroll();$('#jquery-lightbox').css({top:d[1]+(c[3]/10),left:d[0]}).show();$('#jquery-overlay,#jquery-lightbox').click(function(){_finish()});$('#lightbox-loading-link,#lightbox-secNav-btnClose').click(function(){_finish();return false});$(window).resize(function(){var a=___getPageSize();$('#jquery-overlay').css({width:a[0],height:a[1]});var b=___getPageScroll();$('#jquery-lightbox').css({top:b[1]+(a[3]/10),left:b[0]})})}function _set_image_to_view(){$('#lightbox-loading').show();if(j.fixedNavigation){$('#lightbox-image,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide()}else{$('#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide()}var a=new Image();a.onload=function(){$('#lightbox-image').attr('src',j.imageArray[j.activeImage][0]);_resize_container_image_box(a.width,a.height);a.onload=function(){}};a.src=j.imageArray[j.activeImage][0]};function _resize_container_image_box(a,b){var c=$('#lightbox-container-image-box').width();var d=$('#lightbox-container-image-box').height();var e=(a+(j.containerBorderSize*2));var f=(b+(j.containerBorderSize*2));var g=c-e;var h=d-f;$('#lightbox-container-image-box').animate({width:e,height:f},j.containerResizeSpeed,function(){_show_image()});if((g==0)&&(h==0)){if($.browser.msie){___pause(250)}else{___pause(100)}}$('#lightbox-container-image-data-box').css({width:a});$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({height:b+(j.containerBorderSize*2)})};function _show_image(){$('#lightbox-loading').hide();$('#lightbox-image').fadeIn(function(){_show_image_data();_set_navigation()});_preload_neighbor_images()};function _show_image_data(){$('#lightbox-container-image-data-box').slideDown('fast');$('#lightbox-image-details-caption').hide();if(j.imageArray[j.activeImage][1]){$('#lightbox-image-details-caption').html(j.imageArray[j.activeImage][1]).show()}if(j.imageArray.length>1){$('#lightbox-image-details-currentNumber').html(j.txtImage+' '+(j.activeImage+1)+' '+j.txtOf+' '+j.imageArray.length).show()}}function _set_navigation(){$('#lightbox-nav').show();$('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({'background':'transparent url('+j.imageBlank+') no-repeat'});if(j.activeImage!=0){if(j.fixedNavigation){$('#lightbox-nav-btnPrev').css({'background':'url('+j.imageBtnPrev+') left 15% no-repeat'}).unbind().bind('click',function(){j.activeImage=j.activeImage-1;_set_image_to_view();return false})}else{$('#lightbox-nav-btnPrev').unbind().hover(function(){$(this).css({'background':'url('+j.imageBtnPrev+') left 15% no-repeat'})},function(){$(this).css({'background':'transparent url('+j.imageBlank+') no-repeat'})}).show().bind('click',function(){j.activeImage=j.activeImage-1;_set_image_to_view();return false})}}if(j.activeImage!=(j.imageArray.length-1)){if(j.fixedNavigation){$('#lightbox-nav-btnNext').css({'background':'url('+j.imageBtnNext+') right 15% no-repeat'}).unbind().bind('click',function(){j.activeImage=j.activeImage+1;_set_image_to_view();return false})}else{$('#lightbox-nav-btnNext').unbind().hover(function(){$(this).css({'background':'url('+j.imageBtnNext+') right 15% no-repeat'})},function(){$(this).css({'background':'transparent url('+j.imageBlank+') no-repeat'})}).show().bind('click',function(){j.activeImage=j.activeImage+1;_set_image_to_view();return false})}}_enable_keyboard_navigation()}function _enable_keyboard_navigation(){$(document).keydown(function(a){_keyboard_action(a)})}function _disable_keyboard_navigation(){$(document).unbind()}function _keyboard_action(a){if(a==null){keycode=event.keyCode;escapeKey=27}else{keycode=a.keyCode;escapeKey=a.DOM_VK_ESCAPE}key=String.fromCharCode(keycode).toLowerCase();if((key==j.keyToClose)||(key=='x')||(keycode==escapeKey)){_finish()}if((key==j.keyToPrev)||(keycode==37)){if(j.activeImage!=0){j.activeImage=j.activeImage-1;_set_image_to_view();_disable_keyboard_navigation()}}if((key==j.keyToNext)||(keycode==39)){if(j.activeImage!=(j.imageArray.length-1)){j.activeImage=j.activeImage+1;_set_image_to_view();_disable_keyboard_navigation()}}}function _preload_neighbor_images(){if((j.imageArray.length-1)>j.activeImage){objNext=new Image();objNext.src=j.imageArray[j.activeImage+1][0]}if(j.activeImage>0){objPrev=new Image();objPrev.src=j.imageArray[j.activeImage-1][0]}}function _finish(){$('#jquery-lightbox').remove();$('#jquery-overlay').fadeOut(function(){$('#jquery-overlay').remove()});$('embed, object, select').css({'visibility':'visible'})}function ___getPageSize(){var a,yScroll;if(window.innerHeight&&window.scrollMaxY){a=window.innerWidth+window.scrollMaxX;yScroll=window.innerHeight+window.scrollMaxY}else if(document.body.scrollHeight>document.body.offsetHeight){a=document.body.scrollWidth;yScroll=document.body.scrollHeight}else{a=document.body.offsetWidth;yScroll=document.body.offsetHeight}var b,windowHeight;if(self.innerHeight){if(document.documentElement.clientWidth){b=document.documentElement.clientWidth}else{b=self.innerWidth}windowHeight=self.innerHeight}else if(document.documentElement&&document.documentElement.clientHeight){b=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight}else if(document.body){b=document.body.clientWidth;windowHeight=document.body.clientHeight}if(yScroll<windowHeight){pageHeight=windowHeight}else{pageHeight=yScroll}if(a<b){pageWidth=a}else{pageWidth=b}arrayPageSize=new Array(pageWidth,pageHeight,b,windowHeight);return arrayPageSize};function ___getPageScroll(){var a,yScroll;if(self.pageYOffset){yScroll=self.pageYOffset;a=self.pageXOffset}else if(document.documentElement&&document.documentElement.scrollTop){yScroll=document.documentElement.scrollTop;a=document.documentElement.scrollLeft}else if(document.body){yScroll=document.body.scrollTop;a=document.body.scrollLeft}arrayPageScroll=new Array(a,yScroll);return arrayPageScroll};function ___pause(a){var b=new Date();c=null;do{var c=new Date()}while(c-b<a)};return this.unbind('click').click(_initialize)}})(jQuery);


// jQuery  -  "Highlight"
(function($){$.fn.extend({highlight:function(strings){function findText(node,string){if(node.nodeType==3)return searchText(node);else if(node.nodeType==1){i=node.childNodes.length;while(i--)i+=findText(node.childNodes[i],string)||0}function searchText(node){position=node.data.toUpperCase().indexOf(string);if(position>=0)return highlight(position)}function highlight(position){var span=document.createElement('span');span.className='highlight';var text=node.splitText(position);text.splitText(string.length);var clone=text.cloneNode(true);span.appendChild(clone);text.parentNode.replaceChild(span,text);return 1}}return this.each(function(){var i=strings.length;if(typeof strings=='object')while(i--)findText(this,strings[i].toUpperCase());else findText(this,strings.toUpperCase())})}})})(jQuery);


// jQuery  -  "Time Ago"
(function($){$.timeago=function(a){if(a instanceof Date)return inWords(a);else if(typeof a=="string")return inWords($.timeago.parse(a));else return inWords($.timeago.parse($(a).attr("title")))};var k=$.timeago;$.extend($.timeago,{settings:{refreshMillis:60000,allowFuture:false,strings:{prefixAgo:null,prefixFromNow:null,suffixAgo:"Ago",suffixFromNow:"From Now",ago:null,fromNow:null,seconds:"Less Than a Minute",minute:"About a Minute",minutes:"%d Minutes",hour:"About An Hour",hours:"About %d Hours",day:"A Day",days:"%d Days",month:"About a Month",months:"%d Months",year:"About a Year",years:"%d eears"}},inWords:function(a){var b=this.settings.strings;var c=b.prefixAgo;var d=b.suffixAgo||b.ago;if(this.settings.allowFuture){if(a<0){c=b.prefixFromNow;d=b.suffixFromNow||b.fromNow}a=Math.abs(a)}var e=a/1000;var f=e/60;var g=f/60;var h=g/24;var i=h/365;var j=e<45&&sprintf(b.seconds,Math.round(e))||e<90&&b.minute||f<45&&sprintf(b.minutes,Math.round(f))||f<90&&b.hour||g<24&&sprintf(b.hours,Math.round(g))||g<48&&b.day||h<30&&sprintf(b.days,Math.floor(h))||h<60&&b.month||h<365&&sprintf(b.months,Math.floor(h/30))||i<2&&b.year||sprintf(b.years,Math.floor(i));return $.trim([c,j,d].join(" "))},parse:function(a){var s=$.trim(a);s=s.replace(/-/,"/").replace(/-/,"/");s=s.replace(/T/," ").replace(/Z/," UTC");s=s.replace(/([\+-]\d\d)\:?(\d\d)/," $1$2");return new Date(s)}});$.fn.timeago=function(){var a=this;a.each(refresh);var b=k.settings;if(b.refreshMillis>0){setInterval(function(){a.each(refresh)},b.refreshMillis)}return a};function refresh(){var a=k.parse(this.title);if(!isNaN(a)){$(this).text(inWords(a))}return this}function inWords(a){return k.inWords(distance(a))}function distance(a){return(new Date().getTime()-a.getTime())}function sprintf(a,b){return a.replace(/%d/i,b)}if($.browser.msie&&$.browser.version<7.0){document.createElement('abbr')}})(jQuery);


// jQuery  -  RegEx & Replace
$.fn.replaceAttr = function(aName,rxString,repString){return this.attr(aName,function(){return jQuery(this).attr(aName).replace(rxString,repString);});};


//  jQuery  -  "SuperFish" Menus
$.fn.hoverClass=function(c){return this.each(function(){$(this).hover(function(){$(this).addClass(c)},function(){$(this).removeClass(c)})})};