$(function()
{
  $('#btfav').click(function() 
  {
    if (window.sidebar) 
    {
      window.sidebar.addPanel(document.title, location.href , "");
    } 
    else if(window.external) 
    {
      window.external.AddFavorite(location.href, document.title); 
    }
    return false;
  });
  
  /****** IMAGENS AMBIENTE ********/
  $('#imgAmbContainer').cycle(
  { 
    fx:                 'fade', 
    timeout:            5000,
    speed:              2500
  });  
  
  /********* LOGIN **********/
  var login_usr=$("#input_username").val();
  $("#input_username").focus(function()
  {
    if($(this).val()==login_usr)
      $(this).val('');
  });
  $("#input_username").blur(function()
  {
    if($(this).val()=='')
      $(this).val(login_usr);
  });
  
  $("#input_password").focus(function(){$(this).val('');});
  
  
  $('#menu_principal').menuBox();
  
  
  var newsletter=$("#inputNewsletter").val();
  $("#inputNewsletter").focus(function()
  {
    if($(this).val()==newsletter)
      $(this).val('');
  });
  $("#inputNewsletter").blur(function()
  {
    if($(this).val()=='')
      $(this).val(newsletter);
  });
  
    var input=[];
	$('input[type=text],input[type=password]').each(function(){
		input[$(this).attr('id')]=$(this).val();
	});
	
	$('input[type=text],input[type=password]').focus(function(){						
		if($(this).attr('readonly')==false && $(this).val()==input[$(this).attr('id')]){
			$(this).val('');
		}		
	});
	
	$('input[type=text],input[type=password]').blur(function(){
		if($(this).attr('readonly')==false && $(this).val()==''){
			$(this).val(input[$(this).attr('id')]);
		}
	});

  //------ FORM SUBMIT'S
  $("form").submit(function(){
      if($(this).attr('method')=='get'){
          $(this).find('select').each(function(){
          if($(this).children('option:selected').val()==0)
              $(this).attr('disabled','disabled');
          });
          $(this).find('input[type=text]').each(function(){
              if($(this).val()=='' || $(this).val()==input[$(this).attr('id')])
                  $(this).attr('disabled','disabled');
          });
      }        
  });

}); 
