		$(function(){		
			this.swap = function(active, inactive){
				$("#switch_page").css("height", $("#switch_page").height() + "px");
				$(items[active]).fadeOut("slow", function(){
					$(this).removeClass("active");
					$(items[inactive]).fadeIn("slow", function(){
						$(this).addClass("active");
					});
					$("#switch_page").css("height", $(items[inactive]).height() + "px");

					$(pages[active]).removeClass("active");
					$(pages[inactive]).addClass("active");
				});				
			}
	
			this.cycle = function(){
				var active = -1;
				var inactive = -1;

				for(var i = 0; i < count; ++i){					
					if($(items[i]).hasClass("active")){
						inactive = i == count - 1 ? 0 : i + 1;
						active = i;
					}
				}

				_this.swap(active, inactive);
			};
			
			this.clickOn = function(idx){
				window.clearInterval(cycleInterval);
				
				var active = -1;
				var inactive = idx;

				for(var i = 0; i < count; ++i){					
					if($(items[i]).hasClass("active")){
						active = i;
					}
				}

				_this.swap(active, inactive);
				cycleInterval = window.setInterval(_this.cycle, 7000);
				
				return false;
			};
				
			items = $("#switch_page > li").get();
			pages = $("#switcher > li:not(.arrow)").get();
			count = items.length;
				
			_this = this;		
			cycleInterval = window.setInterval(this.cycle, 7000);
			
			$("#switcher > li").click(function(){
				var e = $(this);
				if(e.hasClass("arrow")){
					for(var i = 0; i < count; ++i){
						var ei = $(pages[i]);
						if(ei.hasClass("active")){
							if($(this).hasClass("prev") && i == 0){
								return _this.clickOn(count - 1);
							} else if($(this).hasClass("next") && i == count - 1){
								return _this.clickOn(0);
							} else{ 
								
								return _this.clickOn(i + ($(this).hasClass("prev") == true ? -1 : 1 ));
							}
						}
					}
				}
			
				for(var i = 0; i < count; ++i){
					if(this === pages[i]){
						return _this.clickOn(i);
					}
				}
			});
		});
