/* vars */
var isVraag = false;
var superTagBase = "";


jQuery.cookie = function(name, value, options) {
	if (typeof value != 'undefined') { // name and value given, set cookie
		options = options || {};
		if (value === null) {
			value = '';
			options.expires = -1;
		}
		var expires = '';
		if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
			var date;
			if (typeof options.expires == 'number') {
				date = new Date();
				date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
			} else {
				date = options.expires;
			}
			expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
		}
		// CAUTION: Needed to parenthesize options.path and options.domain
		// in the following expressions, otherwise they evaluate to undefined
		// in the packed version for some reason...
		var path = options.path ? '; path=' + (options.path) : '';
		var domain = options.domain ? '; domain=' + (options.domain) : '';
		var secure = options.secure ? '; secure' : '';
		document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
	} else { // only name given, get cookie
		var cookieValue = null;
		if (document.cookie && document.cookie != '') {
			var cookies = document.cookie.split(';');
			for (var i = 0; i < cookies.length; i++) {
				var cookie = jQuery.trim(cookies[i]);
				// Does this cookie string begin with the name we want?
				if (cookie.substring(0, name.length + 1) == (name + '=')) {
					cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
					break;
				}
			}
		}
		return cookieValue;
	}
};
function multiSelectAddItem() {
	selRoot = $(this).parents(".multiSelect");
	guid = $(this).attr("id");
	inputFieldID = selRoot.attr('rel');
	col2 = selRoot.find(".selcol2");
	col2.append("<div rel='" + guid + "' class='selecteditem'>"
			+ "<div class='controls'><span class='up'>up</span>"
			+ "<span class='dwn'>down</span>"
			+ "</div>"
			+ "<span class='del'>delete</span>"
			+ "<div class='text'>"
			+ $(this).text()
			+ "</div>"
			+ "</div>");
	$(this).hide();
	$(".up").unbind("click");
	$(".dwn").unbind("click");
	$(".del").unbind("click");
	$(".up").click(multiSelectUp);
	$(".dwn").click(multiSelectDwn);
	$(".del").click(multiSelectDel);
	multiSelectSetFormValue(selRoot);

}
function multiSelectUp() {
	ItemToMove = $(this).parents(".selecteditem");
	multiBox = $(this).parents('.multiSelect');
	if (ItemToMove.prev().attr('rel')) {
		ItemToMove.clone(true).insertBefore(ItemToMove.prev());
		ItemToMove.remove();

		multiSelectSetFormValue(multiBox);
	}

}
function multiSelectDwn() {
	ItemToMove = $(this).parents(".selecteditem");
	multiBox = $(this).parents('.multiSelect');
	if (ItemToMove.next().attr('rel')) {
		ItemToMove.clone(true).insertAfter(ItemToMove.next());
		ItemToMove.remove();
		multiSelectSetFormValue(multiBox);
	}
}
function multiSelectDel() {
	multiBox = $(this).parents('.multiSelect');
	guid = $(this).parents(".selecteditem").attr('rel');
	$("#" + guid).show();
	$(this).parent(".selecteditem").remove();
	multiSelectSetFormValue(multiBox);
}
function multiSelectSetFormValue(multiBox) {
	newValues = "";
	multiBox.find(".selecteditem").each(function() {
		if (newValues != "") {
			newValues += ",";
		}
		newValues += $(this).attr("rel");
	});
	mSelect = multiBox.find('input');
	mSelect.val(newValues)
}
function initMultiSelect() {
	$(".multiSelect div.selcol1 ul li.vraag").click(multiSelectAddItem);
	$(".multiSelect").each(function() {
		fieldId = $(this).find('input');

		values = fieldId.val();
		items = values.split(',');
		for (i = 0; i < items.length; i++) {
			$("#" + items[i]).click();
		}
	});

}

function blockenter(field, event) {
    var code = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if(code == 13) { //Enter keycode
        event.cancelBubble = true;
	    event.returnValue = false;
        setLocation();
        
        return false;
    }
    return true;
}

function sendSituatieTag() {
	// SUPERTAG
	situatietag = $("#situationlist").find("a.active").text();
	if($(".choicecontent").find("a.active").text() > "") {
	    situatietag += ":" + $(".choicecontent").find("a.active").text();
	}
	_supertag.antwoord =document.title + ":" + situatietag;
	_supertag.event = "vraag_en_antwoord/vraag_situatie";
	_supertag.submit();
}
    
