/*
Author:     Martin Cayouette, martin.cayouette@nurun.com
Updated:    April 22th 2009

Content:
        PACCATALOG Base namespace setup    
        Init all pages
            Send to Friend pop up
        Other Products 
        Main Navigation for IE/Win
        Main Catalogs Navigation
        WishList Confirmation : Pop up page
        Product Details page : Init
            Product Details : Divers
            Product Details : Drop Down List
            Product Details : Informations            
        Generic Popup Window 
*/


// ------[ PACCATALOG Base namespace setup ]------------------------------------------------- //

var PACCATALOG = {
    globals: {
        labels: {}
    },
    pages: {
        all: {},
        catalogs: {},
        productsDetails: {},
        wishList: {}
    },
    widgets: {}
}

// ------[ Init for all pages ]------------------------------------------------- //

PACCATALOG.pages.all.init = function() {

    //IE6 Only patch Navigation : onmouseover level
    MainNavigationInit();

    //Call the Main Catalogs Navigation
    PACCATALOG.pages.catalogsNavigation.init();

    //Call the BRP Other Products
    PACCATALOG.OtherProducts.Init();
    
    /**
    * Initialize Send to a Friend Pop up page
    */
    PACCATALOG.globals.sendEmail = new YAHOO.widget.Panel(
		"sendtofriend",
		{
		    width: "600px",
		    height: "300px",
		    constraintoviewport: true,
		    underlay: "none",
		    close: true,
		    visible: false,
		    fixedcenter: true,
		    draggable: false,
		    zIndex: 5,
		    modal: false
		}
	);
    //Render the panel for screen
    PACCATALOG.globals.sendEmail.render(document.body);

    //Create an array with all anchor with the classname "sendfriend"
    var el = YAHOO.util.Dom.getElementsByClassName('sendfriend', 'a');

    for (var i = 0; el[i]; i++) {
        el[i].onclick = function() {
            var pnl = PACCATALOG.globals.sendEmail;
            pnl.setBody("<iframe width='600' marginwidth='0' marginheight='0' scrolling='no' frameborder='0' height='300' src='" + this.href + "'></iframe>");
            pnl.render();
            pnl.show();
            return false;
        }
        el[i].style.visibility = "visible";
    }
}

// ------[ Other Products ]------------------------------------------------- //
PACCATALOG.OtherProducts = {
    IsShow: false,
    Timer: null,
    DivElement: null,

    Init: function() {
        this.DivElement = document.getElementById("other-brp-products");
        if (this.DivElement) {
            this.DivElement.onmouseover = this.Show;
            this.DivElement.onmouseout = this.Hide;
        }
    },

    Show: function() {
        clearTimeout(PACCATALOG.OtherProducts.Timer);
        PACCATALOG.OtherProducts.Timer = false;
        PACCATALOG.OtherProducts.DivElement.style.display = "block";
        PACCATALOG.OtherProducts.IsShow = true;
        window.scrollTo(0, 10000000);
    },

    Hide: function() {
        PACCATALOG.OtherProducts.Timer = setTimeout('PACCATALOG.OtherProducts.HideTimer()', 500);
    },

    HideTimer: function() {
        PACCATALOG.OtherProducts.Timer = false;
        PACCATALOG.OtherProducts.DivElement.style.display = "none";
        PACCATALOG.OtherProducts.IsShow = false;
    },

    Display: function() {
        if (this.DivElement) {
            if (!this.IsShow) {
                this.Show();
                //this.Timer = setTimeout('PACCATALOG.OtherProducts.HideTimer()',1500);
            }
            else this.Hide();
        }
    }
};
//YAHOO.util.Event.addListener(window, "load", PACCATALOG.OtherProducts.Init);

// ------[ Main Catalogs Navigation ]------------------------------------------------- //

PACCATALOG.pages.catalogsNavigation = {

    init: function() {
        //Find the UL Navigation
        var containerId = document.getElementById('main-nav-catalogs');

        //Find CALLER button, BOX Categories and add click event
        if (containerId) {
            var linkContent = YAHOO.util.Dom.getElementsByClassName('link', 'div', containerId);
            var boxContent = YAHOO.util.Dom.getElementsByClassName('box', 'ul', containerId);

            for (var i = 0; i < linkContent.length; i++) {
                YAHOO.util.Event.on(linkContent[i], 'click', PACCATALOG.pages.catalogsNavigation.LinkPageEvents, { caller: linkContent[i], box: boxContent[i] });
            }
        }
    },

    LinkPageEvents: function(e, params) {
        e = e || event;
        YAHOO.util.Event.preventDefault(e);

        //Control the close/open Box
        //Array replaceClass  ( el , oldClassName , newClassName )
        if (YAHOO.util.Dom.hasClass(params.caller, 'closedCatalogElement') == true) {
            YAHOO.util.Dom.replaceClass(params.caller, "closedCatalogElement", "openedCatalogElement");
            YAHOO.util.Dom.replaceClass(params.box, "closed", "opened");
        }
        else {
            YAHOO.util.Dom.replaceClass(params.caller, "openedCatalogElement", "closedCatalogElement");
            YAHOO.util.Dom.replaceClass(params.box, "opened", "closed");
        }

    }
};
//YAHOO.util.Event.addListener(window, "load", PACCATALOG.pages.catalogsNavigation.init);

 // ------[ Main Navigation for IE/Win ]------------------------------------------------- //
