/*
 * Copyright 2009 - 2011 Horacio Daniel Ros
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2 of the License, or any later version.
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License along with this program;
 * if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 */

/*
 * Project:       Javascript Slideshow
 * Author:        Horacio Daniel Ros
 * E-mail:        horaciodrs@gmail.com
 * Site:          http://www.javabs.com.ar
 * Date:          2011/07/26
 * Last Update:   2011/07/26
 */
 
function SliderItem(){
	this.Id;
	this.SliderId;
	
	this.PreviewBar;
	
	this.Description;
	this.imgPreview;
	this.PreviewOver;							//contenido que se muestra un contenido cuando el mouse pasa por arriva del preview.
	this.PreviewFn;								//funcion que ejecuta cuando hace click en el boton de preview.
	
	this.htmlDiv;								//div en que se muestran los frames.
	this.htmlDescription;						//div que contiene ls descripcion.
	this.htmlDivPreview;						//div en que se muestran los frames.
	this.htmlDivPreviewOver						//div en que se muestra un contenido cuando el mouse pasa por arriva del preview.
	this.htmlDivEventos;
	
	this.htmlDivPreviewFndLeft;
	this.htmlDivPreviewFndRight;
	
	this.htmlDivImagenPreview;
	
	this.PonerEventos = function(){
		
		if(!this.imgPreview){return;}
	
		this.htmlDivEventos.click(function(me){
			var Slider = SlideManager.Sliders.GetObjectById(me.getAttribute('SliderId'));
			Slider.SetFocusById(me.getAttribute('ItemId'));
			Slider.disable_play = true;
			Slider.Stop();
		});
		
		/*this.htmlDivEventos.mover(function(me){
			var Slider = SlideManager.Sliders.GetObjectById(me.getAttribute('SliderId'));
			var Item = Slider.Items.GetObjectById(me.getAttribute('ItemId'));
			Slider.SetFocusById(me.getAttribute('ItemId'));
			Slider.Stop();
		});
		
		this.htmlDivEventos.mout(function(me){
			var Slider = SlideManager.Sliders.GetObjectById(me.getAttribute('SliderId'));
			Slider.SetFocusById(me.getAttribute('ItemId'));
			Slider.Play();
		});*/
		
		if((this.PreviewOver) && (this.PreviewFn)){
		
			this.htmlDivPreview.click(function(me){
			
				var Slider = SlideManager.Sliders.GetObjectById(me.getAttribute('SliderId'));
				var Item = Slider.Items.GetObjectById(me.getAttribute('ItemId'));
				
				setTimeout(Item.PreviewFn, 0);
			
			});
			
		}
		
	}
	
	this.Init = function(){
		
		if(this.htmlDiv.getAttribute('Preview')){
			this.imgPreview = this.htmlDiv.getAttribute('Preview');
		}
		
		if(this.htmlDiv.getAttribute('PreviewOver')){
			this.PreviewOver = this.htmlDiv.getAttribute('PreviewOver');
		}
		
		if(this.htmlDiv.getAttribute('PreviewFn')){
			this.PreviewFn = this.htmlDiv.getAttribute('PreviewFn');
		}
		
		if(this.htmlDiv.getAttribute('Description')){
			this.Description = this.htmlDiv.getAttribute('Description');
		}
		
		this.htmlDiv.css('position', 'absolute');
		this.htmlDiv.css('overflow', 'hidden');
		this.htmlDiv.setY(0);
		
		if(this.Description){
			this.htmlDescription = this.htmlDiv.newdiv(this.Id+'.Desc');
			this.htmlDescription.css('position', 'absolute');
			this.htmlDescription.css('overflow', 'hidden');
			this.htmlDescription.setX(0);
			this.htmlDescription.html(this.Description);
			this.htmlDescription.css('background-color', '#000000');
			this.htmlDescription.alpha(70);
		}
		
		if(this.imgPreview){
			this.htmlDivPreview = this.PreviewBar.newdiv(this.Id+'.Preview');
			this.htmlDivPreview.css('position', 'absolute');
			this.htmlDivPreview.css('overflow', 'hidden');
			this.htmlDivPreview.cssClass('previewFND');
			this.htmlDivPreview.setAttribute('SliderId', this.SliderId);
			this.htmlDivPreview.setAttribute('ItemId', this.Id);
			
			//this.htmlDivPreview.css('margin', '3px');
			//this.htmlDivPreview.newimg(this.Id+'.imgPreview', this.imgPreview);
			
			this.htmlDivPreviewFndLeft = this.htmlDivPreview.newdiv(this.Id+'.PreviewFndLeft');
			this.htmlDivPreviewFndLeft.css('position', 'absolute');
			this.htmlDivPreviewFndLeft.html('&nbsp;');
			this.htmlDivPreviewFndLeft.cssClass('previewFNDLeft');
			
			this.htmlDivPreviewFndRight = this.htmlDivPreview.newdiv(this.Id+'.PreviewFndRight');
			this.htmlDivPreviewFndRight.css('position', 'absolute');
			this.htmlDivPreviewFndRight.html('&nbsp;');
			this.htmlDivPreviewFndRight.cssClass('previewFNDRight');
			
			this.htmlDivImagenPreview = this.htmlDivPreview.newdiv(this.Id+'.PreviewImagen');
			this.htmlDivImagenPreview.css('position', 'absolute');
			this.htmlDivImagenPreview.css('overflow', 'hidden');
			this.htmlDivImagenPreview.css('cursor', 'pointer');
			this.htmlDivImagenPreview.alpha(70);
			this.htmlDivImagenPreview.newimg(this.Id+'.imgPreview', this.imgPreview);
			this.htmlDivImagenPreview.setAttribute('SliderId', this.SliderId);
			this.htmlDivImagenPreview.setAttribute('ItemId', this.Id);
			
			if(this.PreviewOver){
			
				this.htmlDivPreviewOver = this.htmlDivPreview.newdiv(this.Id+'.PreviewOver');
				this.htmlDivPreviewOver.css('position', 'absolute');
				this.htmlDivPreviewOver.css('overflow', 'hidden');
				this.htmlDivPreviewOver.css('cursor', 'pointer');
				this.htmlDivPreviewOver.cssClass('SliderVideosPreviewOver');
				//this.htmlDivPreviewOver.alpha(100);
				this.htmlDivPreviewOver.html(this.PreviewOver);
				this.htmlDivPreviewOver.setAttribute('SliderId', this.SliderId);
				this.htmlDivPreviewOver.setAttribute('ItemId', this.Id);
				this.htmlDivPreviewOver.hide();
				
			}
			
			this.htmlDivEventos = this.htmlDivPreview.newdiv(this.Id+'.PreviewEventos');
			this.htmlDivEventos.css('position', 'absolute');
			this.htmlDivEventos.css('overflow', 'hidden');
			this.htmlDivEventos.css('cursor', 'pointer');
			this.htmlDivEventos.css('background-color', '#f5f5f5');
			this.htmlDivEventos.alpha(1);
			this.htmlDivEventos.html('&nbsp;');
			this.htmlDivEventos.setAttribute('SliderId', this.SliderId);
			this.htmlDivEventos.setAttribute('ItemId', this.Id);
			this.htmlDivEventos.raiseTop();
			
		}
		
		this.PonerEventos();
		
	}
	
}
 
