var tibexpress = function() {
	
	var
	slideshowDelaySwitch = 6000,
	slideshowTweenDuration = 440,
	slideshowIntervalInstance,
	slideshowCurrentID = 1,
	slideshowNumElements = 4,
	
	checkCurrent = function() {
		var that = $(this);
		
		if(typeof topmenupoint == "undefined") {
			topmenupoint = "none-";
		}
		
		that.find("a").each(function() {
			if($(this).attr("href") == window.location.pathname.toString() || $(this).attr("href").indexOf(topmenupoint) != -1) {
				$(this).parent().addClass("current");
			}
		});
	},
	
	handleBoxMouseOver = function() {
		var $that = $(this);
		var img = $that.find("img");
		
		img.animate({ 
			top: "-12px"
		}, {queue: false, duration: 140});
	},
	
	handleBoxMouseOut = function() {
		var $that = $(this);
		var img = $that.find("img");
		
		img.animate({ 
			top: "0px"
		}, {queue: false, duration: 140});
	},
	
	handleSlideshowClick = function() {
		var $that = $(this);
		var inPos = $that.attr("id").replace("slideshowMenuItem", "");
	
		clearInterval(slideshowIntervalInstance);
		slideshowGoTo(inPos);
	},
	
	slideshowGoTo = function(posID) {
		$("#slideshow-menu li").removeClass("active");
		$("#slideshowMenuItem" + posID).addClass("active");
		var left = posID * 900 - 900;
		
		$("#slider").animate(
				{left: -left + "px"}, 
				{queue: false, duration: slideshowTweenDuration}
		);
	},
	
	handleSlideshowShift = function() {
		slideshowCurrentID++;
		
		if(slideshowCurrentID > slideshowNumElements) {
			slideshowCurrentID = 1;
		}
		
		slideshowGoTo(slideshowCurrentID);
	},
	
	init = function() {	    
	    $("#menu li").each(checkCurrent);
	    
	    $(".top-menu li")			.bind("mouseover", 	handleBoxMouseOver)
									.bind("mouseout", 	handleBoxMouseOut);
	    $("#slideshow-menu li")		.bind("click", 		handleSlideshowClick);
	    
	    slideshowIntervalInstance = setInterval(handleSlideshowShift, slideshowDelaySwitch);
	}
	;

	return {
		init: init
	};
}();


$(document).ready(function() {
	tibexpress.init();
});