function MainNavigationInit() {
    if (document.all && document.getElementById) {
        navRoot = document.getElementById("main-nav-element");
        if (navRoot) MainNavigationLoop(navRoot, 2)
    }
}
function MainNavigationLoop(obj, level) {
    
    for (var i = 0; i < obj.childNodes.length; i++) {
        node = obj.childNodes[i];
       
        if (node.nodeName == "LI") {
            node.level = level;
            node.onmouseover = MainNavOver;
            node.onmouseout = MainOut;
        }

        if (node.childNodes.length >= 2) {
            for(var j=0;j<node.childNodes.length;j++)
            {
                var node2 = node.childNodes[j];
                if(node2.nodeName=="UL")
                {
                    MainNavigationLoop(node2, level + 1);
                    break;
                }
            }
        }
    }
}
function MainNavOver() {
     /*Condition :
      *     Keep the class "last" and "current" in the LI element
      *         "last": This class is used to remove the right Arrow.
      *         "current": This class is used to set the big button background for current section.
      */

    if (this.level.toString() == "2") {
        if (this.className == "last") {
            this.className = this.className.replace("last", "");
            this.className += "last navOver" + this.level.toString();
        } else if (this.className == "current") {
            this.className = this.className.replace("current", "");
            this.className += "current navOver" + this.level.toString();
        } else {
        this.className += "navOver" + this.level.toString();
        //this.setAttribute('class', this.className);
        }
    } else {
        
        this.className += "navOver" + this.level.toString();
    }
 }
function MainOut() {
     if (this.level.toString() == "2") {
         //Level 2 Only
         if (this.className == "last navOver2") {
             this.className = this.className.replace("last navOver2", "last");
         } else if (this.className == "current navOver2") {
            this.className = this.className.replace("current navOver2", "current");
         } else {
             this.className = this.className.replace("navOver2", "");
         }
     } else {
         this.className = this.className.replace("navOver" + this.level.toString(), "");
     }
 }

 // ------[ WishList Confirmation : Pop up page ]------------------------------------------------- //
 PACCATALOG.pages.wishList = {

     init: function() {
         //Initialize WishList Confirmation Pop up page
         PACCATALOG.pages.wishList.wishListConfirmPopUp = new YAHOO.widget.Panel(
		    "wishList-confirm-pop",
		    {
		        width: "400px",
		        height: "200px",
		        constraintoviewport: true,
		        underlay: "shadow",
		        close: true,
		        visible: false,
		        fixedcenter: true,
		        draggable: false,
		        zIndex: 6,
		        modal: true //Window bkg
		    }
	    );

         //Render the panel for screen
         PACCATALOG.pages.wishList.wishListConfirmPopUp.render(document.body);
              
         var kl = new YAHOO.util.KeyListener(document, { keys: 13 },
                                                     { fn: PACCATALOG.pages.wishList.wishListConfirmPopUp.hide,
                                                     scope: PACCATALOG.pages.wishList.wishListConfirmPopUp,
                                                     correctScope: true
                                                     }, "keyup");

         PACCATALOG.pages.wishList.wishListConfirmPopUp.cfg.queueProperty("keylisteners", kl);
     }, //Init

     showWishListConfirmPopUp: function(content) {

         //Create the Panel
         PACCATALOG.pages.wishList.init();

         /*var content;
         content = "<div id='wishList-confirmation'>";
         if (PACCATALOG.globals.cultureId == "fr") {
         content = content + "<h1>Ma liste</h1>";
         content = content + "<div id='wishList-text'><p>L'items <u>" + name + "</u> a été ajouté ŕ votre liste.</p></div>";
         } else {             
         content = content + "<h1>My Wishlist</h1>";
         content = content + "<div id='wishList-text'><p>The product <u>" + name + "</u> has been added to your Wishlist.</p></div>";
         }
         content = content + "<div id='btn-action'><a class='btn' href='javascript:PACCATALOG.pages.wishList.wishListConfirmPopUp.hide();'><span>OK</span></a></div>";
         content = content + "</div>";*/
         PACCATALOG.pages.wishList.wishListConfirmPopUp.setBody(content);
         PACCATALOG.pages.wishList.wishListConfirmPopUp.render();
         PACCATALOG.pages.wishList.wishListConfirmPopUp.show();

         // Put the focus in the Panel to removed the focus in the "Add to my wishlist" button
         var elPanel = YAHOO.util.Dom.get('btn-action');
         var elPanelHref = elPanel.getElementsByTagName('a');
         elPanelHref[0].focus();         
     }
 };

 // ------[ Product Details : Divers ]------------------------------------------------- //
