
var splashMode = "slim";


function showVideo(show, player) {
	if(show) {
		$(".slides_container").css({display : "none"});
		$("#slide_vid").css({display : "block"});
		$(".pagination a").css({display : "none"});
		jwplayer(player).play();
	}else {
		$("#slide_vid").css({display : "none"});
		$(".slides_container").css({display : "block"});
		$(".pagination a").css({display : "block"}).first().click();
	}
};


function addVideo(player, video) {
	var path = "/learningonline.nu/vid/"+video;
	jwplayer(player).setup({
		width: 620,
		height: 316,
		wmode: "transparent",
		icons: false,
		controlbar: "none",
		modes: [
			{	type: "html5",
				config: {
					levels: [
						{ file: (path+".mp4") },
						{ file: (path+".webm") },
						{ file: (path+".ogv") }
					]
				}
			},
			{	type: "flash",
				src: "/learningonline.nu/player.swf",
				config: {
					file: (path+".mp4"),
					screencolor: "111111"
				}			
			}
		],
		events:	{ 
			onComplete: function() {
				showVideo(false, player);
				sjsElem.animate("next", 'slide');
			},
			onPause: function() {
				showVideo(false, player);
			}
		}
	});
};

function extendNews() {
	$("#news_arrow").remove();
	$(".news_link").unbind("mouseenter mouseleave");
	$("#news_items .slim").remove();
	$("#news_items .full").css({display : "block"});
	$("#news_items")
		.css({width : "590px", height : "auto"})
		.find(".inner_block").css({height : "auto", background : "none"})
		.find("article").css({padding: "0 0 10px 0"});
	$("#news_list")
		.css({width : "370px", height : "auto"})
		.find(".inner_block").css({height : "auto"});
};


$(function() {
		
	$("#slides").slides({
		preload : true,
		preloadImage : "/learningonline.nu/img/loading.gif",
		play : 5000,
		pause: 2500,
		slideSpeed : 1000,		
		animationStart: function(current, elem) {
			$('.slides_control div.current').removeClass('current');
			if($('.slides_control div:eq('+ Math.abs(current - 1) +')').hasClass('video')) {

			}
		},
		animationComplete: function(current, elem) {
			
			current = current - 1;
			$('.slides_control div:eq('+ current +')').addClass('current');
			if($('.current').hasClass('video')) {
				clearInterval(elem.data('interval'));
				clearTimeout(elem.data('pause'));
				showVideo(true, "slide_vid");
			}
		} 
	});
	
	
	$("<div id='slide_vid'></div>").insertAfter(".slides_container");
	addVideo("slide_vid", "video_01");
	
	
	
	
	
	
	$("#ni_1").css({display : "block"});
	$("#nl_1").addClass("active");	
	
	$(".news_link").mouseenter(function() {
		if(!$(this).hasClass("active")) {
			var new_y = Math.round($(this).position().top+($(this).outerHeight()/2)-16);
			var speed = Math.abs($("#news_arrow").position().top-new_y)*2;
			
			$("#news_arrow").stop().animate({top : (new_y+"px")}, speed+200);
			$("#news_items article").css({display : "none"});
			
			
			var nr = Number(this.id.substring(3, 4));
			$("#ni_"+nr).css({display : "block"});
			
			$("a.news_link.active").removeClass("active")
			$(this).addClass("active");
		}
	});
	
	$(".extN").click(function() {
		if(splashMode == "slim") {
			extendNews();
			splashMode = "full";
		}
		if(!$(this).hasClass("active") && $(this).hasClass("news_link") ) {
			var nr = Number(this.id.substring(3, 4));
			$("#news_items article").css({display : "none"});
			$("#ni_"+nr).css({display : "block"});
			$("a.news_link.active").removeClass("active")
			$(this).addClass("active");
		}
	});
});

