/*
 *
 * Olivier & Co
 * 
 * */

var Popin = {
    init: function()
    {	
		$$('.popincart').each( function(elmt) {
			$$('.super-attribute-select').each(function(elt){ $(elt).hide(); });
			
			var appearEffect = Effect.Appear($(elmt), { duration: 0.2 });
			Effect.Appear('filter', { 
				duration: 0.2, 
				from: 0.0, 
				to:0.5 
			});

			Event.observe('filter', 'click', Popin.hideFilter);
			Event.observe($('popincart_close'), 'click', Popin.hideFilter);
			Event.observe($('btn_continue'), 'click', Popin.hideFilter);
		});
    },
    
    hideFilter: function()
    {
    	Effect.Fade('filter', { duration: 0.2, from: 0.5, to:0.0 });
    	$$('.super-attribute-select').each(function(elt){ $(elt).show(); });
    	$$('.popincart').each( function(elmt) {
    		Effect.Fade($(elmt), { duration: 0.2 });
    	});

    }
}

jQuery(document).ready(function($) {
	
	if (!(jQuery.browser.msie && jQuery.browser.version < '7')) { 
		//-- On active pas jnice sous ie6
	  	jQuery(function(){jQuery('form.jNice').jNice();	});
	}
	

 $('button.button span span span').dropShadow({
  left: 0,
  top: 0,
  blur: 1
 });
 
 if(jQuery('.popincart').length > 0)
 {
 	Popin.init();
 }

 $('#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');
   }
  });
 });
}
