// 
//  actions.js
//  sfMagasins
//  
//  Created by Pierre Marichez on 2009-08-18.
//  Copyright 2009 D'Oh. All rights reserved.
// 

$(document).ready(function() {
  $('.ose').each(function(i)
  {
    var id = $(this).attr('id');
    href = window.atob(id);

    href = href.substr(4);
    href = href.slice(0, -1);
    $(this).replaceWith('<a href="' + href + '" class="' + $(this).attr('class') + '">' + $(this).html() + '</a>');
  });

  $('#content a.ajax_link').click(function()
  {
    var href = $(this).attr('href');
    var target = href.substring(href.lastIndexOf('#'), href.length);
    if ($(target))
    {
      $(target).html('<img src="/images/icons/loadingAnimation.gif" alt="..." />');
    }
    $.ajax({
      type: 'post',
      url: href,
      success: function(msg)
      {
        if ($(target))
        {
          $(target).html(msg).show('slow');
        }
      }
    });
    return false;
  });

  $('#content a.close_link').click(function()
  {
    var href = $(this).attr('href');
    var target = href.substring(href.lastIndexOf('#'), href.length);
    if ($(target))
    {
      $(target).hide();
    }
    return false;
  });

  $('#page .sub-menu')
  .mouseover(function(){
    $(this).children('ul').css("display", "block")
  })
  .mouseout(function(){
    $(this).children('ul').css("display", "none")
  });

  $('#header input').focus(function() {
    if( this.value == this.defaultValue ) {
      this.value = '';
    }
  }).blur(function() {
    if( !this.value.length ) {
      this.value = this.defaultValue;
    }
  });

  $('#content a.blank').click(function()
    {
      window.open(this.href);
      return false;
    }
  );

  $('#casing td.col').css('height', $('#col').height());
  $('#casing td.col').attr('target', '_blank');

  $("#content a#single_image").fancybox();
  $("#content a#inline").fancybox({
    'hideOnContentClick': true
  });
  $("#content a.group").fancybox({
    'transitionIn'	:	'elastic',
    'transitionOut'	:	'elastic',
    'speedIn'		:	600, 
    'speedOut'		:	200, 
    'overlayShow'	:	false
  });

});
