/* Javascript functionality for the Gillesv theme */

// stupid wordpress behaviour
$j = jQuery.noConflict();

$j(document).ready(function(){
	// searchform pretty-fication: 
	// use the label as the prompt
	label2value(".searchform");
	navigationActiveState();
	
	twttr.anywhere(function(twitter) {
		twitter.hovercards();
	});
	
	// anchor links
	$j("a.anchorLink").anchorAnimate();
});

this.label2value = function(formselector){	
	var inactive = "inactive";
	var active = "active";
	var focused = "focused";
	
	$j(formselector + " label").each(function(){		
		obj = document.getElementById($j(this).attr("for"));
		if(($j(obj).attr("type") == "text") || (obj.tagName.toLowerCase() == "textarea")){			
			$j(obj).addClass(inactive);			
			var text = $j(this).text();
			$j(this).addClass("hidden");			
			$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);		
				};				
			});				
		};	
	});		
};

this.navigationActiveState = function(){
	var location = window.location.toString();
	
	$j(".navigation a").each(function(i){
		var href = $j(this).attr("href").toString();
		
		//if(location.indexOf(href) >= 0)
		if(location == href)
			$j(this).addClass("active");
	});
}