var TimerMenu, TimerCarousel;
var NewsPanel = "NewsItems";
var PanelHeight = 97;

$(document).ready(function () {
    $("#XLW").css("display", "none");
    //Cloud Carousel
    if ($('#Carousel').length) {
        $("#Carousel").CloudCarousel(
            {
                //minScale: 0.05,
                xPos: 465,
                yPos: 42,
                yRadius: -48,
                xRadius: 430,
                speed: 0.1,
                //autoRotate: 'right',
                //autoRotateDelay: 30000,
                //buttonLeft: $(".Left"),
                //buttonRight: $(".Right"),
                //altBox: $("#CarouselInfo"),
                //titleBox: $("#CarouselTitle"),
                //mouseWheel: true,
                //bringToFront: true,
                FPS: 30
            }
	    );
    }

    $(".NewsButtonUp").click(SlideNewsItemsUp);
    $(".NewsButtonDown").click(SlideNewsItemsDown);

    var i;
    for (i in document.images) {
        if (document.images[i].src) {
            var imgSrc = document.images[i].src;
            if (imgSrc.substr(imgSrc.length - 4) === '.png' || imgSrc.substr(imgSrc.length - 4) === '.PNG') {
                document.images[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='" + imgSrc + "')";
            }
        }
    }

    if ($('ul#myRoundabout').length) {
        $('ul#myRoundabout').roundabout(
        {
            shape: 'square',
            duration: 500,
            minScale: 0,
            minOpacity: 1.0,
            btnNext: ".CarouselLeft",
            btnPrev: ".CarouselRight"
        });
        ChangeCarouselText();
    }
});

function initialize() {
    var latlng = new google.maps.LatLng(51.4666168, 5.5358755);
    var myOptions = {
        zoom: 17,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);

    var marker = new google.maps.Marker({
        position: latlng,
        map: map
    });   
}

function validateEmail(p_Email) {
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	return emailPattern.test(p_Email);
}

function CheckRequired() {
    $('.required').each(function () { $(this).removeClass('required'); })
    var Cont = true;
    $('.req').each(function (index) {
        var Name = $(this).attr("name");
        var Value = $(this).val();
        if (Value == "" || Value == null) {
            Cont = false; $("#" + Name).addClass('required');
        }
    });
    $('.email').each(function (index) {
        var Name = $(this).attr("name");
        var Value = $(this).val();
        if (!validateEmail(Value)) { $("#" + Name).addClass('required'); Cont = false; }
    });
    if (Cont) return true;
}

function ChangeCarouselText() {
    $("#myRoundabout").find("li").each(function () {
        ImageLeft = $(this).css("left").replace("px", "");
        ImageAlt = $(this).find("img").attr("alt");
        ImageTitle = $(this).find("img").attr("title");
        parseFloat(ImageLeft);
        //if (ImageLeft > 175 && ImageLeft < 185) {
        if (ImageLeft > 240 && ImageLeft < 250) {
            $("#CarouselTitle").html(ImageTitle);
            $("#CarouselInfo").html(ImageAlt);
        }
    })
    TimerCarousel = setTimeout('ChangeCarouselText()', 1000);
}

function printSelection(node) {

    var content = node.innerHTML
    var pwin = window.open('', 'print_content', 'width=600,height=800');

    pwin.document.open();
    pwin.document.write('<html><body onload="window.print()"><div style=\"color: #454545;font-size:12px;font-family:Segoe UI;line-height:19.5px;overflow:scroll;width:590px;height:790px;\">' + content + '</div></body></html>');
    pwin.document.close();

    setTimeout(function () { pwin.close(); }, 1000);

}

//function SetActiveColorForMenu() {
//    var Page = jQuery.url.segment(2); //1 voor localhost
//    var AmountOfItems = $("#Menu").find("li").length;
//    for (var i = 0; i < AmountOfItems; i++) {
//        //var UrlValue = $("#Url" + i).html().toLowerCase();
//        //UrlValue = UrlValue.replace(/ /g, "-");
//        if (Page != null)
//            if (UrlValue == Page)
//                $("#MenuItem" + i).addClass("ItemActive");
//            else
//                $("#MenuItem" + i).addClass("Item");
//    }

//    TimerMenu = setTimeout('SetActiveColorForMenu()', 1000);
//}
function SlideNewsItemsDown() {
    var MasterHeight = $("#" + NewsPanel).height();
    var MarginTop = $("#" + NewsPanel).css("margin-top").replace("px", "").replace("-", "");

    if ((MasterHeight + -MarginTop) > 15) {
        $("#" + NewsPanel).animate({ marginTop: (-MarginTop - PanelHeight) }, 1000);
    }
}

function SlideNewsItemsUp() {
    var MasterHeight = $("#" + NewsPanel).height();
    var MarginTop = $("#" + NewsPanel).css("margin-top").replace("px", "").replace("-", "");

    if ((MarginTop) > 0) {
        $("#" + NewsPanel).animate({ marginTop: (-MarginTop + PanelHeight) }, 1000);
    }
}
