function cufonInit(){
	Cufon.replace('#navi a:not(.nocufon)', {
		fontFamily: 'TheSansBlackCaps',
		hover: true
	});
	Cufon.replace('h2:not(.nocufon), .linkki h3:not(.nocufon), #compForm h3, #suggestions h1', {
		fontFamily: 'TheSansBlackCaps'
	});
	Cufon.replace('.ingressi:not(.nocufon), #yhteystiedot .fb:not(.nocufon), #yhteystiedot h4:not(.nocufon), #yhteystiedot h3:not(.nocufon), #hakemisto-wrapper h2:not(.nocufon)', {
		fontFamily: 'TheSansExtraBoldPLain'
	});
	Cufon.replace('.tarina a:not(.nocufon)', {
		fontFamily: 'TheSerifBlackPlain',
		hover: true
	});
	Cufon.replace('#avaa-ohje:not(.nocufon)', {
		fontFamily: 'TheSerifBlackPlain',
		hover: false
	});
}
cufonInit();

  $.fn.getformvalues = function(id){
	var params = {};
	params[id] = true;
	$(this).find("input[checked],input[type='text'],input[type='password'],option[selected],textarea").filter(":enabled").each(
		function() {
			params[this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;				
	});			
	$(this).find("input[type='hidden']").each(function(){
		params[this.name || this.id || this.parentNode.name || this.parentNode.id ] = this.value;			
	});
	return params; 
    }
    
  	$.fn.wait = function(time, type) {
        time = time || 1000;
        type = type || "fx";
        return this.queue(type, function() {
            var self = this;
            setTimeout(function() {
                $(self).dequeue();
            }, time);
        });
    };

$(document).ready(function() {


	var ie = /*@cc_on!@*/false;
	var ie7 = (document.all && !window.opera && window.XMLHttpRequest);
	

	var korkeus = 0;
	var leveys = 0;
	var reunaet = 0;
	var infomargin = 0;
	var tarinaetaisyys = 0;
	
	function calcSize() {
	
		leveys = $(window).width();
		
		kokoLeveys = leveys * 6;
	
		korkeus = $(window).height();
	
		if (korkeus > 750) {
			$('#navi').css({'top' : '700px', 'bottom' : 'auto'});
		}
		else {
		    $('#navi').css({'top' : 'auto', 'bottom' : '0'});
            kokoLeveys = kokoLeveys + 90;
		}
		
		$('.view').width(leveys);
		$('#header').width(leveys);
		$('body, #main-container, #overlay').width(kokoLeveys);
		
		reunaet = $('#logo img').offset();
		reunaet = reunaet.left - 110;
		
		infomargin = reunaet + 250 + 'px';
		
		tarinaetaisyys = leveys / 2 - 205 - 95;
		
		//$('#view-content-1').css('margin-left', infomargin);
	
	}

	$.localScroll({
		axis:'x',
		offset: -reunaet
	});

	calcSize();
	
	$(window).resize(function() {
	  calcSize();
	});
	
/*	$(function() {
		$("#slider").slider();
		$("#slider").bind( "slide", function(event, ui) {
			//$("#slider .ui-slider-handle").position().left

			$.each(soundManager.soundIDs, function(index, value) { 			  
				var prcnt = $("#slider .ui-slider-handle").css("left").replace('%', '');				
				soundManager.setVolume(value, prcnt);
			});			
			
			
		});		
	});
*/

	function resetViews(){
		$("#preview").css("display","none");
		if (!ie) {$("#appForm :checkbox").removeAttr("checked");}
		$("#compFormContainer").fadeOut('slow');
		$("#suggestions").fadeOut('slow');
	}
	
	$('#navi a').click(function() {
		if (!($(this).hasClass("current"))) {
			var target = $(this).attr('href');
			resetViews();
			$('.current').removeClass('current');
			$(this).addClass('current');
			$('#overlay').css('display', 'none');
			$('.tarina').css('top', '-1200px');
			$('.video-container').fadeOut('slow');
			$('#hakemisto-wrapper > div').animate({'top':'-450px'},'slow', function() {
				$(this).css({display: 'none'});	
			});
			
			var allViewContents = $('.view-content').not($(target+' .view-content'));
			
			allViewContents.css({'overflow':'hidden'}).animate({'height':'0'},'slow');
			
			$(target+' .view-content').delay(750).animate({'height':'700px'},'slow', function() {
				$(this).css({'overflow':'visible'});
			});
			
		}
		Cufon.refresh('#navi a');
	});

	var compfrom = $('.compFormContainer');


	$('#link-1').click(function(){
		$('#view-content-1').append(compfrom);
		$("#canspam").attr('checked','checked');
	});	

	$('#view-content-1 #tarkka').click(function() {
		$('#yhteystiedot .view-content').delay(750).animate({'height':'700px'},'slow', function() {
			$(this).css({'overflow':'visible'});
		});
	});

	
	$('.kokemus').click(function() {
		$('#overlay').fadeIn('slow');
		$(this).parents(".view-content").css("overflow", "visible");
		var linkinOffset = $(this).position();
		$('.tarina', this).css({'left': 195-linkinOffset.left}).animate({'top':-linkinOffset.top},'slow');
	});
	
	$('#overlay').click(function() {
		$('.tarina').animate({'top':'-1200px'},'slow');
		$('.video-container').fadeOut('slow');
		$(this).fadeOut('slow');
		if (!ie7) {
			$('#vkl2').css({'z-index':'3'});
		}
		if (ie7) {
			$('.kokemus').css({'z-index':'0'});
		}
		$('#hakemisto-wrapper > div').animate({'top':'-450px'},'slow', function() {
			$(this).css({display: 'none'});	
		});
		$(".container").fadeOut('slow');
		$('#suggestions').animate({'top':'-880px'},'slow');
	});

	$('#vkl2').click(function() {
		var linkinOffset = $(this).position();
		if (!ie) {
			$(this).css({'z-index':'auto'});
		}
		if (ie7) {
			$(this).css({'z-index':'20'});
		}
		$('.tarina', this).css({'left': 195-linkinOffset.left}).animate({'top':-linkinOffset.top},'slow');
	});


	if (ie7) {
		$('.kokemus').click(function() {
			$(this).css({'z-index':'20'});
		});
	}	
	
	$('#viikonloppukokemuksia .sulje').click(function() {
		$('.tarina').animate({'top':'-1200px'},'slow');
		$('#overlay').fadeOut('slow');
		if (!ie7) {
			$('#vkl2').css({'z-index':'3'});
		}
		if (ie7) {
			$('.kokemus').css({'z-index':'0'});
		}
		return false;
	});

	$('#open').click(function () {
		var ta = 0;
		var tb = -146;
		//var ie7 = (document.all && !window.opera && window.XMLHttpRequest);
		//if (ie7) {ta = -92; tb = -238;}
		$('#soitin').animate({top: ta+'px'}, 1500, function(){
			$(this).wait(5000).animate({top: tb+'px'}, 1500 );
		});
	});
	
	var flashvars1 = {
   'file': '/Monika2_'+lang+'.flv',
   'skin': '/modieus/modieus.xml',
   'autostart': 'true'
	};
	var flashvars2 = {
   'file': '/Monika2_'+lang+'.flv',
   'skin': '/modieus/modieus.xml',
   'autostart': 'true'
	};
		
	var params = {
	   'allowfullscreen':    'true',
	   'allowscriptaccess':  'always',
	   'bgcolor':            '#ffffff'
	};
	
	var attributes1 = {
	   'id':                 'vplayer1',
	   'name':               'vplayer1'
	};
	var attributes2 = {
	   'id':                 'vplayer2',
	   'name':               'vplayer2'
	};	
	swfobject.embedSWF('player.swf', 'video1', '540', '380', '9', 'false', flashvars1, params, attributes1);
	swfobject.embedSWF('player.swf', 'video2', '540', '380', '9', 'false', flashvars2, params, attributes2);
	

	
	
	$('#video-link1').click(function() {
		$(this).parents(".view-content").css("overflow", "visible");
		$('#overlay').fadeIn('slow');
		$('#video-cont1').fadeIn('slow');
	});
	$('#video-link2').click(function() {
		$(this).parents(".view-content").css("overflow", "visible");
		$('#overlay').fadeIn('slow');
		$('#video-cont2').fadeIn('slow');
	});
	$('.sulje-video').click(function() {
		$('.video-container').fadeOut('slow');
		$('#overlay').fadeOut('slow');
	});
	



	$('#linkkihakemisto a').click(function () {
		var target = $(this).attr('href');
		//console.log(target);
		$('#overlay').fadeIn('slow');
		$(target).css({display: 'block'}).animate({'top':'0'},'slow');
		return false;
	});

	$('#hakemisto-wrapper .sulje').click(function () {
		var container = $(this).parent('div');
		//console.log(container);
		$('#overlay').fadeOut('slow');
		$(container).animate({'top':'-450px'},'slow', function() {
			$(this).css({display: 'none'});	
		});
		return false;
	});
	
	$('.linkki').hover(
		function () {
			$(this).find('.kuvaus').stop(false, true).fadeIn(400);
		},
		function () {
			$(this).find('.kuvaus').stop(false, true).fadeOut(250);
		}
	);

	$('.saannot').click(function() {
		$('#overlay').fadeIn('slow');
		$('#saannot').fadeIn();
		return false;
	});
	
	
	function enableSubmits(){
			$("#test").click(function(){
				var theform = $(this).parent("form");
				theform.addClass("loading");
				$.post("form/formC.php?ajax=true", $(this).parent("form").getformvalues($(this).attr("id")), function(data){				
					//$("#lounatuulen-tuomaa .view-content").css("overflow","visible");
					$('#overlay').fadeIn('slow');
					$("#appForm").html(data).find('#suggestions').append(compfrom);
					theform.removeClass("loading");
					enableSubmits();
					cufonInit();
					$('#suggestions').animate({'top':'-240px'},'slow');

				});		
				return false;
			});

			var nameplace = 'Nimi';
			var emailplace = 'Sähköpostiosoite';
			
			if($('body').hasClass('sv')) {
				nameplace = 'Namn';
				emailplace = 'E-post';
			}				
			
			if($("#name").val() == ""){
				$("#name").val(nameplace);
			}
			if($("#mymail").val() == ""){
				$("#mymail").val(emailplace);
			}
			$("#name").click(function(){
				$(this).val("");
				});
			$("#mymail").click(function(){
				$(this).val("");
				});


			$("#takepart").click(function(){

				if( ($("#name").val() != "") && ($("#mymail").val() != "") && ($("#name").val() != nameplace) && ($("#mymail").val() != emailplace) ) {
	
					var theform = $(this).parent("form");
					theform.addClass("loading");
					$.post("form/formC.php?ajax=true", $(this).parent("form").getformvalues($(this).attr("id")), function(data){				
						theform.siblings('.ingressi').hide();
						$("#compForm").html(data);
						theform.removeClass("loading");
						enableSubmits();
						cufonInit();
					});		
				} else {
					$(this).siblings('div.required').find('input').css({color: 'red'});
				}

			return false;
			});

			$("#canspam").attr('checked','checked');

				
			$(".close").click(function(){
				$(this).parents("div.container").fadeOut('slow');
				$('#overlay').fadeOut('slow');			
				return false;
			});
			
			$('#suggestions .close').click(function() {
				$('#suggestions').animate({'top':'-880px'},'slow');
			});
			
/*			$("#again").click(function(){
				$("#preview").css("display","none");
				if (!ie) {$("#appForm :checkbox").removeAttr("checked");}
				$("#emailFormContainer").fadeOut('slow');
				$("#suggestions").fadeOut('slow');
				return false;
			});
			
			$("#openPreview").click(function(){
				$("#preview").css("display","block");
				$("#lounatuulen-tuomaa .view-content").css("overflow","visible");
				return false;
			});
			$("#openEmail").click(function(){
				$("#lounatuulen-tuomaa .view-content").css("overflow","visible");
				$("#emailFormContainer").css("display","block");
				return false;
			});
*/
		}
	
		enableSubmits();

});			
			
			// Google Maps

/*
function loadScript() {
  var script = document.createElement("script");
  script.type = "text/javascript";
  script.src = "http://maps.google.com/maps/api/js?sensor=false&language=fi&callback=initialize";
  document.body.appendChild(script);
}
  
  loadScript();

	
}); // end document.ready

function initialize() {
    var latlng = new google.maps.LatLng(60.11414511652392, 24.0325927734375);
    var myOptions = {
      zoom: 7,
      center: latlng,
      mapTypeControl: false,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("small_map_canvas"),
        myOptions);
  }
*/	

