/*
 *
 * Olivier & Co
 * 
 * */

jQuery(document).ready(function($) {

 $('button.button span span span').dropShadow({
  left: 0,
  top: 0,
  blur: 1
 });

 $('#add_recipient_button button').click(function() {
  redrawShadow('button.button span span span');
 });


 /*$("#categories-left").accordion({
  active:false,
  autoHeight:false,
  navigation: true,
  header: '.head'
 });

 $("#categories-left .level0.active ul").css('display', 'block');
 $(".catalog-product-view #categories-left").accordion('activate', '.level0.active .head');*/

});

function redrawShadow(el) {
 jQuery(document).ready(function($) {
  $(el).redrawShadow();
 });
}

function displayPane(idToDisplay) {
 var paneToDisplay = '#pane-' + idToDisplay;
 var tabToActivate = '#tab-' + idToDisplay;
 jQuery(document).ready(function($) {
  $('.product-collateral .panes .pane').css('display', 'none');
  $('.product-collateral .tab').removeClass('active');
  $(tabToActivate).addClass('active');
  $(paneToDisplay).css('display', 'block');
  $('button.button span span span').redrawShadow();
 });
}

function changeQty(areaToUpdate, minqty, qty) {
 idToUpdate = document.getElementById(areaToUpdate);
 newValue = Number(idToUpdate.value) + qty;
 if(newValue >= minqty) {
  idToUpdate.value = Number(idToUpdate.value) + qty;
 }
}

function changeCartQty(areaToUpdate, minqty, qty, skinUrl) {
 idToUpdate = document.getElementById(areaToUpdate);
 oldValue = Number(idToUpdate.value)
 changeQty(areaToUpdate, minqty, qty);
 newValue = Number(idToUpdate.value);
 if(newValue != oldValue) {
  document.cart.submit();
  fakeAjaxCart(skinUrl);
 }
}

function fakeAjaxCart(skinUrl) {
 var ajaxLoader = skinUrl + 'images/ajax-loader.gif';
 var htmlStr = '<img style="position: absolute; top: 50%; left: 50%; margin-top: -16px; margin-left: -16px" src="' + ajaxLoader + '" />';
 var cartTableHeight = $('cart-table').getHeight() + 5 + 'px';
 $('cart-table').addClassName('cart-loading');
 $('cart-table').setStyle({
  height: cartTableHeight
 });
 $('cart-table').update(htmlStr);
}

function updateBoutiques(siteUrl, skinUrl, type, id) {
 jQuery(document).ready(function($) {

  var ajaxLoader = skinUrl + 'images/ajax-loader.gif';
  var htmlStr = '<img style="position: absolute; top: 50%; left: 50%; margin-top: -16px; margin-left: -16px" src="' + ajaxLoader + '" />';
    $('.boutiques-area').css('display', 'block');
      $('#boutiquesArea').css('position', 'relative');
    $('#boutiquesArea').css('height', '100px');
  $('#boutiquesArea').html(htmlStr);
  redrawShadow('button.button span span span');

  var link = siteUrl + 'boutiques/index/display?type=' + type + '&id=' + id;
  $.ajax({
   url: link,
   success: function(data) {
    var htmlStr = data;
    $('#boutiquesArea').html(htmlStr);
    $("a[rel='seemap']").colorbox({
     maxHeight: 650,
     scalePhotos: true,
     title: "&nbsp;",
     current: ""
    });
    if(data == '') {
     $('.boutiques-area').css('display', 'none');
    }
    if(type == 'france') {
     document.getElementById('selector-worldwide').selectedIndex = 0;
     $.jNice.SelectUpdate('#selector-worldwide');
    }
    if(type == 'worldwide') {
     document.getElementById('selector-france').selectedIndex = 0;
     $.jNice.SelectUpdate('#selector-france');
    }
    redrawShadow('button.button span span span');
   }
  });
 });
}
