function initLettersScroller() {

  document.lettersScroller = new UI.Carousel("boxMenuLetters");

}

function updateProjectsPage(event) {

  if (event.memo.carousel.id != 'projectsMainScroller') return document.currentProjectsPage;
  
  switch (document.pageAction)
  {
    case '+':
    document.currentProjectsPage = document.currentProjectsPage + 1;
    break;

    case '-':
    document.currentProjectsPage = document.currentProjectsPage - 1;
    break;

    case '|':
    break;
  }

  $('currentProjectPage').innerHTML = document.currentProjectsPage;

  return document.currentProjectsPage;
}

function test() {
  	alert('scroll end');
}

function initProjectsScroller() {

  document.currentProjectsPage = 1;
  
  document.projectsScroller = new UI.Carousel("projectsMainScroller", {direction: 'vertical', nextButton: '.next_project_page', previousButton: '.previous_project_page', container: '.projectsContainer'});

  document.projectsScroller.observe('scroll:ended', updateProjectsPage);
}

function initProjectProductsScroller() {

  document.projectProductScroller = new UI.Carousel("boxProductsScroller", {direction: 'horizontal', nextButton: '.arrowRightFilmStrip', previousButton: '.arrowLeftFilmStrip', container: '.container'});

}

function initImagesProjectScroller() {

  document.imagesProjectScroller = new UI.Carousel("boxImagesProjectScroller", {direction: 'horizontal', nextButton: '.arrowRightProduct', previousButton: '.arrowLeftProduct', container: '.container'});

}

function initProjectProductsScrollerAAlessi() {

  document.projectProductScroller = new UI.Carousel("boxProductsScrollerAAlessi", {direction: 'horizontal', nextButton: '.rightArrowNavSmallProduct', previousButton: '.leftArrowNavSmallProduct', container: '.container'});

}

function initImagesProjectScrollerAAlessi() {

  document.imagesProjectScroller = new UI.Carousel("boxImagesProjectScrollerAAlessi", {direction: 'horizontal', nextButton: '.rightArrowNavProduct', previousButton: '.leftArrowNavProduct', container: '.container'});

}

function initProjectProductsScrollerOffAlessi() {

  document.projectProductScroller = new UI.Carousel("boxProducts", {direction: 'horizontal', nextButton: '.next_button', previousButton: '.previous_button', container: '.container'});

}

function initProjectDesignersScrollerOffAlessi() {

  document.projectDesignerScroller = new UI.Carousel("boxDesignersScroller", {direction: 'vertical', nextButton: '.next_button', previousButton: '.previous_button', container: '.container'});

}

function initImagesProjectScrollerOffAlessi() {

  document.imagesProjectScroller = new UI.Carousel("boxImages", {direction: 'horizontal', nextButton: '.next_button', previousButton: '.previous_button', container: '.container'});

}

function initCategoryProductsScrollerOffAlessi() {

  document.categoryProductsScroller = new UI.Carousel("boxCategoryProducts", {direction: 'horizontal', nextButton: '.next_button', previousButton: '.previous_button', container: '.container'});

}
function initBrandProductsScrollerOffAlessi() {

  document.brandProductsScroller = new UI.Carousel("boxBrandProducts", {direction: 'horizontal', nextButton: '.next_button', previousButton: '.previous_button', container: '.container'});

}

function initDesignerProductsScrollerOffAlessi() {

  document.designerProductsScroller = new UI.Carousel("boxDesignerProducts", {direction: 'horizontal', nextButton: '.next_button', previousButton: '.previous_button', container: '.container'});

}

function initCategoryProductsScrollerAAlessi() {

  document.categoryProductsScroller = new UI.Carousel("boxProductsAAlessi", {direction: 'horizontal', nextButton: '.next_button', previousButton: '.previous_button', container: '.container'});

}

function initDesignerProductsScrollerAAlessi() {

  document.designerProductsScroller = new UI.Carousel("boxDesignerProducts", {direction: 'horizontal', nextButton: '.next_button', previousButton: '.previous_button', container: '.container'});

}

function initSimilarProductsScrollerAAlessi() {

  document.designerProductsScroller = new UI.Carousel("boxSimilarProducts", {direction: 'horizontal', nextButton: '.next_button', previousButton: '.previous_button', container: '.container'});

}

function initBrandProductsScrollerAAlessi() {

  document.designerProductsScroller = new UI.Carousel("boxBrandProducts", {direction: 'horizontal', nextButton: '.next_button', previousButton: '.previous_button', container: '.container'});

}

