// Date and time

var timezoneOffset = 2; // 1 of 2
var timezone = 'CET'; // CET of CEST

$(function($) {
	// %a	dag afkorting
	// %A	dag volledig
	// %b	maand afkoring
	// %B	maand volledig
	// %d	dag (00-31)
	// %H	uur 24 uurs notatie (00-23)
	// %I	uur 12 uurs notatie (01-12)
	// %M	minuut (00-59)
	// %p	am of pm voor 12 uurs notatie
	// %S	seconden (00-59)
	// %y	jaar 2 digits
	// %Y	jaar 4 digits
	var options = {
		utc: true,
		utc_offset: timezoneOffset,
		format: ' %H:%M ' + timezone
	}
	$('.jclock').jclock(options);
});




// Open / close a case
$(function() {
	currentOpenFaq = null;
		
	// Close all narrow cases
	$("ul.faq div.answer").hide();
	
	$("ul.faq a.expand").click(function(e) {
		var childElements = $($(e.target).parent("li").get(0)).children();
		if ($(e.target).hasClass("collapse")) { // Close current
			$(e.target).removeClass("collapse");
			$(childElements[1]).hide();
			currentOpenFaq = null;
		} else { // Open new
			$(childElements[1]).show();
			$(e.target).addClass("collapse");
			if (currentOpenFaq != null) {
				var oldChilds = $($(currentOpenFaq.target).parent("li").get(0)).children();
				$(oldChilds[1]).hide();
				$(currentOpenFaq.target).removeClass("collapse");
			}
			currentOpenFaq= e;
		}
		e.preventDefault();
	    return false;
	});
	
	$("ul.faq a.expand").click(function(e) {
		var childElements = $($(e.target).parent("li").get(0)).children();
		if ($(e.target).hasClass("collapse")) { // Close current
			$(childElements[1]).css({ visibility:"visible"});
			$(childElements[2]).hide();
			$(e.target).removeClass("collapse");
			currentOpenFaq = null;
		} else { // open new
			$(childElements[1]).css({ visibility:"hidden"});
			$(childElements[2]).show();
			$(e.target).addClass("collapse");
			if (currentOpenFaq != null) {
				var oldChilds = $($(currentOpenFaq.target).parent("li").get(0)).children();
				$(oldChilds[2]).hide();
				$(oldChilds[1]).css({ visibility:"visible"});
				$(currentOpenFaq.target).removeClass("collapse");
			}
			currentOpenCaseWide = e;
		}
		e.preventDefault();
	    return false;
	});
});

// show subMenu in header. Hiding is done via Superfish
$(function() {
	$(".bewoners").mouseover(function() {
		$("#bewoners").css("display", "block"); 
		$("#bedrijveninst").css("display", "none");   
		$("#bezoekers").css("display", "none");  
	});
	
	$(".bedrijveninst").mouseover(function() {
		$("#bewoners").css("display", "none"); 
		$("#bedrijveninst").css("display", "block");   
		$("#bezoekers").css("display", "none");    
	});
	
	$(".bezoekers").mouseover(function() {
		$("#bewoners").css("display", "none"); 
		$("#bedrijveninst").css("display", "none");   
		$("#bezoekers").css("display", "block");   
	});
});	

