﻿if(!EWS.Slider){
   EWS.Slider = {};
};

/**
 * Slider组件
 */

EWS.Slider.SliderPhoto_4 = function(config){
	this.config = config;
	this.objId = "#"+config.objId;
	this.direction = config.direction; //图片滚动方向
	this.title = config.title; //是否显示标题
	this.speed = parseInt(config.speed+'0'); //轮播秒数
	this.IndexModel = config.IndexModel;
	if(this.IndexModel == 1){
		this.modelWidth = config.modelWidth; //模板宽度
		this.modelHeight = config.modelHeight; //模板高度
	}else{
		this.modelWidth = config.modelWidth; //模板宽度
		this.modelHeight = config.modelHeight; //模板高度
		this.width = config.width; //图片宽度
		this.height = config.height; //图片高度	
	}
	var _this = this;
    this.changeImg();
};
	
EWS.Slider.SliderPhoto_4.prototype = {
	//图片数据及图片播放效果等,于runChangeImg调用轮播
	changeImg : function(config){
		
		//滚动方向		
		switch (this.direction) {
			case "top" : //向上
				this.scrollPic('top');
				break;
			case "bottom" : //向下
				this.scrollPic('bottom');
				break;
			case "left" : //向左
				this.scrollPic('left');
				break;
			case "right" : //向右
				this.scrollPic('right');
				break;
		};
		 
	 }	 
	,scrollPic : function(direction){
		var speed = this.speed;//速度数值越大速度越慢 
		var part = $(this.objId+' #sliderbox');
		var part1 = $(this.objId+' #sliderbox1');
		var part2 = $(this.objId+' #sliderbox2');
		part2.html(part1.html());
		 $('#sliderbox2 li:last').addClass('last');
		
		switch(direction){
			case 'top' :
				//向上滚动
//				debugger;
				function Marquee1(){
					if(part2[0].offsetTop-part[0].scrollTop<=0){
						part[0].scrollTop-=part1[0].offsetHeight;
					}else{
						part[0].scrollTop++
					}
				} 
				var MyMar= setInterval(Marquee1,speed);
				part[0].onmouseover=function() {clearInterval(MyMar);}
				part[0].onmouseout=function() {MyMar=setInterval(Marquee1,speed)}
				break;
			case "bottom" : 
				//向下滚动
				function Marquee2(){
					if (part1[0].offsetTop - part[0].scrollTop >= 0) {
						part[0].scrollTop += part2[0].offsetHeight;
					}
					else {
						part[0].scrollTop--
					}
				}	
				var MyMar=setInterval(Marquee2,speed)
				part[0].onmouseover=function() {clearInterval(MyMar);}
				part[0].onmouseout=function() {MyMar=setInterval(Marquee2,speed)}
				break;
			case "left" : 
				//向左滚动
				$(this.objId+' #sliderbox ul').css({'float':'left'});
				$(this.objId+' #indemo').css({'width':'800%'});
				function Marquee3(){
					if(part2[0].offsetWidth-part[0].scrollLeft<=0){
						part[0].scrollLeft-=part1[0].offsetWidth;
					}else{
						part[0].scrollLeft++;
					}
				}
				var MyMar=setInterval(Marquee3,speed)
				part[0].onmouseover=function() {clearInterval(MyMar);}
				part[0].onmouseout=function() {MyMar=setInterval(Marquee3,speed)}
				break;
			case "right" :
				//向右滚动
				$(this.objId+' #sliderbox ul').css({'float':'left'});
				$(this.objId+' #indemo').css({'width':'800%'});
				function Marquee4(){					
					if(part[0].scrollLeft<=0){
						part[0].scrollLeft+=part1[0].offsetWidth;
					}else{
						part[0].scrollLeft--;
					}
				}
				var MyMar=setInterval(Marquee4,speed)
				part[0].onmouseover=function() {clearInterval(MyMar);}
				part[0].onmouseout=function() {MyMar=setInterval(Marquee4,speed)}
				break;
		}
	}	 
};