$(document).ready(function(){
	
	//focus clear fields
	$('.default').each(function(){
		$(this).css({'color' : '#999'});
		var _default = $(this)[0].defaultValue;//document.getElementById($(this).attr('id')).defaultValue;
		$(this).focus(function(){
			$(this).css({'color' : '#000'});
			if($(this).val() == _default){
				$(this).val('');	
			}
		});
		$(this).blur(function(){
			if($(this).val() == ''){
				$(this).val(_default);	
				$(this).css({'color' : '#999'});
			}
		});						
	});
	//end of clear focus
	
	
	//textarea simple autoexpand
	/*$('textarea').each(function(){
		$(this).css({overflow: 'hidden'});
		$(this).each(function(){
			if($(this)[0].scrollHeight > $(this).height())	$(this).css({height: $(this)[0].scrollHeight + 10});
		});
		$(this).keyup(expandTextarea);
	});
	
	function expandTextarea(){
		if($(this)[0].scrollHeight > $(this).height()){
			$(this).animate({height: $(this)[0].scrollHeight + 10}, {duration:200, queue:false});
		}
	}*/
	
	(function($) {
		/* Auto-growing textareas; technique ripped from Facebook */
		$.fn.autogrow = function(options) {
			this.filter('textarea').each(function() {
				
				var $this       = $(this),
					minHeight   = $this.height(),
					lineHeight  = $this.css('lineHeight');
				
				var shadow = $('<div></div>').css({
					position:   'absolute',
					top:        -10000,
					left:       -10000,
					width:      $(this).width(),
					fontSize:   $this.css('fontSize'),
					fontFamily: $this.css('fontFamily'),
					lineHeight: $this.css('lineHeight'),
					resize:     'none'
				}).appendTo(document.body);
				
				var update = function() {
					
					var val = this.value.replace(/</g, '&lt;')
										.replace(/>/g, '&gt;')
										.replace(/&/g, '&amp;')
										.replace(/\n/g, '<br/>');
					
					shadow.html(val);
					$(this).css('height', Math.max(shadow.height() + 20, minHeight));
				}
				
				$(this).change(update).keyup(update).keydown(update);
				
				update.apply(this);
				
			});
			return this;
			}   
		})(jQuery);
	$('textarea').autogrow();
	//end of autoexpand
	

	//generic toggler
	$('.toggler').each(function(){
		$('.toggler').next().hide();
	});
	$('.toggler').click(function(){	
		var _h = parseInt($(this).next().css('height'));//height();
		if(_h > 0 || _h == NaN){
			$(this).removeClass('selected');
		}else{
			$(this).addClass('selected');
		}
		$(this).next().animate({height: 'toggle', opacity: 1}, 300);
		if($(this).children('a').text() == '[-]'){
			$(this).children('a').text('[+]');
		}else{
			$(this).children('a').text('[-]');
		}
		return false;
	});
	$('.toggler_close').click(function(){
		obj = $(this);
		while($(obj).prev('.toggler').length == 0){
			obj = $(obj).parent();	
		}
		$(obj).prev().trigger('click');
		return false;
	});
	//end of generic toggler
	
	
	//simple alert
	$(".alert").animate({opacity: 1}, 5000).animate({opacity: 0 }, {duration: 600, easing: 'easeInQuad'}).animate({height: 0, paddingTop: 0, paddingBottom: 0, borderWidth: 0, marginBottom: 0, marginTop: 0}, {duration: 500, easing: 'easeInQuad', complete: 
		function(){$(this).remove();}
	});
	//end of alert
	
	
	// added jquery functions
	String.prototype.rot13 = function rot13() {
		return this.toString().replace(/[a-zA-Z]/g, function(ch) {
			return String.fromCharCode((ch <= "Z" ? 90 : 122) >= (ch = ch.charCodeAt(0) + 13) ? ch : ch - 26);
		});
	}
	//end of addtions
	

	//decode rot13 emails - helps prevent bots from reading
	$('.email-rot13').each(function(){
		$(this).text($(this).text().rot13());	
		$(this).attr('href', "mailto:" + $(this).text());
	});
	//end of decode rot13
	
	//homepage video area
	$("#home a[rel^='vid'], #videos a[rel^='vid']").prettyPhoto({
		animationSpeed: 'fast', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: .8, /* Value betwee 0 and 1 */
		showTitle: false, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'dark_square' /* light_rounded / dark_rounded / light_square / dark_square */
	});
	
	$('#home #videos>div').mouseover(function(){
		if($(this).hasClass('active')){
			//do nothing for now
		}else{
			$('#videos>div.active').removeClass('active'); 
			$(this).addClass('active');
		}
		return false;
	});
	//end of video area
});