	jQuery.fn.extend({

		adjustScreenCaptureNav:function() {
			var shots = $(".screenshot .shots img").length;
			var navwidth = shots * 12;
			$(this).width(navwidth);
			
			if (shots == 1) {
				$("#casestudies .screenshot .outer-nav").hide;
				$("#casestudies .screenshot").addClass("singleShot");
			}
		}

	});


$(document).ready(function(){
	
	// Site Search Box
	$("#header input.search").focus(function () {
	      $(this).css("backgroundImage","none");
	}); $("#header input.search").blur(function () {
		if ($(this).val() == "") {
	      $(this).css("backgroundImage","url(/images/site/searchbg.png)");
		}
	});
	
	/* Identify and Tag All External Links */
	allowedDomains = ['wisdomgroup.com', 'feedburner.com']; 
	$('a[@href^="http"]').each(function(){ 
	       var isExt = true; 
	       for(var i=0;i<allowedDomains.length;i++){ 
	               if(this.href.indexOf(allowedDomains[i])>-1){ 
	                       isExt=false; 
	                       break; 
	               } 
	       } 
	       if(isExt){                       
	   /*            $(this).click(function(){ 
	                       window.open(this.href); 
	                       return false; 
	               }); 
					$(this).after("<div class='external'></div>"); */
					$(this).addClass("external");
	       } 

	});
	
	// Vertical Alignment of Home Page Promos
	jQuery(window).load(function() { 
	var top = ( ( $('#bottom #blog').height() - $('#bottom #promos').height() ) / 2 );
    $('#bottom #promos').css('margin-top', top);
	});

	// Last Child Class
	$("#gallerynav ul li:last-child").addClass('last-child');
	
	// Live Comment Preview
	var $comment = '';
	  $('#comment').keyup(function() {
	    $comment = $(this).val();
	    $comment = $comment.replace(/\n/g, "<br />").replace(/\n\n+/g, '<br />').replace(/(<\/?)script/g,"$1noscript");
		if ($comment != "") {
    		$('#comment-preview').html($comment);
		} else {
			$('#comment-preview').html('Your comment...');
		}
	  });
	var $commentname = 'You';
	  $('#name').keyup(function() {
	    $commentname = $(this).val();
			if ($commentname != "") {
	    		$('#comment-name').html($commentname);
			} else {
				$('#comment-name').html('You');
			}
	  });
	var $commentsite = '';
	  $('#site').keyup(function() {
	    $commentsite = $(this).val();
			 if ($commentsite != "http://") {
	    		$('#comment-name').html('<a href="' + $commentsite + '">' + $commentname + '</a>');
			 } else {
				$('#comment-name').html($commentname);
			}
	  });

	// Case Studies Cycle

	$('.shots').cycle({ 
	    fx:     	'scrollHorz', 
	    speed:   	300,
	    timeout: 	0,
		pager:  	'.inner-nav',
		next:  		'.next',
		prev:  		'.prev'
	});
	
	$("#casestudies .screenshot .inner-nav").adjustScreenCaptureNav();
	
	// Home Page cycle
	
	$('.panels').cycle({
	    speed:   	700,
	    timeout: 	9000,
		pause:      1,
		fastOnEvent: 100,
		fx: 		'fade',  
		after: 		updateSlideBG,
		cleartype:       !$.support.opacity,
		cleartypeNoBg:   true,
		pager:  	'#panel-tabs',
		pagerAnchorBuilder: function(idx, slide) { 
	        // return selector string for existing anchor 
	        return '#panel-tabs li:eq(' + idx + ') a'; 
	    }
	});
	
	$('#panel-tabs li a').click(function() {
		$('.panels').cycle('pause');
	});
	
	function updateSlideBG() {
		$('#panel-tabs').removeClass();
		$('#panel-tabs li#tab-web a.activeSlide').parent().parent().addClass('top');
		$('#panel-tabs li#tab-cloud a.activeSlide').parent().parent().addClass('middle');
		$('#panel-tabs li#tab-go a.activeSlide').parent().parent().addClass('bottom');
	}
	
});
