/*#############################################
 BLACKMILK.JS
	by Blackmilk
###############################################*/

/*#############################################
 JQUERY FUNCTIONS
###############################################*/

jQuery(function( $ ){
	
	// Sivumenu hoover
	$('#sivumenu a')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 -60px)"}, {duration:300})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:300})
		});


	// Tekee uutis blockeista clickattavia
	$(".clickable-news").click(function(){

    	window.location=$(this).find("a").attr("href");return false;

	});



	// Uuttis block hoover
	$("#center-column table tr").mouseover(function(){
		$(this).children("td.table-left").css({'background-color':'#393939'});
		$(this).children("td.table-right").css({'background-color':'#404040'});
	}).mouseout(function(){
		$(this).children("td.table-left").css({'background-color' : '#1e1e1e'});
		$(this).children("td.table-right").css({'background-color' : '#262626'});		
	});

	// Detail sivun hooverit
	$("#center-column ul.news-detail-images li img").css({ opacity: 0.5 }).mouseover(function(){
		$(this).css({opacity: 1.0});
	}).mouseout(function(){
		$(this).css({opacity: 0.5});		
	});	


	/* MEDIACARD MENU MÄÄRITYKSET */

	/* Hoover */
	$("ul.subgation li:first").addClass("active").children().css({ "background" : "#555", color: "#fff"});

	$("ul.subgation li a").click(
		function(){
			$(this).parent().addClass("active");
			$(this).parent().siblings().removeClass("active");
			$(this).parent().siblings().children().css({ "background" : "none", color: "#47494d" });

		}
	);

	$("ul.subgation li a").hover(
		function(){
			if($(this).parent().hasClass("active")){
				
			}else{
				$(this).css({"background" : "#555", color: "#fff"});
			}
		},
		function(){
			if($(this).parent().hasClass("active")){
			}else{
				$(this).css({  "background" : "none", color: "#47494d" });
			}
		}

	);

	/* Tabit */
	var tabContainers = $('div#media-container > div');
	tabContainers.filter(':first').fadeIn(600);
				
	$("ul.subgation li a").click(function () {
		tabContainers.stop().hide();
		tabContainers.filter(this.hash).fadeIn(600);
		return false;
	}).filter(':first').click();



});

/*#############################################
 CODA SLIDER
###############################################*/


		var theInt = null;
		var $crosslink, $navthumb;
		var curclicked = 0;
		
		theInterval = function(cur){
			clearInterval(theInt);
			
			if( typeof cur != 'undefined' )
				curclicked = cur;
			
			$crosslink.removeClass("active-thumb");
			$navthumb.eq(curclicked).parent().addClass("active-thumb");
				$(".stripNav ul li a").eq(curclicked).trigger('click');
			
			theInt = setInterval(function(){
				$crosslink.removeClass("active-thumb");
				$navthumb.eq(curclicked).parent().addClass("active-thumb");
				$(".stripNav ul li a").eq(curclicked).trigger('click');
				curclicked++;
				if( 6 == curclicked )
					curclicked = 0;
				
			}, 6000);
		};
		
		$(function(){
			
			$("#main-photo-slider").codaSlider();
			
			$navthumb = $(".nav-thumb");
			$crosslink = $(".cross-link");
			
			$navthumb
			.click(function() {
				var $this = $(this);
				theInterval($this.parent().attr('href').slice(1) - 1);
				return false;
			});
			
			theInterval();
		});