function initSituations() {
	$("#situationlist ul li a span").each(function() {
		pheight = $(this).parent().height();
		mheight = $(this).height();
		lext = Math.floor((pheight - mheight - 10) / 2);
		$(this).css("margin-top", lext + "px");
	});

	$("ul.choicelist li a span").each(function() {
		pheight = $(this).parent().height();
		mheight = $(this).height();
		lext = Math.floor((pheight - mheight - 10) / 2);
		$(this).css("margin-top", lext + "px");
	});

	$(".choice").hide();
	$(".answer").hide();
	$("#situationlist li a").click(function() {

		cid = $(this).attr("id");
		if (cid == "") {
			return true;
		}
		$("#situationlist ul li a").removeClass("active");
		$(".choicelist li a").removeClass("active");
		$(".choicelist li a").removeClass("disabled");
		$("#situationlist ul li a").addClass("disabled");
		$("div.choice").hide();
		$("div.answer").hide();
		$(this).removeClass("disabled");
		$(this).addClass("active");
		if ($("#item_" + cid).length > 0) {
			// we have multiple answers
			$("#item_" + cid).show();

			$("#rootfaqquestions").show();
		} else {
			// we only have one answer
			$("#ans_1_" + cid).show();

			$("#rootfaqquestions").hide();
		}
		

        sendSituatieTag();
		
		
		
		return false;
	});

	$(".choicelist li a").click(function() {
		cid = $(this).attr("id");
		showid = $(this).attr("href");
		if (cid == "") {
			return true;
		}
		$("div.answer").hide();

		$("#rootfaqquestions").hide();
		$(".choicelist li a").removeClass("active");
		$(".choicelist li a").addClass("disabled");
		$(this).removeClass("disabled");
		$(this).addClass("active");
		$(showid).show();
		sendSituatieTag();
		return false;
	});


}
$(document).ready(function() {

	/// equalize contentcol
	if ($(".syncheight1").size() > 0) {
		$(".syncheight1").each(function() {
			cheight = $(this).height();
			col2 = $(this).parent().parent().find(".syncheight2");
			c2height = col2.height();// + 15;
			if (cheight > c2height) {
				newheight = cheight;
			} else {
				newheight = c2height;
			}
			$(this).css("min-height", newheight + "px");
			col2.css("min-height", (newheight - 9) + "px");
		});
	}

	if ($(".tipslist li a").size() > 0) {
		$(".tipslist li a").each(function() {
			if ($(this).attr("href").indexOf(".pdf") > 0) {
				$(this).css("background-image", "url(/images/icon_pdf2.png)");
			} else if ($(this).attr("href").indexOf(".doc") > 0 || $(this).attr("href").indexOf(".docx") > 0) {
				$(this).css("background-image", "url(/images/icon_wrd.png)");
			}
		});
	}

	// fix voor niet werkende editknopjes
	$(".editinline").click(function(event) {
		location.href = $(this).attr("href");
		event.stopPropagation();
	});


	$(".innerlist>ul>li div.itemcontent").hide();
	$(".innerlist>ul>li>h3").click(function() {
	    if(!$(this).parent().hasClass("active")) {
		    $(".innerlist>ul>li div.itemcontent").hide();
		    $(".innerlist>ul>li").removeClass("active");
		    $(this).parent().find(".itemcontent").show();
		    $(this).parent().addClass("active");
    		
		    // supertag
		    if (superTagBase == "") {
			    superTagBase = document.title;
		    }
		    _supertag.event='vraag_en_antwoord/vraag_stap';
            _supertag.antwoord = superTagBase + ":" + $(this).text().replace(/ +(?= )/g,'');
;
            _supertag.submit();
        }
        _supertag.antwoord = superTagBase;
		
		
		
	});
	$(".innerlist>ul>li>h3").hover(function() {
				$(this).addClass("over")
			},
			function() {
				$(this).removeClass("over")
			});

	$(".innerlist>ul>li>h3:first").click();


    $("a:contains(chat)").click(function() {
        _supertag.event='kanaalsturing/chat';
        _supertag.submit();
    });
    
    $(".video-fancybox img").click(function() {
        _supertag.event='video/start';
        _supertag.submit();
    });


	initMultiSelect();
	initSituations();

	if ($("#werkenBijOpen").length > 0) {
		sh = $("#stage").height();
		oh = $("#open").height();
		if (sh > oh) {
			$("#open").css("height", sh + "px");
			$("#stage").css("height", sh + "px");
		} else {
			$("#open").css("height", oh + "px");
			$("#stage").css("height", oh + "px");
		}

	}

	// Youtube Video Box
	$(".video").click(function() {
		videoLink = $(this).attr("href");
		window.videoBox(videoLink);
		return false;
	});
});

function videoBox(videoLink) {
	$('body').append('<div style="display:none" id="videoBox"><object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/' + videoLink + '?fs=1&amp;hl=nl_NL"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/' + videoLink + '?fs=1&amp;hl=nl_NL" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object><p><a class="close" href="#">X</a></p></div>');
	$('#videoBox').fadeIn('slow', function() {
		$(".close").click(function(e) {
			e.preventDefault();
			$('#videoBox').fadeOut();
			$('#videoBox').remove();
		});
	});
}

