function RotateAdd()
{
    var scrollerHeight = 15;
    var slider = $('addScroller');
    var currentTop = slider.getStyle('top').toInt();
    var itemHeight = slider.getStyle('height').toInt();
    if(itemHeight > scrollerHeight)
    {
        var eff = new Fx.Tween(slider);
        if(((currentTop-scrollerHeight) * -1) >= itemHeight)
            currentTop = scrollerHeight;
        eff.start('top', currentTop, currentTop-scrollerHeight);
    }
}
var footerHeight = 156;
var zoomEventSet = false;
var addScrollerTm;
// Does the proper calculations to ensure that the footer is always at the bottom of the screen and that no scrollbars are showing.
function resetContentHeight() 
{
    if ($defined($('wrapper'))) 
    {
      if (window.getWidth() <= 960) 
      {
        $('wrapper').setStyle('width', '960px')
      } 
      else 
      {
        $('wrapper').setStyle('width', '100%')
      }
    }
    
    // Scrolling promos
    if(!addScrollerTm && $defined($("addScroller")))
    {
        addScrollerTm = window.setInterval("RotateAdd();", 5000);
    }
	
    /* Cart Sliding */
    slideUp = new Fx.Tween('cart-panel', 'top', { duration: 5 , transition: 'linear:easeIn' });
    
    $('cart-slide').addEvent('mouseover', function()
    {
        if(!cartslideIsDown && document.getElementById('header-cart-number-middle').innerHTML != '0')
        {
            slideUp.start('top',-450,0); 
            cartTimerId = setTimeout ( "slideUp.start('top',0,-450);cartslideIsDown=true;", 10000 );
        } 
    });
    $('cart-panel').addEvent('mouseleave', function(){ cartTimerId = setTimeout("slideUp.start('top',0,-450);cartslideIsDown=false;", 500); });
    $('cart-panel').addEvent('mouseenter', function(){ clearTimeout ( cartTimerId ); });
    if($defined($('nav-product-buttons')))
        $('nav-product-buttons').addEvent('mouseenter', function(){switchMoreView(selectedTab);});
    if ($defined($('cart-slider'))) 
    {
        makeScrollbar($('cart-slider'), $('scrollbar2'), $('handle2')) ; //, 'vertical', false
    }
	
    //  Detect the content height size / if necessary remove content bar
    if($defined($('content_wrapper')))
    {
        content_footer_height = 0;
        content_header_height = 0;
        if ($defined($('content-header')))
            content_header_height = $('content-header').getStyle('height').toInt() + $('content-header').getStyle('borderBottom').toInt();
        content_middle_height = $('content').getStyle('height').toInt();
        
        if ($defined($('content-footer')))
        {
            content_footer = $('content-footer').getStyle('height').toInt() + $('content-footer').getStyle('borderTop').toInt();
            content_footer_height = content_footer;
        }

        if ($defined($('content-product-slider')) || $defined($('content-product-slider-grid'))) 
        {
	        content_middle_height = 387;
        }

        contentScrollHeight = window.getHeight() - (footerHeight + content_middle_height + content_header_height + content_footer_height);
        new_content_header_height = Math.ceil(contentScrollHeight / 2);
        new_content_footer_height = Math.floor(contentScrollHeight / 2);

        if(new_content_header_height > 15 && !$defined($('product-cart'))  &&  !$defined($('page-not-found')))
        {
            if ($defined($('content-header')))
                $('content-header').setStyle('paddingTop', new_content_header_height+'px');

            if ($defined($('content-footer')))
            {
                //$('content-footer').setStyle('paddingBottom', new_content_footer_height+'px');
            }
        }
        else if( $defined($('product-cart')) ) 
        {
            content_cart = contentScrollHeight = window.getHeight() - footerHeight - content_middle_height;
            content_cart = content_cart / 2;
            diff_header_footer = (content_cart) - 3;
            if(diff_header_footer > content_header_height)
            {
                $('content-header').setStyle('height', diff_header_footer  + 'px');;
                $('content-footer').setStyle('height', diff_header_footer + 'px');
            }
        }
        else if( $defined($('content-header')) )  // Fix for resize, if no padding has to be set, set it back to 0 in case it was set before.
        {
            $('content-header').setStyle('paddingTop', '0px');
        }
        $('content_wrapper').setStyle('height', window.getHeight() - footerHeight);

        if($('div_swf_gallery'))
        {
            $('div_swf_gallery').setStyle('height','100%');//window.getHeight() - footerHeight
        }
        if(swfList.length > 0)
        {
            for(var x=0;x<swfList.length;x++)
		        $(swfList[x]).setStyle('height', window.getHeight() - footerHeight);
        }
        // Store locator page (iframe)
        if($defined($('locatorFrame')))
        {
            $('locatorFrame').setStyle('height', window.getHeight() - footerHeight);
        }  
        
    }

    // Clipping for product slider versus width total of the screen
    if ($defined($('content-product-slider'))) 
    {
        // 273 is the width of one product.
        var productlisttable = $$('div#content-product-slider table.productlisttable');
        var sliderWidth = 273 * productlisttable.length;
        if (sliderWidth < window.getWidth())
        {
            $('scrollbar1').setStyle('display', 'none');
            $each(productlisttable, function(element) {
                
                var leftValue = window.getWidth() / 2 - sliderWidth / 2;
            
                element.getElements('.img a').setStyle("position", "relative");
                element.getElements('.img a').setStyle("left", leftValue);

                element.getElements('.btm a').setStyle("position", "relative");
                element.getElements('.btm a').setStyle("left", leftValue);

                element.getElements('.btm img').setStyle("position", "relative");
                element.getElements('.btm img').setStyle("left", leftValue);

                element.getElements('.btm a img').setStyle("position", "static");
                element.getElements('.btm a img').setStyle("left", 0);
                
                element.getElements('.btm span.price').setStyle("position", "relative");
                element.getElements('.btm span.price').setStyle("left", leftValue);
            });
        }
        else
        {
            $('scrollbar1').setStyle('display', 'block');
            //scrollbar1
            if (window.getWidth() <= 850) 
            {
                $('content-product-slider').style.clip = "rect(0px, 850px, 387px, 0px)";
            } 
            else 
            {
                $('content-product-slider').style.clip = "rect(0px, " + window.getScrollWidth() + "px, 387px, 0px)";
            }
        }
    }
	// Width Detection
	if (window.getWidth() > 960)
	{
        mywidth = (window.getWidth() - 850) / 2; 
	}
	else
	{
	  mywidth = (960 - 850) / 2; 
	}

    // Product page layer positionning according of the scroll bar appaer or not
    if ($defined($('content-product-page'))) 
    {
        $('content-product-page').setStyle('marginLeft', (mywidth) + "px");
        if ($defined($('arrow-left'))) 
        {
            arrowPosition = (((document.documentElement.clientHeight - footerHeight - content_header_height)/2)-90);	  
            $('arrow-left').setStyle('paddingTop', arrowPosition );
            $('arrow-right').setStyle('paddingTop', arrowPosition );
            $('arrow-right').setStyle('left', (window.getWidth()-25)  +"px" );
                                            
            if(contentScrollHeight < 0)
            {
                $('arrow-right').setStyle('left', (window.getWidth()-42)  +"px" );
            }
        }                                              
    }
    // Gap correection for when scrollbar appear		
    if ($defined($('breadcrumb'))) 
    {
        $('breadcrumb').setStyle('marginLeft', (mywidth) + "px");
    }
    if ($defined($('required-fields'))) 
    {
        $('required-fields').setStyle('marginLeft', (mywidth) + "px");
    }		
    if ($defined($('breadcrumb-sub'))) 
    {
        $('breadcrumb-sub').setStyle('marginLeft', (mywidth) + "px");
    }
    if ($defined($('title-crumb'))) 
    {
        $('title-crumb').setStyle('marginLeft', (mywidth) + "px");
    }	
	if ($defined($('my-account'))) 
	{
        $('my-account').setStyle('marginLeft', (mywidth) + "px");
    }
    if ($defined($('product-cart')))
    {
        $('product-cart').setStyle('marginLeft', (mywidth) + "px");
    }
	if($defined($('cart-panel')) )
	{
		$('cart-panel').setStyle('left', (724 + mywidth) + "px");
	}
	// Fix the newletter page and else the product page
	if($defined($('column1')))
	{
	    if($defined($('page-content-menu-newsletter')))
	    {
	        $('column1').setStyle('height', "auto");
	        $('page-content-menu-newsletter').setStyle('height', "auto");
	        $('page-content-text').setStyle('height', "auto");
	        $('page-content-menu-newsletter').setStyle('height', ($('column2').offsetHeight - 8) + "px");
	        $('page-content-text').setStyle('height', ($('column2').offsetHeight - 8) + "px");
            $('column1').setStyle('width', (mywidth-30) + "px");
            if(Browser.Engine.trident && Browser.Engine.version == 5) // IE7
                $('content').setStyle('height', ($('content_wrapper').offsetHeight - $('content-header').offsetHeight) + 'px');
        }
        else
        {
            $('column1').setStyle('height', "auto");
            $('page-content-menu').setStyle('height', "auto");
            $('column1').setStyle('height', $('column2').offsetHeight + "px");
            $('page-content-menu').setStyle('height', ($('column2').offsetHeight - 21) + "px");
            $('column1').setStyle('width', (mywidth) + "px");
        }
	}
    
	// Product Listing - Activate the slider
	if ($defined($('content-product-slider'))) 
	{
	    $('content-product-slider').setStyle('width', window.getWidth());
        makeScrollbar($('content-product-slider'), $('scrollbar1'), $('handle1'), 'horizontal', false) ;
    }
    if ($defined($('content-product-slider-grid'))) 
    {
        // Center the grid if there are less than 7 rows.
        if($$('table#product-grid td').length < 7)
        {
            var move = Math.floor(($('content-product-slider-grid').getWidth() - $('product-grid').getWidth()) / 2);
            $('product-grid').setStyle('marginLeft', move + 'px');
        }
        if($defined($('scrollbar1')) && $defined($('handle1')))
            makeScrollbar($('content-product-slider-grid'), $('scrollbar1'), $('handle1'), 'horizontal', false);
    }
    if ($defined($('content-product-must-have'))) 
    {
        makeScrollbar($('content-product-must-have'), $('scrollbar1'), $('handle1'), 'horizontal', false);
    }
    
}
var domComplete = false;
window.addEvent('domready', function() {

    // ************************************* Product tab event ****************************************************
    if ($defined($('productTabs'))) {
            var sTab = $('productTabs').getElements('li.selected')[0];

            $('productTabs').getElements('li').addEvent('click', function(event) {

                var clickedLi = this;
                if (clickedLi != sTab) {
                    var clickedClass = clickedLi.getProperty("class");
                    var selectedClass = sTab.getProperty("class").replace(' selected', "");

                    clickedLi.setProperty("class", clickedClass + ' selected');
                    sTab.setProperty("class", selectedClass);

                    var clickedProductTabsResultClass = $('productTabsResult').getElements('div.' + clickedClass).getProperty("class");
                    var selectedProductTabsResultClass = $('productTabsResult').getElements('div.' + selectedClass).getProperty("class")[0].replace(' selected', "");
                    
                    $('productTabsResult').getElements('div.' + clickedClass).setProperty("class", clickedProductTabsResultClass + ' selected');
                    $('productTabsResult').getElements('div.' + selectedClass).setProperty("class", selectedProductTabsResultClass);

                    sTab = clickedLi;
                }
            });
        }


    // pour faire fonctionner le popup du Rating nous changeon la place du div par script
    if ($defined($('dRateProduct'))) {
        $('dRateProduct').inject(document.body, 'bottom');
    }
    // *****************************************


    if (Browser.Engine.gecko)
        footerHeight = 153;

    LoadMouseOvers();

    if ($defined($('closetab-img'))) {
        $('closetab-img').addEvent('click', function() {
            if (navPanel == true) {
                slideUp2.start('top', openPos, closedPos).chain(function() {
                navPanel = false;
                if ($('closetab-img').get('src').indexOf("fr", 1) > 0) {
                    $('closetab-img').set('src', 'images/buffalo/fr/btn_ouvrir.png');
                } else {
                    $('closetab-img').set('src', 'images/buffalo/btn_open.png');
                }
                });
                closeTab();
            }
        });
    }
    if ($defined($('zoom-img'))) {
        $('zoom-img').addEvent('mouseover', function() {
            var dList = $('zoom-img').getElementsByTagName('DIV');
            if (dList) {
                for (var x = 0; x < dList.length; x++) {
                    if (dList[x]) {
                        if (dList[x].className != null && dList[x].className == 'MagicZoomBigImageCont') {
                            document.getElementById('zoom-img-big').appendChild(dList[x]);
                            document.getElementById('zoom-img-big').style.display = '';
                        }
                        if (!zoomEventSet && (dList[x] != null && dList[x].className != null && dList[x].className == 'MagicZoomPup')) {
                            zoomEventSet = true;
                            $(dList[x]).addEvent('mouseout', function() {
                                if (document.getElementById('zoom-img-big').hasChildNodes()) {
                                    document.getElementById('zoom-img').appendChild(document.getElementById('zoom-img-big').firstChild);
                                }
                                document.getElementById('zoom-img-big').style.display = 'none';
                            });
                        }
                    }
                }
            }
        });
        $('zoom-img').addEvent('mouseout', function() {
            if ($defined($('zoom-img-big')) && $defined($('zoom-img'))) {
                document.getElementById('zoom-img-big').style.display = 'none';
                var d = document.getElementById('zoom-img-big').firstChild;
                if (document.getElementById('zoom-img').hasChildNodes() && document.getElementById('zoom-img').childNodes.length > 1 && d)
                    document.getElementById('zoom-img').insertBefore(d, document.getElementById('zoom-img').childNodes[1]);
            }
        });
    }

    resetContentHeight();

    if ($defined($('more-view-slide'))) {
        var closedPos = 336;
        var openPos = 251;
        slideUp2 = new Fx.Tween('nav-product', 'top', { duration: 5, transition: 'linear:easeIn' });
        $('more-view-slide').addEvent('mouseover', function() {
            if (navPanel == false) {
                displayTab('more-views');
                if ($('closetab-img').get('src').indexOf("fr", 1) > 0) {
                    $('closetab-img').set('src', 'images/buffalo/fr/btn_x.png');
                } else {
                    $('closetab-img').set('src', 'images/buffalo/btn_x.png');
                }
                if (!slideStart) {
                    slideUp2.start('top', closedPos, openPos).chain(function() { navPanel = true; slideStart = false; });
                    slideStart = true;
                }
            }
        });
        $('similar-view-slide').addEvent('mouseover', function() {
            if (navPanel == false) {
                displayTab('more-similar');
                if ($('closetab-img').get('src').indexOf("fr", 1) > 0) {
                    $('closetab-img').set('src', 'images/buffalo/fr/btn_x.png');
                } else {
                    $('closetab-img').set('src', 'images/buffalo/btn_x.png');
                }
                if (!slideStart) {
                    slideUp2.start('top', closedPos, openPos).chain(function() { navPanel = true; slideStart = false; });
                    slideStart = true;
                }
            }
        });
        $('complete-view-slide').addEvent('mouseover', function() {
            if (navPanel == false) {
                displayTab('complete-look');
                if ($('closetab-img').get('src').indexOf("fr", 1) > 0) {
                    $('closetab-img').set('src', 'images/buffalo/fr/btn_x.png');
                } else {
                    $('closetab-img').set('src', 'images/buffalo/btn_x.png');
                }
                if (!slideStart) {
                    slideUp2.start('top', closedPos, openPos).chain(function() { navPanel = true; slideStart = false; });
                    slideStart = true;
                }
            }
        });
        $('closetab-x').addEvent('mouseover', function() {
            if (navPanel == false) {
                displayTab('more-views');
                if ($('closetab-img').get('src').indexOf("fr", 1) > 0) {
                    $('closetab-img').set('src', 'images/buffalo/fr/btn_x.png');
                } else {
                    $('closetab-img').set('src', 'images/buffalo/btn_x.png');
                }
                if (!slideStart) {
                    slideUp2.start('top', closedPos, openPos).chain(function() { navPanel = true; slideStart = false; });
                    slideStart = true;
                }
            }
        });
    }

    // Must Have
    if ($defined($('mustHave'))) {

        var selectedItem = $('mustHave').getElements('li')[0];
        selectedItem.className = 'mustHaveBox selectedMh';

        var clickableMh = true;

        $('mustHave').getElements('li.mustHaveBox, li.selectedMh').addEvent('click', function(event) {

            var clickedLi = this;

            if (clickedLi != selectedItem && clickableMh) {
                clickableMh = false;

                var firstEffect = new Fx.Morph(clickedLi, {
                    duration: 500,
                    onComplete: function() {
                        clickedLi.setProperty("class", 'mustHaveBox selectedMh');
                        selectedItem.setProperty("class", 'mustHaveBox');
                        selectedItem = clickedLi;
                        clickableMh = true;
                    }
                });

                firstEffect.start({
                    'background-color': "#ffffff",
                    'border-color': "#cccccc",
                    "height": "235px"
                });

                var marginTopSlider1 = new Fx.Morph(clickedLi.getElement('.header'), {
                    duration: 500
                });

                marginTopSlider1.start({
                    'margin-top': "10px"
                });

                var secondEffect = new Fx.Morph(selectedItem, {
                    duration: 500
                });

                secondEffect.start({
                    'background-color': "#f7f7f7",
                    'border-color': "#f7f7f7",
                    "height": "51px"
                });

                var marginTopSlider2 = new Fx.Morph(selectedItem.getElement('.header'), {
                    duration: 500
                });

                marginTopSlider2.start({
                    'margin-top': "0px"
                });

                var colorEffect = new Fx.Morph(selectedItem.getElement('.header a'), {
                    duration: 500
                });

                colorEffect.start({
                    'color': "#F7F7F7"
                });

                var selectColorEffect = new Fx.Morph(clickedLi.getElement('.header a'), {
                    duration: 500
                });

                selectColorEffect.start({
                    'color': "#464646"
                });

                //********************
                // ****************************
            }
        });
    }

    if($defined($('nav-product-buttons')))
        $('nav-product-buttons').addEvent('mouseenter', function(){switchMoreView(selectedTab);});
    
    if ($defined($$('li.reviews'))) {
        SelectRatingsTab($$('li.reviews'));
    }
    domComplete = true;
});
// -- End of Window load event


