$().ready(function() {
	$("#commentForm").validate();
	$("#contactForm").validate();
	labelToInput.init();	
	Popin.init();
	jQuery("a[rel='works']").colorbox();
	
	$('a.fadeThis').hover(
		function() {
			$(this).find('span').fadeIn();
			$(this).data('title', $(this).attr('title')).attr('title', '');
		},
	    function()
	    {
			$(this).find('span').fadeOut();
			$(this).attr('title', $(this).data('title'));
	    }
	);

});

var labelToInput = {

	init: function() {
	
		jQuery('.labelvalue').each(function(){
			jQuery(this).css("display","none");
			var txt = jQuery(this).text();
			var chpsTxt = jQuery(this).next(':input');
			
			if(chpsTxt.attr('type') == "text") {
				chpsTxt.val(txt);
				chpsTxt.focus(function(e){if(jQuery(e.target).val() == txt) jQuery(e.target).val('')});
				chpsTxt.blur(function(e){if(jQuery(e.target).val() == '') jQuery(e.target).val(txt)});
			}
			else if(chpsTxt.attr('type') == "password") {
				var newInput = jQuery('<input type="text" />');
				jQuery(newInput).attr('class',chpsTxt.attr('class'))
				jQuery(newInput).attr('id',chpsTxt.attr('id'));
				jQuery(newInput).val(txt);
			
				var oldInput = chpsTxt.clone();
				jQuery(chpsTxt).replaceWith(newInput);
				newInput.focus(function(e){ jQuery(e.target).replaceWith(oldInput); oldInput.focus();});
			}
			else
			{
				chpsTxt.val(txt);
				chpsTxt.focus(function(e){if(jQuery(e.target).val() == txt) jQuery(e.target).val('')});
				chpsTxt.blur(function(e){if(jQuery(e.target).val() == '') jQuery(e.target).val(txt)});
			}
		
		});
		
	}

}

var Popin = {

	    init: function()
	    {	
			jQuery('.messages').each( function(elmt) {
				jQuery('#filter').show();
				
				jQuery('#filter').click(function(){
					jQuery('#filter').hide();
			    	jQuery('.messages').hide();
			    	location.href = 'http://www.crazy-link.com'
				});
			});
	    }
}