jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

//$.preloadImages("/wp-content/themes/uutiswelho/images/laajakaista_over.png", "/wp-content/themes/uutiswelho/images/tv_over.png",  "/wp-content/themes/uutiswelho/images/vinkit_over.png", "/wp-content/themes/uutiswelho/images/tarjoukset_over.png");

jQuery(function() {

$("a, input").each(function() {
  $(this).attr("hideFocus", "true").css("outline", "none");
});

// Coda
$('.stripNavL').hover(function () { $(this).css('backgroundPosition', '0 -300px'); }, function () { $(this).css('backgroundPosition', '0 0'); });
$('.stripNavR').hover(function () { $(this).css('backgroundPosition', '0 -300px'); }, function () { $(this).css('backgroundPosition', '0 0'); });

var theInt = null;
var curclicked = 0;
var maxclicked = $('.carousel-loop').length;
		
theInterval = function(cur){
	clearInterval(theInt);
	
	if( typeof cur != 'undefined' ) {
		curclicked = cur;
	} else if ( location.hash != '') {
		curclicked = location.hash.slice(1) - 1;	
	}
	
	$('.current').removeClass("current");
	$('.navi-link:eq('+curclicked+')').addClass("current");
	$(".stripNav ul li a").eq(curclicked).trigger('click');
	
	theInt = setInterval(function(){

		$('.current').removeClass("current");
		$('.navi-link:eq('+curclicked+')').addClass("current");
		$(".stripNav ul li a").eq(curclicked).trigger('click');
	
		curclicked++;
		if( maxclicked == curclicked )
			curclicked = 0;	
	}, 6000);
};

$("div#slider1").codaSlider();
			
$(".navi-link").click(function() {
	var $this = $(this);	
	theInterval($this.attr('href').slice(1) - 1);
	return false;
});
			
theInterval();

// Overlays
$('.overlay', '.carousel-loop').hover(
	function() {
		$('.info', $(this).parent()).stop().animate({"top": "200"}, 250, "expoout");
	},
	function() {
		$('.info', $(this).parent()).stop().animate({"top": "300"}, 450, "expoout");
});
$('.overlay', '.tyot-loop').hover(
	function() {
		$('.info', $(this).parent()).stop().animate({"top": "120"}, 250, "expoout");
	},
	function() {
		$('.info', $(this).parent()).stop().animate({"top": "200"}, 450, "expoout");
});
$('.overlay', '.me-loop').hover(
	function() {
		$('.info', $(this).parent()).stop().animate({"top": "75"}, 250, "expoout");
	},
	function() {
		$('.info', $(this).parent()).stop().animate({"top": "135"}, 450, "expoout");
});

// Footer
$('a[name=clip]', '.aatteemme').mousemove(function(e){
	$("#Zoom").show();
	$("#Zoom").css({
		top: (e.pageY) + "px",
		left: (e.pageX + 20) + "px"
	});
});
$('a[name=clip]', '.aatteemme').mouseout(function(e){
	$("#Zoom").hide();
});

$('.button', '#Footer').toggle(
		function() {
			$(this).parent().stop().animate({"bottom": "-140px"}, 750, "elasout");
		},
		function() {
			$(this).parent().stop().animate({"bottom": "-290px"}, 300, "expoout");
});

// Work
$('img', '#Media').attr('title', '');
$('a', '#Media').mousemove(function(e){
	if($('img', $(this)).attr("alt") == "movie-icon") {
		$("#Watch").show();
		$("#Watch").css({
			top: (e.pageY) + "px",
			left: (e.pageX + 20) + "px"
		});
	} else {
		$("#Zoom").show();
		$("#Zoom").css({
			top: (e.pageY) + "px",
			left: (e.pageX + 20) + "px"
		});
	}
});
$('a', '#Media').mouseout(function(e){
	if($('img', $(this)).attr("alt") == "movie-icon") {
		$("#Watch").hide();
	} else {
		$("#Zoom").hide();
	}
});

$('#Category li').hover(function () {
		$('.cat-hover', $(this)).animate({width: "show"}, {queue:true, duration:0});
	}, function () { 
		$('.cat-hover', $(this)).animate({width: "hide"}, {queue:true, duration:150});
});

// News
$('img', '#newsMedia').attr('title', '');
$('a', '#newsMedia').mousemove(function(e){
	$("#Zoom").show();
	$("#Zoom").css({
		top: (e.pageY) + "px",
		left: (e.pageX + 20) + "px"
	});
});
$('a', '#newsMedia').mouseout(function(e){
	$("#Zoom").hide();
});
$('li', '.news').hover(function () { $('.arrow', this).css('display', 'block'); }, function () { $('.arrow', this).css('display', 'none'); });
$('li', '.blog').hover(function () { $('.arrow', this).css('display', 'block'); }, function () { $('.arrow', this).css('display', 'none');});
$('a', '#News').hover(function() { $('.arrow', $(this).parent()).css('display', 'block'); }, function() { $('.arrow', $(this).parent()).css('display', 'none'); });
$('a', '#News li.active').hover(function() { $('.arrow', $(this).parent()).css('display', 'block'); }, function() { $('.arrow', $(this).parent()).css('display', 'block'); });

});