
var smtJs = {
	
	adYJs : function(sp,es,ms,as){
		
		var cw = 0;
		var ml = 0;
		var adAry = [];
		var maxHeight = 0;
		var mgnH = 0;
		var mgnW = 0;
		var coNum = 0;
		
		init()
		
		function init(){
			
			var  abc = $(".adBreadthContainerList .adCo");
			cw = $(".adBreadthContainer").width();
			ml = abc.length;
			
			if(abc.length > 0){
				for(var i=0; i< abc.length; i++){
					var obj = new Object();
					obj.box = abc[i];
					obj.num = i;
					obj.pos = cw * i;
					adAry.push(obj);
					
					if(maxHeight < $(obj.box).innerHeight()){
						maxHeight = $(obj.box).innerHeight()
					}
					
					mgnW = $(obj.box).innerWidth() - $(obj.box).width();
					mgnH = $(obj.box).innerHeight() - $(obj.box).height();
						
				}
				boxSet()
			}
		}
		
		function boxSet(){
			
			$(".adBreadthContainerList").width(cw);
			$(".adBreadthContainerList").height(maxHeight);
			$(".adBreadthContainerList").css("overflow","hidden").css("position","relative");
			
			
			for(var i=0; i< adAry.length; i++){
				$(adAry[i].box).width(cw - mgnW);
				$(adAry[i].box).height(maxHeight);
				$(adAry[i].box).css("left",adAry[i].pos).css("top",0).css("position","absolute");
				
			}
			
			if(adAry.length > 1){
				var offset = $(".adBreadthContainerList").offset();
				$(".adBreadthContainerList").after("<div id='lrBtn' class='clearfix'><p id='moveLeft'>&larr;</p><p id='moveRight'>&rarr;</p></div>")	
				
				$("#lrBtn").addClass("btnBack")
				$("#moveLeft").addClass("adLeft");
				$("#moveRight").addClass("adRight");
				
				/*
				$("#moveLeft").css("position","absolute").css("top",offset.top).css("left",offset.left);
				$("#moveRight").css("position","absolute").css("top",offset.top).css("left",offset.left + cw);
				*/
				
				var mbw = $("#lrBtn").innerWidth() - $("#lrBtn").width();
				$("#lrBtn").width(cw - mbw)
				$("#moveLeft").click(function(){scrollRight()})
				$("#moveRight").click(function(){scrollLeft()})
			}
			adYJsStart()
		}
		
		function adYJsStart(){
			$(".adBreadthContainerList").scrollLeft(adAry[adAry.length-1].pos);
			coScroll()
		}
		
		
		function scrollLeft(){
			coNum ++ 
			if(coNum > adAry.length -1){coNum = adAry.length -1}
			coScroll()
		}
		function scrollRight(){
			coNum --
			if(coNum < 0){coNum = 0;}
			coScroll()
		}
		
		function coScroll(){
	
			$(".adBreadthContainerList").stop();
			$(".adBreadthContainerList").animate({
				scrollLeft: adAry[coNum].pos
			},{
				duration: sp, 
				easing: es,
				complete: function(){}
			});
		}		
	},

	adTJs : function(sp,es,ms,as){
		
		var maxNum = ms;
		var ml = 0;
		var maxLength = 0;
		var adAry =[];
		var ch = 0;
		var maxCoHeight = 0;
		var moveNum = 0;
		var ID;
		var scrollNum = 0;
		
		init();
		
		function init(){
			
			$(".adContainerList br").not(".adCo br").remove();
			var ab = $(".adContainerList .adCo");
			ml = ab.length;
			
			if(ab.length > 0){
				for(var i=0; i<ab.length; i++){
					var obj = new Object();
					obj.box = ab[i];
					obj.num = i;
					adAry.push(obj);
					
					if(maxCoHeight < $(obj.box).height()){maxCoHeight = $(obj.box).height();}
				}
				
			boxSet()
			}
		}
		
		function boxSet(){

			for(var i=0; i<adAry.length; i++){
				if(as == "click"){
					$(adAry[i].box).height(maxCoHeight);
				}
				adAry[i].pos = maxLength
				maxLength += $(adAry[i].box).innerHeight();
				if(i < maxNum){ch += $(adAry[i].box).innerHeight();}
				
			}
			
			$(".adContainerList").css("overflow","hidden");
			$(".adContainerList").height(ch);
			
			if(adAry.length > maxNum){
				$(".adContainerList").before("<p id='adUp'>&uarr;</p>")
				$(".adContainerList").after("<p id='adDown'>&darr;</p>")
				$("#adUp").addClass("adUp")
				$("#adDown").addClass("adDown")
				
				if(as == "click"){
					$("#adUp").click(function(){scrollDown()})
					$("#adDown").click(function(){scrollUp()})
				}else if(as == "over"){
					$("#adUp").mouseover(function(){overScrollDown()})
					$("#adDown").mouseover(function(){overScrollUp()})
					$("#adUp").mouseout(function(){outScroll()})
					$("#adDown").mouseout(function(){outScroll()})

				}
			}
			adJsStart()
		}
		
		function adJsStart(){
			$(".adContainerList").scrollTop(adAry[ml - maxNum].pos);
			coScroll()
		}
		
		function overScrollUp(){ID = setInterval(scrollUp,10);}
		function overScrollDown(){ID = setInterval(scrollDown,10);}
		function outScroll(){clearInterval(ID);}
		
		function scrollUp(){
			if(as =="click"){
				moveNum += 1;
				if(moveNum > ml - maxNum){moveNum = ml - maxNum}
				coScroll()
			}else if(as == "over"){
				scrollNum += 5
				if(scrollNum > maxLength - ch){scrollNum =  maxLength - ch}
				$(".adContainerList").scrollTop(scrollNum)
			}
		}
		function scrollDown(){
			if(as =="click"){
				moveNum -= 1;
				if(moveNum < 0){moveNum = 0}
				coScroll()
			}else if(as == "over"){
				scrollNum -= 5
				if(scrollNum < 0){scrollNum = 0;}
				$(".adContainerList").scrollTop(scrollNum)
			}
		}
		
		function coScroll(){
			$(".adContainerList").stop();
			$(".adContainerList").animate({
				scrollTop: adAry[moveNum].pos
			},{
				duration: sp, 
				easing: es,
				complete: function(){}
			});
		}
		
	}
	////////////////////////////////////////////
	
}

$(window,"html").load(function(){
	smtJs.adYJs(500,"easeInOutCubic",2,"click");
	smtJs.adTJs(500,"easeInOutCubic",1,"click");
})