// removed from shtml
$(function() {
    $('ul.top').superfish({
        delay: 500,
        autoArrows: false,
        dropShadows: false,
        hoverClass: 'path'
    });
    $('.subMenu').hover(function() { }, function() { $(this).slideUp(200); })
    $('.menu').hover(function() { }, function() { $('.subMenu').slideUp(200); })

    $('ul.xtraLanguages').superfish({
        delay: 500,
        autoArrows: false,
        dropShadows: false,
        hoverClass: 'path'
    });

    var xtraLanguagesMouseover = false;

    $('.otherLanguages').click(function() {
        xtraLanguagesMouseover = false;

        if ($('.xtraLanguages').is(':visible')) {
            $('.xtraLanguages').hide();
        }
        else {
            $('.xtraLanguages').show();
            setTimeout(function() { if (!xtraLanguagesMouseover) { $('.xtraLanguages').hide(); } }, 1000);
        }
    });

    var ctime = null;

    $('.xtraLanguages').mouseover(function() {
        xtraLanguagesMouseover = true;
        if (ctime != null) {
            clearTimeout(ctime);
        }
    });

    $('.xtraLanguages').mouseout(function() {
        ctime = setTimeout(function() { $('.xtraLanguages').hide(); }, 1000);
    });

    // Show/hide 'add to' links
    $('a.addlink').click(function(event) {
        event.preventDefault();

        var uladd = $('ul.add');

        if (uladd.is(':visible')) {
            uladd.hide();
            $(this).css('background-position', '8px -212px')
        }
        else {
            uladd.show();
            $(this).css('background-position', '8px -284px')
        }
    });

    // Close tellafriend popup
    /*$('.close a').click(function(event){
    event.preventDefault();
    $('#tellAFriend').hide();
    });*/

    // Open tellafriend popup
    $('.mail a').click(function(event) {
        event.preventDefault();
        $('.filterOptions').hide();
        $('.filterOptionsSmall').hide();
        $('.tellaFriend').show();
    });

    $('a.tipClick').click(function() {
        $('.tipEditor').show();
        return false;
    });

    $('ul.filter li a.allContentTypes').click(function() {
        $('.contentType').show();
        return false;
    });
    $('ul.filter li a.meta').click(function() {
        $('.metaData').show();
        return false;
    });
    $('ul.filter li a.bron01').click(function() {
        $('.bron').show();
        return false;
    });
    $('ul.filter li a.afzender01').click(function() {
        $('.afzender').show();
        return false;
    });
    $('.close2 a').click(function() {
    $('.contentType').hide(); $('.metaData').hide(); $('.bron').hide(); $('.afzender').hide(); $('.tipEditor').hide(); $('.vandaag').hide(); $('.evenementen').hide(); $('.wijken').hide(); $('.vacatures').hide();
        return false;
    });

    $('.genres .close2 a, .genres input[@type=submit]').click(function(event) {
        event.preventDefault();
        var selectedValues = '';

        if ($('.topHeader input[@type=checkbox]').get(0).checked) {
            selectedValues = $('.topHeader input[@type=checkbox]').next('span').text();
        }
        else {
            var oCheckBoxes = $('.genres').find('.leftRow input[@type=checkbox], .rightRow input[@type=checkbox]');
            oCheckBoxes.each(function() {
                if ($(this).get(0).checked) {
                    if (selectedValues.length > 0) {
                        selectedValues += ', ';
                    }
                    selectedValues += $(this).next('span').text();
                }
            });
        }

        if (selectedValues.length > 0) {
            $('ul.filter li a.alleGenres').html(selectedValues);
        }
        $('.genres').hide();
    });

    /* nieuwe */
    if ($('.zoekbox_uitgebreid').length > 0) {
        $('.vandaag .close2 a, .vandaag input[@type=submit]').click(function(event) {
            event.preventDefault();
            var selectedValues = '';

            if ($('.vandaag .topHeader input[@type=checkbox]').get(0).checked) {
                selectedValues = $('.vandaag .topHeader input[@type=checkbox]').next('span').text();
            }
            else {
                var oCheckBoxes = $('.vandaag').find('.leftRow input[@type=checkbox], .rightRow input[@type=checkbox]');
                oCheckBoxes.each(function() {
                    if ($(this).get(0).checked) {
                        if (selectedValues.length > 0) {
                            selectedValues += ', ';
                        }
                        selectedValues += $(this).next('span').text();
                    }
                });
            }

            if (selectedValues.length > 0) {
                $('ul.filter li a.alleenVandaag').html(selectedValues);
            }
            $('.vandaag').hide();
        });

        $('.wijken .close2 a, .wijken input[@type=submit]').click(function(event) {
            event.preventDefault();
            var selectedValues = '';

            if ($('.wijken .topHeader input[@type=checkbox]').get(0).checked) {
                selectedValues = $('.wijken .topHeader input[@type=checkbox]').next('span').text();
            }
            else {
                var oCheckBoxes = $('.wijken').find('.leftRow input[@type=checkbox], .rightRow input[@type=checkbox]');
                oCheckBoxes.each(function() {
                    if ($(this).get(0).checked) {
                        if (selectedValues.length > 0) {
                            selectedValues += ', ';
                        }
                        selectedValues += $(this).next('span').text();
                    }
                });
            }

            if (selectedValues.length > 0) {
                $('ul.filter li a.alleenWijken').html(selectedValues);
            }
            $('.wijken').hide();
        });

        $('.vacatures .close2 a, .vacatures input[@type=submit]').click(function(event) {
            event.preventDefault();
            var selectedValues = '';

            if ($('.vacatures .topHeader input[@type=checkbox]').get(0).checked) {
                selectedValues = $('.vacatures .topHeader input[@type=checkbox]').next('span').text();
            }
            else {
                var oCheckBoxes = $('.vacatures').find('.leftRow input[@type=checkbox], .rightRow input[@type=checkbox]');
                oCheckBoxes.each(function() {
                    if ($(this).get(0).checked) {
                        if (selectedValues.length > 0) {
                            selectedValues += ', ';
                        }
                        selectedValues += $(this).next('span').text();
                    }
                });
            }

            if (selectedValues.length > 0) {
                $('ul.filter li a.alleenVacatures').html(selectedValues);
            }
            $('.vacatures').hide();
        });


        $('.evenementen .close2 a, .evenementen input[@type=submit]').click(function(event) {
            event.preventDefault();
            var selectedValues = '';

            if ($('.evenementen .topHeader input[@type=checkbox]').get(0).checked) {
                selectedValues = $('.evenementen .topHeader input[@type=checkbox]').next('span').text();
            }
            else {
                var oCheckBoxes = $('.evenementen').find('.leftRow input[@type=checkbox], .rightRow input[@type=checkbox]');
                oCheckBoxes.each(function() {
                    if ($(this).get(0).checked) {
                        if (selectedValues.length > 0) {
                            selectedValues += ', ';
                        }
                        selectedValues += $(this).next('span').text();
                    }
                });
            }

            if (selectedValues.length > 0) {
                $('ul.filter li a.evenementenAgenda').html(selectedValues);
            }
            $('.evenementen').hide();
        });
        

    }
    $('.topHeader input[type=checkbox],.smallBoxHeader input[type=checkbox]').bind('click', function(evt){
    	$('input[type=checkbox]', $(this).parents('fieldset')).attr('checked', $(this).attr('checked'));
    });
    


    $('a.react').click(function() {
        $(this).parent().find('> .forumReaction').show();
        return false;

    });

    $('ul.toolBox li.xtra a').click(function() {
        $('.gccInfo').show();
        return false;
    });

    $('a.tipClick').click(function() {
        $('.tipEditor').show();
        return false;
    });

    $('ul.filter li a.allContentTypes').click(function() {
        $('.contentType').show();
        return false;
    });

    $('ul.filter li a.meta').click(function() {
        $('.metaData').show();
        return false;
    });

    $('ul.filter li a.bron01').click(function() {
        $('.bron').show();
    });

    $('ul.filter li a.alleGenres').click(function(event) {
        event.preventDefault();
        $('.tellaFriend').hide();
        $('.filterOptions').hide();
        $('.filterOptionsSmall').hide();
        $('.genres').show();
    });
    $('ul.filter li a.alleenVandaag').click(function(event) {
        event.preventDefault();
        $('.tellaFriend').hide();
        $('.filterOptions').hide();
        $('.filterOptionsSmall').hide();
        $('.vandaag').show();
    });
    $('ul.filter li a.alleenWijken').click(function(event) {
        event.preventDefault();
        $('.tellaFriend').hide();
        $('.filterOptions').hide();
        $('.filterOptionsSmall').hide();
        $('.wijken').show();
    });
    $('ul.filter li a.alleenVacatures').click(function(event) {
        event.preventDefault();
        $('.tellaFriend').hide();
        $('.filterOptions').hide();
        $('.filterOptionsSmall').hide();
        $('.vacatures').show();
    });
    $('ul.filter li a.evenementenAgenda').click(function(event) {
        event.preventDefault();
        $('.tellaFriend').hide();
        $('.filterOptions').hide();
        $('.filterOptionsSmall').hide();
        $('.evenementen').show();
    });

    $('ul.filter li a.afzender01').click(function() {
        $('.afzender').show();
        return false;
    });

    // Close tellafriend popup (beforde the filterOptionsBG .close a (because of hyarchie fauld)
    $('.close a').click(function(event) {
        event.preventDefault();
        $('.tellaFriend').hide();
        return false;
    });

    $('.filterOptionsBg .close a').click(function() {
        $('li.filterOptionBox').hide();
        return false;
    });

    $('.rightColumn #filterSearchOptions li.metadata').click(function() {
        $('.rightColumn #filterSearchOptions li.filterOptionBox.metadatabox').show();
        $('.rightColumn #filterSearchOptions li.filterOptionBox.contenttypebox').hide();
        $('.rightColumn #filterSearchOptions li.filterOptionBox.bronbox').hide();
        $('.rightColumn #filterSearchOptions li.filterOptionBox.senderbox').hide();
        return false;
    });
    $('.rightColumn #filterSearchOptions li.contenttype').click(function() {
        $('.rightColumn #filterSearchOptions li.filterOptionBox.contenttypebox').show();
        $('.rightColumn #filterSearchOptions li.filterOptionBox.metadatabox').hide();
        $('.rightColumn #filterSearchOptions li.filterOptionBox.bronbox').hide();
        $('.rightColumn #filterSearchOptions li.filterOptionBox.senderbox').hide();
        return false;
    });
    $('.rightColumn #filterSearchOptions li.bronn').click(function() {
        $('.rightColumn #filterSearchOptions li.filterOptionBox.bronbox').show();
        $('.rightColumn #filterSearchOptions li.filterOptionBox.metadatabox').hide();
        $('.rightColumn #filterSearchOptions li.filterOptionBox.contenttypebox').hide();
        $('.rightColumn #filterSearchOptions li.filterOptionBox.senderbox').hide();
        return false;
    });
    $('.rightColumn #filterSearchOptions li.sender').click(function() {
        $('.rightColumn #filterSearchOptions li.filterOptionBox.senderbox').show();
        $('.rightColumn #filterSearchOptions li.filterOptionBox.metadatabox').hide();
        $('.rightColumn #filterSearchOptions li.filterOptionBox.contenttypebox').hide();
        $('.rightColumn #filterSearchOptions li.filterOptionBox.bronbox').hide();
        return false;
    });
    $('a.showMore').click(function() {
        $('ul.moreResults').slideDown(); $('a.showMore').hide(); $('a.showLess').show();
        return false;
    });
    $('a.showLess').click(function() {
        $('ul.moreResults').slideUp(); $('a.showLess').hide(); $('a.showMore').show();
        return false;
    });

    $('a.moreResults').click(function() {
        $('.moreSearchResults').slideDown(); $('a.moreResults').hide(); $('a.lessResults').show();
        return false;
    });
    $('a.lessResults').click(function() {
        $('.moreSearchResults').slideUp(); $('a.lessResults').hide(); $('a.moreResults').show();
        return false;
    });
    $('.usefulInfo .left .radio').click(function() {
        $('.hidden').show();
        /*return false;*/
    });

    var sortEventsMouseover = false;

    $('ul.sortEvents li.sortDropdown a').click(function(event) {
        event.preventDefault();
        sortEventsMouseover = false;

        if ($('ul.sortItem').is(':visible')) {
            $('ul.sortItem').hide();
        }
        else {
            $('ul.sortItem').show();
            setTimeout(function() { if (!sortEventsMouseover) { $('ul.sortItem').hide(); } }, 1000);
        }
    });

    var ctime = null;

    $('ul.sortItem').mouseover(function() {
        sortEventsMouseover = true;
        if (ctime != null) {
            clearTimeout(ctime);
        }
    });

    $('ul.sortItem').mouseout(function() {
        ctime = setTimeout(function() { $('ul.sortItem').hide(); }, 1000);
    });


    //accordion
    $('#accordion').accordion({
        header: '.testwrapper',
        autoheight: false,
        fillSpace: false
    }); 

    $('#accordion h2').each(function(index) {
        $(this).click(function() {
            var maxZIndex = 0;
            var currentVisible = null;
        });
    });
	
	restoreAccordionLinkClick();
});
/**
* We use the initCallback callback
* to assign functionality to the controls
*/
function mycarousel_initCallback(carousel) {
$('.jcarousel-control a').bind('click', function() {
carousel.scroll($.jcarousel.intval($(this).text()));
return false;
});

$('.jcarousel-scroll select').bind('change', function() {
carousel.options.scroll = $.jcarousel.intval(this.options[this.selectedIndex].value);
return false;
});

/*$('#mycarousel-next').bind('click', function() {
carousel.next();
return false;
});

$('#mycarousel-prev').bind('click', function() {
carousel.prev();
return false;
});*/
};