/*
*   Mix of Javascript YUI and JQuery
*/
 PACCATALOG.pages.productDetails = {

     setSelectedSize: function(sizeCode, size) {
         selectedSize = sizeCode;
         variantId = productNumber + selectedSize + selectedColor;
         $('#size').html(size);
         $('.sizeCode.select').attr('class', 'sizeCode');
         $('.sizeCode[sizeCode="' + sizeCode + '"]').attr('class', 'sizeCode select');
     },

     setSelectedColor: function(colorCode) {
         selectedColor = $('#liSelectedColor').attr('colorCode');
         variantId = productNumber + selectedSize + selectedColor;
         /*
         *   Recall the script used to overlay images on the current page.
         */
         initLytebox();
         /*
         *   Recall the script used to the Slideshow image & the Product Details Informations (Features)
         */
         PACCATALOG.pages.productsDetails.init();
     },

     addToWishList: function() {
         if (productNumber !== '' && canAddToWishlist) {
             var url = "" + wishlistUrl + "/?catalogName=" + wishlistCatalog + "&ProductID=" + productNumber + "&VariantID=" + variantId;
             $('#divFrameWishList').html("<iframe name='frameWishList' onload='PACCATALOG.pages.productDetails.frameLoaded();' id='frameWishList' width='1' marginwidth='0' marginheight='0' scrolling='no' frameborder='0' height='1' src=''></iframe>");
             document.getElementById('frameWishList').src = url;
         } else {
             /* 
             *   Create the content and Calling the script to tell the user to select a choice from the dropdown list.
             */
             var content;
             content = "<div id='wishList-confirm'>";
             content = content + "<h1>" + titleMyWishlist + "</h1>";
             content = content + "<div id='wishList-text'><p>" + requiredMyWishlist + "</p></div>";
             content = content + "<div id='btn-action'><a class='btn' href='javascript:PACCATALOG.pages.wishList.wishListConfirmPopUp.hide();'><span>OK</span></a></div>";
             content = content + "</div>";
             PACCATALOG.pages.wishList.showWishListConfirmPopUp("" + content + "");
         }
     },

     frameLoaded: function() {
         loadCountWishList();
         /* 
         *   Create the content and Call the script to tell that the product has been added to the wishlist
         */
         var content;
         content = "<div id='wishList-confirm'>";
         content = content + "<h1>" + titleMyWishlist + "</h1>";
         content = content + "<div id='wishList-text'><p>" + contentMyWishlist + "</p></div>";
         content = content + "<div id='btn-action'><a class='btn' href='javascript:PACCATALOG.pages.wishList.wishListConfirmPopUp.hide();'><span>OK</span></a></div>";
         content = content + "</div>";
         PACCATALOG.pages.wishList.showWishListConfirmPopUp("" + content + "");
     },

     setVariantInfo: function(texte, that, number, price) {
         canAddToWishlist = true;
         variantId = number;
         // Replaced the price
         $('#productPrice').html(price);
         // Show the product number
         $('#productNumberLabel').attr('class', 'opened');
         $('#productNumber').attr('class', 'sku');
         $('#productNumber').html(number);

         // Removed the last element class
         $('#liste li').attr('class', '');
         // Add class in the current element
         $(that).attr('class', 'select');
         // Close de liste
         $('#listes').attr('class', 'closed-element');
         $('#liste').attr('class', 'model-closed');
         // Add the current text element in first
         $('div.select-list').text(texte);
         $('#listes').css('height', 'auto');
         $('div.select-list').css('height', 'auto');
     },

     setDefaultVariantInfo: function() {
         $('#liste').find('li.select').click();
     },

     mouseOverColor: function(caller) {
         $('#color').html(caller.attributes['colorName'].value);
     },

     mouseOutColor: function() {
         $('#color').html($('#liSelectedColor').attr('colorName'));
     }

 };
 
 // ------[ Product Details page : Init ]------------------------------------------------- /

 PACCATALOG.pages.productsDetails.init = function() {

     // Initialize Product Details : Informations
     PACCATALOG.pages.productDetailsInfo.init();

     // Initialize Product Details : Drop Down List
     PACCATALOG.pages.productDetailsDropDownList.init();

     PACCATALOG.pages.productDetails.setDefaultVariantInfo();

     // Initialize small slideshow
     PACCATALOG.globals.slideShow = new PACCATALOG.widgets.Slideshow("slides", "slide-controls", { timer: 8000 }, "inkEnlarge");
     //PACCATALOG.globals.slideShow = new PACCATALOG.widgets.Slideshow("slides-controler", "slide-controls", { timer: 8000 });
 };

