/**
 * Base JS
 *
 * @author Hanzo - http://www.hanzo.es
 */

/*
 * Init Cufon replacement
 */
jQuery.cufon = function() { 
  return {
    init: function (selectors, options, fontName) {
      if (!options) var options = new Object;
      if (!fontName) var fontName = "Helvetica Neue";
      $(selectors).each(function() {                
        var selector = '#' + $(this).parents('*[id]').eq(0).attr('id') + ' ' + this.tagName+(($(this).attr('id'))? '#'+$(this).attr('id') : '')+(($(this).attr('class'))? '.'+$(this).attr('class').replace(/ /g, '.') : '');
        
        /* Use the font-family which is set in CSS, Cufon 1.03 doesn't read it natively -- fontName is set to fix an Opera bug */
        options.fontFamily = $(this).css('font-family') != null ? $(this).css('font-family') : fontName;               
        
        Cufon.replace (selector, options);
      });
    }
  }
}();

$(document).ready(function() {
  
  /* Background management */
  var random = Math.floor(Math.random() * 4) + 1;
  
  $('body').append('<div id="body_background"><img src="#" /></div>');
  $('#body_background img').attr('src', 'graphic/common/hanzo_bg_0' + random  + '.jpg');
  $('#body_background img').load(function() { 
    $('#body_background').ezBgResize();
  });
  
  $('#body_background').ezBgResize();
  $('#body_background').show();
  
  /* Cufon call */
  jQuery.cufon.init('p.who_we_are span');

});

$(window).bind("resize", function(){
  $("#body_background").ezBgResize();
});