var currentCarouselId = 0;
// Ride the carousel...
$(function() {
		$("#mycarousel").jcarousel({
		scroll: 4,
		initCallback: mycarousel_initCallback
		// This tells jCarousel NOT to autobuild prev/next buttons
		//buttonNextHTML: null,
		//buttonPrevHTML: null
	});
	
	// Desaturize the carousel...
	
	//$(".carousel img").mouseover(function() { pixasticReset($(this)); }).each(function() { pixasticDesaturate($(this)); });
	$(".carousel img").mouseover(function() { pixasticReset($(this)); }).each(function() { pixasticDesaturate($(this)); });
});

function pixasticDesaturate(obj)
{
	var index = obj.parent().parent().parent().attr("jcarouselindex");
	obj.attr("id", "jcarousel-item" + index);
	obj.pixastic("desaturate");
	$("#jcarousel-item" + index).mouseover(function() { pixasticReset($(this)); }).attr("src", obj.attr("src"));
}

function pixasticReset(obj)
{
	var img = new Image();
	var canvas = document.getElementById(obj.attr("id"));
	img.src = obj.attr("src");
	img.id = canvas.id;
	
	canvas.parentNode.replaceChild(img, canvas);
	$(img).mouseout(function() { pixasticDesaturate($(this)); });
}

