function popup(file,scrollbar,winHeight,winWidth) {
		var popup = window.open(file,"nieuwsvenster","scrollbars="+scrollbar+",status=no,height="+winHeight+",width="+winWidth);}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}
function display_error(fout,vertraging) {
    var fout = fout.split('|');
    if(fout.length > 0) {
        $.getJSON('/error.json', function(data) {
            $('#error span.error').html(data[fout[0]][fout[1]]["tekst"]);
            $('#error').delay(500).animate({'top':'0'}).delay(data[fout[0]][fout[1]]["duur"]).animate({'top':'-90px'},1000,function() {
                if(data[fout[0]][fout[1]]["vervolg"] != false) {
                    window.location.href = data[fout[0]][fout[1]]["vervolg"];
                }
            });
        });
    }
}
var FlashReplace = {
	elmToReplace : null,
	flashIsInstalled : null,
	defaultFlashVersion : 7,
	replace : function (elmToReplace, src, id, width, height, version, params){
		this.elmToReplace = document.getElementById(elmToReplace);
		this.flashIsInstalled = this.checkForFlash(version || this.defaultFlashVersion);
		if(this.elmToReplace && this.flashIsInstalled){
			var obj = '<object' + ((window.ActiveXObject)? ' id="' + id + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" data="' + src + '"' : '');
			obj += ' width="' + width + '"';
			obj += ' height="' + height + '"';
			obj += '>';
			var param = '<param';
			param += ' name="movie"';
			param += ' value="' + src + '"';
			param += '>';
			param += '';
			var extraParams = '';
			var extraAttributes = '';
			for(var i in params){
				extraParams += '<param name="' + i + '" value="' + params[i] + '">';
				extraAttributes += ' ' + i + '="' + params[i] + '"';
			}
			var embed = '<embed id="' + id + '" src="' + src + '" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"';
			var embedEnd = extraAttributes + '></embed>';
			var objEnd = '</object>';
			this.elmToReplace.innerHTML = obj + param + extraParams + embed + embedEnd + objEnd;
		}
	},

	checkForFlash : function (version){
		this.flashIsInstalled = false;
		var flash;
		if(window.ActiveXObject){
			try{
				flash = new ActiveXObject(("ShockwaveFlash.ShockwaveFlash." + version));
				this.flashIsInstalled = true;
			}
			catch(e){
				alert("U heeft niet de correcte versie van Adobe Flash-Player geinstalleerd, download de correcte versie");
				// Throws an error if the version isn't available
			}
		}
		else if(navigator.plugins && navigator.mimeTypes.length > 0){
			flash = navigator.plugins["Shockwave Flash"];
			if(flash){
				var flashVersion = navigator.plugins["Shockwave Flash"].description.replace(/.*\s(\d+\.\d+).*/, "$1");
				if(flashVersion >= version){
					this.flashIsInstalled = true;
				}
			}
		}
		return this.flashIsInstalled;
	}
};
$(document).mousemove(function(e) {
    // MouseOut menu regelen
    if($('body').attr('hideSubmenu') == 'true') {
       $('div#menu div.active').each(function() {
          $(this).stop();
          $(this).fadeTo(250, 0, function() {
              $(this).attr('class', 'submenu');
              $(this).css('visibility', 'hidden');
          });
       });
    }
    /*
    var d = new Date()
    var tijd = d.getHours()+":"+d.getMinutes()+":"+d.getSeconds()+":"+d.getMilliseconds();
    createCookie("navi",readCookie("navi")+"["+tijd+":{"+e.pageX+","+e.pageY+"}],",1);
    */
});
$(window).load(function() {
    eraseCookie("navi");
    createCookie("navi",window.location.href);
    /* Afbeelding informatie */
    $('img.info[title,alt]').each(function() {
        var image = $(this);
        var title = image.attr('title');
        var alt = image.attr('alt');
        image.css('position','absolute');
        image.wrap('<div class="info" style="width:100%; margin-bottom: 35px; position: relative; overflow: hidden; height:'+image.outerHeight()+'px;"/>');
        elem = image.parent();
        elem.append('<div class="infobox" />');
        elem.find('div.infobox').append('<span class="title">'+title+'</span>');
        elem.find('div.infobox').append('<span class="alt">'+alt+'</span>');
        elem.find('div.infobox').append('<div class="background"/>');
    });
    /* Opacity infobox */
    $('div.infobox div.background').css('opacity', 0.5);
    $('#containerPopup div.bg').css('opacity', 0.5);
    /* Disable text selecteren */
    //$('#menu, #submenu, p, h1, h2, h3, h4, h5, label, li, span, img').addClass("noSelect");
    $('.noSelect').disableTextSelect();//No text selection on elements with a class of 'noSelect'
});
$(document).ready(function() {
    
    /* Disable right mouse context menu */
    $(document).bind("contextmenu",function(e){
        e.preventDefault();
        if($('#containerPopup').css('display') != "block") {
            $('#containerPopup').css('display', 'block');
            $('#overlaybg').css('display', 'block');
            $('#popup').css({'opacity':1,'margin':'-200px -300px','height':'400px','width':'600px'});
            $("#popup").append('<iframe src ="/apps/frontend/copyright.php" width="100%" height="100%" frameborder="0"></iframe>');
        }
        return false;
    });
    /* Disable text selecteren */
    $('#menu, #submenu, p, h1, h2, h3, h4, h5, label, li, span, img').addClass("noSelect");
    /* Even en Oneven Rijkleur */
    $("#content table tbody tr:odd").css("background-color", "#EEF6DE");
    /* Elementen even hoog maken */
    var hoogte = 0;
    $('div.links div.vast').each(function(){
        if(hoogte < $(this).height()) {hoogte = $(this).height();}
    });
    $('div.links div.vast').css('height',hoogte+"px");
    /* Sfeerplaatjes - positioneren */
    $('img.sfeer, a.sfeer').each(function() {
        var top = $('div.links').find('a[name='+$(this).attr('id')+']').position().top - $('div.fill').position().top;
        $(this).css('top',top+'px');
    });
    /* Rechts even hoog maken als links */
    $('div.rechts').css('height',$('div.links').height()+"px");
    /* Submenu */
    $('ul.sf-menu').superfish({
            delay:       500,                               // one second delay on mouseout
            animation:   {opacity:'show',height:'show'},    // fade-in and slide-down animation
            speed:       100,                               // faster animation speed
            autoArrows:  true,                             // disable generation of arrow mark-up
            dropShadows: false                               // disable drop shadows
    });
    // Functie voor een sluitknop binnenin een iFrame
    $(document).bind('closeFrame', function(e) {
        $('#popup iframe').remove();
        $('#containerPopup').css('display', 'none');
        $('#overlaybg').css('display', 'none');        
    });
    $('a.popup').click(function(e) {
        e.preventDefault();
        var url = $(this).attr('href');
        $('#containerPopup').css('display', 'block');
        $('#overlaybg').css('display', 'block');
        $('#popup').css({'opacity':1,'margin':'-300px -425px','height':'600px','width':'850px'});
        $("#popup").append('<iframe src ="'+url+'" width="100%" height="100%" frameborder="0"></iframe>');
        $("iframe").contents().bind("myCustomTrigger", fn);
        /*
         *  TODO: www.schwoerer.nl - Animatie er weer inzetten
         *
         *  TODO: www.schwoerer.nl - Als je buiten de popup klikt, de popup sluiten
         */
        //$('#popup').animate({opacity: 1,margin: '-300px -425px',height: '600px'},{duration: 1000,easing: 'easeOutBounce',complete: function() {$("#popup").append('<iframe src ="'+url+'" width="100%" height="100%" frameborder="0"></iframe>');}});
    });
    $('#popup #close').click(function(e) {
        e.preventDefault();
        $('#popup iframe').remove();
        $('#containerPopup').css('display', 'none');
        $('#overlaybg').css('display', 'none');
        /*
        $('#popup').animate({
            opacity: 0,
            margin: '0px -425px',
            height: '0px'
        }, {
            duration: 1000,
            easing: 'easeOutBounce',
            complete: function() {
                $('#popup iframe').remove();
                $('#containerPopup').css('display', 'none');
                $('#overlaybg').css('display', 'none');
            }
        });         */
    });


    /* Disabele text, geef het element de class: noSelect */
    $.extend($.fn.disableTextSelect = function() {
        return this.each(function(){
                if($.browser.mozilla){//Firefox
                        $(this).css('MozUserSelect','none');
                }else if($.browser.msie){//IE
                        $(this).bind('selectstart',function(){return false;});
                }else{//Opera, etc.
                        $(this).mousedown(function(){return false;});
                }
        });
    });
    $('.noSelect').disableTextSelect();//No text selection on elements with a class of 'noSelect'
});
