function preloadImage (image) {
  var newImgPreloader = new Image();
  newImgPreloader.src = image;
}

var CURRENT_PROJECT = 0;

var ChangeProject = Class.create();
ChangeProject.prototype = {
	initialize: function() {
	  this.current = 0;
  },
  
  change: function( key) {
    if( key == this.current) {
       return false;
    } else {
      $( 'project_' + this.current).hide();
      Effect.Appear('project_' + key, {duration: .2});
      this.current = key;
    }
  },
  
  reset: function() {
    this.current = 0;
  }
}
function change_project( key)
{
  if( key == CURRENT_PROJECT) {
    return false;
  }
  if( $( 'project_' + CURRENT_PROJECT))
  {
    $( 'project_' + CURRENT_PROJECT).hide();
    Effect.Appear('project_' + key, {duration: .2});
    CURRENT_PROJECT = key;
  }
}

function changeStyle (path, current) {
  els = $$( path);
  for (var i=0; i < els.length; i++) {
    Element.removeClassName( els[i], 'current');      
  };
  Element.addClassName( current, 'current');
}

function acordeon(e) {
   if( $('archive_ul').style.display == 'none') {
     new Effect.Appear( 'archive_ul', {duration: .3});
     new Effect.BlindDown( 'archive_ul', {duration: .3});
     var offsets = $('archive').positionedOffset();
     $('archive').style.top = offsets[1];
     $('archive').originalTop = offsets[1];
     $('archive').style.position = 'absolute';
     // new Effect.Move( 'archive', {x:0, y:0, mode: 'absolute', duration: .2})
     Element.addClassName( e, 'open');
   } else {
     Element.removeClassName( e, 'open');
     new Effect.Fade( 'archive_ul', {duration: .3});
     new Effect.BlindUp( 'archive_ul', {duration: .3});
     yPos = $('archive').originalTop;
     // new Effect.Move( 'archive', {x:0, y:yPos, mode: 'absolute', duration: .2});
   }
 }
 
 
 
var CarouselManagement = Class.create();
CarouselManagement.prototype = {
	initialize: function() {
	  Event.observe( 'shower_thumbs', 'mouseover', this.showCarousel.bindAsEventListener( this), false);
    this.startShow = false;
    this.showCarousel();
    Event.observe( 'horizontal_carousel', 'mouseover', this.initEvents.bindAsEventListener( this), false);
  },
  
  initEvents: function() {
    Event.observe( 'slide_canvas', 'mouseover', this.hideCarousel.bindAsEventListener( this), false);
    Event.stopObserving( 'horizontal_carousel', 'mouseover');
  },
  
  moveIn: function() {
    new Effect.Move( 'horizontal_carousel', { x: 0, y: 0, mode: 'absolute', duration: .3 });    
  },
  
  showCarousel: function() {
    if( !this.startShow) {
      this.startShow = true;
      this.moveIn();
      Element.addClassName( 'shower_thumbs', 'shower_thumbs_off');
    }
    // $('shower_thumbs').stopObserving( 'mouseover');
    // Event.observe( 'ref_thumbs', 'mouseout', this.hideCarousel.bindAsEventListener( this), false, false)    
  },
  
  hideCarousel: function() {
    if( !this.startShow) {
      return false;
    }
    new Effect.Move( 'horizontal_carousel', { x: 0, y: 42, mode: 'absolute', duration: .4, afterFinish: this.setStart() }); 
    Element.removeClassName( 'shower_thumbs', 'shower_thumbs_off');
  },
  
  setStart: function() {
    this.startShow = false;
    new Effect.Appear( 'shower_thumbs', { duration: .1 });
  }
}


function customer_toggle( id) {
  var els = $$('#customers_list ul ul');
  for (var i=0; i < els.length; i++) {
    els[i].hide();
  };
  new Effect.Appear( id, 'slide', { duration: .2 })
  new Effect.BlindDown( id, {duration: .2});
}

function show_magnifize( id) {
  var els = $$('#magnifize a');
  for (var i=0; i < els.length; i++) {
    els[i].hide();
  };
  if( $('magnifize_' + id))
    $('magnifize_' + id).show();
}