function initProjectProductsScrollerAlessi() {

  document.projectProductsScroller = new UI.Carousel("boxProjectProducts", {direction: 'horizontal', nextButton: '.next_button', previousButton: '.previous_button', container: '.container'});

}

function initDesignerProductsScroller() {

  document.designerProductsScroller = new UI.Carousel("boxDesignerProductsScroller", {direction: 'horizontal', nextButton: '.next_button', previousButton: '.previous_button', container: '.container'});

}


function openTab(defaultTab, openTab, inactiveButtonClass, activeButtonClass) {

  if (document.boxToClose == null) document.boxToClose = defaultTab;

  if (document.boxToClose != openTab) $(document.boxToClose).hide();

  $(openTab).show(); $(document.boxToClose+'Tab').className = inactiveButtonClass;

  $(openTab + 'Tab').className = activeButtonClass;

  document.boxToClose=openTab;

  return false;

}

/**
  * Dialog Box
  * http://www.itgens.cn/snippets/show/3629
  *
  * Usage:
  * new Dialog.Box([element ID]);
  * $([element ID]).show();
  * $([element ID]).hide();
  */
var Dialog = {};
Dialog.Box = Class.create();
Object.extend(Dialog.Box.prototype, {
  initialize: function(id) {
    this.createOverlay();

    this.dialog_box = $(id);

    this.dialog_box.style.position = "absolute";
    this.dialog_box.style.zIndex = this.overlay.style.zIndex + 1;

    this.dialog_box.show = this.show.bind(this);
    this.dialog_box.hide = this.hide.bind(this);

    this.parent_element = this.dialog_box.parentNode;

    var e_dims = Element.getDimensions(this.dialog_box);
    var b_dims = Element.getDimensions(this.overlay);
    this.dialog_box.style.left = ((b_dims.width/2) - (e_dims.width/2)) + 'px';
    this.dialog_box.style.top = ((b_dims.height/2) - (e_dims.height/2)) + 'px';

  },

  createOverlay: function() {
    if($('dialog_overlay')) {
      this.overlay = $('dialog_overlay');
    } else {
      this.overlay = document.createElement('div');
      this.overlay.id = 'dialog_overlay';
      Object.extend(this.overlay.style, {
        position: 'absolute',
        top: 0,
        left: 0,
        zIndex: 90,
        width: '100%',
        backgroundColor: '#000',
        display: 'none'
      });
      document.body.insertBefore(this.overlay, document.body.childNodes[0]);
    }
  },

  moveDialogBox: function(where) {
    Element.remove(this.dialog_box);
    if(where == 'back')
      this.dialog_box = this.parent_element.appendChild(this.dialog_box);
    else
      this.dialog_box = this.overlay.parentNode.insertBefore(this.dialog_box, this.overlay);
  },

  winWidth: function() { return document.body.offsetWidth || window.innerWidth || document.documentElement.clientWidth || 0; },
  winHeight: function() { return document.body.offsetHeight || window.innerHeight || document.documentElement.clientHeight || 0; },
  
  show: function() {
    this.overlay.style.height = this.winHeight() + 'px';
    var e_dims = Element.getDimensions(this.dialog_box);
    var b_dims = Element.getDimensions(this.overlay);
    this.dialog_box.style.left = ((b_dims.width/2) - (e_dims.width/2)) + 'px';
    this.dialog_box.style.top = ((document.viewport.getHeight()/2) - (e_dims.height/2)) + document.viewport.getScrollOffsets().top + 'px';
    this.moveDialogBox('out');
    this.overlay.onclick = this.hide.bind(this);
    this.selectBoxes('hide');
    new Effect.Appear(this.overlay, {duration: 0.5, from: 0.0, to: 0.4});
    this.dialog_box.style.display = '';
  },

  hide: function() {
    this.selectBoxes('show');
    new Effect.Fade(this.overlay, {duration: 0.1});
    this.dialog_box.style.display = 'none';
    this.moveDialogBox('back');
    $A(this.dialog_box.getElementsByTagName('input')).each(function(e){if(e.type!='submit')e.value=''});
  },

  selectBoxes: function(what) {
    $A(document.getElementsByTagName('select')).each(function(select) {
      Element[what](select);
    });

    if(what == 'hide')
      $A(this.dialog_box.getElementsByTagName('select')).each(function(select){Element.show(select)})
  }
});
/**
  * Fine Dialog Box
  *
  */

/**
  *  inverte la visibilita� di un oggetto
  *  Utilizzata da yav
  *
  */
function toggle(obj) {
    var el = this.$(obj);
    if ( el.style.display != 'none' ) {
        el.style.display = 'none';
    }
    else {
        el.style.display = '';
    }
    
}


