// JavaScript Document
(function(){
	if(!window.slider){window.slider = (function(){
		var play = function(id, params, count){
			if(count==0) return;
			looping = items[id].looping;
			wait = items[id].params.wait;
			d = params.direction * (count/Math.abs(count));
			count = (looping)? 1 : count - (count/Math.abs(count));
			if(d==1){
				$("#" + id).oneTime((looping)?wait:1, function(){
					$("#" + id).animate({left:params.step*-1}, params.duration, function(){
						$("#" + id + " li:first").appendTo("#" + id);
						$("#" + id).css({left:0});
						play(id, params, count);
				  });
				});
			}
			else if(d==2){
				$("#" + id).oneTime((looping)?wait:1, function(){
					$("#" + id).animate({top:params.step*-1}, params.duration, function(){
						$("#" + id + " li:first").appendTo("#" + id);
						$("#" + id).css({top:0});
						play(id, params, count);
					});
				});
			}
			else if(d==-1){
				$("#" + id).oneTime((looping)?wait:1, function(){
					$("#" + id + " li:last").prependTo("#" + id);
					$("#" + id).css({left:params.step*-1});
					$("#" + id).animate({left:0}, params.duration, function(){
						play(id, params, count);
					});
				});
			}
			else if(d==-2){
				$("#" + id).oneTime((looping)?wait:1, function(){
					$("#" + id + " li:last").prependTo("#" + id);
					$("#" + id).css({top:params.step*-1});
					$("#" + id).animate({top:0}, params.duration, function(){
						play(id, params, count);
					});
				});
			}
		},
		init = function(id){
			$("#" + id).find("li").each(function(){
				$(this).mouseenter(function(){
					items[id].pause();
				});
				$(this).mouseleave(function(){
					if (items[id].animate) items[id].loop(); 
				});
			});
		}
		items = [];
		return{
			items : (function(){return items})(),
			add : function(id, params){
				var obj = {
					id : (function(){return id})(),
					params : (function(){return params})(),
					animate : (function(){return false})(),
					looping : (function(){return false})(),
					play : function(count){
						count = (typeof(count)=="undefined")?1:count;
						play(this.id, this.params, count);
					},
					loop : function(){
						if(this.looping) this.pause();
						this.looping = true;
						this.animate = true;
						this.play(1);
					},
					pause : function(){
						$("#" + this.id).stopTime();
						this.looping = false;
					},
					stop : function(){
						this.animate = false;
						this.pause();
					}
				}
				items[id] = obj;
				init(id);
				return obj;
			},
			playAll : function(){
			},
			stopAll : function(){
			}
		}
	})();}
})();


$(document).ready(function(){
	var procs = slider.add("procs", {direction: 1, step: 195, duration: "slow", wait: 1000});
	procs.loop();
	var banner = slider.add("slidingImages", {direction: 1, step: 970, duration: "fast", wait: 3000});
	banner.loop();
	var news = slider.add("newsslide", {direction: 2, step: 135, duration: "slow", wait: 3000});
	$("#proc_buttons > a").each(function(){
		 $(this).mouseenter(function(){
			procs.pause();
		 });
	});
	$("#proc_buttons > a").each(function(){
		 $(this).mouseleave(function(){
			procs.loop();
		 });
	});
	$("#proc_buttons").find(".left").click(function(){
		procs.play();
	});
	$("#proc_buttons").find(".right").click(function(){
		procs.play(-1);
	});
	$("#news_buttons").find(".up").click(function(){
		news.play();
	});
	$("#news_buttons").find(".down").click(function(){
		news.play(-1);
	});
});
