/*
 * Special Productslide script for jaloucity.de
 *
 * THIS SCRIPT IS RESTRICTED FOR USE ON jaloucity.de ONLY
 *
 * (c) Copyright 2011 by mediaopt GmbH <http://www.mediaopt.de/>
 */
 
var Productslide = Class.create();
Productslide.prototype = {
	initialize: function(capture, secExecution, jsonKeys){
	    
	    
		this.capture = capture;
		this.captureMenu = capture+'-pagination';
		this.secExecution = secExecution;
	    this.olPagination  = $(this.captureMenu).firstDescendant();

	    this.jsonKeys = jsonKeys;
	    this.keysNum = this.jsonKeys.length;
	    this.id = 0;
		    
   		this.start();
   		
		this.f = $$('div#'+this.capture+' ul li');
		this.fp = $$('div#'+this.captureMenu+' ul li');
	},
	start: function(){
	    
	    this.effaceP(0);
	    
		this.startPe();
		
    	Event.observe($(this.capture),"mouseout", this.startPe.bind(this));
    	Event.observe($(this.capture),"mouseover", this.stopPe.bind(this));
    	
    	this.startOC();
    	
	},
	startPe: function(){
	this.periodik = new PeriodicalExecuter(this.periodicEvent.bind(this),this.secExecution);	
	},
	stopPe: function(){
	this.periodik.stop();
	},
	startOC: function(){
		Event.observe($(this.captureMenu),"mouseout", this.startPe.bind(this));
		Event.observe($(this.captureMenu),"mouseover", this.stopPe.bind(this));
	},
	defaceP: function(){
		
	    /* .productslide is a pseudo class! */
		$$('.productslide').each( function (s)
    		{
				s.removeClassName('active'); 
				s.removeClassName('arrow'); 
			}
		);

	    /* .pleasehideme is a pseudo class! */
		$$('.pleasehideme').each( function (s)
    		{
				s.hide();
			}
		);
	},
	effaceP: function(tempId){

        if (typeof(tempId) == 'undefined')
        {
            tempId = this.id;
        }
        else
        {
            // remember position
            this.id = tempId;
        }

		this.menuitem = 'menuitem-'+this.jsonKeys[tempId];
		this.dataitem = 'dataitem-'+this.jsonKeys[tempId];
		
		$(this.menuitem).addClassName('active arrow');
        $(this.dataitem).show();
	},
	/* periodicEvent() will be called every this.secExecution, used to cycle*/
	periodicEvent: function() {
	    
	    
	    if (this.id != (this.keysNum-1))
	    {
    	    this.defaceP();
    	    this.effaceP(this.id);
	        this.id = (this.id+1);
	    }
	    else
	    {
	        this.defaceP();
    	    this.effaceP();
	        this.id = 0;
	    }
	    
	},
	stopEvent:function(periodicEvent)
	{
	   if (!periodicEvent)
		 if (window.event)
		   periodicEvent = window.event;
		 else
		   return;
	  if (periodicEvent.cancelBubble != null)
		 periodicEvent.cancelBubble = true;
	  if (periodicEvent.stopPropagation)
		 periodicEvent.stopPropagation();
	  if (periodicEvent.preventDefault)
		 periodicEvent.preventDefault();
	} 
};
