
// Don't break on browsers without console.log();
try { console.assert(1); } catch(e) { console = { log: function() {}, assert: function() {} } }

jQuery(document).ready(function(){

    // We zwengelen het hoofdmenu aan.
    jQuery(".nav")
    .superfish({
        animation : { opacity:"show", height:"show"}, delay:400, speed:"fast"
    })
    .find(">li:has(ul)") // I can has url?
        .mouseover(function(){
            jQuery("ul", this).bgIframe({opacity:false});
        })
        .find("a")
            .focus(function(){
                jQuery("ul", jQuery(".nav>li:has(ul)")).bgIframe({opacity:false});
            });
            
            
    // Maak het zo dat als je '.bericht' aanraakt, dat deze oplicht. 
    jQuery('.bericht, .videobericht, .headline, .dossierblok-content').bind('mouseover', function() { 
        if (typeof(jQuery(this).attr('rel'))!="undefined") {
            jQuery(this).addClass('bericht-over'); 
        }
    }).bind('mouseout', function() { 
        jQuery(this).removeClass('bericht-over'); 
    }); 

    // Nu met Flabber(tm) navigatie!
    jQuery('.bericht, .videobericht, .headline, .dossierblok-content').bind('click', function() { 
        if (typeof(jQuery(this).attr('rel'))!="undefined") {
            location.href = jQuery(this).attr('rel');
        }
    });


	// Externe links openen in een nieuw venster en tracken in GA..
	jQuery("a[href^='http']").attr('target','_blank').click(function(){
		if(pageTracker){
			var fixedLink = this.href;
			fixedLink = fixedLink.replace(/https?:\/\/(.*)/,"$1");
			fixedLink = '/outgoing/' + fixedLink;
			pageTracker._trackPageview(fixedLink);
		};

    });
	
    // Embedcode: klikken is selecteren.
	jQuery('.embedcode textarea').bind('focus', function(){
		this.select();
	});    

	// Fix de CSS voor #berichten .hoofdfoto in safari..
	if (jQuery.browser.safari) {
		jQuery('#berichten .hoofdfoto').addClass('safarihack');		
	}
	
    // Tabjes activeren. 
    jQuery('.tabblok-tab-titel').bind('mouseover', function() {
                
        // Toon het juiste tabblad als active..
        jQuery(this).parent().parent().find('div').removeClass('active');
        jQuery(this).parent().addClass('active');
        
        // toon de juiste inhoud.. 
        jQuery(this).parent().parent().next().find('div').hide();
        jQuery('#'+jQuery(this).attr('rel') ).show();
        
    });
	
	// Newsticker
    jQuery('#newsticker').newsticker();	

});


/**
 * Hieronder volgt script voor de video-player..
 */
// fix the extra click in IE on activex elements
function fixextraclick() {
	var theObjects = document.getElementsByTagName("object");
	for (var i = 0; i < theObjects.length; i++) {
		theObjects[i].outerHTML = theObjects[i].outerHTML;
	}

}
function ws(t) {
	window.status = t;
}
//rescale movie by width and height
function rescale(movid,w,h) {
	if (w> 0 && h > 0) {
		var obmov = document.getElementById(movid)
		if (typeof(obmov) != 'undefined' && obmov != null) {
			obmov.width = w
			obmov.height = h
		}
		obmov =	document.getElementById("emb"+ movid)
		if (typeof(obmov) != 'undefined' && obmov != null) {
			obmov.width = w
			obmov.height = h
		}
	}
}

function openad(url) {
	window.open(url)
}

function movieDimensions (movieOb) {
	var res = ' width="' + (movieOb.initialWidth + 2) + '" '
	res += 'height="' + (movieOb.initialHeight+ 26 + movieOb.directAdFooterImageHeight ) + '" '
	
	return res
}


function createMovieURL (movieOb,site)
{
	var res = site + 'dplayer2_925.swf'
	res += '?movieXmlURL='+ escape(site + movieOb.id + ".xml") 
	res += '&initwidth='+ escape(movieOb.initialWidth) 
	res += '&initheight='+ escape(movieOb.initialHeight) 
	res += '&adFooterWidth='+ escape(movieOb.directAdFooterImageWidth) 
	res += '&adFooterHeight='+ escape(movieOb.directAdFooterImageHeight) 
	return res;
}