//ajaxFunction to get new image and text
var currentItem = 0;
var currentCategorie = 0;

function getHeaderItem(categorie, blnNext, url, intmax)
{
	if (currentCategorie != categorie) {
		currentCategorie = categorie;
		intnumber = 0;
		$('.item.selected .browsing .paging').find('li').each(function() {
		    $list = $(this).find('a');
		    if ($list.length < 1) {
		        currentItem = intnumber;
		    }
		    intnumber++;
		});
    } 
	var list = $('.item.selected .browsing .paging').children('li');
	if(blnNext == true) 
		newcurrentitem = currentItem + 1;
	else
		newcurrentitem = currentItem - 1;
	if(intmax < newcurrentitem) {
		newcurrentitem = intmax;
		return;
    }
    if(newcurrentitem == list.length) {
        currentItem = -1;
        newcurrentitem = 0;
    }
	if(newcurrentitem == -1) {
		currentItem = list.length;
		newcurrentitem = list.length-1;
	}
	var ajaxUrl = url.replace('{0}', currentCategorie).replace('{1}', newcurrentitem);
	$.ajax({
	    type: "GET",
	    //De functie is nog niet zoals deze behoord te zijn. Dit komt echter doordat alles nog statische html is.
	    url: ajaxUrl,
	    success: function(data, status) {
	    //function to update page
	        //var list = $('.item.selected .browsing .paging').children('li');
	        if (blnNext == true) {
	            currentItem += 1;
                $(list[currentItem]).html(currentItem + 1);
                if (currentItem == 0)
                    $(list[(list.length - 1)]).html("<a href=\"#\">" + currentItem + "</a>"); 
                else
                    $(list[currentItem - 1]).html("<a href=\"#\">" + currentItem + "</a>"); 
	        }
	        else {
	            currentItem -= 1;
				$(list[currentItem]).html(currentItem + 1);
				if (currentItem == list.length-1)
					$(list[(0)]).html("<a href=\"#\">" + currentItem + "</a>");
				else
					$(list[currentItem + 1]).html("<a href=\"#\">" + (currentItem + 2) + "</a>");
	        }
	        result = data.split("###");

	        updateHeaderItem(result, currentCategorie);
	    },
	    error: function(XMLHttpRequest, textStatus, errorThrown) {

	    }
	});
}