/**
* Creates a slideshow with previous/next buttons and pips in between representing
* the current slide among the total number of slides in the show
*/
 PACCATALOG.widgets.Slideshow = function(slidesId, controlbarId, userConfig, imgZoom) {
     this.slidesEl = YAHOO.util.Dom.get(slidesId);
     this.controlBarEl = YAHOO.util.Dom.get(controlbarId);

     if (!this.slidesEl || !this.controlBarEl) return;

     //Set to "on" the Enlarge btn
     var zoomButton = YAHOO.util.Dom.get(imgZoom);
     this.slidesEl.onmouseover = function() { zoomButton.className = 'zoom-on'; }
     this.slidesEl.onmouseout = function() { zoomButton.className = 'zoom-off'; }
     zoomButton.onmouseover = function() { this.className = 'zoom-on'; }
     zoomButton.onmouseout = function() { this.className = 'zoom-off'; }

     //this.refreshSlidesElDims();
     this.slidesElDims = {
         xy: YAHOO.util.Dom.getXY(this.slidesEl),
         width: this.slidesEl.offsetWidth,
         height: this.slidesEl.offsetHeight
     };

     this.uc = userConfig || {};
     //HIDE this if you want stop the slider and show all promotions.
     this.slides = YAHOO.util.Dom.getElementsByClassName("slide", this.uc.slidesElType || "li", this.slidesEl);
     this.numSlides = this.slides.length;

     this.slidesPtr = 0;
     this.currentSlide = function() { return this.slidesPtr + 1 }

     /*
     *   Initial States :
     *       Show the products details box
     *       Allow to view all the elements after the content is load
     */
     var elProductsDetailsContent = YAHOO.util.Dom.get("products-details-content");
     elProductsDetailsContent.style.display = "block";

     // Only create previous and next buttons if there is more than one slide
     if (this.numSlides > 1) {

         /*
         *   Previous button
         */
         this.prevBtn = document.createElement(this.uc.buttonNodeName || "div");
         this.prevBtn.innerHTML = "&larr;";
         this.prevBtn.className = this.uc.prevBtnClass || "prev";
         this.prevBtn.id = this.uc.prevBtnClass || "pics-left";
         /*this.prevBtn.onclick = function(that) {
         return function() {
         that.goTo(-1);
         that.resetTimer();
         return false;
         }
         } (this);*/
         this.controlBarEl.appendChild(this.prevBtn);

         /*
         *   Main Slider Indicator
         */
         this.mainIndicator = document.createElement(this.uc.buttonNodeName || "div");
         this.mainIndicator.id = this.uc.indicatorClass || "main-indicator";
         //Add no click for the control Bar
         this.mainIndicator.onclick = function() {
             return false;
         }
         this.controlBarEl.appendChild(this.mainIndicator);
         /*
         *   Slider Indicator
         */
         this.indicator = document.createElement(this.uc.buttonNodeName || "div");
         this.indicator.className = this.uc.indicatorClass || "indicator";
         this.indicator.id = this.uc.indicatorClass || "pics-indicator";
         //Add no click for the control Bar
         this.indicator.onclick = function() {
             return false;
         }
         this.pips = [];

         // On Mouse Over on "LI" element stop de slider for MEDIUM images
         // and clear the Timer until the onmouseout reset the Timer.
         for (var i = 0; i < this.numSlides; i++) {
             //console.log("this.slides[i] = " + this.slides[i].className);

             this.slidesContent = YAHOO.util.Dom.getElementsByClassName("slide-content", "div", this.slides[i]);
             this.numSlidesContent = this.slidesContent.length;

             for (var x = 0; x < this.numSlidesContent; x++) {
                 //console.log("this.slidesContent = " + this.slidesContent[x].className);
                 //stopTimer
                 this.slidesContent[x].onmouseover = function(that) {
                     return function() {
                         //that.stopTimer();
                         return false;
                     }
                 } (this);
                 //setTimer
                 this.slidesContent[x].onmouseout = function(that) {
                     return function() {
                         //that.setTimer();
                         return false;
                     }
                 } (this);
             }
         }

         /*
         *   Create all THUMBNAILS Slider Images and Click Action
         */
         for (var i = 0; i < this.numSlides; i++) {
             var pip = document.createElement("div");
             this.slidesContent = YAHOO.util.Dom.getElementsByClassName("slide-content", "div", this.slides[i]);
             this.numSlidesContent = this.slidesContent.length;

             for (var x = 0; x < this.numSlidesContent; x++) {
                 //Find href link for each Wide Img
                 this.slidesHref = this.slidesContent[x].getElementsByTagName("a");
                 this.imagesMediumInfo = this.slidesHref[x];

                 //Find enlarge btn zoom
                 this.aZoom = YAHOO.util.Dom.get(imgZoom);

                 // Initialize the enlarge btn zoom link (first slide)
                 if (i == "0") {
                     this.aZoom.href = this.imagesMediumInfo.href;
                     this.aZoom.title = this.imagesMediumInfo.title;
                 }
                 
                 //Fix the width for the last slide (normal is egal to 79px)
                 if ((i + 1) == this.numSlides) {
                     pip.style.width = "72px";
                 }

                 //Find link thumbnails Img
                 this.slidesImg = this.slidesContent[x].getElementsByTagName("img");
                 this.imagesThumbnails = this.slidesImg[0].getAttribute('thumb');

                 //Add number of Slide : pip.innerHTML = i + 1;
                 pip.innerHTML = "<img src='" + this.imagesThumbnails + "'/>"

                 if ((i + 1) === this.currentSlide()) {
                     pip.className = "current";
                 }

                 pip.onclick = function(that, num, a, link) {
                     return function() {
                         //If the current slide click == to same click, do nothing
                         if (that.slidesPtr != num) {
                             var dir = (that.slidesPtr > num) ? -1 : 1;
                             that.goTo(dir, num);
                             //that.resetTimer();
                             //Set the enlarge btn zoom link
                             a.href = link;
                         }
                     }
                 } (this, i, this.aZoom, this.imagesMediumInfo);

                 this.indicator.appendChild(pip);
                 this.pips.push(pip);
             }
         }
         this.mainIndicator.appendChild(this.indicator);
         //javascript: x = document.body.innerHTML.replace(/</g, '&lt;').replace(/\n/g, '<br>');
         //document.body.innerHTML = x;  

         /*
         *   Next button
         */
         this.nextBtn = document.createElement(this.uc.buttonNodeName || "div");
         this.nextBtn.innerHTML = "&rarr;";
         this.nextBtn.className = this.uc.nextBtnClass || "next";
         this.nextBtn.id = this.uc.nextBtnClass || "pics-right";

         /*this.nextBtn.onclick = function(that) {
         return function() {
         that.goTo(1);
         that.resetTimer();
         return false;
         }
         } (this);*/
         this.controlBarEl.appendChild(this.nextBtn);

         // Get slides out of the way for Safari 2.0.x because they block page links
         for (var i = 1; this.slides[i]; i++) {
             this.slides[i].style.top = "-3000px";
             this.slides[i].style.left = "-3000px";
         }

         this.goTo(0); // to initialize the first slide if it has a popup
         //this.setTimer(); // set automated forward timer

         /*
         *   Initialize the SlideShow Selector
         */
         PACCATALOG.widgets.Slideshow.ImageSelectorScroll.prototype.Init();

     } else {
         /*
         *   Hide the Control Bar El & the title (More Views) when we have Only 1 image product
         */
         this.controlBarEl.style.display = "none";
         var elMoreView = YAHOO.util.Dom.getElementsByClassName('more-views', 'p');
         elMoreView[0].style.display = "none";
         /*
         *   Set the Zoom buttom : Only 1 image product
         */
         // Find href link for the first Wide Img
         this.slidesContent = YAHOO.util.Dom.getElementsByClassName("slide-content", "div", this.slides[0]);
         this.slidesHref = this.slidesContent[0].getElementsByTagName("a");
         this.imagesMediumInfo = this.slidesHref[0];
         // Find enlarge btn zoom
         this.aZoom = YAHOO.util.Dom.get(imgZoom);
         // Initialize the enlarge btn zoom link (first slide)
         this.aZoom.href = this.imagesMediumInfo.href;
         this.aZoom.title = this.imagesMediumInfo.title;
     }
 }  //init