var slideStart = false;
var navPanel = false;
window.addEvent('resize', function() {  resetContentHeight()  });

var cartTimerId = 0;
var cartslideIsDown = false;
function resetInput(thisID)
{
	thisID.value = "";
}

function photoEnlarge()
{
  $('click-enlarge').setStyle('visibility','hidden');	
  $('view-smaller').setStyle('visibility','visible');	
}
function photoNormal()
{
  $('view-smaller').setStyle('visibility','hidden');	
  $('click-enlarge').setStyle('visibility','visible');	
}


var selectedTab = 0;

function switchMoreView(ind){
  
  if(domComplete == true)
  {
      // Set the selected view
      var container = document.getElementById('more-views');
      
      if(container)
      {
          container.getElementsByTagName('DIV')[selectedTab].getElementsByTagName('IMG')[0].className = '';
          container.getElementsByTagName('DIV')[ind].getElementsByTagName('IMG')[0].className = 'selected';
          if(selectedTab != ind)
          {
            selectedTab = ind;
          
            if($defined($('zoom-img')))
            {
                var dList = $('zoom-img').getElementsByTagName('DIV');
                var found1 = false;
                for(var x=0;x<dList.length;x++)
                {
                    if(dList[x])
                    {
                        if(dList[x].className == 'MagicZoomPup')
                        {
                            if(found1)
                            {
                                $('zoom-img').removeChild(dList[x]);
                            }
                            else
                            {
                                found1 = true;
                            }
                        }
                    }
                }
              
                var selSrc = container.getElementsByTagName('DIV')[ind].getElementsByTagName('IMG')[0].src;
              
                //if(window.MagicZoom_stopZooms != null && document.getElementById('zoom-img'))
                {
                    try{
                        // Stop Magic Zoom
                        MagicZoom_stopZooms();
                    }
                    catch(e)
                    {
                        
                    }
                    // Get the reference to the <A> tag
                    var zoomLink = document.getElementById('zoom-img');
                    // Change the URL for the large image
                    zoomLink.href = selSrc.replace(/icon/, 'large');
                    // Change the small image
                    zoomLink.firstChild.src = selSrc.replace(/icon/, 'medium');
                    // Re-initialize Magic Zoom
                    MagicZoom_findZooms();
                    
                    
                }
            }
          }
        }
    }
}

