﻿$(document).ready(function(){
	$('.fixpng').ifixpng();

	$(window).bind('resize', function(){
		resizeit();
	});
	resizeit();
		
	
	function resizeit(){
		var yt_left = $(".yhteystiedot #contentwrap div:eq(0)").height();
		var yt_right = $(".yhteystiedot #contentwrap div:eq(1)").height();
		if (yt_left < yt_right) {
		$('.yhteystiedot #contentwrap div:eq(0)').css('height', ''+yt_right+'px');
		}else if (yt_right < yt_left) {
		$('.yhteystiedot #contentwrap div:eq(1)').css('height', ''+yt_left+'px');
		}
		
		var ka_img = $(".kalusto #contentwrap .kalustoesittely:eq(0)").height() - 20;
		$('.kalusto #contentwrap .content_smallpadding').css('height', ''+ka_img+'px');
		
		var pa_left = $(".palvelut #contentwrap div:eq(1)").outerHeight(true);
		var pa_right = $(".palvelut #contentwrap div:eq(0)").innerHeight();
		var pa_splash = $(".palvelut #contentwrap #splasher").innerHeight();
		if ((pa_left + pa_splash) < pa_right) {
			var pa_left_height = pa_right - (pa_left + pa_splash);
			var pa_left_new = $('.palvelut #contentwrap div:eq(1)').height() + pa_left_height + 2;
			$('.palvelut #contentwrap div:eq(1)').css('height', ''+pa_left_new+'px');
		}else if (pa_right < (pa_left + pa_splash)) {
			var pa_right_height = (pa_left + pa_splash) - pa_right;
			var pa_right_new = $('.palvelut #contentwrap div:eq(0)').height() + pa_right_height - 2;
			$('.palvelut #contentwrap div:eq(0)').css('height', ''+pa_right_new+'px');
		}
	}
	
	$(".yhteydenotto").ajaxForm({
		beforeSubmit: function() {
			var form_height = $(".yhteystiedot #contentwrap div:eq(1)").height();
			
			$(".yhteystiedot #contentwrap div:eq(1) :child").hide();
			$(".yhteystiedot #contentwrap div:eq(1)").css('height', ''+form_height+'px');
		},
		success:    function() { 
			$(".yhteystiedot #contentwrap div:eq(1)").append('<h2>Kiitos yhteydenotostasi</h2><p>Olemme yhteydessä sinuun mahdollisimman pian.</p>');
		}
	});
	
	if ($("#splasherimage").length > 0 ) {
		$('#splasherimage').flash({
			src: 'assets/flash/splasher.swf',
			width: 900,
			height: 200
		});
	}


});