function Slider(){
	this.Id;
	
	this.htmlDiv;
	this.Container;
	
	this.htmlDivContent; 						//div que contiene el contenido de cada frame.
	this.htmlDivPreview; 						//div que contiene los preview de cada frame.
	this.htmlBottomBar;
	this.htmlTopBar;
	this.htmlLeftCtrl;
	this.htmlRightCtrl;
	this.htmlPreviewBar;
	this.htmlTitleBar;
	
	this.ControlContainer;
	this.ControlSize = 40;
	
	this.cssSliderContainer;
	this.cssBottomBar;
	this.cssTopBar;
	this.cssLeftControl;
	this.cssRightControl;
	
	this.Width;
	this.Height;
	this.Padding = 2;
	
	this.Title;
	this.TitlePosition;
	this.cssTitleBar;
	this.ShowPaging = true;
	
	this.ToolbarPosition = 'Bottom';
	this.Controls = true;
	this.Preview = false;
	this.AutoPlay = false;
	this.Efect;
	this.TopBar = false;
	this.BottomBar = false;
	
	this.TopBarHeight = 30;
	this.BottomBarHeight = 30;
	
	this.Items = new ObjectsList();
	
	this.PreviousItemFocusId;
	this.PreviousItemFocusIndex;
	
	this.ItemFocusId;
	this.ItemFocusIndex;
	
	this.timerPlay;
	this.FirstPlay = true;
	this.ms = 6000;
	
	this.runing = false;
	
	this.Stop = function(){
		clearTimeout(this.timerPlay);
	}
	
	this.disable_play = false;
	
	this.Play = function(){
	
		if(this.disable_play==true){return;}
	
		if(this.FirstPlay == true){
			this.FirstPlay = false;
			this.timerPlay = setTimeout('SlideManager.Sliders.GetObjectById(\''+this.Id+'\').Play()', this.ms);
			return;
		}
		
		if(this.AutoPlay == true){
		
			if(this.ItemFocusIndex == this.Items.Count()-1){
				this.ItemFocusIndex = -1;
			}

			if(this.AnimationRuning == false)
				this.Next();
		}

		this.timerPlay = setTimeout('SlideManager.Sliders.GetObjectById(\''+this.Id+'\').Play()', this.ms);

	}
	
	this.Next = function(){
	
		if(this.runing == true){return;}
	
		if(this.ItemFocusIndex > this.Items.Count() - 2){
			return;
		}else{
			this.PreviousItemFocusIndex = this.ItemFocusIndex;
			this.ItemFocusIndex++;
		}
		
		this.SetFocus();
	
	}
	
	this.Back = function(){
	
		if(this.runing == true){return;}
	
		if(this.ItemFocusIndex == 0){
			return;
		}else{
			this.PreviousItemFocusIndex = this.ItemFocusIndex;
			this.ItemFocusIndex--;
		}
		
		this.SetFocus();
	
	}
	
	this.SetFocusById = function(pId){
	
		this.PreviousItemFocusId = this.ItemFocusId;
		this.ItemFocusId = pId;
		
		this.PreviousItemFocusIndex = this.Items.GetIndexById(this.PreviousItemFocusId);
		this.ItemFocusIndex = this.Items.GetIndexById(pId);
		
		this.SetFocus();
		
	}
	
	this.AnimationRuning = false;
	this.TimeoutAnnimation;
	this.AnimationMS = 10;
	this.AnimationStep = 10;
	
	if((Browser.IE8() == true) || (Browser.IE7() == true) || (Browser.IE6() == true)){
		this.AnimationStep = 40;
		this.AnimationMS = 10;
	}
	
	this.SetFocusAnimated = function(){

		try{
		
			var item_to_focus = this.Items.Objects[this.ItemFocusIndex];
			var item_to_blur = this.Items.Objects[this.PreviousItemFocusIndex];
			
			this.runing = true;
		
			if(this.PreviousItemFocusIndex < this.ItemFocusIndex){
			
				//en este caso debo moverme hacia la izquierda.
				
				if(item_to_focus.htmlDiv.iLeft > 0){
					
					if((item_to_focus.htmlDiv.iLeft - this.AnimationStep) < 0){
						clearTimeout(this.TimeoutAnnimation);
						this.SetFocusWithoutEfect();
						this.runing = false;
						this.AnimationRuning = false;
					}else{
						item_to_blur.htmlDiv.setX(item_to_blur.htmlDiv.iLeft - this.AnimationStep)
						item_to_focus.htmlDiv.setX(item_to_focus.htmlDiv.iLeft - this.AnimationStep)
						
						this.TimeoutAnnimation = setTimeout('SlideManager.Sliders.GetObjectById(\''+this.Id+'\').SetFocusAnimated()', this.AnimationMS);
					}
				
				}else{
					
					//en este caso termino la animacion. pongo la coordenada x en cero y hago un clear timeout.
					clearTimeout(this.TimeoutAnnimation);
					this.SetFocusWithoutEfect();
					this.runing = false;
					this.AnimationRuning = false;
				}
			
			}else{
			
				//en este caso debo moverme hacia la derecha.
			
				if(item_to_focus.htmlDiv.iLeft < 0){
				
					if(Sum([item_to_focus.htmlDiv.iLeft, this.AnimationStep]) > 0){
						clearTimeout(this.TimeoutAnnimation);
						this.SetFocusWithoutEfect();
						this.runing = false;
						this.AnimationRuning = false;
					}else{
						
						item_to_blur.htmlDiv.setX(Sum([item_to_blur.htmlDiv.iLeft, this.AnimationStep]))
						item_to_focus.htmlDiv.setX(Sum([item_to_focus.htmlDiv.iLeft, this.AnimationStep]))
						
						this.TimeoutAnnimation = setTimeout('SlideManager.Sliders.GetObjectById(\''+this.Id+'\').SetFocusAnimated()', this.AnimationMS);
					}
				
				}else{
					
					//en este caso termino la animacion. pongo la coordenada x en cero y hago un clear timeout.
					clearTimeout(this.TimeoutAnnimation);
					this.SetFocusWithoutEfect();
					this.runing = false;
					this.AnimationRuning = false;
				
				}
			
			}	

		}catch(e){
			this.ItemFocusIndex = 0;
			this.PreviousItemFocusIndex = this.Items.Count() - 1;
			this.SetFocus();
			return;
		}
	
	}
	
	this.SetFocusWithoutEfect = function(){
		for(var i=0;i<this.Items.Count();i++){
			var desp_focus = this.getDivFrameW() * this.ItemFocusIndex;
			this.Items.Objects[i].htmlDiv.setX((this.getDivFrameW() * i)-desp_focus);
			if(this.Preview == true)
				this.Items.Objects[i].htmlDivImagenPreview.alpha(50);
		}
		if(this.Preview == true)
			this.Items.Objects[this.ItemFocusIndex].htmlDivImagenPreview.alpha(100);
		
		this.htmlTitleBar.html(this.Title + '&nbsp('+Sum([this.ItemFocusIndex, 1])+'/'+this.Items.Count()+')');
		
	}
	
	this.SetFocus = function(){
	
		if(this.Efect == 'None'){
			
			for(var i=0;i<this.Items.Count();i++){
				var desp_focus = this.getDivFrameW() * this.ItemFocusIndex;
				this.Items.Objects[i].htmlDiv.setX((this.getDivFrameW() * i)-desp_focus);
				
				if(this.Preview == true){
					
					this.Items.Objects[i].htmlDivImagenPreview.alpha(50);
					
					if(this.Items.Objects[i].PreviewOver){
						this.Items.Objects[i].htmlDivPreviewOver.hide();
					}
					
				}
				
			}
			
			if(this.Preview == true){

				this.Items.Objects[this.ItemFocusIndex].htmlDivImagenPreview.alpha(100);

				if(this.Items.Objects[this.ItemFocusIndex].PreviewOver){
					//alert(this.Items.Objects[this.ItemFocusIndex].PreviewOver);
					this.Items.Objects[this.ItemFocusIndex].htmlDivPreviewOver.display();
				}

			}
			
		}
		
		if(this.Efect == 'Animated'){
		
			this.AnimationRuning = true;
			
			this.SetFocusAnimated();
			
			/*
			for(var i=0;i<this.Items.Count();i++){
				var desp_focus = this.getDivFrameW() * this.ItemFocusIndex;
				this.Items.Objects[i].htmlDiv.setX((this.getDivFrameW() * i)-desp_focus);
				
				if(this.Preview == true)
					this.Items.Objects[i].htmlDivImagenPreview.alpha(50);
			}
			
			if(this.Preview == true)
				this.Items.Objects[this.ItemFocusIndex].htmlDivImagenPreview.alpha(100);
			*/
		}
	
	}
	
	this.getDivFrameY = function(){
		if(this.TopBar == true){
			return Sum([this.Padding, this.TopBarHeight]);
		}else{
			return this.Padding;
		}
	}
	
	this.getDivFrameX = function(){
		return this.Padding;
	}
	
	this.getDivFrameW = function(){
		return this.Width - this.Padding*2;
	}
	
	this.getDivFrameH = function(){
	
		var return_height = this.Height;
	
		return_height -= this.Padding*2;
	
		if(this.TopBar == true){
			return_height -= this.TopBarHeight;
		}
		
		if(this.BottomBar == true){
			return_height -= this.BottomBarHeight;
		}
	
		return return_height;
	}
		
	this.PositionItems = function(){
	
		for(var i=0;i<this.Items.Count();i++){
		
			this.Items.Objects[i].htmlDiv.setX(this.getDivFrameW() * i);
			this.Items.Objects[i].htmlDiv.setW(this.getDivFrameW());
			this.Items.Objects[i].htmlDiv.setH(this.getDivFrameH());
			
			if(this.Items.Objects[i].Description){
				this.Items.Objects[i].htmlDescription.setW(this.getDivFrameW());
				this.Items.Objects[i].htmlDescription.setY(this.getDivFrameH()-this.Items.Objects[i].htmlDescription.clientHeight);
			}
			
			if(this.Preview == true){
			
				this.Items.Objects[i].htmlDivPreview.setX(Sum([i*this.GetPreviewControlWidth(), this.Padding*i]));
				this.Items.Objects[i].htmlDivPreview.setY(0);
				this.Items.Objects[i].htmlDivPreview.setW(this.GetPreviewControlWidth());
				this.Items.Objects[i].htmlDivPreview.setH(this.Height - this.getDivFrameH()-this.Padding);
				
				
				this.Items.Objects[i].htmlDivPreviewFndLeft.setW(this.GetPreviewControlWidth());
				this.Items.Objects[i].htmlDivPreviewFndRight.setW(this.GetPreviewControlWidth());
				
				//Acomoda las imagenes de previsualizacion.
				
				this.Items.Objects[i].htmlDivImagenPreview.setX(6);
				this.Items.Objects[i].htmlDivImagenPreview.setY(6);
				this.Items.Objects[i].htmlDivImagenPreview.setW(this.Items.Objects[i].htmlDivPreview.iWidth-12);
				this.Items.Objects[i].htmlDivImagenPreview.setH(this.Items.Objects[i].htmlDivPreview.iHeight-22);
				
				this.Items.Objects[i].htmlDivEventos.setX(0);
				this.Items.Objects[i].htmlDivEventos.setY(0);
				this.Items.Objects[i].htmlDivEventos.setW(this.Items.Objects[i].htmlDivPreview.iWidth);
				this.Items.Objects[i].htmlDivEventos.setH(this.Items.Objects[i].htmlDivPreview.iHeight);
			
			}
			
		}
	}
	
	this.GetPreviewBarLeft = function(){
		if(this.Controls == true){
			return this.ControlSize;
		}
		return 0;
	}
	
	this.GetPreviewBarWidth = function(){
		if(this.Controls == true){
			return this.Width-this.Padding*2 - this.ControlSize*2;
		}
		return this.Width-this.Padding*2;
	}
	
	this.GetPreviewControlWidth = function(){
		return parseInt((this.GetPreviewBarWidth()-this.Padding*(this.Items.Count()-1)) / this.Items.Count());
	}
	
	this.Ponerventos = function(){
		
		if(this.Controls == true){
			
			this.htmlRightCtrl.setAttribute('SliderId', this.Id);
			this.htmlLeftCtrl.setAttribute('SliderId', this.Id);
			
			this.htmlRightCtrl.click(function(me){
				
				var Slider = SlideManager.Sliders.GetObjectById(me.getAttribute('SliderId'));
				
				Slider.Next();
				
			});
			
			this.htmlLeftCtrl.click(function(me){
				
				var Slider = SlideManager.Sliders.GetObjectById(me.getAttribute('SliderId'));
				
				Slider.Back();
				
			});
			
		}
		
	}
	
	this.Init = function(){
		
		this.htmlDiv = go(this.Id);
		
		if(this.htmlDiv.parentNode){
			this.Container = this.htmlDiv.parentNode
		}else{
			this.Container = document;
		}
		
		this.htmlDiv.css('position', 'relative');
		
		
		if(this.cssSliderContainer){
			this.htmlDiv.cssClass(this.cssSliderContainer);
		}else{
			this.htmlDiv.css('background-color', '#c5c5c5');
		}
		
		if(this.Width)
			this.htmlDiv.setW(this.Width);
			
		if(this.Height)
			this.htmlDiv.setH(this.Height);
			
		//creamos el div para el contenido de los items.
			
		this.htmlDivContent = go(this.htmlDiv.childs('div')[0]);
		
		this.htmlDivContent.css('position', 'absolute');
		this.htmlDivContent.css('overflow', 'hidden');
		//this.htmlDivContent.css('background-color', '#00ff99');
		
		this.htmlDivContent.setX(this.getDivFrameX())
		this.htmlDivContent.setY(this.getDivFrameY())
		
		this.htmlDivContent.setW(this.getDivFrameW())
		this.htmlDivContent.setH(this.getDivFrameH())
		
		
		//Creamos la barra superior.
		
		if(this.TopBar == true){
		
			this.htmlTopBar = this.htmlDiv.newdiv(this.Id+'.BottomBar');
			
			this.htmlTopBar.css('position', 'absolute');
			this.htmlTopBar.css('overflow', 'hidden');
			this.htmlTopBar.html('&nbsp;');
			
			if(this.cssTopBar){
				this.htmlTopBar.cssClass(this.cssTopBar);
			}
			
			this.htmlTopBar.setX(this.Padding);
			this.htmlTopBar.setY(this.Padding);
			this.htmlTopBar.setW(this.Width - this.Padding*2);
			this.htmlTopBar.setH(this.TopBarHeight);
			
			if(this.ToolbarPosition){
				if(this.ToolbarPosition.upper() == 'TOP'){
					this.ControlContainer = this.htmlTopBar;
				}
			}
			
		}
		
		//creamos la barra inferior
		
		if(this.BottomBar == true){
			this.htmlBottomBar = this.htmlDiv.newdiv(this.Id+'.BottomBar');
			
			this.htmlBottomBar.css('position', 'absolute');
			this.htmlBottomBar.css('overflow', 'hidden');
			this.htmlBottomBar.html('&nbsp;');
			
			if(this.cssBottomBar){
				this.htmlBottomBar.cssClass(this.cssBottomBar);
			}
			
			this.htmlBottomBar.setX(this.Padding);
			this.htmlBottomBar.setY(this.Height-this.BottomBarHeight);
			this.htmlBottomBar.setW(this.Width - this.Padding*2);
			this.htmlBottomBar.setH(this.BottomBarHeight-this.Padding);
			
			if(this.ToolbarPosition){
				if(this.ToolbarPosition.upper() == 'BOTTOM'){
					this.ControlContainer = this.htmlBottomBar;
				}
			}else{
				this.ControlContainer = this.htmlBottomBar;
			}

		}
		
		//Creamos la barra de preview.
		if(this.Preview == true){
		
			if(this.ControlContainer){
			
				this.htmlPreviewBar = this.ControlContainer.newdiv(this.Id+'.PreviewBar');
				this.htmlPreviewBar.css('position', 'absolute');
				this.htmlPreviewBar.css('overflow', 'hidden');
				//this.htmlPreviewBar.css('background-color', '#f5f5f5');
				this.htmlPreviewBar.html('&nbsp;');
				this.htmlPreviewBar.setX(this.GetPreviewBarLeft());
				this.htmlPreviewBar.setY(0);
				this.htmlPreviewBar.setW(this.GetPreviewBarWidth());
				this.htmlPreviewBar.setH(this.Height - this.getDivFrameH()-this.Padding);
			
			}
			
		}
		
		
		//Creamos los bottones de control.
		
		if(this.Controls == true){	
			
			if(this.ControlContainer){
				//creo el boton derecho
				this.htmlRightCtrl = this.ControlContainer.newdiv(this.Id+'.RightCtrl');
				this.htmlRightCtrl.css('position', 'absolute');
				this.htmlRightCtrl.css('overflow', 'hidden');
				this.htmlRightCtrl.css('cursor', 'pointer');
				this.htmlRightCtrl.html('&nbsp;');
				this.htmlRightCtrl.setX(this.Width-this.Padding*2-this.ControlSize);
				this.htmlRightCtrl.setY(0);
				this.htmlRightCtrl.setW(this.ControlSize);
				this.htmlRightCtrl.setH(this.ControlSize);
				
				if(this.cssRightControl){
					this.htmlRightCtrl.cssClass(this.cssRightControl);
				}
				
				//creo el boton izquierdo
				this.htmlLeftCtrl = this.ControlContainer.newdiv(this.Id+'.LeftCtrl');
				this.htmlLeftCtrl.css('position', 'absolute');
				this.htmlLeftCtrl.css('overflow', 'hidden');
				this.htmlLeftCtrl.css('cursor', 'pointer');
				this.htmlLeftCtrl.html('&nbsp;');
				this.htmlLeftCtrl.setX(0);
				this.htmlLeftCtrl.setY(0);
				this.htmlLeftCtrl.setW(this.ControlSize);
				this.htmlLeftCtrl.setH(this.ControlSize);
				
				if(this.cssLeftControl){
					this.htmlLeftCtrl.cssClass(this.cssLeftControl);
				}
			
			}
			
		}
		
		this.CreateItems();
		
		if(this.Title){
			
			if((this.TitlePosition == 'Bottom') && (this.BottomBar == true)){
			
				this.htmlTitleBar = this.htmlBottomBar.newdiv(this.Id+'TitleBar');
				
				this.htmlTitleBar.css('position', 'absolute');				
				this.htmlTitleBar.css('overflow', 'hidden');
				if(this.cssTitleBar)
					this.htmlTitleBar.cssClass(this.cssTitleBar);
				this.htmlTitleBar.html(this.Title + '&nbsp(1/'+this.Items.Count()+')');
				this.htmlTitleBar.setX(this.GetTitleLeft());
				this.htmlTitleBar.setY(0);
				this.htmlTitleBar.setW(this.GetTitleWidth());
				this.htmlTitleBar.setH(this.BottomBarHeight-this.Padding);
				
			}
			
			if((this.TitlePosition == 'Top') && (this.TopBar == true)){
			
				this.htmlTitleBar = this.htmlTopBar.newdiv(this.Id+'TitleBar');
				
				this.htmlTitleBar.css('position', 'absolute');
				this.htmlTitleBar.css('overflow', 'hidden');
				
				if(this.cssTitleBar){
					this.htmlTitleBar.cssClass(this.cssTitleBar);
				}
				
				this.htmlTitleBar.html(this.Title + '&nbsp(1/'+this.Items.Count()+')');
				this.htmlTitleBar.setX(this.GetTitleLeft());
				this.htmlTitleBar.setY(0);
				this.htmlTitleBar.setW(this.GetTitleWidth());
				this.htmlTitleBar.setH(this.TopBarHeight-this.Padding);
				
			}
			
		}
		
		
		
		this.PositionItems();
		this.Ponerventos();
		
	}
	
	this.CreateItems = function(){
		
		//Inicializamos los items.
		var div_items = this.htmlDivContent.childs('div');
		
		for(var i=0; i<div_items.length; i++){
			var newItem = new SliderItem();
			
			newItem.Id = this.Id + '.Item.' + i;
			newItem.SliderId = this.Id;
			newItem.htmlDiv = div_items[i];
			
			if(this.Preview == true){
				newItem.PreviewBar = this.htmlPreviewBar;
			}
			
			newItem.Init();
			
			if(i==0){
				this.ItemFocusId = newItem.Id;
				this.ItemFocusIndex = 0;
			}
			
			this.Items.Add(newItem);
			
		}
		
		if(this.Items.Count() > 0){
		
			this.ItemFocusId = this.Items.Objects[0].Id;
			this.ItemFocusIndex = 0;
			
		}

		
	}
	
	this.GetTitleLeft = function(){
		
		if((this.TitlePosition == 'Bottom') && (this.ToolbarPosition == 'Bottom') && (this.Controls = true)){
			return parseInt(Sum([this.Padding, this.ControlSize]));
		}
		
		if((this.TitlePosition == 'Top') && (this.ToolbarPosition == 'Top') && (this.Controls = true)){
			return parseInt(Sum([this.Padding, this.ControlSize]));
		}
		
	}
	
	this.GetTitleWidth = function(){
		
		if((this.TitlePosition == 'Bottom') && (this.ToolbarPosition == 'Bottom') && (this.Controls = true)){
			return parseInt(this.Width-this.Padding*2-this.ControlSize) - this.ControlSize;
		}
		
		if((this.TitlePosition == 'Top') && (this.ToolbarPosition == 'Top') && (this.Controls = true)){
			return parseInt(this.Width-this.Padding*2-this.ControlSize) - this.ControlSize;
		}
		
	}
	
}