var lastTab="";
function displayTab (tab)
{
    if(domComplete)
    {
        if(window.pageTracker)
            pageTracker._trackPageview('/producttabs/'+lastTab);
        if(lastTab != "")
        {
          $(lastTab).setStyle('visibility','hidden');
          if($(lastTab+"-img").src.indexOf('/fr/') > 0)
            $(lastTab+"-img").src ="images/buffalo/fr/btn_"+lastTab+".png";
          else
              $(lastTab+"-img").src ="images/buffalo/btn_"+lastTab+".png";
        }
        $(tab).setStyle('visibility','visible');
        if($(tab+"-img").src.indexOf('/fr/') > 0)
            $(tab+"-img").src ="images/buffalo/fr/btn_"+tab+"_o.png";
        else
            $(tab+"-img").src ="images/buffalo/btn_"+tab+"_o.png";
        lastTab = tab;
    }
}

function closeTab()
{
	$(lastTab+"-img").src ="images/buffalo/btn_"+lastTab+".png";
}

window.addEvent('domready', function() {

    if ($defined($('productTabsResult'))) {
        // ******************************************************************
        //Il est important de s'asurer que l'element est display block avant de faire le MooScroll
        $('productTabsResult').getElements('div.reviews').setProperty("class", 'reviews scroll selected');

        var myScroll = new MooScroll({
            disabledOpacity: 0
        });

        $('productTabsResult').getElements('div.reviews').setProperty("class", 'reviews scroll');
        // ******************************************************************
    }

    bgimgRollovers = function(rollovers) {
        rollovers.each(function(thisro) {
            thisro.setStyle('background-position', '0px -13px');
            thisro.set('tween', {
                duration: 150
            });
            thisro.addEvent('mouseenter', function() {
                this.tween('background-position', '0px 0px');
            });
            thisro.addEvent('mouseleave', function() {
                this.tween('background-position', '0px -13px');
            });
        });
    };
    bgimgRollovers($$('.bg_ro'));



    if ($defined($('footer'))) {
        $$('.footer').each(function(el) {
            if (el.hasClass('nav_active')) {
                el.setStyle('background-position', '0px 0px');
            } else {
                el.setStyle('background-position', '0px -5px');
                el.set('tween', { transition: 'quint:out' });
                el.addEvent('mouseenter', function() {
                    el.tween('background-position', '0px 0px');
                    if ($defined(active_nav)) {
                        active_nav.tween('background-position', '0px -5px');
                    }
                });
                el.addEvent('mouseleave', function() {
                    el.tween('background-position', '0px -5px');
                    if ($defined(active_nav)) {
                        active_nav.tween('background-position', '0px 0px');
                    }
                });
            }
        });

        active_subnav = $('subnav').getElement('.nav_active');

        if ($defined(active_subnav)) {
            active_subnav.set('tween', { transition: 'quint:out' });
        }

        $$('.subnav').each(function(el) {
            if (el.hasClass('nav_active')) {
                El.setStyle('background-position', '0px 0px');
            } else {
                el.set('tween', { transition: 'quint:out' });
                el.setStyle('background-position', '0px -35px');
                el.addEvent('mouseenter', function() {

                    el.tween('background-position', '0px 0px');
                    if ($defined(active_subnav)) {
                        active_subnav.tween('background-position', '0px -35px');
                    }
                });

                el.addEvent('mouseleave', function() {
                    el.tween('background-position', '0px -35px');
                    if ($defined(active_subnav)) {
                        active_subnav.tween('background-position', '0px 0px');
                    }
                });
            }
        });
    }


    if ($defined($('careers_node')) && $defined($('careers_postings'))) {
        if ($('careers_postings_content').getSize().y > $('careers_postings').getSize().y) {
            var careers_moobar = new MooBar($('careers_postings'), $('careers_postings').getSize().y, {});
        }
    }



    doRollovers = function(elements) {
        elements.each(function(thisel) {
            var src = thisel.getProperty('src');
            src = src.replace('_ro.', '.');
            var extension = src.substring(src.lastIndexOf('.'), src.length);
            thisel.getParent().getParent().setStyle('background', 'url(' + src.replace(extension, '_ro' + extension) + ') no-repeat');
            thisel.addEvent('mouseenter', function() { this.fade(0.01); });
            thisel.addEvent('mouseleave', function() { this.fade(1); });
        });
    };

    doRollovers($$('.rollover'));

    doStdRollovers = function(elements) {
        elements.each(function(thisel) {
            var src = thisel.getProperty('src');
            src = src.replace('_ro.', '.');
            var extension = src.substring(src.lastIndexOf('.'), src.length);
            var newsrc = src.replace(extension, '_ro' + extension);
            new Asset.image(newsrc);
            thisel.addEvent('mouseenter', function() {
                this.setProperty('src', newsrc);
                if (Browser.Engine.trident4) {
                    new pngFix({ imgElements: $$(this) });
                }
            });
            thisel.addEvent('mouseleave', function() {
                this.setProperty('src', src);
                if (Browser.Engine.trident4) {
                    new pngFix({ imgElements: $$(this) });
                }
            });
        });
    };
    doStdRollovers($$('.stdrollover'));


}); 

function getWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return {width:myWidth, height:myHeight};
}

function HideSizeChart(){
    var win = document.getElementById('dSizeChart').style.display = 'none';
    document.getElementById('fade').style.display='none';
}

function HideAlertLightBox() {
    showSelects();
    var win = document.getElementById(div2Close).style.display = 'none';
    document.getElementById('fade').style.display='none';
    div2Close = '';
}
var swfList = new Array();
function SwfResize(id)
{
    swfList[swfList.length] = id;
}

// Overload the alert method so we can use a custom light box.
function alert(msg){
 ShowMessageLightBox(msg, 'classicAlertBox', true);
}

var div2Close = '';
// Used for change country only
function ShowMessageLightBox(msg, divId, showOkButton) {
    hideSelects();
    div2Close = divId;
    if(divId.indexOf('classic') != -1)
    {
        if(showOkButton)
        {
            document.getElementById('alertLightBoxOkButton').style.display = 'block';
        }
        else
        {
            document.getElementById('alertLightBoxOkButton').style.display = 'none';
        }
        document.getElementById('alertMsg').innerHTML = msg;
    }
        
    if ( (!(navigator.userAgent.toLowerCase().indexOf('msie 7') > -1)) )
    {
        //if Internet explorer 7, do not do this, because all the page became work and cannot work
    }
        document.getElementById('fade').style.display='block';
    
    var win = document.getElementById(divId);
    var wSize = getWindowSize();
    var tPos = (wSize.height/2)-250;
    win.style.left =  ((wSize.width/2) - (470/2)) + 'px';
    win.style.top =  tPos + 'px';
    win.style.display = 'block';
}

