var htmlMap = 
    '<img src="/artwork/spacer.gif" width="500" height="388" alt="" usemap="#regioMap" />' +
    '<map name="regioMap" id="regioMap">' +
        '<area id="wadden" shape="poly" alt="Waddeneilanden" coords="0,0, 500,0, 500,31, 366,45, 284,62, 147,149, 0,223" href="de+kerken/regio.aspx?category=41811935212437507.AAABENvauYIAAAEQ29q5ggAAARDb2rmD0" />' +
        '<area id="nw" shape="poly" alt="Noordwest Friesland" coords="274,86, 295,105, 285,246, 219,237, 174,267, 112,245, 166,124" href="de+kerken/regio.aspx?category=41811859542409219.AAABENvauYIAAAEQ29q5ggAAARDb2rmD0" />' +
        '<area id="no" shape="poly" alt="Noordoost Friesland" coords="418,197, 274,86, 385,44, 468,35, 450,170" href="de+kerken/regio.aspx?category=41811860558741507.AAABENvauYIAAAEQ29q5ggAAARDb2rmD0" />' +
        '<area id="m" shape="poly" alt="Midden Friesland" coords="295,105, 285,246, 330,257, 384,174" href="de+kerken/regio.aspx?category=41811855762325507.AAABENvauYIAAAEQ29q5ggAAARDb2rmD0" />' +
        '<area id="zw" shape="poly" alt="Zuidwest Friesland" coords="174,267, 219,237, 330,257, 304,377, 129,350" href="de+kerken/regio.aspx?category=41811860976533505.AAABENvauYIAAAEQ29q5ggAAARDb2rmD0" />' +
        '<area id="zo" shape="poly" alt="Zuidoost Friesland" coords="304,377, 330,257, 384,174, 418,197, 469,171, 500,282, 323,387" href="de+kerken/regio.aspx?category=41811861239693315.AAABENvauYIAAAEQ29q5ggAAARDb2rmD0" />' +
    '</map>';

var htmlMapSmall = 
    '<img src="/artwork/spacer.gif" width="250" height="194" alt="" usemap="#regioMapSmall" />' +
    '<map name="regioMapSmall" id="regioMapSmall">' +
        '<area id="wadden" shape="poly" alt="Waddeneilanden" coords="0,0, 250,0, 250,31, 183,22, 142,31, 73,74, 0,111" href="page.aspx?category=41811935212437507.AAABENvauYIAAAEQ29q5ggAAARDb2rmD0" />' +
        '<area id="nw" shape="poly" alt="Noordwest Friesland" coords="137,43, 147,52, 142,123, 109,118, 87,133, 56,122, 83,62" href="page.aspx?category=41811859542409219.AAABENvauYIAAAEQ29q5ggAAARDb2rmD0" />' +
        '<area id="no" shape="poly" alt="Noordoost Friesland" coords="209,98, 137,43, 192,22, 234,17, 225,85" href="page.aspx?category=41811860558741507.AAABENvauYIAAAEQ29q5ggAAARDb2rmD0" />' +
        '<area id="m" shape="poly" alt="Midden Friesland" coords="147,52, 142,123, 165,128, 192,87" href="page.aspx?category=41811855762325507.AAABENvauYIAAAEQ29q5ggAAARDb2rmD0" />' +
        '<area id="zw" shape="poly" alt="Zuidwest Friesland" coords="87,133, 109,118, 165,128, 152,188, 64,175" href="page.aspx?category=41811860976533505.AAABENvauYIAAAEQ29q5ggAAARDb2rmD0" />' +
        '<area id="zo" shape="poly" alt="Zuidoost Friesland" coords="152,188, 165,128, 192,87, 209,98, 234,85, 250,141, 161,193" href="page.aspx?category=41811861239693315.AAABENvauYIAAAEQ29q5ggAAARDb2rmD0" />' +
    '</map>';

function selectMap(int) {
    $('#regiomap').css('backgroundPosition', (int * -500) + 'px 0');
    $('#regiomapsmall').css('backgroundPosition', (int * -250) + 'px 0');
}
function resetMap() {
    selectMap(0);
}

