var swapimages = new Class({

	Implements: [Events, Options],
	
	Options: {
		handle : $empty,
		currentImg : 1,
 		total_banner : 0,
 		showimg : 0,
 		playerStatus : true,
 		attachid : "pg",
		name : "",
		prevImg : 1,
		attachid : "pg",
		licounts : 0
	},
	
	initialize: function(wrapper, relatedname, count, paging_names,options) {
			this.setOptions(options);
			this.wrapper = $(wrapper);
			this.relatedname = $(relatedname);
        	this.total_banner = count;
			this.name = relatedname;
			this.currentImg =1;
			attachid = "pg";
			this.playerStatus = true;
			this.paging_namesli = paging_names;
			
			$(relatedname+'1').fade(1).setStyle('margin-top', '0');
			
			this.Paging = new Element('ul').set("id",this.name+'_Paging').set("class","img_paging").injectBefore(this.relatedname); //inserting UL above the images
		
		if (this.paging_namesli.length >= 0){
			if(this.total_banner > this.paging_namesli.length){
			     this.licounts = this.total_banner-this.paging_namesli.length;
			     for (i=0;i<this.licounts;i++)
			     this.paging_namesli[this.paging_namesli.length] = '*';
			}
			for(i=1;i<=this.total_banner;i++){
			    this.linumber = new Element('li')
                    .set("id", relatedname + i + 'pg')
                    .set("text", this.paging_namesli[i - 1])
                    .injectInside(this.name + '_Paging')
                    .addEvent('click', this.showrequested.bind(this, i)); //insert LI inside UL
		    }
		} else{
		    for(i=1;i<=this.total_banner;i++){
			    this.linumber = new Element('li')
                .set("id", relatedname+i+'pg')
                .set("text", i)
                .injectInside(this.name + '_Paging')
                .addEvent('click', this.showrequested.bind(this, i)); //insert LI inside UL
		    }
		}
		
		// inserting a play button inside ul
		this.player = new Element('div')
            .set("id", relatedname+'_click')
			.set("class", "player")
            .injectTop(relatedname + '_Paging')
            .addEvent('click', this.showcurrent.bind(this, relatedname+'_click'));
		
		$(relatedname+'1pg').setStyle('background-color','#CEC7C1');
		$(relatedname+'1pg').setStyle('color','#000');
		
		//call to rotate function
		this.handle = this.showAdd.periodical(6000,this,this.total_banner,this.name);
	},
	
    /*Function to for rotate image every 6 sec image*/
    showAdd: function(){
	    this.prevImg = this.currentImg;
	
	    if(this.prevImg==0)
	    {
	    $(this.name+attachid).setStyle('background-color','#000');
	    }
	    else
	    {
		    $(this.name+this.prevImg+attachid).setStyle('background-color','#000');
		    $(this.name+this.prevImg+attachid).setStyle('color','#fedf00');
	    }
	
	    if(this.currentImg>=this.total_banner) 
	    {
		    this.currentImg = 0;
	    }
		$(this.name+this.prevImg).fade(0);
		this.currentImg = this.currentImg+1;
		$(this.name+this.currentImg).fade(1);
		$(this.name+this.currentImg).setStyle('margin-top','0');
		$(this.name+this.currentImg+attachid).setStyle('background-color','#CEC7C1');
		$(this.name+this.currentImg+attachid).setStyle('color','#000');
    },

    /*Function to for still image*/
    showcurrent: function(divid){
		if (this.playerStatus == true) {
            this.playerStatus = false;
            $(divid).setStyle('background', 'url(/_images/_interface/utility/play.jpg) no-repeat top left');
			$clear(this.handle);
        }
        else {
            this.playerStatus = true;
            $(divid).setStyle('background', 'url(/_images/_interface/utility/pouse.jpg) no-repeat top left');
			this.showAdd();
			this.handle = this.showAdd.periodical(6000,this,this.total_banner,this.name);
        }
    },

    showrequested: function(clicked){
		$(this.name+this.currentImg).fade(0);
		$(this.name+this.currentImg+attachid).setStyle('background-color','#000');
		$(this.name+this.currentImg+attachid).setStyle('color','#fedf00');
		this.currentImg = clicked;
		$(this.name+this.currentImg).setStyle('margin-top','0');
		$(this.name+this.currentImg).fade(1);
		$(this.name+this.currentImg+attachid).setStyle('background-color','#ccc');
		$(this.name+this.currentImg+attachid).setStyle('color','#000');
		$clear(this.handle);
		if (this.playerStatus == true) {
				this.handle = this.showAdd.periodical(6000,this,this.total_banner,this.name);
		}
    }

});




var swapimages_noplayer = new Class({

	Implements: [Events, Options],
	
	Options: {
		handle : $empty,
		currentImg : 1,
 		total_banner : 0,
 		showimg : 0,
 		attachid : "pg",
		name : "",
		prevImg : 1,
		licounts : 0
	},
	
	initialize: function(wrapper, relatedname, count, paging_names,options) {
			this.setOptions(options);
			this.wrapper = $(wrapper);
			this.relatedname = $(relatedname);
        	this.total_banner = count;
			this.name = relatedname;
			this.currentImg =1;
			attachid = "pg";
			this.paging_namesli = paging_names;
			
			$(relatedname+'1').fade(1).setStyle('margin-top', '0');
			
			this.Paging = new Element('ul')
                .set("id", this.name+'_Paging')
                .set("class", "img_paging")
                .injectBefore(this.relatedname); //inserting UL above the images

			if (this.paging_namesli.length >= 0) {

			    if(this.total_banner > this.paging_namesli.length){
			         this.licounts = this.total_banner-this.paging_namesli.length;
			         for (i=0;i<this.licounts;i++)
			         this.paging_namesli[this.paging_namesli.length] = '*';
			     }

			    for(i=1;i<=this.total_banner;i++){
			    this.linumber = new Element('li')
                    .set("id", relatedname+i+'pg')
                    .set("text", this.paging_namesli[i-1])
                    .injectInside(this.name + '_Paging')
                    .addEvent('click', this.showrequested.bind(this, i)); //insert LI inside UL
		        }
		    } else{
		        for(i=1;i<=this.total_banner;i++){
			        this.linumber = new Element('li')
                        .set("id", relatedname+i+'pg')
                        .set("text", i )
                        .injectInside(this.name + '_Paging')
                        .addEvent('click', this.showrequested.bind(this, i)); //insert LI inside UL
		        }
		   }
		
		$(relatedname+'1pg').setStyle('background-color','#CEC7C1');
		$(relatedname+'1pg').setStyle('color','#000');
		
	},

    showrequested: function(clicked){
				    $(this.name+this.currentImg).fade(0);
				    $(this.name+this.currentImg+attachid).setStyle('background-color','#000');
				    $(this.name+this.currentImg+attachid).setStyle('color','#fedf00');
				    this.currentImg = clicked;
				    $(this.name+this.currentImg).setStyle('margin-top','0');
				    $(this.name+this.currentImg).fade(1);
				    $(this.name+this.currentImg+attachid).setStyle('background-color','#ccc');
				    $(this.name+this.currentImg+attachid).setStyle('color','#000');
    }

});
