﻿var scrollInterval = 0;
var intervalSeconds = 5000;


function ScrollBack() {
    Scroll(-250);
}

function ScrollForward() {
    Scroll(250);
}

function Scroll(distance) {
    var m = Number($("#ScrollContent").css("margin-left").replace('px', ''));
    $("#ScrollContent").animate({ marginLeft: (m + distance) + "px" }, 1500);
}

function initializeMap(longitude, latitude) {
    var latlng = new google.maps.LatLng(latitude, longitude);
    var myOptions = {
        zoom: 14,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);

    var positionMarker = new google.maps.Marker({
        position: latlng,
        map: map
    });
}

function initializeMap(address) {
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode({ 'address': address }, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            var myOptions = {
                zoom: 14,
                center: results[0].geometry.location,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            
            var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

            map.setCenter(results[0].geometry.location);
            
            var marker = new google.maps.Marker({
                map: map,
                position: results[0].geometry.location
            });
        } else {
            alert("Geocode was not successful for the following reason: " + status);
        }
    });
    
}

$(document).ready(function() {

    //$('.ScrollContainer').infiniteCarousel();
    $('.ScrollContentWrapper').jCarouselLite({
        btnNext: ".ScrollRight",
        btnPrev: ".ScrollLeft",
        speed: 1100,
        scroll: 3,
        visible: 3
    });

    $('.MaatwerkItem').mouseover(function() {
        $(".MaatwerkPopup").css("visibility", "visible");
        clearInterval(scrollInterval);
    }).mouseout(function() {
        $(".MaatwerkPopup").css("visibility", "hidden");
        scrollInterval = setInterval("automaticScroll()", intervalSeconds);
    });

    $('.BeestItem').mouseover(function() {
        $(".BeestPopup").css("visibility", "visible");
        clearInterval(scrollInterval);
    }).mouseout(function() {
        $(".BeestPopup").css("visibility", "hidden");
        scrollInterval = setInterval("automaticScroll()", intervalSeconds);
    });

    $('.GraffitiItem').mouseover(function() {
        $(".GraffitiPopup").css("visibility", "visible");
        clearInterval(scrollInterval);
    }).mouseout(function() {
        $(".GraffitiPopup").css("visibility", "hidden");
        scrollInterval = setInterval("automaticScroll()", intervalSeconds);
    });

    $('.GroenItem').mouseover(function() {
        $(".GroenPopup").css("visibility", "visible");
        clearInterval(scrollInterval);
    }).mouseout(function() {
        $(".GroenPopup").css("visibility", "hidden");
        scrollInterval = setInterval("automaticScroll()", intervalSeconds);
    });

    $('.PoetserItem').mouseover(function() {
        $(".PoetserPopup").css("visibility", "visible");
        clearInterval(scrollInterval);
    }).mouseout(function() {
        $(".PoetserPopup").css("visibility", "hidden");
        scrollInterval = setInterval("automaticScroll()", intervalSeconds);
    });

    $('.SchilderItem').mouseover(function() {
        $(".SchilderPopup").css("visibility", "visible");
        clearInterval(scrollInterval);
    }).mouseout(function() {
        $(".SchilderPopup").css("visibility", "hidden");
        scrollInterval = setInterval("automaticScroll()", intervalSeconds);
    });

    $('.AfvalItem').mouseover(function() {
        $(".AfvalPopup").css("visibility", "visible");
        clearInterval(scrollInterval);
    }).mouseout(function() {
        $(".AfvalPopup").css("visibility", "hidden");
        scrollInterval = setInterval("automaticScroll()", intervalSeconds);
    });

    //scrollInterval = setInterval("automaticScroll()", intervalSeconds);
    scrollInterval = setInterval("automaticScroll()", intervalSeconds);

});

var randomPictureId = 0

function GetRandomPicture(professionid, settlementid, typeid, languageid) {
    $.getJSON("/json/randomPic.ashx?action=get&profession=" + professionid + "&settlement=" + settlementid + "&type=" + typeid + "&language=" + languageid + "&id=" + randomPictureId,
    function(data) {
        $("#randomSmoel").attr("src", data.OriginalFilename);
        $("#randomSmoel").attr("alt", data.Comment);
        $("#randomSmoel").attr("title", data.Comment);
        $("#hrandomsmoel").html(data.Lastname + " " + data.Firstname);
        $("#prandomsmoel").html('"' + data.ShoutSentence + '"');
        randomPictureId = data.Id
    });
}

function GetRandomPictureRight(professionid, settlementid, typeid, languageid) {
    $.getJSON("/json/randomPic.ashx?action=get&profession=" + professionid + "&settlement=" + settlementid + "&type=" + typeid + "&language=" + languageid + "&id=" + randomPictureId,
    function(data) {
        $("#randomsmoelright").attr("src", data.OriginalFilename);
        $("#randomsmoelright").attr("alt", data.Comment);
        $("#randomsmoelright").attr("title", data.Comment);
        randomPictureId = data.Id
    });
}

function automaticScrollOld() {
    //alert('scroll');
    $('.ScrollContainer').trigger('next');
}

function automaticScroll() {
    //alert('scroll');
    $('.ScrollRight').trigger('click');
}
