$.fn.exists = function(){return $(this).length>0;}

/* BEHAVIORS---------------------------------------------------------- */

$.fn.uiInput = function(mode)
{
	var mode = (!mode) ? 0 : mode;
	
	if(mode == 0)
	{
		$(' input, textarea',this).focus(function(){ if( $(this).val() == '' ) $(' + label',this).css('opacity',.5); });
		$(' input, textarea',this).blur(function(){  if( $(this).val() == '' ) $(' + label',this).css('opacity',1).fadeIn(300); });
		$(' input, textarea',this).keyup(function(){ if( $(this).val() == '' ){ $(' + label',this).fadeIn(300); } else { $(' + label',this).hide(); } });
		
		$(this).each(function(){ if( $(' input, textarea',this).val() != '' ){ $(' label',this).hide(); }	});
	}
	else if(mode == 1)
	{
		$(' input, textarea, select',this).css({marginTop:'20px',marginBottom:'20px'});
		$(' label',this).css({left:'1px',top:0,fontWeight:'bold',color:'#555'}).show();
	}
	else if(mode == 2)
	{
		$(' label',this).show();
	}
}

$.fn.uiDropdown = function()
{
	$(' .uiDropdownButton',this).click(function()
	{
		// hide visible menues, show requested
		
		$('.uiDropdownMenuWrapper').hide();
		$(' + .uiDropdownMenuWrapper',this).show();
		
		// return false to prevent default html,body click event.
		
		return false;
	});
	
	bindDocHides();
}

// uiDropdown Helpers
function bindDocHides()  { $('html,body').bind('click',function(){ $('.uiDropdownMenuWrapper').hide(); }); }
function unbindDocHides(){ $('html,body').unbind('click'); }
$.fn.bindSticky = function(){ $(this).hover( 
	function(){ unbindDocHides(); },
	function(){	bindDocHides(); });
}

function gaucho_makeMail()
{
	var val = '';
	
	$('.mkml').each(function()
	{
		val = $(this).text();
		val = val.split('::');
		$(this).html('<a href="mailto:'+val[0]+'@'+val[1]+'.'+val[2]+'">'+val[0]+'@'+val[1]+'.'+val[2]+'</a>');	
	});
}

if( GAUCHO_ENVIRONMENT == 'development' )
{	
	$("html,body").keypress(function(event)
	{
  		if( event.which == 71 )
		{
			if( $(".container_12").hasClass("show_grid") )
			{
				$(".container_12").removeClass("show_grid");
			}
			else
			{
				$(".container_12").addClass("show_grid");
			}		
   		}
	});
}