// Uitzending Gemist Hele Aflevering Video Box
$(document).ready(function() {
	$(".uitzending").click(function() {
		uitzendingLink = $(this).attr("href");
		window.uitzendingBox(uitzendingLink);
		return false;
	});
});

function uitzendingBox(uitzendingLink) {
	$('body').append('<div style="display:none" id="videoBox"><object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="618" height="348"><param name="source" value="http://embed.player.omroep.nl/sle/ugslplayer.xap"/><param name="enablehtmlaccess" value="true"/><param name="initParams" value="version=sl.1.9.9,episodeID=' + uitzendingLink + ',playlistEnabled=yes,playMode=pause,volume=100,seekTime=00:00:00,subtitlesEnabled=false" /><embed source="http://embed.player.omroep.nl/sle/ugslplayer.xap" type="application/x-silverlight-2" enablehtmlaccess="true" width="618" height="348" seekTime="00:00:00" initParams="version=sl.1.9.9,episodeID=' + uitzendingLink + ',playlistEnabled=yes,playMode=pause,volume=100,seekTime=00:00:00,subtitlesEnabled=false"><a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"><img src="http://embed.player.omroep.nl/sle/downloadsilverlight.jpg" alt="Get Microsoft Silverlight" style="border-style: none"/></a> <br /> <a href="http://player.omroep.nl/?aflID=13157727">Bekijk de video in andere formaten.</a> </embed> </object><p><a class="close" href="#">X</a></p></div>');
	$('#videoBox').fadeIn('slow', function() {
		$(".close").click(function(e) {
			e.preventDefault();
			$('#videoBox').fadeOut();
			$('#videoBox').remove();
		});
	});
}

// Uitzending Gemist Fragment Video Box
$(document).ready(function() {
	$(".fragment").click(function() {
		fragmentLink = $(this).attr("href");
		window.fragmentBox(fragmentLink);
		return false;
	});
});

