$(document).ready(function() {
	/*				   
	$("#work-links a").append("<em></em>");
	
	$("#work-links a").hover(function() {
		$(this).find("em").animate({opacity: "show", top: "-40"}, "slow");
		var hoverText = $(this).attr("title");
	    $(this).find("em").text(hoverText);
	}, function() {
		$(this).find("em").animate({opacity: "hide", top: "-50"}, "fast");
	});
	*/
	
	// fancypants
	$("a.zoom").fancybox({
		'overlayColor'		:	'#000'					 
	});
	// fancypants without overlay
	$("a.zoom_map").fancybox({
		frameWidth			:	600,
		frameHeight			:	400,
		overlayShow			:	false					 
	});
	
	// news-item click & hover
	$("#news-list .news-item").click(function(){
    	window.location = $(this).find("a").attr("href");
		return false;
	});
    $("#news-list .news-item").hover(
      function() {
        $(this).addClass("hover");
      },
      function() {
        $(this).removeClass("hover");
      }
    ); 
	
	// magnifier fade in/out
	$("#work-displayarea .pic a").hover(
      function () {
        $(this).append($("<span class='zoom-in'></span>").fadeIn());
      }, 
      function () {
        $(this).find("span:last").fadeOut();
      }
    );
	
	// basic fade
	$('.fade').append('<span class="hover"></span>').each(function () {
	  var $span = $('> span.hover', this).css('opacity', 0);
	  $(this).hover(function () {
	    $span.stop().fadeTo(250, 1);
	  }, function () {
	    $span.stop().fadeTo(250, 0);
	  });
	});
	
	// scroll to top
	$('#scrolltop').click(function(event){
		event.preventDefault();
        $('html, body').animate({scrollTop:0}, 'slow');
    });
	
	// external icon - työnäytteet
	$("#work-displayarea a").filter(function() {
    	return this.hostname && this.hostname !== location.hostname;
	}).addClass('external');
	
	// attachment offer
	$(".offer-form .attachment label").toggle(
      function () {
        $(".offer-form .attachment .file").fadeIn();
      },
      function () {
        $(".offer-form .attachment .file").fadeOut();
      }
    );
	// attachment recruit
	$(".recruit-form .attachment label").toggle(
      function () {
        $(".recruit-form .attachment .file").fadeIn();
      },
      function () {
        $(".recruit-form .attachment .file").fadeOut();
      }
    );
	
	// intro
	/*$("#slidenav").tabs("#slides > div", {
		initialIndex: 1,
		effect: 'fade',
		fadeInSpeed: 200,
		fadeOutSpeed: 'slow',
		rotate: true
	}).slideshow({autopause: true,autoplay: true,interval: 8000,clickable: false});*/
	/*$("#slidenav a").click(function(event){
		event.preventDefault();
    	$('#slidenav-arrow').animate({
    		top:$(this).attr("rel")
    	}, "slow", "easeInOutBack");
	});*/
	
	// INTRO START
	$("#slides").scrollable({
		clickable:false,
		vertical:true,
		size: 1,
		speed:800,
		easing: 'easeInOutQuart', 
		onBeforeSeek: function(){
			var api = $('#slides').data("scrollable");
			var amount = ((api.getIndex() + 1) % 3) * 83 - 3;
			$('#slidenav-arrow').animate({ top: amount + 'px' }, 800, "easeInOutQuart");
		}
	}).circular().navigator({  
        navi: "#slidenav", 
        naviItem: 'a',
		activeClass: "current"
    }).autoscroll({autoplay: true,autopause: true, interval: 8000}); 

	$("#slidenav a").bind('click.kluuSlidenav', function() {
		var api = $('#slides').data("scrollable");
		api.pause();
		var amount = api.getIndex() * 83 - 3;
		$('#slidenav-arrow').stop().animate({ top: amount + 'px'}, 800, "easeInOutQuart");
	});
	
	// lue lisää
	$("#slides a").hover(
      function () {
        $(this).append($("<span class='rollover'></span>").fadeIn());
      }, 
      function () {
        $(this).find("span:last").fadeOut();
      }
    );
	// INTRO END

	
	// work-list
	$('#work .work-list-items li').hover(function(){
		$(".read-more", this).stop().fadeTo(500, 1);
	  }, function () {
	    $(".read-more", this).stop().fadeTo(500, 0);
	});
	// kolmas elementti saa .last -arvon
	$('#work .work-list li:nth-child(3n)').addClass("last");
	
	
	// #content-divin sisällä oleva .row-taulukon rivitys
	$('#content .zebra tr:odd').addClass("odd");
	
	$("ul#form-links").tabs("#form-displayarea > div", {
        effect: 'default',
        rotate: true 
	}).history(); 
	$("ul#form-links").click(function() {
 		this.blur();
	});
	

	$("#work-links").tabs("#work-displayarea > div", {
        effect: 'fade',
        rotate: true 
	}).history(); 

	var api = $("#work-links").tabs(0);
	$("a.next").click(function() {
		api.next();
	});
	$("a.prev").click(function() {
		api.prev();
	});

});