function $t(term){
  document.write(Gucci.getTerm(term));
}

var Gucci = {
  locale: '',
  _animation: { menu: false },
  MAIN_MENU: 0,
  SUB_MENU: 1,
  PAGE_MENU: 2,
  MENU_TIMEOUT: 1000,
  currentMenuPanel: 0,
  _defaultMenuPanel: 0,
  _menuPanelTimeout: null,
  _smallScreen: false,
  _activeSubMenu: -1,
  _changedSubmenu: false,
  minibagOffset: 0,
  layoutHeight: 510,
  cubic: function(pos) {
    pos /= 0.5; return pos<1 ? 0.5*pos*pos*pos : 0.5*((pos-2)*(pos-2)*(pos-2)+2);
  },
  _open: { 'menu-left':false, 'menu-right':false },
  projectedWidths: function(){
    var width = Position.getPageSize().window.width-65;
    var contentWidth = $A($('content').cleanWhitespace().childNodes).inject(0,function(memo,node){ return memo+(node.offsetWidth || 0) });
    var fillingWidth = width-contentWidth-(236*2+65);
    return [fillingWidth, contentWidth, width];
  },
  redraw: function(){
    var scrollLeft = Position.scrollX();
    var pageHeight = Position.getPageSize().window.height;
    var _layout = $('layout');
    var _logo = $('logo');
    
    if(!_layout && !_logo) return;
    
    var layoutTop = parseInt((pageHeight - 504)/2) - Gucci.minibagOffset;
    layoutTop = (layoutTop < 0 ? 0 : layoutTop);
    
    var logoOffset = layoutTop;
    var layoutOffset = _layout.offsetLeft;
  
    if($('thumbs-icon'))
      $('thumbs-icon').setStyle({ top: ((pageHeight - 504)/2) + 520 + 'px' });
   
    _layout.setStyle({ top: layoutTop + 'px' });
    _logo.setStyle({ top: logoOffset + Gucci.layoutHeight + 'px', marginLeft: layoutOffset - 68 - 22 + 'px' }).show();
    
    if($('filling')) {
      if(Gucci.beforeFillingEvent) Gucci.beforeFillingEvent();
      var widths = Gucci.projectedWidths();
      var width = widths[2], contentWidth = widths[1], fillingWidth = widths[0];
      
      if(fillingWidth > 0){
        $('filling').show().setStyle({width: width-contentWidth-(236*2+65)+'px'});
        $('wrapper').setStyle({width: width+'px'});
        $('layout').setStyle({width: width+'px'});
      } else {
        $('filling').hide();
        $('wrapper').setStyle({width: contentWidth+(236*2+65)+'px'});
        $('layout').setStyle({width: contentWidth+(236*2+65)+'px'});
      }
    };

    Gucci.positionMinibag();
    
  },
  initialize: function(id){
    $('logo').hide();
    
    Gucci.id     = id;
    Gucci.locale = 'de';
    Gucci.parseMenu();
    
    Gucci.minibagOffset = parseInt($('layout').getStyle('paddingTop')); // XXpx -> XX conversion
    Gucci.layoutHeight = parseInt($('layout').getHeight()); // XXpx -> XX conversion
    
    if(Engine.isMSIE7)
      $('page-body').addClassName('ie6');
      
    Event.observe(window,'resize',Gucci.redraw);
    Gucci.redraw();
    
    Event.observe(window,'scroll',Gucci.positionMinibag);
    
    if(arguments[1]) {
      this._defaultMenuPanel = arguments[1];
      if(Gucci._activeSubMenu>-1 && this._defaultMenuPanel==this.SUB_MENU) {
        Gucci.openSubmenu(Gucci._activeSubMenu,{animation:false});
      } else {
		if (Gucci._activeSubMenu == -99 && Gucci.id != 'search') {
			Gucci.currentMenuPanel = 0;
			Gucci._defaultMenuPanel = 0;
			this.showMenuPanel(this.MAIN_MENU,{animation:false});
		}
		else 
			this.showMenuPanel(arguments[1],{animation:false});
      }
    }
    
    if(Gucci._activeSubMenu>-1) Gucci._renderSubMenu(Gucci._activeSubMenu);
    
    ['menu-left','menu-right'].each(function(side){
      if($(side)){
        Event.observe(side,'mouseout',this.startMenuPanelTimeout.bindAsEventListener(this));
        Event.observe(side,'mousemove',this.clearMenuPanelTimeout.bindAsEventListener(this));
      }
    }.bind(this));
    
    /* Fix positioning of left and right menus for scrollable minibag */
    $$('.menu').each(function(menuEl){
      var menuContainer = menuEl.setStyle({top: '0'}).up();
      menuContainer.getStyle('position') == 'absolute' ? menuContainer.setStyle({top: '60px'}) : menuContainer.setStyle({top: '0'});
    });
    
    if($('logo') && !$('logo').hasClassName('noscroll')){
		if (typeof salenav!="undefined" && salenav) {
			// scroll left for sale pages, no return to main page -- sale over, preventing behavior with '1==2' above
	   		Event.observe('logo','click',function(){new Effect.HScrollTo(0)});
	 		$('logo').up().href = "#";
		}
       else
			Event.observe('logo','click',function(){
        		// oog - copied from getCookie in localize.js

      			var dc = document.cookie;
      			var prefix = "site=";
      			var begin = dc.indexOf("; " + prefix);      
      			if (begin == -1) {
      	  			begin = dc.indexOf(prefix);
      	  			if (begin != 0) return;
      			}
      			else {
      	  			begin += 2;
      			}
      			var end = document.cookie.indexOf(";", begin);
      			if (end == -1) {
      	  			end = dc.length;
      			}
      			var page = '/' + unescape(dc.substring(begin + prefix.length, end))
          		+ '/index2.html';
      			prefix = "";
      			var durl = document.URL;
      			begin = durl.indexOf('://');
      			if(begin != -1) {
      	  			begin += 3;
      	  			end = durl.indexOf('/', begin);
      	  			if(end != -1) {
      	    			prefix = 'http://' + unescape(durl.substring(begin, end));
      	  			}
      			}
        		document.location = prefix + page;
      		});  
    }
    $$('div.spacer-column').each(function(s,i){
      Event.observe(s,'click',function(event){
        Gucci.spacerEvent ? Gucci.spacerEvent(i, Event.localPointer(event)[0]<33 ? 1 : -1) : 
          new Effect.HScroll(Event.localPointer(event)[0]<33 ? 821 : -821);
      });
      Event.observe(s,'mousemove',function(event){
        var d = Event.localPointer(event)[0]<33 ? '-65' : '-130';
        s.style.backgroundPosition = d + 'px 0px';
      });
      Event.observe(s,'mouseout',function(event){
        s.style.backgroundPosition = '0px 0px';
      });
    });

			// this little gem of a hack rewrites the url on the free shipping and phone assistance 
			// links on the registration and optout pages.
			var url = window.location;
			var re = /gogreen|registration2/;
			var is_ssl_page = re.test(url);
			var ssl_url = window.location.protocol;
			var host = window.location.host;

  if (typeof phoneassistance != 'undefined' && phoneassistance && $$('ul.legal-information') && $$('ul.legal-information').length > 0) {
		var legalul = $$('ul.legal-information')[0];

  		var phoneelement = document.createElement('li');
  		var phonelink = document.createElement('a');
  		var phonetext = document.createTextNode('877.482.2430');
		
			non_ssl_root = ssl_url + "//" + host +"/";

			if (is_ssl_page){
				ssl_url = ssl_url.replace(new RegExp(/^https\:/i),"http:");
				non_ssl_root = ssl_url + "//" + host +"/";
				}
	
 	
  		phonelink.setAttribute("href",non_ssl_root +Gucci.getCookie('site')+'/'+Gucci.getCookie('language')+'/'+Gucci.getCookie('site')+'/'+'about-gucci/legal-notices/assistance.html');
			phonelink.appendChild(phonetext);
  		phoneelement.appendChild(phonelink);
  		legalul.appendChild(phoneelement); 
	}
    
  	if (typeof freeshipping != 'undefined' && freeshipping && $$('ul.legal-information') && $$('ul.legal-information').length > 0 && location.href.indexOf('index') == -1) {
  		var legalul = $$('ul.legal-information')[0];
		
		var freeshipelement = document.createElement('li');
  	var freeshiplink = document.createElement('a');
  	var freeshiptext = document.createTextNode(Gucci.getTerm('free shipping'));		
				 			
		non_ssl_root = ssl_url + "//" + host +"/";
		
		if (is_ssl_page){
			ssl_url = ssl_url.replace(new RegExp(/^https\:/i),"http:");
			non_ssl_root = ssl_url + "//" + host +"/";
			}
		
		freeshiplink.setAttribute("href","#");
		freeshiplink.onclick = function() {Gucci.openPopup(non_ssl_root + Gucci.getCookie('site')+'/'+Gucci.getCookie('language')+'/'+Gucci.getCookie('site')+'/'+'popup_freeshipping.shtml'); return false;};	
		
  		freeshiplink.appendChild(freeshiptext);
  		freeshipelement.appendChild(freeshiplink);
  		legalul.appendChild(freeshipelement);
  	}

	if (typeof giftcardpromo != 'undefined' && giftcardpromo && $$('ul.legal-information') && $$('ul.legal-information').length > 0) {
			var legalul = $$('ul.legal-information')[0];

	  		var giftcardelement = document.createElement('li');
	  		var giftcardlink = document.createElement('a');
	  		var giftcardtext = document.createTextNode('gift card');

				non_ssl_root = ssl_url + "//" + host +"/";

				if (is_ssl_page){
					ssl_url = ssl_url.replace(new RegExp(/^https\:/i),"http:");
					non_ssl_root = ssl_url + "//" + host +"/";
					}


	  		giftcardlink.setAttribute("href",non_ssl_root +Gucci.getCookie('site')+'/'+Gucci.getCookie('language')+'/'+Gucci.getCookie('site')+'/gift-card/');
			giftcardlink.appendChild(giftcardtext);
	  		giftcardelement.appendChild(giftcardlink);
	  		legalul.appendChild(giftcardelement); 
	}
    
    if(Engine.isMSIE) $$('a').each(function(n){ n.hidefocus = 'hidefocus' })
  },
  
  positionMinibag: function(){
    var el = $('minibag');
    var layout = $('layout');
    var pageSize = Position.getPageSize();
    var scrollOffsets = document.viewport.getScrollOffsets();
    
    if(!el) return;
    
    if(parseInt(layout.getStyle('width')) < pageSize.window.width){
      el.setStyle({'position':'absolute', 'right': '30px'});
    } else if(parseInt(layout.getStyle('height')) + 80 > pageSize.window.height && scrollOffsets.top > 0) {
      if(!Engine.isMSIE6)
        el.setStyle({'position':'absolute', 'right': ((pageSize.window.width - parseInt(layout.getStyle('width')))*-1) - scrollOffsets.left + 182 + 'px'}, {duration: .15});
    } else {
      if(!Engine.isMSIE6) // MSIE 6 doesn't support position 'fixed', so we'll emulate it with CSS expression
        el.setStyle({'position':'fixed', 'right': '102px'});
    };
  },
  
  setSpacerEvent: function(callback){
    Gucci.spacerEvent = callback;
  },
  
  setOnBeforeFilling: function(callback){
    Gucci.beforeFillingEvent = callback;
  },
  
  setCustomTimeoutMenuEvent: function(e){
    this._customTimeoutMenuEvent = e;
  },
  
  startMenuPanelTimeout: function(event){
    if($('menu-left')) {
      var p = Event.localPointer(event,'menu-left');
      if(p[0]>0 && p[0]<236 && p[1]>0 && p[1]<504) return;
    }
    if($('menu-right')) {
      var p = Event.localPointer(event,'menu-right');
      if(p[0]>0 && p[0]<236 && p[1]>0 && p[1]<504) return;
    }
    this.clearMenuPanelTimeout();
    this._menuPanelTimeout = setTimeout(function(){
      if(Gucci._customTimeoutMenuEvent) {
        Gucci._customTimeoutMenuEvent();
        return;
      }
      Gucci.showMenuPanel(Gucci._defaultMenuPanel,{restore:true}) 
    }, Gucci.MENU_TIMEOUT);
  },
  clearMenuPanelTimeout: function(){
    if(this._menuPanelTimeout) {
      clearTimeout(this._menuPanelTimeout);
      this._menuPanelTimeout = null
    }
  },
  getTerm: function(term) {
    return Gucci._menu ? (Gucci._menu.term[term] || '!('+term+')') : '!(menu?)';
  },
  getScaledLayoutFactor: function(delta) {
    var curWidth = $('wrapper').offsetWidth;
    return ((curWidth+delta)/curWidth)*100;
  },
  scaleLayout: function(delta) {
    var pct = this.getScaledLayoutFactor(delta);
    return [
      new Effect.Scale('wrapper',pct, {scaleY:false,scaleContent:false,sync:true}),
      new Effect.Scale('layout', pct, {scaleY:false,scaleContent:false,sync:true})
    ]
  },
  setMenu: function(menu){
    Gucci._menu = menu;
  },
  parseMenu: function(){
    function _renderItem(item){
      var cl = (Gucci.id == item.id) ? ['active'] : [];
	  if (cl == 'active') foundactive = true;
      if(item.klass) cl.push(item.klass);
      var c = '';
      var url = "http://" + location.host + item.url;
      if(item.secure) {
        url = "https://" + location.host + item.url;
      } 
      if(cl.length>0) c = ' class="'+cl.join(' ')+'"';

	  var pc = '';
	  if(item.pklass)
		pc = ' class="'+item.pklass+'"';

	  item.refinedname = item.name.gsub(/\n/,'<br/>').gsub(/\s/,'&nbsp;');
	  
	  if (cl.join(' ').indexOf('menusubmenu') != -1)
		 Gucci._menuPanel += '<p'+pc+'><a href="#" onclick="Gucci.changeSubmenu(' + item.url + '); return false;"'+c+' name="'+item.refinedname+'">'+item.refinedname+'</a></p>';
      else if (cl.join(' ').indexOf('menuheader') != -1)
	  	 Gucci._menuPanel += '<p'+pc+'><a href="#" onclick="return false;"'+c+' name="'+item.refinedname+'">'+item.refinedname+'</a></p>';
	  else if (cl.join(' ').indexOf('menuspacer') != -1)
		 Gucci._menuPanel += '<p>&nbsp;</p>';
	  else
      	 Gucci._menuPanel += '<p'+pc+'><a href="'+url+'"'+c+' name="'+item.refinedname+'">'+item.refinedname+'</a></p>';
    }
    function _renderSubmenuItem(item, subklass){
      if(Gucci.id == item.id){
        Gucci._activeSubMenu = currentSubmenu;
      }
      var cl = (Gucci.id == item.id) ? ['active'] : [];
	  if (cl == 'active') foundactive = true;
      if(item.klass) 
		cl.push(item.klass);
	  else {
		if(subklass)
			cl.push(subklass);
	  }
      var c = '';
      if(cl.length>0) c = ' class="'+cl.join(' ')+'"';

	  var pc = '';
	  if(item.pklass)
		pc = ' class="'+item.pklass+'"';
		
	  item.refinedname = item.name.gsub(/\n/,'<br/>').gsub(/\s/,'&nbsp;');
	  if (cl.join(' ').indexOf('menusubmenu') != -1)
		 Gucci._subMenus[currentSubmenu] += '<p'+pc+'><a href="#" onclick="Gucci.changeSubmenu(' + item.url + '); return false;"'+c+' name="'+item.refinedname+'">'+item.refinedname+'</a></p>';
      else if (cl.join(' ').indexOf('menuheader') != -1)
	  	 Gucci._subMenus[currentSubmenu] += '<p'+pc+'><a href="#" onclick="return false;"'+c+' name="'+item.refinedname+'">'+item.refinedname+'</a></p>';
	  else if (cl.join(' ').indexOf('menuspacer') != -1)
		 Gucci._subMenus[currentSubmenu] += '<p>&nbsp;</p>';
	  else
      	 Gucci._subMenus[currentSubmenu] += '<p'+pc+'><a href="http://' + location.host + item.url+'"'+c+' name="'+item.refinedname+'">'+item.refinedname+'</a></p>';
    }
    function _renderSubmenu(submenu){
      currentSubmenu++;
      Gucci._subMenus.push('');
      
	  
      var cl = ['submenu'];
      if(submenu.klass) cl.push(submenu.klass);

	  var pc = '';
	  if(submenu.pklass)
		pc = ' class="'+submenu.pklass+'"';
      
      Gucci._menuPanel += '<p'+pc+'><a class="'+cl.join(' ')+'" href="#" onclick="Gucci.openSubmenu('+currentSubmenu+'); return false">'+submenu.name.gsub(/\s/,'&nbsp;')+'</a></p>';
	  if(submenu.subklass){
		if(submenu.item) submenu.item.each(function(e) {_renderSubmenuItem(e,submenu.subklass);});
	  }
	  else
      	if(submenu.item) submenu.item.each(_renderSubmenuItem);
    }
    function _renderList(list){
      if(list.item) list.item.each(_renderItem);
      if(list.submenu) list.submenu.each(_renderSubmenu);
    }
    function _renderBlock(block){
      if(block.item) block.item.each(_renderItem);
      if(block.list) block.list.each(_renderList);
      Gucci._menuPanel += '<br/>';
    }
    var currentSubmenu = -1;
    var foundactive = false;

    Gucci._menuPanel = '';
    Gucci._subMenus  = [];
    Gucci._menu.block.each(_renderBlock);
    
    ['menu-left','menu-right'].each(function(side){
      if($(side+'-main')) $(side+'-main').update(Gucci._menuPanel);
    });

	if (!foundactive) 
		Gucci._activeSubMenu = -99;
  },
  _renderSubMenu: function(submenu, custom){
    submenu = custom ? custom : Gucci._subMenus[submenu];
    if($('menu-left-submenu')) $('menu-left-submenu').update(submenu+
      '<p class="level-up"><a href="#" onclick="Gucci.showMenuPanel(Gucci.MAIN_MENU);return false">' +
      Gucci._menu.term.main +
      '</a></p>'
    );
    if($('menu-right-submenu')) $('menu-right-submenu').update(submenu+
      '<p class="level-up"><a href="#" onclick="Gucci.showMenuPanel(Gucci.MAIN_MENU);return false">' +
      Gucci._menu.term.main +
      '</a></p>'
    );
  },
  showMenuPanel: function(panel){
    if(Gucci._animation.menu) return;
    
    var options =  Object.extend({
      animation: true,
      restore:   false,
      custom:    false
    }, arguments[1] || {});
    
    if(options.restore && Gucci._activeSubMenu>-1){
	  if (Gucci._changedSubmenu){
		$('menu-left-submenu').fade({
			duration: 0.4,
			afterFinish: function() {
				$('menu-left-submenu').appear({duration: 0.4});
			}
		});
		$('menu-right-submenu').fade({
			duration: 0.4,
			afterFinish: function() {
				$('menu-right-submenu').appear({duration: 0.4});
			}
		});

		setTimeout(function(){Gucci._renderSubMenu(Gucci._activeSubMenu, options.custom); Gucci._changedSubmenu = false; },400);
	  }
	  else
      	Gucci._renderSubMenu(Gucci._activeSubMenu, options.custom);
    }
    
    if(!options.animation){
      if($('menu-left-scroll')) {
        $('menu-left-scroll').style.left = -$('menu-left').offsetWidth * panel + 'px';
        $('menu-left-background').style.left = -$('menu-left').offsetWidth * panel + 'px';
      }
      if($('menu-right-scroll')) {
        $('menu-right-scroll').style.left = -$('menu-right').offsetWidth * (2-panel) + 'px';
        $('menu-right-background').style.left = -$('menu-right').offsetWidth * (2-panel) + 'px';
      }
      Gucci.currentMenuPanel = panel;
      return;
    }
    
    Gucci._animation.menu = true;
    if($('menu-left-scroll')) new Effect.Move('menu-left-scroll',{ 
      x: -(panel-Gucci.currentMenuPanel)*$('menu-left').offsetWidth,
      transition: Gucci.cubic, 
      duration: 0.6,
      afterUpdate: function(){
        $('menu-left-background').style.left = $('menu-left-scroll').style.left;
      },
      afterFinish: function(){
        Gucci.currentMenuPanel = panel;
        Gucci._animation.menu = false;
      }
    });
    if($('menu-right-scroll')) new Effect.Move('menu-right-scroll',{ 
      x: (panel-Gucci.currentMenuPanel)*$('menu-right').offsetWidth,
      transition: Gucci.cubic, 
      duration: 0.6,
      afterUpdate: function(){
        $('menu-right-background').style.left = $('menu-right-scroll').style.left;
      },
      afterFinish: function(){
        Gucci.currentMenuPanel = panel;
        Gucci._animation.menu = false;
      }
    });
  },
  openSubmenu: function(submenu){
    if(Gucci._animation.menu) return;
    if($('menu-left-submenu')) $('menu-left-submenu').update(Gucci._subMenus[submenu]+
      '<p class="level-up"><a href="#" onclick="Gucci.showMenuPanel(Gucci.MAIN_MENU);return false">' +
      Gucci._menu.term.main +
      '</a></p>'
    );
    if($('menu-right-submenu')) $('menu-right-submenu').update(Gucci._subMenus[submenu]+
      '<p class="level-up"><a href="#" onclick="Gucci.showMenuPanel(Gucci.MAIN_MENU);return false">' +
      Gucci._menu.term.main +
      '</a></p>'
    );
    
    Gucci.showMenuPanel(Gucci.SUB_MENU,arguments[1]||null);
  },
  changeSubmenu: function(submenu){
	if(Gucci._animation.menu) return;
		Gucci._changedSubmenu = true;
		
		if ($('menu-left-submenu'))
			$('menu-left-submenu').fade({
				duration: 0.4,
				afterFinish: function() {
					$('menu-left-submenu').appear({duration: 0.4});
				}
			});
		if ($('menu-right-submenu'))
			$('menu-right-submenu').fade({
				duration: 0.4,
				afterFinish: function() {
					$('menu-right-submenu').appear({duration: 0.4});
				}
			});
		
		setTimeout(function(){Gucci.openSubmenu(submenu);},400);
  },
  getPageFragmentIdentifier: function(){
    return location.href.split('#')[1];
  },
  setPageFragmentIdentifier: function(productData) {
    var url = location.href.split('#');
	if (location.href.indexOf('/womens-runway/') != -1 || location.href.indexOf('/mens-runway/') != -1 || location.href.indexOf('/womens-fashion/') != -1)
		location.href = url[0] + '#' + productData;
	else
    	location.href = url[0] + '#' + Object.values(productData).join('-');
  },  
  openPopup: function(url) {
    var w = window.open(url,'gucci','height=450,width=395,directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=no');
    w.focus();
  },
  _scrollPanels: {},
  scrollPanel: function(panel, handle, track, scrollHeight) {
    if(panel.scrollHeight > (scrollHeight || 372)) {
      panel.addClassName('with-scrollbar');
      $(track).setStyle({ 'display': 'block' });
      this._scrollPanels[panel] = new Control.Slider( handle, track, { 
        axis: 'vertical',
        onSlide:function(v) { 
          var height = panel.scrollHeight;
          panel.scrollTop = (v*(height-(scrollHeight || 372)));
        },
        onChange:function(v) {
          var height = panel.scrollHeight;
          panel.scrollTop = (v*(height-(scrollHeight || 372)));
        }
      });
      wheelCallback = function(delta){
        var factor = Engine.isKHTML ? 0.03 : 0.07;
        Gucci._scrollPanels[panel].setValueBy(delta > 0 ? -factor : factor);
      }
    } else {
      //display none for scrollbar if not needed
      track.setStyle({display: "none"});
    }
  },
  centerPanel: function(panel, width){
    panel = $(panel);
    width = width || panel.offsetWidth;
    Position.prepare();
    var w = Position.getPageSize().window.width;
    var p = Position.cumulativeOffset(panel)[0];
    var d = (p - (w - width)/2) - Position.scrollX();
    if(d == 0) return false;    
    new Effect.HScroll(d,Object.extend({
      duration: (Math.log(Math.abs(d*d))/10),
      transition: Gucci.cubic
    }, arguments[2] || {}));
  },
  positionOverlay: function(){
	var overlay = $('overlay_panel');
	if (!overlay) return;
	
	var targetleft;
	var panelwidth = overlay.getWidth();

	if ((document.viewport.getWidth()/2) <= (panelwidth/2))
		targetleft = 0;
	else {
		if (Engine.isMSIE)
			targetleft = (document.viewport.getWidth()/2) - (panelwidth/2) - $('layout').cumulativeOffset()[0];
		else
			targetleft = (document.viewport.getWidth()/2) - (panelwidth/2);
	}	
	var scrollOffsets = document.viewport.getScrollOffsets();
	targetleft += scrollOffsets.left;
	
	overlay.setStyle({left:targetleft + 'px'});
  },
  showOverlay: function(){
	var content = $('content');

	if (Object.isElement($('overlay_screen')) || typeof content == 'undefined')
		return false;	

	var overlayscreen = new Element('div',{'id': 'overlay_screen'});
	if (document.viewport.getWidth() > content.getWidth())
		overlayscreen.setStyle({width:document.viewport.getWidth() + 'px'});
	else
		overlayscreen.setStyle({width:content.getWidth() + 'px'});	

	var overlay = new Element('div',{'id': 'overlay_panel'});
	
	var targetleft;
	var panelwidth = 420;
	
	if ((document.viewport.getWidth()/2) <= (panelwidth/2))
		targetleft = 0;
	else {
		if (Engine.isMSIE)
			targetleft = (document.viewport.getWidth()/2) - (panelwidth/2) - $('layout').cumulativeOffset()[0];
		else
			targetleft = (document.viewport.getWidth()/2) - (panelwidth/2);
	}
	
	overlay.setStyle({left:targetleft + 'px'});
	overlay.setStyle({top:parseInt((Position.getPageSize().window.height - 504)/2) + 'px'});
	
	Event.observe(window,'scroll',Gucci.positionOverlay);
	
	if (Engine.isMSIE){
		$('layout').appendChild(overlayscreen);
		$('layout').appendChild(overlay);
		overlayscreen.setStyle({height: document.viewport.getHeight() + 'px'});	
		overlayscreen.setStyle({top:-$('layout').cumulativeOffset()[1] + 'px'});	
		overlayscreen.setStyle({left:-$('layout').cumulativeOffset()[0] + 'px'});	
	}
	else {
		$$('body')[0].appendChild(overlayscreen);
		$$('body')[0].appendChild(overlay);
	}
	
	overlayscreen.appear({duration: 1.5, from: 0, to: 0.7});
	overlay.appear({duration: 1.5, from: 0, to: 0.95});
	return overlay;
  },
  showCountryRedirectPanel: function(countrylinks){
	var countryoverlay = Gucci.showOverlay();
	if (!countryoverlay)
		return;
	var countryselections = new Element('div',{'id':'coverlay_display'});
	var searchurl;
	Object.values(countrylinks).each(function(e) {
		searchurl = e[0];
		if (e[0].indexOf('#') > -1)
			searchurl = e[0].substring(0,e[0].indexOf('#')-1);
		if (document.location.href.indexOf(searchurl) != -1) {
			var removecode = "Gucci.removeOverlay();";
			if (searchurl != e[0])
				removecode += " Shop.goToAndOpen(\'" + e[0]  + "\');"
			if (Engine.isMSIE)
				countryselections.appendChild(new Element('a',{'class': 'country','href':'javascript:' + removecode,'style':'opacity: 0; cursor: pointer;'}).update(e[1]));
			else {
				removecode += " return false;"
				countryselections.appendChild(new Element('a',{'class': 'country','href':'#','onclick':removecode,'style':'opacity: 0; cursor: pointer;'}).update(e[1]));
			}
		}
		else
			countryselections.appendChild(new Element('a',{'class': 'country','href':e[0],'style':'opacity: 0;'}).update(e[1]));
	countryselections.appendChild(new Element('br'));
	});
	
	setTimeout(function() {
		$$('div#coverlay_display a.country').each(function(e,i) {
		 		setTimeout(function() {
		 		          new Effect.Appear(e);
		 		       }, 100*i);
		});
	}, 1000);

	countryoverlay.appendChild(new Element('p').update('please select a country'));
	countryoverlay.appendChild(countryselections);
  },
  checkOverlay: function(){
	if (document.cookie.indexOf('forceCountryRedirectOverlay=') != -1){
		

		// kill force overlay cookie immediately
		var today = new Date();
		var expire = new Date();
		expire.setTime(today.getTime()-1000);
		document.cookie = "forceCountryRedirectOverlay=''; expires=" + expire.toGMTString() + "; path=/";
		document.cookie = "forceCountryRedirectDefaultSite=''; expires=" + expire.toGMTString() + "; path=/";
		
		// set promo references
		var promocode = "";
		if (document.cookie.indexOf('forceCountryRedirectPromoCode=') != -1){
			var tempindex = document.cookie.indexOf('forceCountryRedirectPromoCode=');
			if (document.cookie.indexOf(';',tempindex) < 0)
				promocode = document.cookie.substring(tempindex+30);
			else
				promocode = document.cookie.substring(tempindex+30,document.cookie.indexOf(';',tempindex));
			promocode = promocode.replace(/%2F/g,'/').replace(/%2D/g,'-');
			document.cookie = "forceCountryRedirectPromoCode=''; expires=" + expire.toGMTString() + "; path=/";
			
			var exdate = new Date();
			exdate.setDate(exdate.getDate()+30);
			document.cookie= "promotion=" + escape(promocode) + "; expires="+exdate.toGMTString() + "; path=/";
		}
		
		var ccookies = new Array();
		ccookies[0] = ['forceCountryRedirectat','at','austria'];
		ccookies[1] = ['forceCountryRedirectbe','be','belgium'];
		ccookies[2] = ['forceCountryRedirectca%2Den','caen','canada - english'];
		ccookies[3] = ['forceCountryRedirectcn','cn','中国 - 简体'];
		ccookies[4] = ['forceCountryRedirectcn%2Den','cnen','china - english'];
		ccookies[5] = ['forceCountryRedirectch','ch','switzerland'];
		ccookies[6] = ['forceCountryRedirectde','de','germany'];
		ccookies[7] = ['forceCountryRedirectfr','fr','france'];
		ccookies[8] = ['forceCountryRedirectie','ie','ireland'];
		ccookies[9] = ['forceCountryRedirectit','it','italy'];
		ccookies[10] = ['forceCountryRedirectjp','jp','japan'];
		ccookies[11] = ['forceCountryRedirectkr','kr','korea'];
		ccookies[12] = ['forceCountryRedirectnl','nl','netherlands'];
		ccookies[13] = ['forceCountryRedirectuk','uk','united kingdom'];
		ccookies[14] = ['forceCountryRedirectus','us','united states'];
		ccookies[15] = ['forceCountryRedirectint','int','all other countries'];
				
		var clinks = new Object();
		for (var i = 0; i < ccookies.length; i++){
			var tempindex;
			tempindex = document.cookie.indexOf(ccookies[i][0] + '=');
			if (tempindex != -1) {
				var targetlink;
				if (document.cookie.indexOf(';',tempindex) < 0)
					targetlink = document.cookie.substring(tempindex+ccookies[i][0].length+1);
				else
					targetlink = document.cookie.substring(tempindex+ccookies[i][0].length+1,document.cookie.indexOf(';',tempindex));
				targetlink = targetlink.replace(/%2F/g,'/').replace(/%2D/g,'-').replace(/%23/g,'#');
				clinks[ccookies[i][1]] = [targetlink,ccookies[i][2]];
			}
		}	

		Gucci.showCountryRedirectPanel(clinks);
	}
  },
  removeOverlay: function(pageName){
	Event.stopObserving(window,'scroll',$('overlay_panel'));
	$('overlay_screen').fade({duration: 1, afterFinish: function() { $('overlay_screen').remove(); } });
	$('overlay_panel').fade({duration: 0.3, afterFinish: function() { $('overlay_panel').remove(); } });	
	if (typeof guccivideo == 'object') {
		guccivideo.play();
	}
  },
  getCookie: function(name){
	  var dc = document.cookie;
	  var prefix = name + "=";
	  var begin = dc.indexOf("; " + prefix);

	  if (begin == -1) {
	    begin = dc.indexOf(prefix);
	    if (begin != 0) return null;
	  } else
	    begin += 2;
	  var end = document.cookie.indexOf(";", begin);
	  if (end == -1)
	    end = dc.length;
	  return unescape(dc.substring(begin + prefix.length, end));
  }
}

