/* ------------------------------------------------------------------------
	Document ready stuff
------------------------------------------------------------------------- */

	$(function(){
		contributors.init();
		
		input_focus.init();
	});
	

/* ------------------------------------------------------------------------
	Contributors: Used to slide the contributors lists
------------------------------------------------------------------------- */

	contributors = {
		init : function(){
			maxHeight = 0;
			currentPage = 0;
			totalPage = $('#contributors li').size();
			$('#contributors li').each(function(i){ // Find the highest LI and position absolute
				$(this).width($('#contributors').width() - 20);
				
				maxHeight = ($(this).height() > maxHeight) ? $(this).height() : maxHeight;

				$(this).css({
					'position': 'absolute',
					'left': $(this).width() * i + 20
				});
			});

			// Set the list AND nav buttons height
			$('#contributors, #contributors li').height(maxHeight);
			if($('body').hasClass('home')) $('#contributors #left-arrow, #contributors #right-arrow').height(maxHeight);

			// Bind the clicks
			$('#contributors #left-arrow').bind('click',function(){
				contributors.changePage('previous');
			});

			$('#contributors #right-arrow').bind('click',function(){
				contributors.changePage('next');
			});
			
			if($.browser.msie && $.browser.version == 6 ) DD_belatedPNG.fix('#contributors #left-arrow, #contributors #right-arrow');
		},
		changePage : function(direction) {
			itemWidth = $('#contributors li:first').width();

			if(direction=='next'){
				currentPage ++;
				direction = -1;

				if(currentPage > totalPage-1){
					currentPage = 0;
				}
			}else if(direction=='previous'){
				currentPage --;
				direction = 1;

				if(currentPage < 0){
					direction = -1; // Invert the direction to go to the last page
					currentPage = totalPage - 1;
				}
			}else{
				desiredpage = direction; // cache the desired page
				if(currentPage < direction){
					direction = 1;
				}else{
					direction = 1;
				}

				currentPage = desiredpage;
			}

			// Slide the pages, logic ++
			$('#contributors li').each(function(i){
				$(this).animate({
					'left': (i * itemWidth) - (itemWidth * currentPage) + 20
				});
			});
		}
	}
	

/* ------------------------------------------------------------------------
	input_focus: Used to remove the current text on input focus
------------------------------------------------------------------------- */

	input_focus = {
		init : function(){			
			$('input[rel*=search], #email').each(function(){
				var default_val;
				$(this).focus(function(){
					// Save the default value upon first click
					if(typeof default_val == "undefined") default_val = $(this).val();

					// If the current value is the default, empty the field
					if($(this).val() == default_val) $(this).val('');
				});

				$(this).blur(function(){
					if($(this).val() == '') {
						$(this).val(default_val);
					}
				});
			});
		}
	}