var Local = {

    onCommentReply: function(id) {
		Comments.openReply(id);
	},

    onCancelReply: function(id) {
		Comments.closeReply();
	}

};

if (!window['wt']) {
    window['wt'] = {};
    var wt = window['wt'];
}

wt.browserSucks = (jQuery.browser.msie && jQuery.browser.version < 8) ? true : false;
wt.browserSucksEggs = (jQuery.browser.msie && jQuery.browser.version < 7) ? true : false;


(function() { // This is where jQuery code can safely go without foobarring prototype
	var $ = jQuery;
    
	
	$(document).ready(function() { // These functions get called on DOM ready
	    
	    if (wt.browserSucksEggs) {
    	    jQuery.ifixpng('/images/clear.gif');
		}
		
		
		$('a').click(function() { $(this).blur(); }); // prevents outlines on links for IE
		wt.hero(); // Crossfades hero shots if applicable
		wt.googleMap();
		$('div.sidebar div.block:last').addClass('last');
		
		$('ul.all-attachments li').each(function() {
			$(this).wrapInner(
					$(jQuery('<a />')).attr({'href': $(this).find('img').attr('src'), 'rel': 'lightbox[gallery]', 'title': $(this).find('span').html()})
				)
			$(this).find('span').addClass('title_span')
		});
		
		
		wt.lightbox();
		
		wt.newsletterFormDefault();

		if($('.news_block li').size()){
		  $('.news_block li span.date').each(function(){
		    var kore = $(this),
			date = kore.text().split(',')[0].split(' '),
			months = {'January':'01', 'February':'02', 'March':'03', 'April':'04', 'May':'05', 'June':'06', 'July':'07', 'August':'08', 
'September':'09',
'October':'10', 
'November':'11',
'December':'12'};
		    kore.text(months[date[0]]+'.'+((date[1].length==1)? '0'+date[1] : date[1]));
		  });
		}
})
	
	$(window).load(function() { // These functions get called when everything has loaded
	})
	
	
	wt.googleMap = function() {
	    if(!$('div#map_canvas').size()) { return; }
	    
	    if (GBrowserIsCompatible()) {
          var map = new GMap2(document.getElementById("map_canvas"));
          var point = new GLatLng(35.245549, -85.885792);
          map.setCenter(point, 13);
          map.setUIToDefault();
          map.addOverlay(new GMarker(point));
          map.setMapType(G_PHYSICAL_MAP);
        }
        
	}
	
	wt.formDefaults = function() { // Swaps default text form input values to blank on focus and back to default text on blur
		$('input:text,textarea').each(function() {
			var elem = $(this);
			var defaultText = elem.val();
			elem.focus(function(){
				if(elem.val() == defaultText) {
					elem.val('');
				}
			});
			elem.blur(function(){
				if(elem.val() == '') {
					elem.val(defaultText);
				}
			})
		})
	}


    wt.newsletterFormDefault = function() { // Swaps default text form input values to blank on focus and back to default text on blur
		$('div.join_block form input.input-text').each(function() {
			var elem = $(this);
			var defaultText = 'Email Address';
			
			if(elem.val() == '') {
                elem.val(defaultText);
            } 
            
			
			elem.focus(function(){
				if(elem.val() == defaultText) {
					elem.val('');
				}
			});
			elem.blur(function(){
				if(elem.val() == '') {
					elem.val(defaultText);
				}
			})
		})
	}
	

	wt.hero = function() { // Heroshot crossfader; set options below this function

		if(!$('.heroshots').size()) {
			return;
		}
		$('.heroshots').each(function(index) {
            var heroshot = $(this);
            var interval = null;
    		var fade = heroshot.find('input[name=fadevalue]');
    		fade = fade.val() * 1000;
    		heroshot.find('input[name=fadevalue]').remove();

    		var dur = heroshot.find('input[name=showvalue]');
    		dur = dur.val() * 1000;
    		heroshot.find('input[name=showvalue]').remove();
    		
    		heroshot.attr({
                'fade': fade,
                'dur': dur
    		})
    		if(wt.hero.useForeground) {
    			heroshot.append(
    				$(jQuery('<div class="foreground" />'))
    			);
    		}
    		
    		if(wt.hero.useCaptions) {
    			if(heroshot.children('a:first-child').size()) {
    				var firstCaption = heroshot.children('a:first-child').children('img').attr('alt')
    			} else if(heroshot.children('img:first-child').size()) {
    				var firstCaption = heroshot.children('img:first-child').attr('alt')
    			} else {
    				var firstCaption = ''
    			}

    			heroshot.append(
    				$(jQuery('<div class="caption" />'))
    					.append(
    						$(jQuery('<span class="holder" />'))
    							.show()
    							.text(firstCaption)
    					)
    			)
    		}
    		
    		if(heroshot.children('a,img').size() < 2) { // Less than two images, we don't need to xfade or add controls
    			return
    		}
    		
    		if(wt.hero.useControls) {
    			heroshot.append(
    					$(jQuery('<div class="controls" />'))
    						.append(
    							$(jQuery('<ul />'))
    								.append(
    									$(jQuery('<li />'))
    										.append(
    											$(jQuery('<a href="#previous" class="previous" title="Previous">Previous</a>'))
    												.click(function(c){
    													c.preventDefault()
    													clearInterval(interval)
    													wt.hero.rotate('prev', heroshot)
    													heroshot.find('.pause').hide()
    													heroshot.find('.play').show()
    												})
    										)
    								)
    								.append(
    									$(jQuery('<li />'))
    										.append(
    											$(jQuery('<a href="#pause" class="pause" title="Pause">Pause</a>'))
    												.click(function(c){
    													c.preventDefault()
    													clearInterval(interval)
    													heroshot.find('.pause').hide()
    													heroshot.find('.play').show()
    												})
    												.css({display: 'block'})
    												.show()
    										)
    								)
    								.append(
    									$(jQuery('<li />'))
    										.append(
    											$(jQuery('<a href="#play" class="play" title="Play">Play</a>'))
    												.click(function(c){
    													c.preventDefault()
    													interval = setInterval(function(){
    														wt.hero.rotate('next', heroshot)
    													}, dur + fade)
    													heroshot.find('.pause').show()
    													heroshot.find('.play').hide()
    												})
    												.css({display: 'block'})
    												.hide()
    										)
    								)
    								.append(
    									$(jQuery('<li />'))
    										.append(
    											$(jQuery('<a href="#next" class="next" title="Next">Next</a>'))
    												.click(function(c){
    													c.preventDefault()
    													clearInterval(interval)
    													wt.hero.rotate('next', heroshot)
    													heroshot.find('.pause').hide()
    													heroshot.find('.play').show()
    												})
    										)
    								)
    						)
    				)
    		}
    		
    		heroshot.children('a:first-child,img:first-child').attr({current: 'current'})
    		heroshot.children('a:not(:first-child),img:not(:first-child)').hide()
    		if(jQuery.browser.safari) {
    			heroshot.children('a:not(:first-child),img:not(:first-child)').css({display: 'none'})
    		}
    		
    		interval = setInterval(function() {
    			wt.hero.rotate('next', heroshot)
    		}, dur + fade)
    		
		});

		


		wt.hero.rotate = function(dir, heroshot) {
			if(typeof dir == 'undefined') {
				var dir = 'next'
			}
			if(typeof heroshot == 'undefined') {
				return
			}
			
			var images = heroshot.children('a,img')
			var current = heroshot.children('a[current],img[current]')
			if(dir == 'next') {
				if(current.next('a,img').size()) {
					var to = current.next('a,img')
				} else {
					var to = $(images[0])
				}
			} else {
				if(current.prev('a,img').size()) {
					var to = current.prev('a,img')
				} else {
					var to = $(images[images.size() - 1])
				}
			}
            
            var fade = heroshot.attr('fade')
			current.removeAttr('current').fadeOut(fade / 2)
			
			if(wt.hero.useCaptions) {
				heroshot.find('.holder').fadeOut(fade / 2, function(){
					heroshot.find('.holder').text(to.find('img').size() ? to.find('img').attr('alt') : to.attr('alt'))
					heroshot.find('.holder').fadeIn(fade / 2)
				})
				if($('div.services #bd'|'div.pointe-general-contractors #bd').size()) {
    				$('#services_hero_caption p').fadeOut(fade, function(){
    					$('#services_hero_caption p span').text(to.find('img').size() ? to.find('img').attr('alt') : to.attr('alt'))
    					$('#services_hero_caption p').fadeIn(fade)
    				})
    			}
                
			}
			
		    
			if(wt.hero.useForeground) {
				if(to.href != 'undefined') {
					heroshot.find('.foreground').bind('click',function() {
						window.location = to.href
					})
				} else {
					heroshot.find('.foreground').unbind('click',function() {
						window.location = to.href
					})
				}
			}
			to.attr({current: 'current'}).fadeIn(fade / 2)
		}
	}

	// Heroshot options
	wt.hero.useForeground = true
	wt.hero.useControls = true
	wt.hero.useCaptions = true
    

        wt.lightbox = function(ajax, html) {
        	if(typeof ajax == 'undefined') {
        		ajax = false;
        	}
        	if(typeof html == 'undefined') {
        		html = '';
        	}
        	if(typeof initLightbox == 'function') {
        		Event.stopObserving(window, 'load', initLightbox, false);
        	}
        	$(window).load(function(){
        		Lightbox = function() {
        			return false;
        		}
        		ImageGallery = function() {
        			return false;
        		}
        	})
        	if(!$('#overlay').size()) {
        		$('body').append(
        				$(jQuery('<div />'))
        					.attr({ 'id': 'overlay' })
        					.css({'display': 'none'})
        			)
        	}
        	wt.lightbox.overlay = $('#overlay').height($('body').height())
            wt.lightbox.overlay.click(function() {wt.lightbox.closeLightbox() });

        	if(!$('#popup').size()) {
        		$('body').append(
        				$(jQuery('<div />'))
        					.attr({ 'id': 'popup' })
        					.addClass('lightbox')
        					.css({'display': 'none'})
        			)
        	}
        	wt.lightbox.popup = $('#popup')

        	wt.lightbox.closeLightbox = function() {
        		wt.lightbox.popup.fadeOut('normal', function(){
        			if(wt.browserSucks) {
        				wt.lightbox.overlay.hide()
        			} else {
        				wt.lightbox.overlay.fadeOut('normal')
        			}
        		})
        		wt.lightbox.popup.fadeOut('normal')
        		if(typeof wt.lightbox.photoTarget != 'undefined') {
                wt.lightbox.photoTarget.find('img').remove()
                }
        	}

        	if(!wt.lightbox.popup.find('a.close').size()) {
        		wt.lightbox.close = $(jQuery('<a />'))
        		wt.lightbox.close.addClass('close').html('Close').attr({'href': '#close'}).click(function(c){
        			c.preventDefault() 
        			wt.lightbox.closeLightbox()
        		})
        		wt.lightbox.close.appendTo(wt.lightbox.popup)
        	}

        	wt.lightbox.hotkeys = function(e) {
        		e.preventDefault()
        		var key = e.which
        		if(key == 0 || key == 120) { // Esc or X
        			wt.lightbox.closeLightbox()
        		} else if(key == 110) { // P
        			if(typeof wt.lightbox.next != 'undefined') {
        				wt.lightbox.next.click()
        			}
        		} else if(key == 112) { // N
        			if(typeof wt.lightbox.prev != 'undefined') {
        				wt.lightbox.prev.click()
        			}
        		}
        	}

        	if(!ajax) {
        		wt.lightbox.links = $('a[rel*=lightbox]')
        	} else if(typeof html == 'object') {
        		wt.lightbox.links = html.find('a[rel*=lightbox]')
        	} else {
        		return
        	}

        	if(!wt.lightbox.links.size()) {
        		return
        	}

        	if(wt.lightbox.thumbsOnPopup && !wt.lightbox.popup.find('photo-wrapper').size()) {
        		wt.lightbox.thumbs = $(jQuery('<div />'))
        		wt.lightbox.thumbs.addClass('thumbs')
        		wt.lightbox.thumbsTarget = $(jQuery('<div />'))
        		wt.lightbox.thumbsTarget.addClass('thumbs-wrapper').appendTo(wt.lightbox.thumbs)
        		wt.lightbox.photoTarget = $(jQuery('<div />'))
        		wt.lightbox.photoTarget.addClass('photo-wrapper')
        		wt.lightbox.thumbsTarget.width(wt.lightbox.thumbWidth * wt.lightbox.links.size())
        	} else {
        		wt.lightbox.photoTarget = wt.lightbox.popup
        	}
        	if(wt.lightbox.thumbsOnPopup) {
        		if(!wt.lightbox.popup.find('photo-wrapper').size()) {
        			wt.lightbox.popup.append(wt.lightbox.photoTarget)
        			wt.lightbox.popup.append(wt.lightbox.thumbs)
        		}
        		wt.lightbox.thumbs.prev = $(jQuery('<a />'))
        		wt.lightbox.thumbs.prev.addClass('prev').html('Previous').attr({'href': '#previous','title': 'Previous Photos'}).click(function(c) {
        			c.preventDefault()
        			wt.lightbox.thumbs.prev.blur()
        			var totalWidth = wt.lightbox.thumbsTarget.width()
        			var viewWidth = wt.lightbox.thumbs.width()
        			var currentLeft = parseInt(wt.lightbox.thumbsTarget.css('left'),10)
        			if(currentLeft + viewWidth >= 0) {
        				if(currentLeft != 0 ) {
        					wt.lightbox.thumbsTarget.animate({
        						'left': 0
        					})
        				}
        			} else {
        				wt.lightbox.thumbsTarget.animate({
        					'left': currentLeft + viewWidth
        				})
        			}
        		})
        		wt.lightbox.thumbs.prev.prependTo(wt.lightbox.thumbs)
        		wt.lightbox.thumbs.next = $(jQuery('<a />'))
        		wt.lightbox.thumbs.next.addClass('next').html('Next').attr({'href': '#next','title': 'Next Photos'}).click(function(c) {
        			c.preventDefault()
        			wt.lightbox.thumbs.next.blur()
        			var totalWidth = wt.lightbox.thumbsTarget.width()
        			var viewWidth = wt.lightbox.thumbs.width()
        			var currentLeft = parseInt(wt.lightbox.thumbsTarget.css('left'),10)
        			if(currentLeft - viewWidth < 0 - totalWidth) {
        				if(totalWidth + (currentLeft - viewWidth) < totalWidth % viewWidth) {
        					wt.lightbox.thumbsTarget.animate({
        						'left': 0 - totalWidth + (totalWidth % viewWidth)
        					})
        				}
        			} else {
        				wt.lightbox.thumbsTarget.animate({
        					'left': currentLeft - viewWidth
        				})
        			}
        		})
        		wt.lightbox.thumbs.next.appendTo(wt.lightbox.thumbs)
        	}
        	if(!wt.lightbox.thumbsOnPopup || wt.lightbox.prevNextAlways) {
        		if(typeof wt.lightbox.prev == 'undefined') {
        			wt.lightbox.prev = $(jQuery('<a />'))
        			wt.lightbox.prev.addClass('prev').html('Previous').attr({'href': '#previous','title': 'Previous Photo'}).css({'visibility': 'hidden'}).click(function(c) {
        				c.preventDefault()
        				wt.lightbox.prev.blur()
        				if(wt.lightbox.photoTarget.find('img').size()) {
        					var count = parseInt(wt.lightbox.photoTarget.find('img').attr('count'),10)
        					$(wt.lightbox.links[count - 1]).click()	
        				}
        			})
        			wt.lightbox.prev.prependTo(wt.lightbox.photoTarget)
        		}

        		if(typeof wt.lightbox.next == 'undefined') {
        			wt.lightbox.next = $(jQuery('<a />'))
        			wt.lightbox.next.addClass('next').html('Next').attr({'href': '#next','title': 'Next Photo'}).css({'visibility': 'hidden'}).click(function(c) {
        				c.preventDefault()
        				wt.lightbox.next.blur()
        				if(wt.lightbox.photoTarget.find('img').size()) {
        					var count = parseInt(wt.lightbox.photoTarget.find('img').attr('count'),10)
        					$(wt.lightbox.links[count + 1]).click()	
        				}
        			})
        			wt.lightbox.next.appendTo(wt.lightbox.photoTarget)
        		}

        		wt.lightbox.photoTarget.hover(
        			function() {
        				wt.lightbox.prev.css({'visibility': 'visible'})
        				wt.lightbox.next.css({'visibility': 'visible'})
        			},
        			function() {
        				wt.lightbox.prev.css({'visibility': 'hidden'})
        				wt.lightbox.next.css({'visibility': 'hidden'})
        			}
        		)
        	}
        	if(wt.lightbox.useCaptions) {
        		wt.lightbox.caption = $(jQuery('<div />'))
        		wt.lightbox.caption.addClass('caption').appendTo(wt.lightbox.photoTarget)
        	}

        	wt.lightbox.links.each(function(i){
        		var link = $(this)
        		link.find('img').css({
        			'width': '',
        			'height': ''
        		})
        		link.attr({'count': i})
        		if(wt.lightbox.thumbsOnPopup) {
        			link.clone(true).click(function(c) {
        				c.preventDefault()
        				link.click()
        			}).appendTo(wt.lightbox.thumbsTarget)
        		}
        		link.click(function(c){
        			c.preventDefault()
        			link.blur()
        			var img = new Image()
        			if(wt.lightbox.popup.css('display') != 'block') {
        				img.onload = function() {
        					$(img).appendTo(wt.lightbox.photoTarget)
        					if(wt.browserSucks) {
        						wt.lightbox.overlay.show()
        						if(wt.browserSucksEggs) {
            					    scroll(0,0)
        					    }
        					} else {
        						wt.lightbox.overlay.fadeIn('normal')
        					}
    						if(img.height > $(window).height()) {
    							wt.lightbox.popup.css({'position': 'absolute'})
    						}
    						wt.lightbox.photoTarget.width(img.width)
    						wt.lightbox.photoTarget.height(img.height)
    						wt.lightbox.photoTarget.css({
    							'margin-top': 0 - Math.ceil(img.height / 2),
    							'margin-left': 0 - Math.ceil(img.width / 2)
    						})
    						
        					wt.lightbox.popup.fadeIn('normal')
        					if(ajax) {
        						wt.lightbox.overlay.find('.loading').remove()
        					}
        				}
        				img.src = link.attr('href')
    					if (wt.browserSucksEggs) {
        					jQuery('div#popup img[src$=png]').ifixpng();
    					}
                		
        				$(img).attr({ 'count': link.attr('count') })
        				if(wt.lightbox.useCaptions) {
        					wt.lightbox.caption.html(link.attr('title'))
        				}
        			} else {
        				wt.lightbox.photoTarget.addClass('loading')
        				if(wt.lightbox.useCaptions) {
        					wt.lightbox.caption.fadeOut('normal', function() {
        						wt.lightbox.caption.html(link.attr('title'))
        					})
        				}
    					wt.lightbox.photoTarget.width(wt.lightbox.photoTarget.width())
    					wt.lightbox.photoTarget.height(wt.lightbox.photoTarget.height())
        				wt.lightbox.photoTarget.find('img').fadeOut('normal', function() {
        					img.style.display = 'none'
        					img.onload = function() {
        						wt.lightbox.photoTarget.find('img').remove()
        						$(img).appendTo(wt.lightbox.photoTarget)
        						if(wt.lightbox.useCaptions) {
        							wt.lightbox.caption.fadeIn('normal')
        						}
    							if(img.height > $(window).height()) {
    								wt.lightbox.popup.css({'position': 'absolute'})
    							}
    							wt.lightbox.photoTarget.css({
    								'margin-top': 0 - Math.ceil(img.height / 2),
    								'margin-left': 0 - Math.ceil(img.width / 2)
    							}, 'normal')
    							wt.lightbox.photoTarget.animate({
    								'width': img.width,
    								'height': img.height
    							}, 'normal')
        						$(img).fadeIn('normal', function() {
        							wt.lightbox.photoTarget.removeClass('loading')
        						})
        						if(ajax) {
        							wt.lightbox.overlay.find('.loading').remove()
        						}
        					}
        					img.src = link.attr('href')
        					if (wt.browserSucksEggs) {
            					jQuery('div#popup img[src$=png]').ifixpng();
        					}
                            
        					$(img).attr({ 'count': link.attr('count') })
        				})
        			}
        		})
        	})
        }

        // Lightbox options
        wt.lightbox.thumbsOnPopup = false
        wt.lightbox.useCaptions = true
        wt.lightbox.thumbWidth = 196
        wt.lightbox.prevNextAlways = false

    	wt.banner = function() {
    		if(!$('html#home').size()) return
    		var images = $('.banner img')
    		images.not(':first-child').hide()

    		images.each(function(i) {
    			var image = $(this)
    			if(i == 0) {
    				$(window).load(function() {
    					image.fadeOut(1500)
    					image.next('img').fadeIn(1500)
    				});
    			} else if(i < images.size() - 1) {
    				$(window).load(function() {
    					setTimeout(function() {
    						image.fadeOut(1500)
    						image.next('img').fadeIn(1500)
    					}, i * 1500)
    				});
    			}
    		})

    	}
})();