PACCATALOG.widgets.Slideshow.ImageSelectorScroll = function() {};
    PACCATALOG.widgets.Slideshow.ImageSelectorScroll.prototype = {
    picActualPosition: 0,
    listId: 'main-indicator',
    itemsList: 'pics-indicator',
    scrollPrevious: 'pics-left',
    scrollNext: 'pics-right'
    };

PACCATALOG.widgets.Slideshow.ImageSelectorScroll.prototype.Init = function() {
    this.scrollableListContainer = document.getElementById(this.listId);
    this.scrollableList = document.getElementById(this.itemsList);
    this.lnkPrevious = document.getElementById(this.scrollPrevious);
    this.lnkNext = document.getElementById(this.scrollNext);
    this.picsArray = this.scrollableList.getElementsByTagName('div');

    this.picsWidth = this.picsArray[0].offsetWidth;
    this.picsCount = this.picsArray.length;

    // Set the correct "width" for the list : ignoring the scrollableListContainer width
    // Remove "7" because the last slide is 72px (normal is egal to 79px)
    this.scrollableList.style.width = this.picsWidth * this.picsCount - 7 + "px";
    this.ViewablePics = parseInt(this.scrollableListContainer.offsetWidth / this.picsWidth);

    YAHOO.util.Event.addListener(this.lnkPrevious, 'click', this.Scrolling, { caller: this, direction: -1 });
    YAHOO.util.Event.addListener(this.lnkNext, 'click', this.Scrolling, { caller: this, direction: 1, pics: this.ViewablePics, count: this.picsCount });

    //Show the Slider Scroll button if 4 products and more
    if (this.picsCount > "4") {
        YAHOO.util.Dom.setStyle(this.lnkPrevious, 'display', 'block');
        YAHOO.util.Dom.setStyle(this.lnkNext, 'display', 'block');
        this.RefreshNavigation();
    }

    if (this.picActualPosition != 0) {
        var elContainerXY = YAHOO.util.Dom.getXY(this.scrollableListContainer);
        var originalXY = YAHOO.util.Dom.getXY(this.scrollableList);
        var newXY = [elContainerXY[0] + ((this.picActualPosition * -1) * this.picsWidth), originalXY[1]];
        YAHOO.util.Dom.setXY(this.scrollableList, newXY);
    }
};

PACCATALOG.widgets.Slideshow.ImageSelectorScroll.prototype.RefreshNavigation = function() {

    if (this.picActualPosition > 0) {
        //this.lnkPrevious.style.visibility = "visible";
        YAHOO.util.Dom.setStyle(this.lnkPrevious, 'opacity', 1);
    }
    else {
        //this.lnkPrevious.style.visibility = "hidden";
        YAHOO.util.Dom.setStyle(this.lnkPrevious, 'opacity', 0.2);
    }

    if ((this.picActualPosition + this.ViewablePics) < this.picsCount-1) {
        //this.lnkNext.style.visibility = "visible";
        YAHOO.util.Dom.setStyle(this.lnkNext, 'opacity', 1);
    }
    else {
        //this.lnkNext.style.visibility = "hidden";
        YAHOO.util.Dom.setStyle(this.lnkNext, 'opacity', 0.2);
    }
};

