var S_slider = Class.create({
	initialize: function(ext_options){
		this.pausescroll = false;
		this.company_data = "";
		this.slider_element = null;
		this.content_height = 0;
		this.content_pe = null;
		this.content_pe_effect = null;
		
		this.options = {
			data: new Array(),
			next_btn: null,
			prev_btn: null,
			slide_content_container: null,
			main_container: Object,	// Hover per pause scroll
			duration: 0.3,
			step: 150,
			autoslide: false,
			base_company_path: '/ebook/company.php?id=',
			url_data: '/ajax_php/ebook_companies.php?view=videopaginecontent'
			
		};

		Object.extend(this.options, ext_options || { });
		
		if(this.options.slide_content_container){
			if(!this.options.main_container){
				this.options.main_container = this.options.slide_content_container.up(1);	// Hover per pause scroll
			}
			this.slider_element = $(this.options.slide_content_container);
			this.slider_element.setStyle({top: 0});

			this.options.next_btn.observe('click', this._slide_up.bind(this));
			this.options.prev_btn.observe('click', this._slide_down.bind(this));

			this.load_data();
		}
	},
	
	autoslide_it: function(){
		//events
		Event.observe(this.options.main_container ,'mouseover', (function() {
			  this.pausescroll = true;
			  if(this.content_pe_effect){
				  this.content_pe_effect.cancel();
			  }
		}).bind(this));
		Event.observe(this.options.main_container ,'mouseout', (function(){
			  this.pausescroll = false;
		}).bind(this));

		this.content_pe = new PeriodicalExecuter(
				this.autoslide_element.bind(this), 
				2);
	},
	autoslide_element: function(){
		if(this.pausescroll != true){
			this._slide_up(null,true);
		}
	},
	_slide: function(back, autoscroll){
		if(autoscroll == true){
			var prev_top = this.slider_element.getStyle("top");
			prev_top.replace("px", "");
			prev_top = parseInt(prev_top);
			
			if(back == false){
				prev_top -= 20;
				if((prev_top.ceil().abs())> this.content_height){
					prev_top = 0;
				}
			}
			
			this.content_pe_effect = new Effect.Morph(this.slider_element, {
				style: 'top:'+prev_top+"px" ,
				duration: 2,
				transition: Effect.Transitions.linear
			});
			
		}else{
			var prev_top = this.slider_element.getStyle("top");
			prev_top.replace("px", "");
			prev_top = parseInt(prev_top);
			
			if(back == false){
				prev_top -= this.options.step;
				if((prev_top.ceil().abs())> this.content_height){
					prev_top = 0;
				}
			}else{
				prev_top += this.options.step;
				if(prev_top > 0){
					prev_top = 0;
				}
			}
			
			new Effect.Morph(this.slider_element, {
				style: 'top:'+prev_top+"px" ,
				duration: this.options.duration
			});
		}		
	},
	_slide_up: function(event, parameter){
		if(parameter == true){
			this._slide(false, true);
			
		}else{
			this._slide(false);
			event.stop();
		}
	},
	_slide_down: function(event){
		this._slide(true);
		event.stop();
	},
	
	load_data: function(){
		//	Ajax loader
		if(!this.options.url_data.blank()){
			var _load_result = "";
			var _url = this.options.url_data;
			
			new Ajax.Request(_url,{
				method: 'get',
				asynchronous: true,
				evalJS: false,
				onFailure: function(transport) {
					return false;
				},
				onSuccess: (function(transport) {
					var _load_result = transport.responseText;
					if(!_load_result.blank()){
						this.slider_element.update(_load_result);
						this.content_height = this.slider_element.getHeight();
						
						if(this.options.autoslide == true){
							this.autoslide_it();
						}
					}
				}).bind(this)
			});		
		}
	}
});