var smm = function () {
	var init = function () {		
		// Sets minimum height of container element
		setContainerHeight();
		$(window).bind("resize", setContainerHeight);
		
		// Handling available languages drop down
		$("#choose-language-opener").click(function () {
			$("#available-languages").toggle();
			return false;
		});
		$(document).click(function () {
			$("#available-languages").hide();
		});
		
		if ($.fn.infiniteCarousel) {
			$("#introductory-carousel").infiniteCarousel({
				infinite : true
			});
			
			var articleCarousel = $("#article-picture-carousel"),
				carouselheight = articleCarousel.find("ul").height();
			
			articleCarousel.infiniteCarousel({
				infinite : true,
				useCounter : true
			});
			
			
			articleCarousel.height(carouselheight);
			articleCarousel.children(".wrapper").height(carouselheight);
		}
		
		if ($.fn.elastic) {
			$("textarea").elastic();
		}
		
		// Slideshow color box/lightbox
		if ($.fn.colorbox) {
			// Applies ColorBox event to all image links (Note: that are NOT inside a cloned list item used for the carousel function)
			$("li:not(.cloned) a[rel='slideshow-lightbox'], li:not(.cloned) a[rel='slideshow-lightbox-video']").each(function () {
				$(this).colorbox({
					slideshow : true,
					slideshowAuto : false,
					opacity : "0.7",
					title : $(this).parent().find("p.description").html(),
					slideshowStart : "Starta bildspel",
					slideshowStop : "Stoppa bildspel",
					slideshowSpeed : 5000,
					current : "Bild {current} av {total}",
					previous : "Föregående",
					next : "Nästa",
					close : "Stäng",
					maxWidth : "90%",
					maxHeight : "90%",
					scalePhotos : true,
					photo : true
				}
			);		
			});
			
			// Applies autostartevent for link starting the slideshow
			$("a.slideshow-lightbox-autoplay").click(function (evt) {
				$("li:not(.cloned) a[rel='slideshow-lightbox']").colorbox({
					open : true,
					slideshow : true,
					slideshowAuto : true
				});
				return false;
			});
		}
	},
	setContainerHeight = function () {
		$("#container").css("min-height", ($(document).height() - $("#page-footer").height()) + "px");
	};
	return {
		init : init
	};
}();
$(document).ready(function () {
	smm.init();
});