/**
 * Internal mail contact
 * @version:  01.01.01 Alpha
 * @modified: 2009-07-06 15:58:00
 */
var slideShow = newObject({
    
    //autoInit  : true,
    slide_url					: [],
    slide_img					: [],
    cur_img						: 0,
    current_featured_link		: 0,
	featured_links_container	: [],
	featured_links_root			: '',
	timer						: null,
	
    init : function(slide_url, featured_links_root)
    {
        this.slide_url				= slide_url;
		this.featured_links_root	= featured_links_root;
    },

    onready : function()
    {
		this.featured_links_container = this.$("#" + this.featured_links_root).getChildren();
		
		for (var i = 0; i < this.featured_links_container.length; i++) {
			this.featured_links_container[i].addListener(this, "onmouseover", "changeImageOnFLinkOver");
			this.featured_links_container[i].addListener(this, "onmouseout", "runSlideShowOnMouseOut");
		}

        var container, i;
        //getting container element of image
        container = this.$("#" + this.config.modelId);

        if (!container) {
            return;
        }

        //make image wrappers
        this.slide_img[0] = container.getChild(0);

        for (i = 1; i < this.slide_url.length; i++) {
            this.slide_img[i] = this.$w0.makeElement('img', {src: this.slide_url[i], alt : 'Model of the month'});
            this.slide_img[i].hide();
            container.elm.appendChild(this.slide_img[i].elm);
        }
		
		this.startTimer();
    },

    onTimer : function()
    {
         this.slide_img[this.cur_img].hide();
         this.cur_img++;

		 this.featured_links_container[this.current_featured_link].removeClass("active");
		 this.current_featured_link++;

         if (this.cur_img >= this.slide_url.length) {
             this.cur_img = 0
         }
		 
		 if (this.current_featured_link >= this.featured_links_container.length) {
			 this.current_featured_link = 0;
		 }
		 
		 this.featured_links_container[this.current_featured_link].addClass("active");
         this.slide_img[this.cur_img].show();
    },
	// Change image on mouse over feature link
	changeImageOnFLinkOver : function(ewr)
    {
		clearTimeout(this.timer);

		for (_li_key in this.featured_links_container) {
			this.featured_links_container[_li_key].removeClass('active');
		}

		this.slide_img[this.cur_img].hide();

		var currentLiId = ewr.elmWr.elm.id;
		var currentId	= parseInt(currentLiId.substr(-1)) - 1;
		this.cur_img	= this.current_featured_link = currentId;
		
		this.slide_img[currentId].show();
		
		ewr.elmWr.addClass('active');
	},
	runSlideShowOnMouseOut : function()
    {
		this.startTimer();
	},
	stopTimer : function()
    {
		clearTimeout(this);
	},
	startTimer : function()
    {
		this.timer = this.setInterval(this.config.period, this, 'onTimer');
	},

    config : {
         "modelId" : 'model_month',
         "period"  : 5000
    }


});