function fragmentBox(fragmentLink) {
	$('body').append('<div style="display:none" id="videoBox"><object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="618" height="348"><param name="source" value="http://embed.player.omroep.nl/sle/ugslplayer.xap"/><param name="enablehtmlaccess" value="true"/><param name="initParams" value="version=sl.1.9.9,fragmentID=' + fragmentLink + ',videoQuality=std,playlistEnabled=yes,playMode=pause" /><embed source="http://embed.player.omroep.nl/sle/ugslplayer.xap" type="application/x-silverlight-2" enablehtmlaccess="true" width="618" height="348" initParams="version=sl.1.9.9,fragmentID=' + fragmentLink + ',videoQuality=std,playlistEnabled=yes,playMode=pause"><a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"><img src="http://embed.player.omroep.nl/sle/downloadsilverlight.jpg" alt="Get Microsoft Silverlight" style="border-style: none"/></a><br /><a href="http://player.omroep.nl/?aflID=' + fragmentLink + '&start=00:18:40&end=00:19:45">Bekijk de video in andere formaten.</a></embed></object><p><a class="close" href="#">X</a></p></div>');
	$('#videoBox').fadeIn('slow', function() {
		$(".close").click(function(e) {
			e.preventDefault();
			$('#videoBox').fadeOut();
			$('#videoBox').remove();
		});
	});
}
var lastID = 0;
$(document).ready(function() {

	//$.pseudoFocus();

	$("#partnerWrap a").hover(
			function() {
				$(this).addClass("active");
			},
			function() {
				$(this).removeClass("active");
			}
	);

	/*$(".videoblock a").hover(
			function() {
				$(this).addClass("active");
			},
			function() {
				$(this).removeClass("active");
			}
	);

	$("#video a").hover(
			function() {
				$(this).addClass("active");
			},
			function() {
				$(this).removeClass("active");
			}
	);

	$("#mediaVideo a").hover(
			function() {
				$(this).addClass("active");
			},
			function() {
				$(this).removeClass("active");
			}
	);*/

	// Start Partner Box
	$('a[name=box]').click(function(e) {
		e.preventDefault();

		var id = $(this).attr('href');
		$('#boxes').css('display', 'block');

		var winH = $(window).height();
		var winW = $(window).width();

		$(id)
				.css({
					"top": "50%",
					"left": "50%"
				});
		lastID = id;
		$(id).show();
	});

	$('.window .close').click(function(e) {
		e.preventDefault();
		if (lastID && lastID != 0) {
			$(lastID).hide();
		}
		$('#boxes').hide();
	});

	$('#mask').click(function() {
		$(this).hide();
		$('#boxes').hide();
		$('.window').hide();
	});
	// End Partner Box

	if ($(".print").length > 0) {
		$(".print").show();
		$(".print").click(function(e) {
			window.print();
			_supertag.event='vraag_en_antwoord/printen';
			_supertag.submit();
			e.preventDefault();
		});
	}
	$(".link_mailuwvraag").click(function() {
		$("#mailuwvraag").toggle();
		return false;
	});
	$(".link_reactieoppagina").click(function() {
		$("#reactieoppagina").toggle();
		return false;
	});

	var links = $('#content a').filter(function() {
		return (this.hostname && this.hostname != location.hostname && this.hostname.indexOf("test") < 0 && this.hostname.indexOf("juridischloket.nl") < 0 && $(this).attr("href").indexOf("http") >= 0);
	});

	links.each(function() {
		// strip tags for shitty Sharepoint editor
		if (jQuery.trim($(this).html().replace(/(<.*?>)/ig, "")) > "") {
			$(this).after('<img src="/images/a_extern.gif" alt="external link" class="externalimage" />');
		}
	});

	/// now remove the images from external lists in the tips list!
	$(".tipslist img").each(function() {
		$(this).remove();
	});

	$(".main").hover(function() {
		$(this).find(".foldout").show();
		$(this).find("a:first").addClass("selected");
	}, function() {
		$(this).find(".foldout").hide();
		$(this).find("a:first").removeClass("selected");
	});

	//$(".trefwoord").Watermark("Vul hier een trefwoord in", "#8b8989");

	/* font size */

	$("#metaFontsizeSmall").attr('href', '#').click(function() {
		$("body").removeClass('fontsizeSmall fontsizeNormal fontsizeLarge').addClass('fontsizeSmall');
		$(".fontsizes a").removeClass("active");
		$(this).addClass("active");
		$.cookie('fSize', 'fontsizeSmall', { path: '/' });
		if ($.browser.msie && $.browser.version == "6.0") {
			document.location = document.location;

		}

		return false;
	});
	$("#metaFontsizeRegular").attr('href', '#').click(function() {
		$("body").removeClass('fontsizeSmall fontsizeNormal fontsizeLarge').addClass('fontsizeNormal');
		$(".fontsizes a").removeClass("active");
		$(this).addClass("active");
		$.cookie('fSize', 'fontsizeNormal', { path: '/' });
		if ($.browser.msie && $.browser.version == "6.0") {
			document.location = document.location;
		}

		return false;
	});
	$("#metaFontsizeLarge").attr('href', '#').click(function() {
		$("body").removeClass('fontsizeSmall fontsizeNormal fontsizeLarge').addClass('fontsizeLarge');
		$(".fontsizes a").removeClass("active");
		$(this).addClass("active");
		$.cookie('fSize', 'fontsizeLarge', { path: '/' });
		if ($.browser.msie && $.browser.version == "6.0") {
			document.location = document.location;
		}
		return false;
	});
	if ($.cookie('fSize')) {
		$("body").removeClass('fontsizeSmall fontsizeNormal fontsizeLarge').addClass($.cookie('fSize'));
		$(".fontsizes a").removeClass("active");
		var a = $.cookie('fSize');
		var capitalCook = a.charAt(0).toUpperCase() + a.substr(1);
		$("#meta" + capitalCook).addClass("active");

	}


	if ($('.themeFaq').length > 0) {
		/* alles inklappen */
		$(".themeFaq").children("li").each(function(i) {
			$(".themeFaq").children("li:eq(" + i + ")").find("a.act").addClass("inact").removeClass("act");
			$(".themeFaq").children("li:eq(" + i + ")").find("div").hide();

		});


		/* uitklappen onclick */
		$(".themeFaq > li").each(function() {

			$("a:eq(0)", this).click(function() {

				 switch ($(this).attr('class')) {
				 case "inact":
				 $(this).removeClass('inact').addClass('act');
					if (superTagBase == "") {
						superTagBase = _supertag.antwoord;
					}
					_supertag.antwoord = superTagBase + ":" + $(this).text();
					_supertag.event = "vraag_en_antwoord/subvraag";
					_supertag.submit();
				 break;
				 case "act":
                      _supertag.antwoord=superTagBase;
                      //_supertag.submit();

				 	$(this).removeClass('act').addClass('inact');
				 break;
				 }
				 $(this).parent().find('div').toggle();

				return false;
			});
		});
	}
	$(".formMessageClose").click(function() {

		$(".formMessage").hide();
	});

	// this fixes the IE6 problem where the #video div gets displayed too low
	// see issue 22513
	// as you can see, it doesn't actually change anything, but it works...
	var oldMarginTop = $("#video").css("margin-top");
	$("#video").css("margin-top", "-1px");
	$("#video").css("margin-top", oldMarginTop);

});