PACCATALOG.widgets.Slideshow.ImageSelectorScroll.prototype.Scrolling = function(e, params) {
    
    if (params.direction == "1") {
        // Next
        if ((params.caller.picActualPosition + params.pics) >= params.count-1) {
            //Stop the Click Event if we are in maximum in RIGHT position
            return false;
        } else {
            // Set the new position counter
            params.caller.picActualPosition += params.direction;
        }
    } else {
        // Previous
        if (params.caller.picActualPosition <= 0) {
            //Stop the Click Event if we are in maximum in LEFT position
            return false;
        } else {
            // Set the new position counter
            params.caller.picActualPosition += params.direction;
        }
    }
    var elContainerXY = YAHOO.util.Dom.getXY(params.caller.scrollableListContainer);

    // Get the actual xy postion of the DIV;
    var originalXY = YAHOO.util.Dom.getXY(params.caller.scrollableList);
    // Calculate the new coordinates
    var newXY = [elContainerXY[0] + ((params.caller.picActualPosition * -1) * params.caller.picsWidth), originalXY[1]];
    /* 
    * Anim subclass for moving elements along a path
    * Defined by the "opacity" and "points" member of "attributes"
    * Set the Duration (0.5) and Method (EaseOut) for the animation
    */
    var animSlide = new YAHOO.util.Motion(params.caller.scrollableList, { opacity: { from: 0.3, to: 1 }, points: { to: newXY} }, 0.5, YAHOO.util.Easing.EaseOut);
    animSlide.animate();

    params.caller.RefreshNavigation();

};

PACCATALOG.widgets.Slideshow.prototype.setTimer = function() {
    if (this.uc.timer) {
        this.slideShowInterval = window.setInterval(
		    function(that) {
		        return function() {
		            that.goTo(1);
		        }
		    } (this),
		    this.uc.timer
	    );
    }
}

PACCATALOG.widgets.Slideshow.prototype.resetTimer = function() {
    if (this.slideShowInterval) {
        window.clearInterval(this.slideShowInterval);
        this.setTimer();
    }
}

PACCATALOG.widgets.Slideshow.prototype.stopTimer = function() {
    if (this.slideShowInterval) {
        window.clearInterval(this.slideShowInterval);
    }
}

PACCATALOG.widgets.Slideshow.prototype.refreshSlidesElDims = function() {
    this.slidesElDims = {
        xy: YAHOO.util.Dom.getXY(this.slidesEl),
        width: this.slidesEl.offsetWidth,
        height: this.slidesEl.offsetHeight
    };
}

PACCATALOG.widgets.Slideshow.prototype.goTo = function(dir, skipTo) {
    this.slidesElDims = {
        xy: YAHOO.util.Dom.getXY(this.slidesEl),
        width: this.slidesEl.offsetWidth,
        height: this.slidesEl.offsetHeight
    };

    var outSlide = this.slides[this.slidesPtr];
    var outSlideXY = YAHOO.util.Dom.getXY(outSlide);
    var outSlideWidth = outSlide.offsetWidth;

    if (dir == -1) {
        var outSlideAnim = new YAHOO.util.Motion(outSlide, {
            opacity: {
                from: 1,
                to: 0
            },
            points: {
                from: [
                    this.slidesElDims.xy[0],
                    this.slidesElDims.xy[1]
                ],
                to: [
                    this.slidesElDims.xy[0] + this.slidesElDims.width,
                    this.slidesElDims.xy[1]
                ]
            }
        }
    );
        outSlideAnim.onComplete.subscribe(
       function(el) {
           return function() {
               el.style.top = "-3000px";
               el.style.left = "-3000px";
           }
       } (outSlide)
    );
        outSlideAnim.duration = 0.5;
        outSlideAnim.method = YAHOO.util.Easing.easeOutStrong;

        this.slidesPtr = (this.slides[skipTo]) ? skipTo : this.slides[this.slidesPtr - 1] ? this.slidesPtr - 1 : this.numSlides - 1;
        var inSlide = this.slides[this.slidesPtr];
        var inSlideXY = YAHOO.util.Dom.getXY(inSlide);
        var inSlideAnim = new YAHOO.util.Motion(inSlide, {
            opacity: {
                from: 0,
                to: 1
            },
            points: {
                from: [
                    this.slidesElDims.xy[0] - this.slidesElDims.width,
                    this.slidesElDims.xy[1]
                ],
                to: [
                    this.slidesElDims.xy[0],
                    this.slidesElDims.xy[1]
                ]
            }
        }
    );
        inSlideAnim.duration = 0.5;
        inSlideAnim.method = YAHOO.util.Easing.easeOutStrong;

        outSlideAnim.animate();
        inSlideAnim.animate();


    } else if (dir == 1) {
        var outSlideAnim = new YAHOO.util.Motion(outSlide, {
            opacity: {
                from: 1,
                to: 0
            },
            points: {
                from: [
                    this.slidesElDims.xy[0],
                    this.slidesElDims.xy[1]
                ],
                to: [
                    this.slidesElDims.xy[0] - this.slidesElDims.width,
                    this.slidesElDims.xy[1]
                ]
            }
        }
    );
        outSlideAnim.onComplete.subscribe(
       function(el) {
           return function() {
               el.style.top = "-3000px";
               el.style.left = "-3000px";
           }
       } (outSlide)
    );
        outSlideAnim.duration = 0.5;
        outSlideAnim.method = YAHOO.util.Easing.easeOutStrong;

        this.slidesPtr = (this.slides[skipTo]) ? skipTo : this.slides[this.slidesPtr + 1] ? this.slidesPtr + 1 : 0;
        var inSlide = this.slides[this.slidesPtr];
        var inSlideXY = YAHOO.util.Dom.getXY(inSlide);
        var inSlideAnim = new YAHOO.util.Motion(inSlide, {
            opacity: {
                from: 0,
                to: 1
            },
            points: {
                from: [
                    this.slidesElDims.xy[0] + this.slidesElDims.width,
                    this.slidesElDims.xy[1]
                ],
                to: [
                    this.slidesElDims.xy[0],
                    this.slidesElDims.xy[1]
                ]
            }
        }
    );
        inSlideAnim.duration = 0.5;
        inSlideAnim.method = YAHOO.util.Easing.easeOutStrong;

        outSlideAnim.animate();
        inSlideAnim.animate();
    }
    
    if (this.indicator) {
        for (var i = 0; this.pips[i]; i++) {
            if ((i + 1) === this.currentSlide()) {
                this.pips[i].className = "current";
            } else {
                this.pips[i].className = "";
            }
        }
    }
}

