/**
* jQuery Cookie plugin
*
* Copyright (c) 2010 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
jQuery.cookie = function (key, value, options) {

    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

jQuery.fn.equalHeights = function(px) {
	$(this).each(function(){
		var currentTallest = 0;
		$(this).children().each(function(i){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
		});
		$(this).children().css({'min-height': currentTallest}); 
	});
	return this;
};

jQuery.fn.checkAll = function(flag) {
	if($(this).length != 0){
		if(flag == 1){
			$(this).attr('checked','checked');
		} else {
			$(this).removeAttr('checked');
		}
	}
};
jQuery.fn.refreshForm = function() {
	
	var myForm = $(this).closest("form");
	myForm.submit();

};

$(document).ready(function() {
	$("form.autoRefresh").find("input:submit").remove();
	$("a.checkAll").click(function(){
		$(this).parent().parent().find("input:checkbox").checkAll(1);
		var myForm = $(this).closest("form");
		myForm.submit();
	});
	$("a.uncheckAll").click(function(){
		$(this).parent().parent().find("input:checkbox").checkAll(0);
		var myForm = $(this).closest("form");
		myForm.submit();
	});
	
	
	$("form.autoRefresh").find("input:checkbox").change(function(){
		$(this).refreshForm();
	});
	
	$("#tabs").tabs({ cookie: { expires: 1 } });
	
	$("a.button").button();
	
	$("#footer .divFull").equalHeights(true);
	$("#onder-de-aandacht div.widget:last").css({marginRight: 0});
	
	$("#sticky-slide").cycle({next:'#sn-next',prev:'#sn-prev'});
	
	
	$("#stadsdeel-navigatie > div").hide().first().show();
	// Animaties en acties na klik op kaart
	$("#sd-nav-stap1 area").click(function(event){
		
		event.preventDefault();
		var myId = $(this).attr("href");
		$("#sd-nav-stap1").hide();
		$("#sticky-nieuws").hide();
		$("#stadsdeel-navigatie").css({width: 953});
		$(myId).show().addClass("current-part");
		$(myId).children().hide().first().show();
		
	});
	
	
	//Navigatie binnen blok1
	$("div.stadsdeel-blok1 li a").click(function(event){
		event.preventDefault();
		var sid = $(this).attr("href");
		
		$("div.stadsdeel-blok2, #detail_posts").hide();
		$(sid).show();
		$(this).parent().addClass("active").siblings().removeClass("active");
	});
	
	
	//Navigatie binnen blok2
	$("div.stadsdeel-blok2 li a").click(function(event){
		event.preventDefault();
		var sid = $(this).attr("href");
		
		$("#detail_posts").show().children().hide();
		$("#detail_posts "+sid).show();
		$(this).parent().parent().addClass("active").siblings().removeClass("active");
	});
	
	
	//Functie om terug te gaan naar oorspronkelijk scherm
	$("div.stadsdeel-blok1 a.back, div.stadsdeel-blok1 div.close").click(function(event){
		event.preventDefault;
		$("#stadsdeel-navigatie").css({width: 630});
		$("div.stadsdeel").hide();
		$("#sd-nav-stap1").show();
		$("#sticky-nieuws").show();
	});
	
	
	//Sluitfunctie blok2
	$("div.stadsdeel-blok2 div.close").click(function(){
		$("#detail_posts").hide().children().hide();
		$("div.stadsdeel-blok2").hide();
		$("div.stadsdeel-blok1 li").siblings().removeClass("active");
	});
	
	//Sluitfunctie blok3
	$("#detail_posts .close").click(function(){
		$("#detail_posts").hide().children().hide();
		$("div.stadsdeel-blok2 ul li").removeClass("active");
	});
	
	
	//Freaking hack for WP custom post types
	$("#menu-hoofdmenu").each(function(){
		var scndbkp = $("#breadcrumbs a").eq(1).text();
		if(scndbkp === "Activiteiten"){
			$("#menu-item-90").addClass("current-menu-item");
		}
		if(scndbkp === "Locaties"){
			$("#menu-item-91").addClass("current-menu-item");
		}
		if(scndbkp === "Projecten"){
			$("#menu-item-79").addClass("current-menu-item");
		}
		if(scndbkp === "Nieuws"){
			$("#menu-item-71").addClass("current-menu-item");
		}
		if(scndbkp === "Over Combiwel"){
			$("#menu-item-836").addClass("current-menu-item");
		}
	});
	

	
		jQuery("#map-container AREA").mouseover(function(){
				var regionMap = '.'+$(this).attr('id')+'-map';
				jQuery(regionMap).css('display', 'inline');
			}).mouseout(function(){
				var regionMap = '.'+$(this).attr('id')+'-map';
				if (! jQuery(regionMap).hasClass('selected')) {
					jQuery(regionMap).css('display', 'none');
				}
			});

	// voeg de class "last" toe aan het derde element in de footer
	$("#footer div.divFull div.widget").eq(2).addClass("last");

});