function inlinemovie(movieOb, b) {
	
	var res =  '<' + 'object id="' + movieOb.id +'" ' + "\n";

	res += 'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ' 
	res += 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0" '
	res += movieDimensions(movieOb)
	res += 'align="middle">'+ "\n"
	res += '<' + 'param name="allowScriptAccess" value="sameDomain" />'+ "\n"
	res += '<' + 'param name="allowFullScreen" value="true" />'+ "\n"
	res += '<' + 'param name="movie" value="' 
	res += createMovieURL(movieOb,movieOb.urlprefix)
	res += '" />'+ "\n"
	res += '<' + 'param name="loop" value="false" />'+ "\n"
	res += '<' + 'param name="menu" value="false" />'+ "\n"
	res += '<' + 'param name="quality" value="high" />'+ "\n"
	res += '<' + 'param name="scale" value="noscale" />'+ "\n"
	res += '<' + 'param name="salign" value="lt" />'+ "\n"
	res += '<' + 'param name="wmode" value="transparent" />'+ "\n"
	res += '<' + 'param name="bgcolor" value="#ffffff" />'+ "\n"
	res += '<' + 'embed id="emb' + movieOb.id + '" src="' 
	res += createMovieURL(movieOb,movieOb.urlprefix)
	res += '" loop="false" '+ "\n"
	res += 'menu="false" quality="high" scale="noscale" '+ "\n"
	res += 'salign="lt" bgcolor="#ffffff" '+ "\n"
	res += movieDimensions(movieOb)
	res += 'swLiveConnect=false '+ "\n"
	res += 'align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" wmode="transparent" '+ "\n"
	res += 'pluginspage="http://www.macromedia.com/go/getflashplayer" />'+ "\n"
	res += '<' + '/object>'+ "\n"


	//if (b) {
	//	res += '<p class="embedcode">HTML code om te delen: <br /><textarea>' + res + '</textarea><br /><small>Klik om alles te selecteren, en dan kun je de code kopi&euml;ren. </small></p>';
	//} 	

	return res;

}

function showpop (title, movieOb) {
	var w = window.open("","pop","width=" + (movieOb.initialWidth + 8) + ",height=" + (movieOb.initialHeight + 49))
	if (typeof(w) != "undefined" && w != null) {
		w.document.write ('<' + 'HTML' + '><'+ 'head' + '><' + 'title' + '>' + title + '<' + '/title' + '><' + '/head'+ '>' + "\n");
		w.document.write ('<' + 'script'+ '>' + 'function rescale(movieOb.id,w,h) {'+ "\n")
		w.document.write ('	obmov =	document.getElementById(movieOb.id)'+ "\n")
		w.document.write ('     if (typeof(obmov) != "undefined" && obmov != null) {'+ "\n")
		w.document.write ('	obmov.width= w '+ "\n")
		w.document.write ('	obmov.height= h'+ "\n")
		w.document.write ('	}')
		w.document.write ('	obmov =	document.getElementById("emb" + movieOb.id)'+ "\n")
		w.document.write ('     if (typeof(obmov) != "undefined" && obmov != null) {'+ "\n")
		w.document.write ('	obmov.width= w '+ "\n")
		w.document.write ('	obmov.height= h'+ "\n")
		w.document.write ('	}')
		w.document.write ('	window.resizeBy (w - document.body.clientWidth ,(h + 20) - document.body.clientHeight)'+ "\n")

		w.document.write ('}<'+ '/script' + '>'+ "\n")

		w.document.write ('<' + 'BODY style="margin:0">'+ "\n")
		w.document.write (inlinemovie(movieOb, false))
		w.document.write ("</body></html>")
	}
	else {
		alert ('Disable popup blocker')
	}
}



/*
 *
 * Copyright (c) 2006/2007 Sam Collett (http://www.texotela.co.uk)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * Version 2.0
 * Demo: http://www.texotela.co.uk/code/jquery/newsticker/
 *
 * $LastChangedDate$
 * $Rev$
 *
 */
 
(function($) {
/*
 * A basic news ticker.
 *
 * @name     newsticker (or newsTicker)
 * @param    delay      Delay (in milliseconds) between iterations. Default 4 seconds (4000ms)
 * @author   Sam Collett (http://www.texotela.co.uk)
 * @example  $("#news").newsticker(); // or $("#news").newsTicker(5000);
 *
 */
$.fn.newsTicker = $.fn.newsticker = function(delay)
{
	delay = delay || 4000;
	initTicker = function(el)
	{
		stopTicker(el);
		el.items = $("li", el);
		// hide all items (except first one)
		el.items.not(":eq(0)").hide().end();
		// current item
		el.currentitem = 0;
		startTicker(el);
	};
	startTicker = function(el)
	{
		el.tickfn = setInterval(function() { doTick(el) }, delay)
	};
	stopTicker = function(el)
	{
		clearInterval(el.tickfn);
	};
	pauseTicker = function(el)
	{
		el.pause = true;
	};
	resumeTicker = function(el)
	{
		el.pause = false;
	};
	doTick = function(el)
	{
		// don't run if paused
		if(el.pause) return;
		// pause until animation has finished
		el.pause = true;
		// hide current item
		$(el.items[el.currentitem]).fadeOut("slow",
			function()
			{
				$(this).hide();
				// move to next item and show
				el.currentitem = ++el.currentitem % (el.items.size());
				$(el.items[el.currentitem]).fadeIn("slow",
					function()
					{
						el.pause = false;
					}
				);
			}
		);
	};
	this.each(
		function()
		{
			if(this.nodeName.toLowerCase()!= "ul") return;
			initTicker(this);
		}
	)
	.addClass("newsticker")
	.hover(
		function()
		{
			// pause if hovered over
			pauseTicker(this);
		},
		function()
		{
			// resume when not hovered over
			resumeTicker(this);
		}
	);
	return this;
};

})(jQuery);

