function sitestat(ns_l)
{
  ns_l+="&ns__t="+new Date().getTime();
  ns_pixelUrl=ns_l;
  if(document.images)
  {
     ns_1=new Image();
     ns_1.src=ns_l;
  }
  else
    document.write("<img src="+ns_l+" width=\"1\" height=\"1\">");
}

/**
 * openPlayer(sURL, iWidth, iHeight)
 *
 * Open the 'embedded' player with the given url.
 *
 * @version 1.0
 * @access  public
 * @author  A.J. de Vries
 * @modified_by bartz for www.zapp.nl
 * @param   [string]  sURL    - the url to the player with the movie as argument (GET).
 * @return  [false]
 */
function openPlayer(url) {
	iWidth = 800;
	iHeight = 612;
		
	var iLeftPos = (screen.availWidth - iWidth) / 2;
	var iTopPos = (screen.availHeight - iHeight) / 2; 
	var sOpts = "toolbar=no, status=no, location=no, menubar=no, resizable=yes,";
	    sOpts += " width=" + iWidth + ", height=" + iHeight + ", scrollbars=no,";
	    sOpts += "top=" + iTopPos + ",left=" + iLeftPos;
	var eDialog = window.open(url, "player", sOpts);
	eDialog.focus();
	return false;
}

function nieuws_tag(value) {
	if(value)
		location = '/nieuws/onderwerp/' + value;
	else
		location = '/nieuws';
}

/**
 * Called when the choose-your-zapper quiz is completed.
 * If the caller window is the registration form, select the zapper on the form.
 * Else reload the caller and close the window.
 */
function close_zapper_quiz(zapper) {
	if(window.opener.$('form#registration').length > 0) {
		window.opener.$('#'+zapper).attr('checked', 'checked');
	} else {
		window.opener.location.reload(true);
	}  

	window.close();
}

/**
 * Used by the geluid.swf player.
 */
function setSoundStatus(soundFlashStatus) {
	$.cookie('soundStatus', soundFlashStatus, { expires: 31 });
}

/**
 * Flip the login box into a notification area.
 */
function flappen_notification() {
	var notification = '<div id="notification"><div class="logo"></div>\
		<div class="note">\
		<p>\
			<a href="/login"><strong>Log nu in!</strong></a> \
			Dan spaar je flappen voor in de Z@PPzone!\
		</p></div></div>';
	$('#loginbox').
		prepend(notification);
	setTimeout("$('#loginbox').find('#notification').remove()", 10000);
}

/**
 * Do things when the document is loaded, which is the first moment all the html is in place.
 */
$(document).ready(function() {

	$('body').addClass("js");
	
	// Makes <a href="http://example.com" rel="external"> open in a new window.
    $('a[rel*=external]').attr("target", "_blank");

	// Makes <a href="http://player.omroep.nl" rel="player"> open in the publieke omroep player.
	$('a[rel*=player]').click(function() {
		openPlayer(this.href);
		return false;
	});
	
	// Makes <a href="http://zone.zapp.nl" rel="zone"> open in the Z@PPzone.
	$('a[rel*=zone]').click(function() {
		newwindow = window.open(this.href, "", "height=650,width=950,menubar='no',location='no',scrollbars='no',resizable='no'");
		if (window.focus) {newwindow.focus()}
		return false;
	})
	
    // Validate all forms with a classname of 'validate'
    $("form.validate").validate({
		messages: {
			"user[login]": {
				remote: "Is bezet"
			},
			"user[email]": {
				remote: "Bestaat al"
			}
		}
	});
	
	/* remove background on focus */		
    $('#sidebar input').focus(function() {    	
    	$(this).addClass("focus");
    });
	    
    /* on blur if there is no entered value, return the background */
    $('#sidebar input').blur(function() {
    	if ( $(this).val() == '' ) {
    		$(this).removeClass("focus");
		};
    });

	/* remove background on focus */		
	$('form.login input').focus(function() {    	
		$(this).addClass("focus");
	});

	/* on blur if there is no entered value, return the background */
	$('form.login input').blur(function() {
		if ( $(this).val() == '' ) {
			$(this).removeClass("focus");
		};
	});

    $('ul.star-rating').hover(
    	function() { $(this).addClass('star-rating-hover'); },
    	function() { $(this).removeClass('star-rating-hover'); }
    );

	// elements with class fetch-feed load their content dynamically using Ajax.
	// the url to load the content from must be in an inner element with classname fetch-feed-url.
	$('.fetch-feed').each(function() {
		var element = $(this);
		var url = element.find('.fetch-feed-url').html();
		$.get(url, function(data) {
			element.html(data);
		})
	})
});


/**
 * Perform things when the window is loaded.
 * This happens after the dom:loaded from above, but has browser completed information.
 */
 $(window).load(function () {
	$("#loginbox input").each(function() {
		// when the user has the browser remember username/password, this will remove the hint
		if ( $(this).val() ) {
			$(this).addClass("focus");
		}
	});
});


/**
 * Translated default messages for the jQuery validation plugin.
 * By Joost Baaij http://www.spacebabies.nl/ joost@spacebabies.nl
 * Language: NL
 * Skipped date/dateISO/number.
 */
jQuery.extend(jQuery.validator.messages, {
        required: "Dit veld is verplicht.",
        maxlength: jQuery.format("U kunt niet meer dan {0} karakters invoeren."),
        minlength: jQuery.format("U dient minimaal {0} karakters in te voeren."),
        rangelength: jQuery.format("U dient minimaal {0} en maximaal {1} karakters in te voeren."),
        email: "Een geldig emailadres is verplicht.",
        url: "Een geldig URL is verplicht.",
        date: "Een geldige datum is verplicht.",
        number: "Een geldig getal is verplicht.",
        digits: "Gebruik alleen cijfers.",
        equalTo: "Herhaal de invoer nogmaals.",
        range: jQuery.format("U dient een waarde tussen {0} en {1} in te voeren."),
        max: jQuery.format("U dient een waarde kleiner dan of gelijk aan {0} in te voeren."),
        min: jQuery.format("U dient een waarde groter dan of gelijk aan {0} in te voeren."),
        creditcard: "Een geldig creditcardnummer is verplicht."
});

/**
 * Cookie plugin
 *
 * Copyright (c) 2006 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
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
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;
    }
};