$(function(){
    $('#scrollEtusivu').hide();
    $('#scrollToiminnanohjaus').hide();
    $('#scrollPalvelut').hide();
});

$(document).ready(function() {

    $('#scrollEtusivu').effect('slide', {direction: "up"}, 800);
    $('#scrollToiminnanohjaus').show('fold', 800);
    $('#scrollPalvelut').effect('slide', {direction: "up"}, 800);

    // Yhteydenottolomake
    $(".submit").click(function() {

        var name = $("input#name").val();
        var email = $("input#email").val();
        var phone = $("input#phone").val();
        var text = $("textarea#text").val();
        var ip = $("input#ip").val();

	 $("div.error").remove();

	 // Virheruutu
	 if ((name == "") || (text == "")) {
	 	$('fieldset.contact').prepend("<div class='error'><img src='images/cross.png' alt='' class='error_cross' /> Virhe, seuraavat kentÃ¤t ovat pakollisia: </div>");
	 }

	 // Pakolliset kentät
	 if (name == "") {
		$("input#name").focus().addClass("red");
		$('div.error').append("Nimi");
		if(text == "") {
			$('div.error').append(", ");
		}

	 } else {
		 $("input#name").removeClass("red");
	 }

	 if (text == "") {
		 $("textarea#text").focus().addClass("red");
		 $('div.error').append("Viesti");
	 } else {
		 $("textarea#text").removeClass("red");
	 }

	 if ((name == "") || (text == "")) {
	 	return false;
	 }
		
        $.ajax({
            type: "POST",
            url: "kontakti.php",
            data: ({
                name: name,
                email: email,
                phone: phone,
                text: text,
                ip: ip
            }),
            success: function(){
                $('fieldset.contact').html("<div class='success'><img src='images/tick.png' alt='' class='success_tick' /> Kiitos viestistÃ¤nne, otamme yhteyttÃ¤ mahdollisimman pian.</div>");
            }

        });
        
        return false;


    });

});


// Kartta
function initialize() {

    var latlng = new google.maps.LatLng(65.01903,25.48485);
    var myOptions = {
        zoom: 15,
        center: latlng,
        mapTypeControl: false,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    var map = new google.maps.Map(document.getElementById("kartta"), myOptions);

    var eeImage = new google.maps.MarkerImage('images/sijainti.png',
        new google.maps.Size(45,55),
        new google.maps.Point(0,0),
        new google.maps.Point(22,51) /* kokieltu 30,5 */
    );

    var eePos = new google.maps.LatLng(65.01903,25.48485);

    var eeMarker = new google.maps.Marker({
        position: eePos,
        map: map,
        icon: eeImage,
        title: "Consummo",
        zIndex: 1
    });
}