// ------[ Product Details : Drop Down List ]------------------------------------------------- //

PACCATALOG.pages.productDetailsDropDownList = {

    divListeId: null,
    ulListeId: null,
    ddListeInterval: 0,
    elTimer: 2000,

    init: function() {
        //Find the DIV and UL Liste
        divListeId = document.getElementById('listes');
        ulListeId = document.getElementById('liste');

        //Find CALLER button, LISTE option and add click event
        if (divListeId && ulListeId) {
            YAHOO.util.Event.on(divListeId, 'click', PACCATALOG.pages.productDetailsDropDownList.openEvents, { caller: divListeId, box: ulListeId });
            
            //YAHOO.util.Event.on(ulListeId, 'mouseover', PACCATALOG.pages.productDetailsDropDownList.stopTimer, PACCATALOG.pages.productDetailsDropDownList, true);
            YAHOO.util.Event.on(ulListeId, 'mouseover', function() {
                var container = ulListeId;
                return function(e) {
                    e = e || event;
                    relatedTarget = YAHOO.util.Event.getRelatedTarget(e);
                    //console.log("mouseover relatedTarget = " + relatedTarget);
                    if (typeof relatedTarget === "undefined") {
                        /*If Outside ViewPort*/
                        //console.log("if relatedTarget = undefined");
                        PACCATALOG.pages.productDetailsDropDownList.stopTimer();
                    } else {
                        /*Look if we are inside the Parent Element*/
                        var isInside = YAHOO.util.Dom.getAncestorBy(relatedTarget, function(el) {
                            //console.log("el.id = " + el.id);
                            //console.log("relatedTarget = " + relatedTarget);
                            if (el.id === container.id) {
                                //console.log("mouseover isInside = true ");
                                 return true;
                            }
                            return false;
                        });
                        if (!isInside) {
                            //console.log("mouseover !isInside = stopTimer ");
                            PACCATALOG.pages.productDetailsDropDownList.stopTimer();
                        }
                    }
                }
            } (), PACCATALOG.pages.productDetailsDropDownList, true);
            
            //YAHOO.util.Event.on(ulListeId, 'mouseout', PACCATALOG.pages.productDetailsDropDownList.resetTimer, PACCATALOG.pages.productDetailsDropDownList, true);
            YAHOO.util.Event.on(ulListeId, 'mouseout', function() {
                var container = ulListeId;
                return function(e) {
                    e = e || event;
                    relatedTarget = YAHOO.util.Event.getRelatedTarget(e);
                    if (typeof relatedTarget === "undefined") {
                        /*If Outside ViewPort*/
                        //console.log("mouseout if relatedTarget = undefined");
                        //PACCATALOG.pages.productDetailsDropDownList.stopTimer();
                    } else {
                        /*Look if we are inside the Parent Element*/
                        if (YAHOO.util.Dom.hasClass(divListeId, 'opened-element') == true) {
                            var isInside = YAHOO.util.Dom.getAncestorBy(relatedTarget, function(el) {
                                //console.log("mouseout el.id = " + el.id);
                                //console.log("mouseout container.id = " + container.id);
                                //console.log("mouseout relatedTarget = " + relatedTarget);
                                //console.log("mouseout relatedTarget.id = " + relatedTarget.id);
                                if (el.id === container.id || relatedTarget.id === container.id) {
                                    //console.log("mouseout isInside = true ");
                                    return true;
                                }
                                return false;
                            });
                            if (!isInside) {
                                //console.log("mouseout !isInside = resetTimer ");
                                PACCATALOG.pages.productDetailsDropDownList.resetTimer();
                            }
                        }
                    }
                }
            } (), PACCATALOG.pages.productDetailsDropDownList, true);

        }
    },

    openEvents: function(e, params) {
        e = e || event;
        YAHOO.util.Event.preventDefault(e);
        //Control the close/open Box
        //Array replaceClass  ( el , oldClassName , newClassName )
        if (YAHOO.util.Dom.hasClass(params.caller, 'closed-element') == true) {
            YAHOO.util.Dom.replaceClass(params.caller, "closed-element", "opened-element");
            YAHOO.util.Dom.replaceClass(params.box, "model-closed", "model-opened");
            PACCATALOG.pages.productDetailsDropDownList.setTimer(); // set automated timer
        }
        else {
            YAHOO.util.Dom.replaceClass(params.caller, "opened-element", "closed-element");
            YAHOO.util.Dom.replaceClass(params.box, "model-opened", "model-closed");
            PACCATALOG.pages.productDetailsDropDownList.stopTimer(); // stop timer
        }
    },

    closeEvents: function(interval) {
        PACCATALOG.pages.productDetailsDropDownList.stopTimer();
        //Closed DIV and UL element
        YAHOO.util.Dom.replaceClass(divListeId, "opened-element", "closed-element");
        YAHOO.util.Dom.replaceClass(ulListeId, "model-opened", "model-closed");
    },

    setTimer: function() {
        if (this.elTimer) {
            this.ddListeInterval = window.setInterval(PACCATALOG.pages.productDetailsDropDownList.closeEvents, this.elTimer);
        }
    },

    resetTimer: function() {
        if (this.ddListeInterval) {
            window.clearInterval(this.ddListeInterval);
            PACCATALOG.pages.productDetailsDropDownList.setTimer();
        }
    },
    
    stopTimer: function() {
        if (this.ddListeInterval) {
            window.clearInterval(this.ddListeInterval);
        }
    }
};
//YAHOO.util.Event.addListener(window, "load", PACCATALOG.pages.catalogsNavigation.init);