function smallMap(page) {
    $rm = $('#regiomapsmall');
    if ($rm.length) {
        $rm.html(htmlMapSmall.replace(/page\.aspx/g, page)).css('width', '250px').css('background', 'url(/Tsjerkepaad/images/map-small.gif) no-repeat left top');
        $('#regiomapsmall #m').hover(function() { selectMap(1); }, resetMap);
        $('#regiomapsmall #nw').hover(function() { selectMap(2); }, resetMap);
        $('#regiomapsmall #no').hover(function() { selectMap(3); }, resetMap);
        $('#regiomapsmall #zw').hover(function() { selectMap(4); }, resetMap);
        $('#regiomapsmall #zo').hover(function() { selectMap(5); }, resetMap);
        $('#regiomapsmall #wadden').hover(function() { selectMap(6); }, resetMap);
    }
}

$(function() {
    $rm = $('#regiomap');
    if ($rm.length) {
        $rm.html(htmlMap).css('width', '500px').css('background', 'url(/Tsjerkepaad/images/map.gif) no-repeat left top');
        $('#regiomap #m').hover(function() { selectMap(1); }, resetMap);
        $('#regiomap #nw').hover(function() { selectMap(2); }, resetMap);
        $('#regiomap #no').hover(function() { selectMap(3); }, resetMap);
        $('#regiomap #zw').hover(function() { selectMap(4); }, resetMap);
        $('#regiomap #zo').hover(function() { selectMap(5); }, resetMap);
        $('#regiomap #wadden').hover(function() { selectMap(6); }, resetMap);
    }
    
    var thisIndex = 0;
    $('#margin .ContentItemDetailNewsItem .FormFieldTitle a').each(function() {
        thisIndex += 1;
        $(this).attr('href', $(this).attr('href') + '#' + thisIndex);
    });
    
    var hrefSplit = window.location.href.split('#');
    if (hrefSplit.length > 1) {
        var hrefItem = parseInt(hrefSplit[1]);
        if (!isNaN(hrefItem)) {
            $('.ContentItemNewsItem:eq(' + (hrefItem - 1) + ') .FormFieldBody').addClass('active');
        }
    }
	
    if (typeof subgurim_ !== 'undefined') {
        window.setTimeout(function() {
            if (typeof Cms !== 'undefined') {
                GEvent.addListener(subgurim_, 'click', function(a, b){
                    if (b) {
                        if (clearContentMenus) {
                            clearContentMenus();
                        }
                        $('.ContentItemContentGroupLocation > div:last').css('display', 'none');
                        $('.ContentItemContentGroupLocation .ContentGroupMenu').css('display', 'none');
                        $('.ContentItemContentGroupLocation .ContentGroupAddNew').css({
                            width: '',
                            height: '',
                            visibility: '',
                            position: '',
                            left: ''
                        });
                        $('.ContentItemContentGroupLocation .ContentGroupAddNew .LatLngLat input').val(b.lat().toString().replace('.', ','));
                        $('.ContentItemContentGroupLocation .ContentGroupAddNew .LatLngLng input').val(b.lng().toString().replace('.', ','));
                        $('.ContentItemContentGroupLocation .ContentGroupAddNew .FormFieldTitle input').focus();
                    }
                });
            }
            jQuery.each(subgurim_.Jk, function() {
                GEvent.addListener(this, 'mouseover', function(){
                    this.openInfoWindow('<div id="' + this.id.replace('ThisMarker', 'MarkerDiv') + '"></div>');
                });
            });
        }, 3000);
    }

    $('.ContentItemDetailNewsItem:first .FormFieldBody, .ContentItemDetailCustomContent:first .FormFieldBody').css('display', 'block');
	$('.ContentItemDetailNewsItem, .ContentItemDetailCustomContent .FormH2 a').click(function() {
        if ($(this).closest('#margin').length == 0) {
            $('.ContentItemDetailNewsItem, .ContentItemDetailCustomContent').find('.FormFieldBody').removeClass('active');
    		$(this).closest('.ContentItemDetailNewsItem, .ContentItemDetailCustomContent').find('.FormFieldBody').toggleClass('active');
    		return false;
        }
	});
    
});

