/**
 * Sivuston yleiset efektit
 * 
 * @version $Id: index.php 2312 2010-03-30 11:24:57Z ville $
 * @copyright Agileus Software Oy
 */

jQuery(document).ready(function() {
	$('.bannerthemes').cycle({
		fx: 'fade',
		timeout: '7000',
		speed: '800'
	});
	$('.leftthemes').cycle({
		fx: 'fade',
		timeout: '7000',
		speed: '800'
	});

	if($.fancybox){
		$(".galleryitem a").fancybox({
			'speedIn'		:	600, 
			'speedOut'		:	200, 
			'overlayShow'	:	true,
			'titleShow'		: true,
			'titlePosition' : 'inside',
			'width'         : 600,
			'height'        : 480,
			'scrolling'		: 'no',
			'transitionIn' : 'elastic',
			'transitionOut' : 'elastic'				
		});

		$(".naytapopup").fancybox({
			'speedIn'		:	600, 
			'speedOut'		:	200, 
			'overlayShow'	:	true,
			'titleShow'		: false,
			'autoDimensions'	: true,
			'scrolling'		: 'auto'		
		});
	}

	$(".webgallery a.image").mouseenter(function(){
		 $(this).animate(
		{
			opacity: "1.0"
		}, 
		{
			duration:"40"
		});
	}).mouseleave(function(){
		$(this).animate({
			opacity: "0.7"
		}, 
		{
			duration:"40"
		});
	});
	
	// kaupunkihaun "selectboxin" fadeinit ja outit
	var mouse_is_inside = false;
	var selected_town = "";
	
	$('.towns').hide();
	
	$('#select_town').hover(function(){ 
        mouse_is_inside=true; 
    }, function(){ 
        mouse_is_inside=false; 
    });
	$('.towns').hover(function(){ 
        mouse_is_inside=true; 
    }, function(){ 
        mouse_is_inside=false; 
    });
	
	
	$('#select_town').click(function() {
			if($('.towns').is(':visible')) {
				$('.towns').fadeOut('fast');
			} else $('.towns').fadeIn('fast');
	});
	$('.towns').bind("mouseleave", function(){
			setTimeout(function() {
					if(! mouse_is_inside){
						$('.towns').fadeOut('fast');
					}
				}, 1000);
	});
	$('#select_town').bind("mouseleave", function(){
			setTimeout(function() {
					if(! mouse_is_inside){
						$('.towns').fadeOut('fast');
					}
				}, 1000);
	});
	$('.wrapper').click(function() {
			if($('.towns').is(':visible')) {
				if(! mouse_is_inside){
					$('.towns').fadeOut('fast');
				}
			}
	});
	
	
	$('.town').click(function() {
		$('.selected_town').text($(this).text());
		selected_town = $(this).attr("ref");
		
		if($('.towns').is(':visible')) {
			$('.towns').fadeOut('fast');
		}
	});
	
	
	$('.submit_town').click(
		function(){
			if(selected_town){
				window.location = "./alue/" + selected_town + "/";
			}
		}
	);
	
	// Tooltip 
	$("a[title]").tooltip({ 
		position: "bottom left",
		offset: [10, 260],
		opacity: 0.9,
		effect: "fade",
		layout: "<div><div class='tooltip_arrow'></div></div>"
	});

	
});

