var Local = {

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

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

};

var wt = {}; // This is the setup for the webtools namespace

(function() { // This is where jQuery code can safely go without foobarring prototype
	var $ = jQuery
	
	$(document).ready(function() { // These functions get called on DOM ready
		$('a').click(function() { $(this).blur() }) // prevents outlines on links for IE
		wt.hero() // Crossfades hero shots if applicable
		wt.navHovers();
		wt.submitQuestionLink();
		wt.ajaxSubmit();
		wt.shareIt();
		wt.authorInfo();
		wt.staffInfo();
		$('.lightbox ul.all-attachments img').each(function() {
			$(this).wrap(
					$(jQuery('<a />')).attr({'href': $(this).attr('src'), 'rel': 'lightbox[gallery]'})
				)
		});
		wt.lightbox();
		if(jQuery.browser.msie) {
			$('#hd ul.navigation a').each(function() {
				if($(this).attr('href') == window.location.pathname) {
					if($(this).parents('ul.subnav').size()) {
						$(this).parents('ul.subnav').siblings('a').addClass('ancestor')
					} else {
						$(this).addClass('selected')
					}
				}
			});
		}
//		wt.banner()
	})
	
	$(window).load(function() { // These functions get called when everything has loaded
		
	})
	
	wt.authorInfo = function() {
	    $('h5.author_name').each(function() {
	        var author = $(this)
	        
	        $(author).append(
                $(jQuery('<div class="popcontent"><div class="details" /></div>'))
            )
	            
	        $(author).find('div.popcontent div.details').load($(author).find('a.author_lightbox').attr('href') + ' div#bd div#content div.author');
	        
	        $(author).find('div.popcontent').append(
	            $(jQuery('<h4 class="close"><a href="#">Close</a></h4>'))
            );
	        
	        $(author).find('a').click(function(c) {
	            c.preventDefault();
	            if ($(author).find('div.popcontent').css('display') == 'block') {
    	            $(author).find('div.popcontent').hide();
	            } else {
	                $(author).find('div.popcontent').show();
    	            $(author).find('div.popcontent h4.close a').click(function(c) {
    	                c.preventDefault();
        	            $(author).find('div.popcontent').hide();
    	            });
    	            
	            }
	        });
	        
	        
	    });
		
	}
	
	
	wt.staffInfo = function() {
	    if (!$('div.staff div.staff_member').size()) { return }
	    $('div.staff div.staff_member:last').addClass('last')
        $('div.staff div.staff_member').each(function() {
            $(this).css("z-index","0")
            var staffMember = $(this);
            $(staffMember).find('h3').addClass('unselected');
            $(staffMember).find('div.popcontent').append(
                $(jQuery('<h4 class="close"><a href="#">Close</a></h4>'))
            )
            
            $(staffMember).find('h3 a').click(function(c) {
                c.preventDefault();
                
                if ($(staffMember).find('div.popcontent').css('display') == 'block') {
                    closeThings();
	            } else {
	                closeThings();
                    $(staffMember).find('h3').removeClass('unselected').addClass('selected');
                    $(staffMember).css("z-index","10001");
                    $(staffMember).find('div.popcontent').show();
                    $(staffMember).find('div.popcontent').css("z-index","10003");
    	            
	            }
	            
            });

            $(staffMember).find('div.popcontent h4.close a').click(function(c) {
                c.preventDefault();
                closeThings();
            });

            function closeThings() {
                $('div.staff_member div.popcontent').hide();
                $('div.staff div.staff_member').css("z-index","0")
                $('div.staff div.staff_member h3.selected').removeClass('selected').addClass('unselected');
            
            }

        });

	    
        
        
	}
	
	
	wt.shareIt = function(){
	  var links = $('a.stbutton')
	  
	  wt.workintitle = document.title || "DeMoss Capital&trade;"

      	wt.bitlyParse = function(data){
      		var result
      		for(var i in data.results){
      			result = data.results[i]; break
      		}
      		return result.shortUrl
      	}
      	wt.bitly = function(url,funk){
      		BitlyClient.shorten(url,funk)
      	}
      	wt.twitterBoom = function(data){
      		var url = wt.bitlyParse(data)
      		window.open('http://twitter.com/home?status=' + encodeURIComponent(wt.workintitle) + '%20' + encodeURIComponent(url), 'tweet')
      	}
      	wt.twitterGo = function(u){
      		wt.bitly(u,'wt.twitterBoom')
      	}
  	
      	// Upwards ones, like at bottom of news items
    	  if(typeof links != undefined){
      	  links.each(function(){
      	    var link = $(this)
      	    var butan = new ShareDis(link,null,null,'top center', [null,["Twitter",function(url,title,event){wt.twitterGo(window.location)}],["Email","mailto:?subject=__TITLE__&body=__URL__"]])
      	  })
      	}
	}
	
	
	
	wt.ajaxSubmit = function() {
        if (!$('div#bd div.ajax_form form').size()) { return }
        $('div#bd div.ajax_form div.form-wrapper').removeClass('form-wrapper');
        $('div#bd div.ajax_form').prepend(jQuery('<div class="success" /><div class="loading"><div class="spinner" /></div>'));
        $('div#bd div.ajax_form form div.form-type-text input').addClass('required');
        $('div#bd div.ajax_form form textarea').addClass('required');
        
        $('div#bd div.ajax_form form').validate({
            // set submit handler
            submitHandler: function(form) {
                $('div#bd div.ajax_form div.success').html('')
                $('div#bd div.ajax_form div.loading').show();
                // $('div#bd div.ajax_form form').hide();

                $.ajax({
                    url: form.action,
                    type: 'POST',
                    data: $(form).serialize(),
                    dataType: 'text',
                    success: function() {
                        $('div#bd div.ajax_form div.loading').hide();
                        $('div#bd div.ajax_form div.success').html('<div id="popthis"><div class="success_msg">Thanks for your message.<br/>We will respond shortly.<h4><a class="closer" href="#">Close</a></h4></div></div>');

                        $(':input','div#bd div.ajax_form form')
                         .not(':button, :submit, :reset, :hidden')
                         .val('')
                         .removeAttr('checked')
                         .removeAttr('selected');
                        
                        $('div#popthis h4 a').click(function(c){
                            c.preventDefault();
                            $('div.ajax_form div.success').html('');
                        });

                    }
                });
                
                // above this
            }
            
        });
        
        


    }
    
    
    
	
	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.hero = function() { // Heroshot crossfader; set options below this function

		if(!$('#imageFadeContainer').size()) {
			return
		}
		
		wt.hero.interval = null
		
		wt.hero.container = $('#imageFadeContainer')

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

			wt.hero.container.append(
				$(jQuery('<div />'))
					.attr({id: 'hero-caption'})
					.append(
						$(jQuery('<span />'))
							.attr({id: 'caption-holder'})
							.show()
							.text(firstCaption)
					)
			)
		}

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

		wt.hero.interval = setInterval(function() {
			wt.hero.rotate('next')
		}, wt.hero.dur + wt.hero.fade)

		wt.hero.rotate = function(dir) {
			if(typeof dir == 'undefined') {
				var dir = 'next'
			}
			var images = wt.hero.container.children('a,img')
			var current = wt.hero.container.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])
				}
			}

			current.removeAttr('current').fadeOut(wt.hero.fade)
			
			if(wt.hero.useCaptions) {
				wt.hero.container.find('#caption-holder').fadeOut(wt.hero.fade / 2, function(){
					wt.hero.container.find('#caption-holder').text(to.find('img').size() ? to.find('img').attr('alt') : to.attr('alt'))
					wt.hero.container.find('#caption-holder').fadeIn(wt.hero.fade / 2)
				})
			}

			if(wt.hero.useForeground) {
				if(to.href != 'undefined') {
					wt.hero.container.find('#hero-foreground').bind('click',function() {
						window.location = to.href
					})
				} else {
					wt.hero.container.find('#hero-foreground').unbind('click',function() {
						window.location = to.href
					})
				}
			}
			to.attr({current: 'current'}).fadeIn(wt.hero.fade)
		}
	}

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

    
    wt.submitQuestionLink = function() {
	    $('#bd .submit_question').click(function(c) {
	        c.preventDefault()
	        window.location.hash="submit_question_form";
	        $('#bd .form-contact-form form .form-name input').focus()
	    })
	    
	}
	
	wt.navHovers = function() {
	    
		$('#hd ul.navigation ul.subnav').hide()
		
		if($('div.small-business').size()) {
			$('#hd ul.navigation li.nav-small-business').addClass("show_it")
			$('#hd ul.navigation li.nav-small-business ul.subnav').show()
		}

		if($('div.wealth-management').size()) {
			$('#hd ul.navigation li.nav-wealth-management').addClass("show_it")
			$('#hd ul.navigation li.nav-wealth-management ul.subnav').show()
		}
		
		if ($('#hd ul.navigation > li.ancestor').next('ul.subnav').size()) {
		    $('#hd ul.navigation > li.ancestor').addClass("show_it").next('ul.subnav').show();
		} else {
			$('#hd ul.navigation > li > a').mouseover(
				function() {
					var nav = $('#hd ul.navigation');
					var this_link = $(this)
					var this_item = this_link.parent('li')
					if(!this_link.next('ul.subnav').size()) {
						return
					}

					if (this_item.is('.show_it')) {
					    return
					} else {
					    $('#hd ul.navigation ul.subnav').fadeOut("slow");
					    nav.find('.show_it').removeClass('show_it');
	                    this_item.find('ul.subnav').fadeIn("slow");
	                    this_item.addClass("show_it")
					}
				}
			)
		}
	}

    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')

    	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(jQuery.browser.msie && jQuery.browser.version < 7) {
    				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.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'})
    				}
    			)
    			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.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'})
    				}
    			)
    			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(jQuery.browser.msie && jQuery.browser.version < 7) {
    						wt.lightbox.overlay.show()
    						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')
    				$(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')
    					$(img).attr({ 'count': link.attr('count') })
    				})
    			}
    		})
    	})
    }

    // Lightbox options
    wt.lightbox.thumbsOnPopup = false
    wt.lightbox.useCaptions = false
    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)
				});
			}
		})
		
	}
})();