// starting the script on page load
$(document).ready(function(){

	$(".hidden").hide();
	
	$('<span class="nav-bg"></span>').appendTo('#nav_palvelut > li > a');
	$('<span class="button-bg"></span>').appendTo('#banneri .button');

	$(".drop_nav").hover(
		function () {
			$(this).addClass("hover");
			$(this).children("ul:not(:animated)").slideDown(100);
			$('<span class="white"></span>').appendTo(this);
		}, 
		function () {
			$(this).children("ul:not(:animated)").slideUp(100);
			$(this).removeClass("hover");
			$(this).children('.white').remove();
		}
	);
	
	$("a.btn").hover(
		function () {
			$(this).fadeTo(100, 0.85);
		}, 
		function () {
			$(this).fadeTo(100, 1);
		}
	);
	
	$("#a_video").click(function () {
		$("#esittelyvideo:hidden").fadeIn(500); 
	});
	
	$("#close_video").click(function () {
		$("#esittelyvideo").fadeOut(500); 
	});
	
	var Hash = window.location.hash;
	if(Hash == '')
		var Active = false;
	else
		var Active = $('#'+ Hash.replace('#', ''));
	$("#henkilosto").accordion({
		active: Active,
		collapsible: true,
		autoHeight: false,
		changestart: function(event, ui) {
			ui.newHeader.children('a').hide();
			ui.oldHeader.children('a').show();
		}
	});
	
	$("#henkilosto .contact-button").click(function() {
		return false;
	});
	
	$('a.thickbox').lightBox({
		fixedNavigation:true,
		txtImage: 'Kuva',
		txtOf: ' / '
	});
	
});


/*
 * Image preview script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 
this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});	
		
};