function SlideMngr(){

	this.Sliders = new ObjectsList();
	
	this.HideDescription = function(pSliderId, pItemIndex){
		this.Sliders.GetObjectById(pSliderId).Items.Objects[pItemIndex].htmlDescription.hide();
	}
	
	this.ShowDescription = function(pSliderId, pItemIndex){
		this.Sliders.GetObjectById(pSliderId).Items.Objects[pItemIndex].htmlDescription.display();
	}
	
	this.Play = function(){
	
		for(var i=0; i<this.Sliders.Count(); i++){
		
			if(this.Sliders.Objects[i].AutoPlay == true){
			
				this.Sliders.Objects[i].Play();
			}
		}
	
	}

	this.Init = function(){
		
		var divs = go('div{Type}{Slideshow}');
		
		for(var i=0;i<divs.length; i++){
			
			var newSlider = new Slider();
			
			newSlider.Id = divs[i].getAttribute('id');
			
			newSlider.Width = divs[i].getAttribute('Width');
			newSlider.Height = divs[i].getAttribute('Height');
			
			newSlider.ToolbarPosition = divs[i].getAttribute('ToolbarPosition');
			
			if(divs[i].getAttribute('Controls').upper() == 'TRUE'){
				newSlider.Controls = true;
			}else{
				newSlider.Controls = false;
			}
			
			if(divs[i].getAttribute('Preview').upper() == 'TRUE'){
				newSlider.Preview = true;
			}else{
				newSlider.Preview = false;
			}
			
			if(divs[i].getAttribute('AutoPlay').upper() == 'TRUE'){
				newSlider.AutoPlay = true;
			}else{
				newSlider.AutoPlay = false;
			}
			
			if(divs[i].getAttribute('ms'))
				newSlider.ms = divs[i].getAttribute('ms');
			
			if(divs[i].getAttribute('TopBar')){
				if(divs[i].getAttribute('TopBar').upper() == 'TRUE'){
					newSlider.TopBar = true;
				}else{
					newSlider.TopBar = false;
				}
			}else{
				newSlider.TopBar = false;
			}
			
			if(divs[i].getAttribute('BottomBar')){
				if(divs[i].getAttribute('BottomBar').upper() == 'TRUE'){
					newSlider.BottomBar = true;
				}else{
					newSlider.BottomBar = false;
				}
			}else{
				newSlider.BottomBar = false;
			}
			
			
			if(divs[i].getAttribute('TopBarHeight'))
				newSlider.TopBarHeight = divs[i].getAttribute('TopBarHeight');
				
			if(divs[i].getAttribute('BottomBarHeight'))
				newSlider.BottomBarHeight = divs[i].getAttribute('BottomBarHeight');
			
			if(divs[i].getAttribute('Padding'))
				newSlider.Padding = divs[i].getAttribute('Padding');
			
			if(divs[i].getAttribute('Title'))
				newSlider.Title = divs[i].getAttribute('Title');
			
			if(divs[i].getAttribute('TitlePosition'))
				newSlider.TitlePosition = divs[i].getAttribute('TitlePosition');
			
			if(divs[i].getAttribute('cssTitleBar'))
				newSlider.cssTitleBar = divs[i].getAttribute('cssTitleBar');
			
			if(divs[i].getAttribute('Padding'))
				newSlider.Padding = divs[i].getAttribute('Padding');
			
			if(divs[i].getAttribute('cssSliderContainer'))
				newSlider.cssSliderContainer = divs[i].getAttribute('cssSliderContainer');
			
			if(divs[i].getAttribute('cssBottomBar'))
				newSlider.cssBottomBar = divs[i].getAttribute('cssBottomBar');
			
			if(divs[i].getAttribute('cssTopBar'))
				newSlider.cssTopBar = divs[i].getAttribute('cssTopBar');
				
			if(divs[i].getAttribute('cssLeftControl'))
				newSlider.cssLeftControl = divs[i].getAttribute('cssLeftControl');
				
			if(divs[i].getAttribute('cssRightControl'))
				newSlider.cssRightControl = divs[i].getAttribute('cssRightControl');
			
			if(divs[i].getAttribute('Efect')){
				newSlider.Efect = divs[i].getAttribute('Efect');
			}else{
				newSlider.Efect = 'None';
			}
			
			newSlider.Init();
			
			this.Sliders.Add(newSlider);
			
		}
		
		this.Play();
		
	}
 
}

var SlideManager = new SlideMngr();
 
Page.OnLoad(function(){
	SlideManager.Init();
});