function HideLightBox(divId, obj)
{
    if($defined(divId))
    {
        $(divId).setStyle('display', 'none');
    }
    else
    {
        while(obj.style.position != 'absolute')
        {
            obj = obj.parentElement;
        }
        obj.style.display = 'none';
    }
    $('fade').setStyle('display', 'none');
}

function ResetGGPopup()
{
    $('ggContent').setStyle('display', '');
    $('ggResponse').setStyle('display', 'none');
}

function ShowLightBox(divId, objWidth)
{
    document.getElementById('fade').style.display='block';
    var win = document.getElementById(divId);
    win.style.width = objWidth + 'px';
    $$("div#" + divId + " div.lBoxTop").setStyle('width', objWidth + 'px');
    $$("div#" + divId + " div.lBoxContent").setStyle('width', (objWidth-8) + 'px'); // 8 is the div borders
    $$("div#" + divId + " div.lBoxFooter").setStyle('width', objWidth + 'px');
    
    if(navigator.userAgent.match(/MSIE/) && win.nextSibling != document.getElementById('fade'))
    {
        document.body.insertBefore(win, document.getElementById('fade'));
    }
    
    var wSize = getWindowSize();
    var tPos = (wSize.height/2) - 250;
    win.style.left =  ((wSize.width/2) - (objWidth/2)) + 'px';
    win.style.top =  tPos + 'px';
    win.style.display = '';
}