if(typeof localizedMenu != "undefined") document.write('<script type="text/javascript" src="'+localizedMenu+'"></script>');


/***********************************
	
	Variations Class
	Copyright wollzelle GmbH, 2008
	
***********************************/

var GUCCI = {};

GUCCI.VariationPanel = Class.create({
	initialize: function(mainObj, lightbox, lightboxObject, options) {
		this.options = {};
		Object.extend(this.options, options || {});
		
		/* Variations related */
		this.lightboxEl = $(lightbox);
		this.lightboxElObject = lightboxObject;
		this.DOMinitialized = false;
		this.variationsMap = [];
		this.mainObj = mainObj;

		
		/* Tooltips realted */
		this.tooltipTextFadeDuaration = 0.3;
		this.tooltipVisible = false;
		this.toolipTimeout = null;
	},
	buildPanel: function(){
		var i = this.lightboxEl.id;

	    this.lightboxEl.insert('<div class="variants" style="display:none; width: 0" id="' + i + '_variants">' +
	      '<div id="' + i + '_current-style-marker" class="current-style-marker"> </div>' +
	      '<div id="' + i + '_hover-style-marker" class="hover-style-marker" > </div>' +
	      '<div class="image-container" id="' + i + '_imagecontainer"></div>' +
	      '<div class="info" id="' + i + '_info" style="display:none"><div></div></div>' +
	      '</div>');
	
		//lightbox.down('div.variants').setStyle({left:'780px',width:'0px',display:'none'});
		
		this.DOMinitialized = true;
	},
	buildVariationsMap: function() {
		var imageContainer =  $(this.lightboxEl.id + '_imagecontainer');
		var images = imageContainer.select('img');
		for (var i = 0; i < images.length; i++) {
			var image = images[i];
			var position = Position.cumulativeOffset(image);
			var map = {
				image: image,
				x1: position[0],
				y1: position[1],
				x2: position[0] + image.getWidth(),
				y2: position[1] + image.getHeight()
			};
			this.variationsMap.push(map);
		}
	},
	prepareAndOpenVariation: function(variation, i) {
		var img;
		if (variation.images.thumb == '' || !variation.images.thumb) {
			// to activate textual overlays, do uncomment
			//naText = new Element('span', { className: 'not_available' });
			//naText.update(Gucci.getTerm('variation image unavailable'));
			img = new Element('img', { src: Gucci.variationsThumbUnavailable , alt: '' });
		} else {
			img = new Element('img', { src: variation.images.thumb, alt: '' });
		}

		if (Prototype.Browser.IE) {
			img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.src + "',sizingMethod='scale')";
			img.src = Shop.THUMB_EMPTY;
		}

		img.observe('mouseover', function(event) {
			this.showInfo(event, variation, i);
		}.bind(this));

		img.observe('tooltip:renew', function(event) {
			this.showInfo(event, variation, i);
		}.bind(this));

		return img;
	},
	prepareAndOpenVariations: function(thumbId) {
		var displayGroup = this.options.getDisplayGroupFromThumbId(thumbId);
		if (!displayGroup) return;
		
		var variations = displayGroup.getVariationsWithLeadStyleFirst();
		
		// If the product has only one variation we'll not show the variation panel. If the VP already shown we'll hide it.
		if(variations.length <= 1 && (typeof(GucciSearch)=='undefined')) {
			this.closeVariations();
			return;
		}
		
		// Building DOM elements
		if(!this.DOMinitialized) this.buildPanel();
		
		var colsCount = (variations.length/6).ceil();
		var imageContainer = $(this.lightboxEl.id + '_imagecontainer');
		imageContainer.setStyle({width: (colsCount * 65) + 'px', opacity: 0}).update('');

		var cols = [];
		colsCount.times(function(i) {
			cols.push(new Element('div', { className: 'variations-col' }));
			imageContainer.insert(cols[i]);
		});

		variations.each(function(variation, i){
			var img = this.prepareAndOpenVariation(variation, i);
			var colToInsert = cols[(i > 5) ? 1 : 0];
			colToInsert.insert(img);
		}.bind(this));

		$(this.lightboxEl.id + '_hover-style-marker').observe('mouseout', this.hideInfo.bindAsEventListener(this));
		this.openVariations(thumbId);
	},
	openVariations: function(thumbId) {
	  var displayGroupInfo = this.options.getDisplayGroupFromThumbId(thumbId);
	  if (!displayGroupInfo) return;
		var width = (displayGroupInfo.variations.length/6).ceil() * 65;
		var lightboxContainer = this.lightboxEl;
		var variantsContainer = $(this.lightboxEl.id + '_variants');
		var imageContainer    = $(this.lightboxEl.id + '_imagecontainer');
		var hoverStyleMarker  = $(this.lightboxEl.id + '_hover-style-marker').hide();
		var currentStyleMarker  = $(this.lightboxEl.id + '_current-style-marker').setOpacity(0).show();
		
		// In search results for 1 product we need an actual width of the lightbox container. For all other cases it's fixed 
		var lightboxContainerWidth = (typeof(GucciSearch)!='undefined') ? lightboxContainer.down('.container').getWidth() : 780;
		
		variantsContainer.show();
    	var _self = this;

		new Effect.Parallel([
			new Effect.Morph(variantsContainer, { style: 'width:' + width + 'px', sync: true }),
			new Effect.Morph(lightboxContainer, { style: 'width:' + (lightboxContainerWidth + width) + 'px', sync: true })
		].concat(Gucci.scaleLayout(width)),
		{
			transition: Gucci.cubic,
			duration: .7,
			queue: 'end',
			afterFinish: function() {        
				lightboxContainer.down('div.shadow-right').setStyle({visibility:'visible'});
				variantsContainer.setStyle({overflow:'visible'});
				this.buildVariationsMap();

				// reposition current style marker for Firefox2
				this.repositionCurrentStyleMarker(thumbId);

				new Effect.Morph(imageContainer, {
					style: { opacity: '1' },
					transition: Gucci.cubic,
					duration: 0.7,
					afterFinish: function() {
						currentStyleMarker.morph('opacity:0.46', { duration: 0.7 });
					}
				});
				_self.mainObj.adjustLayoutWidth();
			}.bind(this),
			beforeStart: function() {
				this.lightboxEl.down('div.shadow-right').setStyle({visibility:'hidden'});
			}.bind(this)
		});
	},
	clearVariations: function(){
		var imageContainer = $(this.lightboxEl.id + '_imagecontainer');
		var currentStyleMarker  = $(this.lightboxEl.id + '_current-style-marker')
		
		if(!imageContainer && !currentStyleMarker) return;
		
		new Effect.Parallel([
			new Effect.Morph(imageContainer, { style: "opacity: 0", sync: true}),
			new Effect.Fade(currentStyleMarker, { style: "opacity: 0", sync: true})
		], {
			transition: Gucci.cubic, 
			duration: 0.7
		});
	},
	selectVariation: function(event, thumbId, styleIndex) {
	  if (this.lightboxEl.isBusy()) return;
	  
		var displayGroup = this.options.getDisplayGroupFromThumbId(thumbId);
		var stylenumberToSelect = displayGroup.getStyleNumbersWithLeadStyleFirst()[styleIndex];

		var displayGroupInfo = this.options.DomIdToDisplayGroup.get(thumbId);
		displayGroupInfo.currentStyle = stylenumberToSelect;

		this.repositionCurrentStyleMarker(thumbId);
		this.lightboxEl.down('div.current-style-marker').setStyle('opacity:0').morph('opacity:0.46');

		var selectedThumb = $(thumbId).down('img') || $(thumbId).down('div.panel-thumb-unavailable') || $(thumbId);
		this.mainObj.selectStyle(selectedThumb, stylenumberToSelect);

		var newThumb = this.mainObj.changeThumbnail($(thumbId), displayGroup.getProduct(displayGroupInfo.currentStyle));
		this.lightboxEl.activeThumbnail = newThumb.up();
		this.lightboxElObject.activeProduct = newThumb;

		// TODO: make this work for variation tooltips
		this.hideInfo(event);
	},
  closeVariations: function(options) {
  		var variants = $(this.lightboxEl.id + '_variants');
		var lightbox = this.lightboxEl;
  		var options = options || {};
  		// If no variations exist, then exit
  		if(!variants) {
				if (options.afterFinish)
             		options.afterFinish();
	   			return;
		}

		new Effect.Parallel([
			new Effect.Morph(variants, { style: 'width: 0px', sync: true }),
			new Effect.Morph(lightbox, { style: 'width: 780px', sync: true })
		], 	
		{
  			transition: Gucci.cubic,
  			duration: .7,
  			beforeStart: function() {
  				variants.setStyle({ overflow:'hidden', borderLeft: "" });
  				this.lightboxEl.down('div.shadow-right').setStyle({visibility:'hidden'});
  				this.lightboxEl.down('div.shadow-bottom').setStyle({visibility:'hidden'});
  			}.bind(this),
  			afterFinish: function() {
  				variants.hide();
  				this.mainObj.adjustLayoutWidth();
  				this.lightboxEl.down('div.shadow-right').setStyle({visibility:'visible'});
  				this.lightboxEl.down('div.shadow-bottom').setStyle({visibility:'visible'});
  				if (options.afterFinish)
             		options.afterFinish();
  			}.bind(this)
  		});
	},
	repositionCurrentStyleMarker: function(thumbId) {
		var displayGroupInfo = this.options.DomIdToDisplayGroup.get(thumbId);
		var displayGroup = this.options.getDisplayGroupFromThumbId(thumbId);

		for (var idx=0;idx<displayGroup.variations.size();idx++) {
			if (displayGroup.variations[idx].style_number == displayGroupInfo.currentStyle) {
				currentThumbIndex = idx; break;
			}
		}

		var i = $(this.lightboxEl.id + '_imagecontainer').select('img')[currentThumbIndex];
		var p = [i.offsetLeft, i.offsetTop];
		$(this.lightboxEl.id + '_current-style-marker').setStyle('top:'+p[1]+'px;left:'+p[0]+'px');
	},
	showInfo: function(event, variation, variationsIndex) {
		var currentImg = event.element();
		
		this.tooltipMovedLeft = false;
		

		
		function getBulletHeight(ulele) {
			var height = 0;
			ulele.childElements().each(function(e) { height += e.getHeight(); });
			return height;
		}
			
		function cutBulletOverlayText(text) {
			var tempbulletcontainer = new Element('div',{'class': 'tempbulletcontainer'});
			if (typeof text != 'undefined' && text.indexOf('showIconOverlay') != -1) {
				text = text.replace(/<a(.*)>(.*)<\/a>/g,'$2');
			}
			if (typeof text != 'undefined' && text.indexOf('<li>') != -1) {
				tempbulletcontainer.update(text);
				$('layout').appendChild(tempbulletcontainer);			
				var tooltip_ul = tempbulletcontainer.down('ul');
				var tooltip_ul_height = ((parseInt(tooltip_ul.getStyle('height')) > 40) ? parseInt(tooltip_ul.getStyle('height')) : 40);
				if (typeof tooltip_ul != 'undefined') {	
					while (getBulletHeight(tooltip_ul) > tooltip_ul_height && tooltip_ul.childElements().size() > 1) {
						tooltip_ul.childElements().last().remove();
						tooltip_ul.childElements().last().innerHTML += '...';
					}		
				}
				tempbulletcontainer.remove();				
				text = tempbulletcontainer.innerHTML;
			}
			return text;
		}

		function cutText(tooltip) {
			if (typeof tooltip.down('p') == 'undefined')
				return;
			var tooltip_p = tooltip.down('p');

			if ((Engine.isMSIE && tooltip_p.innerHTML.strip().length <= 105) || tooltip_p.innerHTML.strip().length <= 115)
				return;
			var newtext = tooltip_p.innerHTML.strip();
			if (Engine.isMSIE)
				tooltip_p.innerHTML = newtext.substring(0,newtext.lastIndexOf(' ',102)) + '...';
			else
				tooltip_p.innerHTML = newtext.substring(0,newtext.lastIndexOf(' ',112)) + '...';
		}

		if (this.toolipTimeout) {
			clearTimeout(this.toolipTimeout);
		}
		var tooltip = this.lightboxEl.down('div.info');
		if (this.mainObj.currentInfo == variation) {
			return;
		}
		this.mainObj.currentInfo = variation;
		var headerText = variation.formatStyleNumber(' ');
		var text;
		if (typeof variation.text.vardesc != 'undefined' && variation.text.vardesc.indexOf('<li>') == -1 && variation.text.vardesc.indexOf('showIconOverlay') == -1) 
			text = '<div class="info-bg">' +
				   '<div style="opacity:0" class="info-fade">' +
				   '<div class="wrapper">' + 
				   '<h1>'+ headerText +'</h1><div class="infotext">' +
				   '<p>' + (variation.text.vardesc ? variation.text.vardesc.escapeHTML() : '') + '</p></div>';
		else 
			text = '<div class="info-bg infobullet">' +
				   '<div style="opacity:0" class="info-fade">' +
				   '<div class="wrapper infobullet">' +
				   '<h1 class="infobullet">'+ headerText +'</h1><div class="infotext">' +
					cutBulletOverlayText(variation.text.vardesc) + '</div>';
		
		if (variation.priceDisplay && variation.priceDisplay.indexOf('sale') != -1)
			variation.priceDisplay = variation.priceDisplay.replace(new RegExp(/(.*)(<span style.*<\/span>)(.*)/gi),'$2');
			
		text += '<p class="price">' +
				(variation.priceDisplay ? variation.priceDisplay : '') +
				'</p></div>' +
				'</div>' +
				'</div>';
	
		var hoverStyleMarkerId = this.lightboxEl.id + '_hover-style-marker';
		var hoverStyleMarker = $(hoverStyleMarkerId);
		if (hoverStyleMarker) {
			hoverStyleMarker.remove();
		}
		hoverStyleMarker = new Element('div', { id: hoverStyleMarkerId });

		this.__hoverStyleMarkerPosition = {
			x: event.element().offsetLeft,
			y: event.element().offsetTop
		};
		hoverStyleMarker.setStyle({
			top: this.__hoverStyleMarkerPosition.y + 'px',
			left: this.__hoverStyleMarkerPosition.x + 'px'
		}).addClassName('hover-style-marker');
		var thumbId = this.options.getThumbIdFromDisplayGroupId(variation._parent.displayGroup_id);
		
		
		
		hoverStyleMarker.observe('click', this.selectVariation.bindAsEventListener(this, thumbId, variationsIndex));

		if (!this.__detailswrapper_observed) {
			var wrapper = $(this.lightboxEl.id + '_details-wrapper') || this.lightboxEl.getChild('details');
			this._detailsWrapperMouseOverHandler = this.detailsWrapperMouseOverHandler.bindAsEventListener(this, this.lightboxElObject, wrapper);
			wrapper.observe('mouseover', this._detailsWrapperMouseOverHandler);
			this.__detailswrapper_observed = true;
		}
		hoverStyleMarker.observe('mouseout', this.hideInfo.bindAsEventListener(this));
		$(this.lightboxEl.id + '_variants').insertBefore(hoverStyleMarker, $(this.lightboxEl.id + '_info'));

		// move tooltip out of the way
		// afterFinish, check if the mouse is positioned above another image
		// if so, fire a custom event which calls Shop.info again to dispaly the correct tooltip
		if (!this.__tooltip_observed) {
			this.__tooltip_observed = true;
			tooltip.observe('mouseover', function(event) {
				if(event.element() != tooltip && event.element() != tooltip.down('.info-bg'))
					return;
				
				var imgParentOffset = this.__hoverStyleMarkerPosition.x;
				var morphTarget = imgParentOffset == 130 ? -125 : -190;
				
				this.tooltipMovedLeft = true;
				
				tooltip.morph({ left: morphTarget + 'px' }, {
					duration: this.tooltipTextFadeDuaration,
					afterFinish: function() {
						var mouseX = Shop._currentMousePosX + Position.scrollX();
						var mouseY = Shop._currentMousePosY;						
						var mapEntry = this.variationsMap.find(function(map){
							if (mouseX >= map.x1 && mouseX < map.x2 && mouseY >= map.y1 && mouseY < map.y2)
								return true;
						});
						if (mapEntry) {
							var displayGroupInfo = this.options.DomIdToDisplayGroup.get(thumbId);
							var currentThumbIndex = displayGroupInfo.currentThumbIndex || 0;
							var currentImage = this.lightboxEl.select('div.variants div.image-container img')[currentThumbIndex];
							// don't fire if this images is currently selected
							if(currentImage != mapEntry.image) {
								$(mapEntry.image).fire('tooltip:renew');
							}
						} else {
							this.hideInfo(event);
						}
					}.bind(this)
				});
			}.bind(this));
		}
		i = this.lightboxEl.select('div.variants div.image-container img')[variationsIndex];
		var p = [i.offsetLeft, i.offsetTop];
		var y = p[1]==0 ? 0 : (p[1] == 420 ? 360 : p[1] - 30);
		if (!this.tooltipVisible) {
			tooltip.update(text).setStyle({
				top:y+'px',
				left:(p[0]-190)+'px',
				opacity:1,
				display:'none'
			});
			
			tooltip.down('div.info-fade').setStyle({opacity: 1});
					
			cutText(tooltip);
			
			if(Prototype.Browser.IE) {
				cutText(tooltip);
				tooltip.show();
				
				if(Engine.isMSIE6) {
					var select = currentImg.up('.lightbox').down('.size');
					if (typeof(select)!="undefined") {
						var selecty = Element.cumulativeOffset(select)[1];
						var tooltipy = Element.cumulativeOffset(tooltip)[1];
						var tooltiph = parseInt(tooltip.getStyle('height'),10);
						if (selecty<=(tooltipy+tooltiph) && selecty>=tooltipy)	
							this.prepareIE('hidden');	
					}
				}

			} else {
				if(this.tooltipFX) this.tooltipFX.cancel();
				tooltip.appear({duration: this.tooltipTextFadeDuaration});
			}
			

			
			
		} else {
			var effx=[];

			effx.push(new Effect.Morph(tooltip,{style: {top: y+'px',left: (p[0]-190)+'px'}, duration: this.tooltipTextFadeDuaration}));
			effx.push(new Effect.Fade(tooltip.down('div.info-fade'), {duration: this.tooltipTextFadeDuaration}));
			if(Engine.isMSIE6) {
				var select = currentImg.up('.lightbox').down('.size');
				if (typeof(select)!="undefined") {
					var selecty = Element.cumulativeOffset(select)[1];
					var tooltipy = y;
					var tooltiph = parseInt(tooltip.getStyle('height'),10);
					if (selecty<=(tooltipy+tooltiph) && selecty>=tooltipy)	{
						this.prepareIE('hidden');	
					} else {
						this.prepareIE('visible');
					}
						

				}
			}
			new Effect.Parallel(effx, {duration: this.tooltipTextFadeDuaration,
				afterFinish: function () {
					tooltip.update(text);
					cutText(tooltip);
					tooltip.down('div.info-fade').appear({duration: this.tooltipTextFadeDuaration});
				}.bind(this)
			}); 
		}
		this.tooltipVisible = true;
	},
	hideInfo: function(event) {
		var tooltip = this.lightboxEl.down('div.info');
		if (!this.tooltipVisible) {
			return;
		}
		if (this.toolipTimeout) {
			clearTimeout(this.toolipTimeout);
		}
		var currentTarget = event.element();
		this.toolipTimeout = setTimeout(function() {
			// ensure info tooltip is hidden only when cursor is not over another variation
			if (currentTarget && !currentTarget.hasClassName("details-wrapper") && (this.tooltipMovedLeft && parseInt(tooltip.getStyle('left'), 10) > -190) )
				return;
			
			if(Prototype.Browser.IE) {
				tooltip.hide();
				if(!Shop._sizeGuideOpen)
					this.prepareIE('visible');
			} else {
				this.tooltipFX = new Effect.Fade(tooltip, {
					duration: this.tooltipTextFadeDuaration
				});
			}
			this.tooltipVisible = false;
			this.tooltipMovedLeft = false;
			$(this.lightboxEl.id + '_hover-style-marker').hide();
			this.mainObj.currentInfo = -1;
				
		}.bind(this), 100);
	},
	detailsWrapperMouseOverHandler: function(event, lightboxObject, wrapper) {
		this.hideInfo(event);
		wrapper.stopObserving('mouseover', this._detailsWrapperMouseOverHandler);
		lightboxObject.__detailswrapper_observed = false;
	},
	prepareIE: function(visibility){
		$$('select').invoke('setStyle', {visibility: visibility});
	}
});

Element.observe(document,"dom:loaded", function() { Gucci.checkOverlay(); });