var $j = jQuery.noConflict();

/*
 * label2value
 * jquery based script for using form labels as text field values
 * more info on http://cssglobe.com/post/1500/using-labels- 
 *
 * Copyright (c) 2008 Alen Grakalic (cssglobe.com)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 */
var inactive = "inactive";
var active = "active";
var focused = "focused";
var timespan = 200;

this.label2value = function(){
	
	// function
	$j("label").each(function(){
		obj = document.getElementById($j(this).attr("for"));
		
		if ( !$j(obj).val() || $j(obj).val() == "" ) {
		
			if(($j(obj).attr("type") == "text")){	
				$j(obj).addClass(inactive);			
				var text = $j(this).text();
				$j(this).css("display","none");
				$j(obj).val(text);
				$j(obj).focus(function(){
					$j(this).addClass(focused);
					$j(this).removeClass(inactive);
					$j(this).removeClass(active);
					if($j(this).val() == text) $j(this).val("");
				});
				$j(obj).blur(function(){
					$j(this).removeClass(focused);
					if($j(this).val() == "") {
						$j(this).val(text);
						$j(this).addClass(inactive);
					} else {
						$j(this).addClass(active);
					};
				});
			};
		
		} else {
			return;
		}
	});
};

this.clearInputs = function(){
	$j("form").submit(function() {
		$j("label").each(function(){
			var obj = document.getElementById($j(this).attr("for"));
			if($j(obj).hasClass(inactive)){
				$j(obj).val(null);
			}
		});
	});

	$j(window).unload( function () {
		$j("label").each(function(){
			var obj = document.getElementById($j(this).attr("for"));
			if($j(obj).hasClass(inactive)){
				$j(obj).val(null);
			}
		});
	});
};

$j(function() {
	label2value();
	clearInputs();
	
	$j("#crew_nav").animate({top: 0}, 200);

	$j('#crew_nav a').hover(
		function () {
			$j(this).find('span').css({'z-index' : 1000}).animate({opacity:1}, 200);
		},
		function () {
			$j(this).find('span').css({'z-index' : 1}).animate({opacity:0}, 200);
		}
	);
	
	$j('#carousel') 
		.after('<div id="controls">') 
		.cycle({ 
			fx: 'scrollHorz',
			speed: 300, 
			timeout: 10000, 
			pager: '#controls' 
	});
	
	$j("#gallery a").lightBox();
	
	reinitializeLightbox = function () {
		$j("#gallery a").lightBox();
	}
	
	$j(".tubepress_thumb a").click(function(event){
		event.preventDefault();
	});
	
	function showLoad() {
		$j("#gallery").unload().html("<img class='loading' src='/wordpress/wp-content/themes/doomtree/_/img/loader.gif' />");
	}
	
	$j("#photosets a").click(function(event){
	    var url = "/includes/phpFlickr/feed.php" + $j(this).attr("href");
		
		showLoad();
		$j("#gallery").load(url, '', reinitializeLightbox);
			
		event.preventDefault();
	});
	
	var which_element = ''
	if ($j.browser.webkit) {
		which_element = 'body';
	} else {
		which_element = 'html';
	}
	
	$j('#menu-item-4714 a').click(function(e){
	    e.preventDefault();
	    scrollPage($j(this), which_element);
	});
	
	$j('#menu-item-4715 a').click(function(e){
	    e.preventDefault();
	    scrollPage($j(this), which_element);
	});
	
});

function scrollPage(link_element, which_element){
    $j(which_element).animate({
			scrollTop: $j($j(link_element).attr('href')).offset().top
			}, timespan * 4, 'easeInOutQuint');
}