function ShowSizeChart(obj)
{
    var objWidth = document.getElementById(obj).style.width.toString().replace(/px/,'');
    ShowLightBox(obj, objWidth);
}

// When the user click on a color in the product listing page. It changes the image for this color.
function SlideShowImage(productID, frontImage, backImage)
{
    // Place the spinner in front of the image
    if(!$('spinner_'+productID))
    {
        var spinner = document.createElement('IMG');
        spinner.style.position = 'absolute';
        spinner.src = "images/spinner.gif";
        spinner.style.zIndex = 99999;
        spinner.style.display = 'none';
        spinner.id = 'spinner_' + productID;
        document.body.appendChild(spinner);
    }

    var pos = $('ProductPic'+productID).getPosition(); //returns {x: 100, y: 500};

    pos.x += 100;
    pos.y += 100;

    $('spinner_'+ productID).setStyle('left', pos.x + 'px');//.setPosition(pos);
    $('spinner_'+ productID).setStyle('top', pos.y + 'px');
    $('spinner_'+ productID).setStyle('diaplay', 'block');

    var images = [frontImage, backImage];
    window.slloader = new Asset.images(images, {    
            onComplete: function(){
                $('spinner_'+productID).setStyle('diaplay', 'none');
            }
        });
    document.getElementById('ProductPic' + productID).src = frontImage;
}

