$(document).ready(function() {
	
	$("#change-language-select").change(function(e) {
		
		// Stop the event
		e.preventDefault();
		
		var currentUrl = window.location.pathname;
		var about = (currentUrl == "/page/about-us/") ? "about/" : "home/";
		
		var langId = (parseInt($(this).val()) !== NaN) ? parseInt($(this).val()) : "default";
		var url = "/language/"+langId+"/"+about;
		
		window.location.pathname = url;
	});
	
	if ($(".carousel").length > 0) {
		$(".carousel").jCarouselLite({
			visible: 1,
			auto: 10000,
			speed: 500,
			circular: true,
			btnGo:
			[".carousel .1", ".carousel .2",
			".carousel .3", ".carousel .4"],
			afterEnd: function(a) {
				//alert("After animation ends:" + a);
				//console.debug(a);
				var classes = $(a).attr("class").split(" ");
				$.each(classes, function(i, ele) {
					//console.log(ele);
					if (ele.indexOf("item-") >= 0)
					{
						var itemIndexArr = ele.split("-");
						var itemIndex = parseInt(itemIndexArr[1]);
						itemIndex += 1;
						//console.log("index:", itemIndex);
					}
					
					$(".carousel .home-page-navigation ul li").each(function(i, ele) {
						//console.log(ele, itemIndex);
						$(this).removeClass("active");
						
						if ($(this).attr("class").indexOf(itemIndex) >= 0)
						{
							$(this).addClass("active");
						}
					});
				});
			}
		});
	}
});
