//Define globals variables
var artibox;

// on document loaded
$(document).ready(function() {
  // Instantiate all artiboxes
  if (Artibox) artibox = new Artibox();
  artibox.scanLinks();
  //Call artibox  onLoad function if the content is loaded in iframe
  if ($('body').hasClass('lightbox')) {
	  artibox.hideParentIframeLoading();
	  artibox.setupLoadingElements(1);
	
  }	
	
  //set up autosubmit on languages form
  $('#language').change(function()
  {
    $('#formLanguageSelection').submit();
  });

  // manage focus / blur event on the login field
  if($('#signin_username').val()!=undefined)
  {
    var signin_username_def_val=$('#signin_username').val();
    $('#signin_username').focus(function()
    {
      if($('#signin_username').val()==signin_username_def_val)
      {
        $(this).val('');
      }
    });

    $('#signin_username').blur(function()
    {
      if($('#signin_username').val()=='')
      {
        $(this).val(signin_username_def_val);
      }
    });
  }

  // manage focus / blur event on the tiny search field
  if($('#TinySearchForm_keywords').val()!=undefined)
  {
    $('#TinySearchForm_keywords').focus(function()
    {
      if($('#TinySearchForm_keywords').val()==artilinki.options.tiny_keywords_def_val)
      {
        $(this).val('');
      }
    });

    $('#TinySearchForm_keywords').blur(function()
    {
      if($('#TinySearchForm_keywords').val()=='')
      {
        $(this).val(artilinki.options.tiny_keywords_def_val);
      }
    });

    if($('#TinySearchForm_keywords').val()=='')
    {
      $('#TinySearchForm_keywords').val(artilinki.options.tiny_keywords_def_val);
    }
  }

  //hide flash notice if existant
  if($('.actionOk').html()!=null)
  {
    setTimeout('$(\'.actionOk\').slideUp(600)', 4000);
  }


  //Launch the lives if its necessary
  if ($('.live').length > 0) {
    $(document).find('.live').each(function(i, val) {
	  $(i).artlive({elt: val, id: i});
    });
  }   
  
  //Setting up history back (forms) buttons
  //@TODO : Check if the action is already the same with the group
  $(document).find("input[type='reset'].historyBack").each(function(i, val) {
	  $(val).click(function() {
		  window.history.back(-1);
	  });
  });
});