// Called on mouseover and mouse out of an image in the product listing page
function ShowBackImage(imgID, isReset)
{
    var imSrc = document.getElementById(imgID).src;
    var isProduct = imSrc.indexOf('icon');
    if(isReset)
    {
        if(isProduct != -1)
        {
            imSrc = imSrc.replace(/iconLargeSwap/i, 'iconLarge');
        }
        else
        {
            imSrc = imSrc.replace(/musthaveSwap/i, 'musthave');
        }
    }
    else
    {
        if(isProduct != -1)
        {
            imSrc = imSrc.replace(/iconLarge/i, 'iconLargeSwap');
        }
        else
        {
            imSrc = imSrc.replace(/musthave/i, 'musthaveSwap');
        }
    }
    document.getElementById(imgID).src = imSrc;
}

// Change the image and thumbnails on the product page for a specific color.
var prodImages;
function SwitchProductImages(imName)
{
    if(document.getElementById('more-views'))
    {
        var photoPos = $('photo').getPosition();
        photoPos.x -= 3;
        photoPos.y -= 55;
        $('photo_over').setStyle('left', photoPos.x+'px');
        $('photo_over').setStyle('top', photoPos.y+'px');
        $('photo_over').setStyle('display', 'block');

        // We check if there are 3 or 4 thumbnails. if 4, we load them as well
        var has4 = true;
        var dList = document.getElementById('more-views').getElementsByTagName('DIV');
        if(dList.length > 3 && dList[3].style.display == 'none')
            has4 = false;
        
        // Preload images (medium, large and thumbnails.
        prodImages = ['images/product/large/'+imName+'.jpg', 'images/product/medium/'+imName+'.jpg', 
            'images/product/icon/'+imName+'.jpg', 'images/product/icon/'+imName+'_1.jpg', 'images/product/icon/'+imName+'_2.jpg'];
            
        if(has4)
            prodImages[prodImages.length] = 'images/product/icon/'+imName+'_3.jpg';
            
        
        prodImages[prodImages.length] = 'images/product/medium/'+imName+'.jpg';
        prodImages[prodImages.length] = 'images/product/medium/'+imName+'_1.jpg';
        prodImages[prodImages.length] = 'images/product/medium/'+imName+'_2.jpg';
         
        if(has4)
            prodImages[prodImages.length] = 'images/product/medium/'+imName+'_3.jpg';

        prodImages[prodImages.length] = 'images/product/large/'+imName+'.jpg';
        prodImages[prodImages.length] = 'images/product/large/'+imName+'_1.jpg';
        prodImages[prodImages.length] = 'images/product/large/'+imName+'_2.jpg';
        
        if(has4)
            prodImages[prodImages.length] = 'images/product/large/'+imName+'_3.jpg';
        
        window.prloader = new Asset.images(prodImages, {    
                onComplete: function()
                {
                    var imList = prodImages.length;
                    if($defined($('zoom-img')))
                    {
                        // Stop Magic Zoom
                        MagicZoom_stopZooms();
                        // Get the reference to the <A> tag
                        var zoomLink = document.getElementById('zoom-img');
                        // Change the URL for the large image
                        zoomLink.href = prodImages[0];
                        // Change the small image
                        zoomLink.firstChild.src = prodImages[1];
                        // Re-initialize Magic Zoom
                        MagicZoom_findZooms();
                    }
                    // Replace Thumbnails
                    var tList = $('more-views').getElementsByTagName('DIV');
                    
                    if(tList.length > 3)
                    {              
                        for(var x=0;x<4;x++)
                        {
                            // If were trying to update the 4th image, make sure that we have preloaded that image by looking at the array length
                            if(x < 3 || (x == 3 && imList == 14))
                            {
                                tList[x].firstChild.firstChild.src = prodImages[x+2];
                                tList[x].style.display = '';
                            }
                        }
                    }
                    $('photo_over').setStyle('display', 'none');
                },
                onError: function(){$('photo_over').setStyle('display', 'none');}
            });
    }
}

function PopupRating(url)
{
    document.getElementById('frmRating').src = url;
    ShowMessageLightBox('', 'dRateProduct', false);
}

function SelectRatingsTab(RatingsTab)
{
    if (window.document.URL.indexOf("rate=1")>1)
    {
        window.setTimeout("$$('li.reviews').fireEvent('click');", 100);
    }
}

function hideSelects() {
    if (navigator.userAgent.toLowerCase().indexOf('msie 6') > -1) {
        var selects = $('content_wrapper').getElements('select');
        selects.setStyle("visibility", "hidden");
    }
}

function showSelects() {
    if (navigator.userAgent.toLowerCase().indexOf('msie 6') > -1) {
        var selects = $('content_wrapper').getElements('select');
        selects.setStyle("visibility", "visible");
    }
}