// usage: log('inside coolFunc',this,arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  if(this.console){
    console.log( Array.prototype.slice.call(arguments) );
  }
};

function equalHeight(group) {
  var tallest = 0;
  group.each(function() {
    var thisHeight = $(this).height();
    if(thisHeight > tallest) {
      tallest = thisHeight;
    }
  });
  group.height(tallest);
}

$.fn.imagesLoaded = function( callback ){
  var elems = this.find( 'img' ),
    elems_src = [],
    len = elems.length;


  if ( !elems.length ) {
    callback.call( this );
    return this;
  }

  elems.one('load error', function() {
    if ( --len == 0 ) {
      // Rinse and repeat.
      len = elems.length;
      elems.one( 'load error', function() {
        if ( --len == 0 ) {
          callback.call( elems, this );
        }
      }).each(function() {
        this.src = elems_src.shift();
      });
    }
  }).each(function() {
    elems_src.push( this.src );
    // webkit hack from http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f
    // data uri bypasses webkit log warning (thx doug jones)
    this.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
  });

  return this;
};




jQuery(document).ready(function($) {
  //$("body").imagesLoaded(equalHeight($("#main .col .inside")))
  

   // $ refers to jQuery
  //$("select[name='archive_chrono'] option:first").remove();
   
  var s1 = $('#s1').cycle({ 
    timeout: 0,
    fx:     'scrollHorz'
  });
  
  var s2 = $('#s2').cycle({ 
    timeout: 0,
     fx:     'scrollHorz'
  });

  var s3_gallery = $('#s3_gallery').cycle({ 
    timeout: 4500,
    fx:     'scrollHorz'
  });
  
  var pagers =  $('#pager div');
  $('#pager a').each(function(i) {
      $(this).click(function() {
        pagers.removeClass('active');
        $(this).parents('div:first').addClass('active');
        s1.cycle(i);  
        s2.cycle(i);
        log(i);
        return false;
    });
  });

  $('.sub_menu>li').hover(function() {
      $(this).siblings().addClass("hide");
    }, function(){
      $('.sub_menu>li').removeClass("hide");
    }
  );
  /* --- lavalamp
  ============================================================================== */
  // $('.sub_menu').lavaLamp({
  //   fx: 'easeOutBack',  
  //   speed:500,
  //   selectedClassName: "current_page_item"
  // });
  // $('.sub_menu li').hover(
  //   function() {
  //     $('.sub_menu li').removeClass("inactive").removeClass("active");
  //     $(this).siblings().addClass("inactive");
  //     $(this).addClass('active');
  //   },
  //   function(){
  //     //$('.sub_menu li').removeClass("inactive");
  //   }
  // );
  // $('.sub_menu').hover(
  //   function() {
  //   },
  //   function(){
  //     $('.sub_menu li').removeClass("inactive").removeClass("active");;
  //   }
  // );
  
});

/* ============================================================================
--- Explorer Fixing
============================================================================== */
$(function() {
  if (window.PIE) {
    $('.inside_wrapper, .top_section, #promo_section, #header_inner').each(function() {
      PIE.attach(this);
    });
  }
});
