$(function() {
	mp_initSlideshows();
	mp_initFlash();
	mp_initForms();
	
	$('#search_widget.fi #type').bind('change', function() {
		$('#search_widget #mp_locations, #search_widget #mpp_locations').hide();
		if($(this).val() == 'mp') $('#search_widget #mp_locations').show();
		if($(this).val() == 'mpp') $('#search_widget #mpp_locations').show();
	});
	
	$('#search_widget.fi #search').bind('click', function() {
		if($('#search_widget #type').val() == 'mp') {
			if(!$('#search_widget #mp_locations').val()) return;
			location = 'http://www.methodputkisto.com/fi/3/107#' + encodeURIComponent($('#search_widget #mp_locations').val());
		}
		if($('#search_widget.fi #type').val() == 'mpp') {
			if(!$('#search_widget #mpp_locations').val()) return;
			location = 'http://www.methodputkisto.com/fi/3/31#' + encodeURIComponent($('#search_widget #mpp_locations').val());
		}	
	});
	
	$('#search_widget.uk #search').bind('click', function() {
		if(!$('#search_widget #inst_locations').val()) return;
		location = 'http://www.methodputkisto.com/uk/3/30#' + encodeURIComponent($('#search_widget #inst_locations').val());
	});
	
	
});

function mp_initSlideshows() {
	$('.slideshow').each(function() {
		var slideShowDivId = $(this).attr('id');
		
		var parts = slideShowDivId.split(';');

		if(parts.length == 2) {
			var slideShowName = parts[0];
			var slideShowHeight = parts[1];
		}
		
		else { 
			var slideShowName  = parts[0];
			var slideShowHeight = 370;
		}
		
		var slideShowConfigFile = slideShowName + '.xml';
		swfobject.embedSWF("http://www.methodputkisto.com/slideshow/MP_slideshow"+ slideShowHeight +".swf", slideShowDivId, "789", slideShowHeight, "9.0.0", null, { configfile : slideShowConfigFile }, { allowscriptaccess : "always", wmode: 'transparent' });
	});
}


function mp_initFlash() {
	if($('.tp_flashvideo')[0]) {
		if(music_playing) mp_toggleMusic();
	}
	tpFlash.renderFlashMovies();
}

function mp_initForms() {
	$('.mpform').each(function() {
		$form = $(this);
		
		$(this).find('.text').bind('keypress', function() {
			$form.find('.submit').show();
		});
		
		$thankyou = $(this).find('.thankyou');
		$submit = $(this).find('.submit');
		$thankyou.hide();
		
		var options = {
			beforeSend : function() {
				$submit.hide();
				
			},
			
			complete : function() {
				$thankyou.show(); 
				setTimeout(function() { $thankyou.fadeOut(); }, 4000);
			}
		};
		
		$(this).ajaxForm(options);
	});
	
}

function mp_toggleElement(elementId,arrowId) {
	el=document.getElementById(elementId);
	arr=document.getElementById(arrowId);
	
	if(el.style.display == 'table') {
		el.style.display = 'none';
		arr.setAttribute('src', 'http://srv12.louhi.net/methodputkisto.com/img/arr_right.gif');
		}
	
	else {
		el.style.display = 'table';
		arr.setAttribute('src', 'http://srv12.louhi.net/methodputkisto.com/img/arr_right.gif');
		}
	}