$(document).ready(function() {

    // Yhteydenottolomake
    $("input.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;

    });

    // Toteutuskuva
    $('#toteutus img').css({opacity: 0.7});

    $('#toteutus img').hover(function() {
            $(this).stop().animate({opacity: 1.0}, 600);
    } , function () {
            $(this).stop().animate({opacity: 0.7}, 300);
    });

    // Galleria
    $("a[rel=lightbox]").fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'fade',
                'speedIn'               : 1200,
                'speedOut'              : 600,
                'easingIn'              : 'easeOutQuad',
                'easingOut'             : 'easeInQuad'
    });
    //this is for the empty span tags for the magnifying glass icon
    //$("ul li").append('<span></span>');
    //$("ul li span").hide().fadeIn(600);
    //this is for the preloader

    $('img.galleryImage').hide().fadeIn(600);

});





// Kartta
function initialize() {

    var latlng = new google.maps.LatLng(64.986305,25.456610);
    var myOptions = {
        zoom: 13,
        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(64.986305,25.456610);

    var eeMarker = new google.maps.Marker({
        position: eePos,
        map: map,
        icon: eeImage,
        title: "Oulun Teollisuuskojeistot Oy - Oritkarintie 6 - 90400 Oulu",
        zIndex: 1
    });

}