function updateHeaderItem(newcontent, categoryid) 
{
	//$("#homephoto" + categoryid).attr("src", newcontent[0]);
	$("#paragraph" + categoryid).html(newcontent[0]);
	$("#title" + categoryid).html(newcontent[1]);
	restoreAccordionLinkClick();
}

//ajaxfunction to get subitem;
var currentSubItem = 0;


function getSubItem(blnNext, url, intmax) {
	var listsub = $('.containerTypeA .paging').children('li');
    if(blnNext == true)
		newcurrentitem = currentSubItem + 1;
    else 
		newcurrentitem = currentSubItem - 1;
    if(newcurrentitem == listsub.length) {
        currentSubItem = -1;
        newcurrentitem = 0;
    }
	if(newcurrentitem == -1) {
		currentSubItem = listsub.length;
		newcurrentitem = listsub.length-1;
	}
    if(intmax < newcurrentitem) {
        newcurrentitem = intmax;
        return;
    } 
    var ajaxUrl = url.replace('{0}', newcurrentitem);
    $.ajax({
        type: "GET",
        //De functie is nog niet zoals deze behoord te zijn. Dit komt echter doordat alles nog statische html is.
        url: ajaxUrl,
        success: function(data, status) {
            
           //var listsub = $('.containerTypeA .paging').children('li');
           
            //function to update page
            if (blnNext == true) {
                currentSubItem += 1;
                $(listsub[currentSubItem]).html(currentSubItem + 1);
                if (currentSubItem == 0)
                    $(listsub[(listsub.length - 1)]).html("<a href=\"#\">" + currentSubItem + "</a>"); 
                else
                    $(listsub[currentSubItem - 1]).html("<a href=\"#\">" + currentSubItem + "</a>"); 
            }
			else {
	            currentSubItem -= 1;
				$(listsub[currentSubItem]).html(currentSubItem + 1);
				if (currentSubItem == listsub.length-1)
					$(listsub[(0)]).html("<a href=\"#\">" + currentSubItem + "</a>");
				else
					$(listsub[currentSubItem + 1]).html("<a href=\"#\">" + (currentSubItem + 2) + "</a>");
	        }
            result = data.split("###");

            updateSubItem(result);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {

        }
    });
}

function getSubItemTypeC(blnNext, url, intmax) {
	var listsub = $('.containerTypeC .paging').children('li');
    if(blnNext == true)
        newcurrentitem = currentSubItem + 1;
    else
        newcurrentitem = currentSubItem - 1;
	if(newcurrentitem == listsub.length) {
        currentSubItem = -1;
        newcurrentitem = 0;
    }
	if(newcurrentitem == -1) {
		currentSubItem = listsub.length;
		newcurrentitem = listsub.length-1;
	}

    if(intmax < newcurrentitem)
    {
        newcurrentitem = intmax;
        return;
    }
    var ajaxUrl = url.replace('{0}', newcurrentitem);
    $.ajax({
        type: "GET",
        //De functie is nog niet zoals deze behoord te zijn. Dit komt echter doordat alles nog statische html is.
        url: ajaxUrl,
        success: function(data, status) {
           
           //var listsub = $('.containerTypeC .paging').children('li');
         
            //function to update page
            if (blnNext == true) {
                currentSubItem += 1;
                $(listsub[currentSubItem]).html(currentSubItem + 1);
                if (currentSubItem == 0)
                    $(listsub[(listsub.length - 1)]).html("<a href=\"#\">" + currentSubItem + "</a>"); 
                else
                    $(listsub[currentSubItem - 1]).html("<a href=\"#\">" + currentSubItem + "</a>"); 
            }
			else {
	            currentSubItem -= 1;
				$(listsub[currentSubItem]).html(currentSubItem + 1);
				if (currentSubItem == listsub.length-1)
					$(listsub[(0)]).html("<a href=\"#\">" + currentSubItem + "</a>");
				else
					$(listsub[currentSubItem + 1]).html("<a href=\"#\">" + (currentSubItem + 2) + "</a>");
	        }
            result = data.split("###");

            updateSubItem(result);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {

        }
    });
}

function updateSubItem(newcontent) {
    if(newcontent[0] != "") {
		$("#subImage").show();
		$("#subImage").attr("src", newcontent[0]);
	} else {
		$("#subImage").hide();
	}
	$("#subParagraph").html(newcontent[1]);
	$("#subTussenkopje").html(newcontent[2]);
}


var currentGemeenteNieuwsItem = 0;

function getShortItemsGemeenteNiews(blnNext, url, intmax) {
    if(blnNext == true)
        newcurrentitem = currentGemeenteNieuwsItem + 1;
    else
        newcurrentitem = currentGemeenteNieuwsItem - 1;
	var listGemeente = $('.one .paging').children('li');
	if(newcurrentitem == listGemeente.length) {
        currentGemeenteNieuwsItem = -1;
        newcurrentitem = 0;
    }
	if(newcurrentitem == -1) {
		currentGemeenteNieuwsItem = listGemeente.length;
		newcurrentitem = listGemeente.length-1;
	}
    if(intmax < newcurrentitem) {
        newcurrentitem = intmax;
        return;
    }
  
    var ajaxUrl = url.replace('{0}', newcurrentitem);
    $.ajax({
        type: "GET",
        //De functie is nog niet zoals deze behoord te zijn. Dit komt echter doordat alles nog statische html is.
        url: ajaxUrl,
        success: function(data, status) {
           
           //var listGemeente = $('.containerTypeC .paging').children('li');
         
            //function to update page
            if (blnNext == true) {
                currentGemeenteNieuwsItem += 1;
                $(listGemeente[currentGemeenteNieuwsItem]).html(currentGemeenteNieuwsItem + 1);
                if (currentGemeenteNieuwsItem == 0)
                    $(listGemeente[(listGemeente.length - 1)]).html("<a href=\"#\">" + currentGemeenteNieuwsItem + "</a>"); 
                else
                    $(listGemeente[currentGemeenteNieuwsItem - 1]).html("<a href=\"#\">" + currentGemeenteNieuwsItem + "</a>"); 
            }
			else {
	            currentGemeenteNieuwsItem -= 1;
				$(listGemeente[currentGemeenteNieuwsItem]).html(currentGemeenteNieuwsItem + 1);
				if (currentGemeenteNieuwsItem == listGemeente.length-1)
					$(listGemeente[(0)]).html("<a href=\"#\">" + currentGemeenteNieuwsItem + "</a>");
				else
					$(listGemeente[currentGemeenteNieuwsItem + 1]).html("<a href=\"#\">" + (currentGemeenteNieuwsItem + 2) + "</a>");
	        }
            result = data.split("###");

            updateShortItemsGemeenteNiews(result);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {

        }
    });	
}

function updateShortItemsGemeenteNiews(content)
{
    $("#gemeenteParagraph").html(content[0]);
	$("#gemeenteTitle").html(content[1]);
}


// stadsnieuws


var currentStadsNieuwsItem = 0;

function getShortItemsStadsNiews(blnNext, url, intmax) {
    if(blnNext == true)
        newcurrentitem = currentStadsNieuwsItem + 1;
    else
        newcurrentitem = currentStadsNieuwsItem - 1;
	var listNieuws = $('.two .paging').children('li');
	if(newcurrentitem == listNieuws.length) {
        currentStadsNieuwsItem = -1;
        newcurrentitem = 0;
    }
	if(newcurrentitem == -1) {
		currentStadsNieuwsItem = listNieuws.length;
		newcurrentitem = listNieuws.length-1;
	}
    if(intmax < newcurrentitem)
    {
        newcurrentitem = intmax;
        return;
    }
    var ajaxUrl = url.replace('{0}', newcurrentitem);
    $.ajax({
        type: "GET",
        //De functie is nog niet zoals deze behoord te zijn. Dit komt echter doordat alles nog statische html is.
        url: ajaxUrl,
        success: function(data, status) {
           
           //var listGemeente = $('.containerTypeC .paging').children('li');
         
            //function to update page
            if (blnNext == true) {
                currentStadsNieuwsItem += 1;
                $(listNieuws[currentStadsNieuwsItem]).html(currentStadsNieuwsItem + 1);
                if (currentStadsNieuwsItem == 0)
                    $(listNieuws[(listNieuws.length - 1)]).html("<a href=\"#\">" + currentStadsNieuwsItem + "</a>"); 
                else
                    $(listNieuws[currentStadsNieuwsItem - 1]).html("<a href=\"#\">" + currentStadsNieuwsItem + "</a>"); 
            } else {
	            currentStadsNieuwsItem -= 1;
				$(listNieuws[currentStadsNieuwsItem]).html(currentStadsNieuwsItem + 1);
				if (currentStadsNieuwsItem == listNieuws.length-1)
					$(listNieuws[(0)]).html("<a href=\"#\">" + currentStadsNieuwsItem + "</a>");
				else
					$(listNieuws[currentStadsNieuwsItem + 1]).html("<a href=\"#\">" + (currentStadsNieuwsItem + 2) + "</a>");
	        }
            result = data.split("###");

            updateShortItemsStadNiews(result);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {

        }
    });
}

function updateShortItemsStadNiews(content)
{
	$("#stadParagraph").html(content[0]);
	$("#stadTitle").html(content[1]);
}



var currentEntertainNieuwsItem = 0;

function getShortEntertainStadsNiews(blnNext, url, intmax) {
	if(blnNext == true)
	    newcurrentitem = currentEntertainNieuwsItem + 1;
	else
	    newcurrentitem = currentEntertainNieuwsItem - 1;
	var listEntertain = $('.three .paging').children('li');
	if(newcurrentitem == listEntertain.length) {
        currentEntertainNieuwsItem = -1;
        newcurrentitem = 0;
    }
	if(newcurrentitem == -1) {
		currentEntertainNieuwsItem = listEntertain.length;
		newcurrentitem = listEntertain.length-1;
	}
	if(intmax < newcurrentitem)
	{
		newcurrentitem = intmax;
		return;
	}
	var ajaxUrl = url.replace('{0}', newcurrentitem);
    $.ajax({
          type: "GET",
		  //De functie is nog niet zoals deze behoord te zijn. Dit komt echter doordat alles nog statische html is.
          url: ajaxUrl,
          success: function(data, status) 
          {
          
            //function to update page
			if(blnNext == true)
			{
			    currentEntertainNieuwsItem += 1;
                $(listEntertain[currentEntertainNieuwsItem]).html(currentEntertainNieuwsItem + 1);
                if (currentEntertainNieuwsItem == 0)
                    $(listEntertain[(listEntertain.length - 1)]).html("<a href=\"#\">" + currentEntertainNieuwsItem + "</a>"); 
                else
                    $(listEntertain[currentEntertainNieuwsItem - 1]).html("<a href=\"#\">" + currentEntertainNieuwsItem + "</a>");
			}
			else {
	            currentEntertainNieuwsItem -= 1;
				$(listEntertain[currentEntertainNieuwsItem]).html(currentEntertainNieuwsItem + 1);
				if (currentEntertainNieuwsItem == listEntertain.length-1)
					$(listEntertain[(0)]).html("<a href=\"#\">" + currentItem + "</a>");
				else
					$(listEntertain[currentEntertainNieuwsItem + 1]).html("<a href=\"#\">" + (currentEntertainNieuwsItem + 2) + "</a>");
	        }
			result = data.split("###");
			
			updateShortItemsEntertainNiews(result);
          },
          error: function (XMLHttpRequest, textStatus, errorThrown) {
            
          }
    });
}

function updateShortItemsEntertainNiews(content)
{
	$("#entertainParagraph").html(content[0]);
	$("#entertainTitle").html(content[1]);
}

//function voor setting type of agenda (static (no jscript) or dynamic)
function setAgendasort()
{

}

function showUitgebreidZoeken(blnFocus) 
{
    $(".zoekbox_uitgebreid").animate({ height: "180px" }, 400);
    if (blnFocus) 
    {
        $("#zoekwoorden").focus();
    }
      
    return false;
}

function blurfocus(elm, text, newval) 
{
    if ($(elm).val() == text) 
    {
        $(elm).val(newval);
    }
}

function enlargeItem(elm) 
{
    $(elm).find("p").toggle();
}

function refreshUitgelicht()
{
    setInterval( "getSubItem( true,'ajaxPage_subitem_{0}.htm' )", 5000);
}

function restoreAccordionLinkClick()
{
	$('#accordion h2 a').click(function(event) {
		if ($(this).parent().parent('.testwrapper').is('.selected'))
		{
			window.location = $(this).attr('href');
		}
	});
}
if(jQuery) (function($){
	$.extend($.fn, {
		olm: function() {
			if( !o ) var o = {};
			this.each(function(){
				o.ol = $('ol', this);
				$.each(o.ol, function(){
					$(this).css({listStyleType:'none'});
					o.k = 0;
					$.each($(this).children(), function(){
						o.k++;
						if($(this).find('span.nbr').html() != null)
							$(this).find('span.nbr').append(o.k+'.')
						else
							$(this).prepend('<span class="nbr">'+o.k+'.</span>')
						$.each($(this).find('li'), function() {
							if($(this).find('span.nbr').html() == null) $(this).prepend('<span class="nbr">'+o.k+'.</span>')
						})

					})
				})
			});
		}
	})
})(jQuery);
$(document).ready(function(){
	$('.content').olm();
});