// ------[ Product Details : Informations ]------------------------------------------------- //

PACCATALOG.pages.productDetailsInfo = {

    init: function() {

        //Find the DIV features information
        this.containerId = document.getElementById('features');

        //Find CALLER button, BOX and add click event
        if (this.containerId) {
            this.linkContent = YAHOO.util.Dom.getElementsByClassName('features-info', 'span', this.containerId);
            this.boxContent = YAHOO.util.Dom.getElementsByClassName('box', 'ul', this.containerId);

            for (var i = 0; i < this.linkContent.length; i++) {
                YAHOO.util.Event.on(this.linkContent[i], 'click', PACCATALOG.pages.productDetailsInfo.LinkBoxEvents, {
                    caller: this.linkContent[i],
                    box: this.boxContent[i],
                    number: this.linkContent,
                    boxAll: this.boxContent
                }
                );
            }
        }
    },

    LinkBoxEvents: function(e, params) {
        e = e || event;
        YAHOO.util.Event.preventDefault(e);

        //Close all box before opening the new
        for (var i = 0; i < params.number.length; i++) {
            if (params.caller !== params.number[i]) {
                if (YAHOO.util.Dom.hasClass(params.number[i], 'openedFeaturesEl') == true) {
                    YAHOO.util.Dom.replaceClass(params.number[i], "openedFeaturesEl", "closedFeaturesEl");
                    YAHOO.util.Dom.replaceClass(params.boxAll[i], "opened", "closed");
                }
            }
        }

        //Control the close/open Box
        //Array replaceClass  ( el , oldClassName , newClassName )
        if (YAHOO.util.Dom.hasClass(params.caller, 'closedFeaturesEl') == true) {
            YAHOO.util.Dom.replaceClass(params.caller, "closedFeaturesEl", "openedFeaturesEl");
            YAHOO.util.Dom.replaceClass(params.box, "closed", "opened");
        }
        else {
            YAHOO.util.Dom.replaceClass(params.caller, "openedFeaturesEl", "closedFeaturesEl");
            YAHOO.util.Dom.replaceClass(params.box, "opened", "closed");
        }

    }
};
//YAHOO.util.Event.addListener(window, "load", PACCATALOG.pages.productDetailsInfo.init);

// ------[ Generic Popup Window ]------------------------------------------------- //
function popWin(url, w, h, scroll, tools, name, center) {
    var str = "height=" + h + ",innerHeight=" + h;
    str += ",width=" + w + ",innerWidth=" + w;
    if (!center) center = true;
    if (!scroll) scroll = 0;
    if (!tools) tools = 0;
    if (!name) name = "pop";

    if ((window.screen) && (center)) {
        var ah = screen.availHeight - 30;
        var aw = screen.availWidth - 10;

        var xc = (aw - w) / 2;
        var yc = (ah - h) / 2;

        str += ",left=" + xc + ",screenX=" + xc;
        str += ",top=" + yc + ",screenY=" + yc;
    }
    window.name = "main";
    pop = window.open(url, name, 'toolbar=' + tools + ',location=0,directories=0,status=0,menubar=0,scrollbars=' + scroll + ',resizable=0,' + str).focus();
}