(function($){
//==================================================
// document load

$(function(){
	
	//==================================================
	// minimal input boxes
	
	$.fn.mininput = function(options){
		
		this.closest('form').submit(function(){
			$(this).find('input.defaulted').val('');
			});
		
		return this.each(function(){
			
			var $this = $(this);
			
			// handle label
			$this.data('label',$this.attr('title')).removeAttr('title');
			
			// events
			$this.blur(function(){
				var $this = $(this);
				if (!$this.val() || $this.val()==$this.data('label')){
					$this.val($this.data('label')).addClass('defaulted');
					}
				else{
					$this.attr('type',$this.data('otype'));
					}
				});
			$this.focus(function(){
				var $this = $(this).removeClass('defaulted');
				if ($this.val()==$this.data('label')){
					$this.val('');
					}
				});
				
			// blur element
			$this.blur();
			
			});
		
		}
	
	//==================================================
	// subscribe form
	
	// hide labels
	$('#subscribe p.field:not(.datatypeMultiSelectMany) label').hide();
	
	// remove brs
	$('#subscribe div.basic-fields br').remove();
	$('#subscribe div.custom-fields p.field:not(.datatypeMultiSelectMany) br').remove();
	
	// mininput
	$('#subscribe input:text').mininput();
	
	// if the subscribe form exists, hide extra fields
	var $customfields = $('#subscribe div.custom-fields')
		.hide()
		.each(function(){
			
			// get this and style
			var $this = $(this)
				.css({
					overflow: 'hidden'
					});
			
			// get container height
			var expandedHeight = $this.height();
			
			// hide container
			$this.height(0);
			
			// add the reveal button
			var $reveal = $('<p class="more"><a href="#">more +</a></p>')
				.insertBefore($this);
			
			// click handling
			var $a = $reveal
				.find('a')
				.click(function(){
					
					// blur a
					$a.blur();
					
					if ($reveal.hasClass('more')){
						
						// show the container
						$this.stop().animate({height:expandedHeight},{duration:300});
						
						// switch more to less
						$reveal.removeClass('more').addClass('less');
						$a.html('less -');
						
						}
					else{
						
						// hide the container
						$this.stop().animate({height:0},{duration:300});
						
						// switch more to less
						$reveal.removeClass('less').addClass('more');
						$a.html('more +');
						
						}
					
					// return false
					return false;
					
					});
			
			});
	
	//==================================================
	// fancybox
	
	$('a.flickr-photo').fancybox();
			
	//==================================================
	
	});

//==================================================
})(jQuery);;
