/**
 * brand.slideshow  
 * @memberOf brand
 */
brand.slideshow = Class.create({
    loop: false, 
    autoStart: false,  
    hasNav: false,  
    interval: 2, 
    looks: null,
    currentSlideIndex: -1,
    totalSlides: 0,
    slides: [],
    header: null,
    slide: null,
    link: null,
      
    initialize: function (args) { 
        if (!args.looks||!args.slide) return;
        //console.log("brand.slideshow");
     
        Object.extend(this, args || {});
        var self = this;   
     
        this.totalSlides = this.looks.length;
        var slide, look, header;
        for (var i=0;i<this.totalSlides;i++) {
            slide = {};
            slide.title = this.looks[i].title;
            //preload slides
            slide.slide = new Image();
            slide.slide.src = this.looks[i].image;
            slide.slide.link = this.looks[i].link;  
            //preload headers 
            slide.header = new Image();
            slide.header.src = this.looks[i].header;
            this.slides.push(slide); 
        };
     
        this.hasNav = (this.nav && this.nav.left && this.nav.right);
        if (this.hasNav) {
            if (this.looks.length==1) {
                if (this.nav && this.nav.left) this.nav.left.style.visibility = "hidden";
                if (this.nav && this.nav.right) this.nav.right.style.visibility = "hidden";  
            } else { 
                if (this.nav.left) this.nav.left.observe("click", function() {self.changeSlide(1)} );
                if (this.nav.right) this.nav.right.observe("click",function() { self.changeSlide(-1)} );
            } 
        } 
     
        this.changeSlide(1); 
    }, 
    changeSlide: function(n) {
        this.currentSlideIndex += n;
        if (this.currentSlideIndex > (this.totalSlides-1)) {
            if (this.loop) {
                this.currentSlideIndex = 0;
            } else {
               //hide next btn?
               return;  
            } 
        } else if (this.currentSlideIndex < 0) {
            if (this.loop) {
                this.currentSlideIndex = this.slides.length - 1;
            } else {
               //hide prev btn?
               return;  
            } 
        }
           
        this.setSlide();
    },
    setSlide: function() { 
        console.log("brand.slideshow.changeSlide: "+this.currentSlideIndex);
        this.slide.src = this.slides[this.currentSlideIndex].slide.src;
        if (this.header) this.header.style.backgroundImage = "url("+ this.slides[this.currentSlideIndex].header.src + ")"; 
        if (this.link) this.link.href = this.slides[this.currentSlideIndex].slide.link; 
    }
});
