/*
	author information:
	
	Wilfred Nas / wnas
	twitter.com/wnas
	wilfred@wnas.nl
	http://wnas.nl

	plugin to build a step list for a form
	
	usage: $(foo).steps();
*/
/*
(function($) {
  $.fn.extend({	

    steps : function() {
      $(this).find('li').each( function ( i ){ 
		$(this).children().prepend('<span class="step">'+(i+1)+'</span>');
      });
    }
  });
})(jQuery);
*/
/*
 * jQuery autoTab plugin 0.1
 *
 * http://wnas.nl/
 *
 * Copyright (c) 2008 Wilfred Nas
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

/*
	Autotab plugin by Wilfred Nas

	
	in order to implement you have to have some stuff in the html
	
	like three fields to collect days, months and years.
	by putting the trigger class on the first two, you force the autotab.
	the last one has a manual tab, which is (imho) like the users expect it to.
	<input type="text" maxlength="2" class="day foo" />
	<input type="text" maxlength="2" class="month foo" />
	<input type="text" maxlength="4" class="year" />
	
	REQUIRED
	-a maxlength on the input type='text'
	
	to call it do:
	
	// autotab plug in ...
	jQuery('input.foo').autotab();
	
	that's it, zero configuration in your javascript. 
	You just set the maxlenght, a class and you're done.
*/

/*
jQuery.fn.autotab = function (){
	jQuery(this).keyup(function(e){
		switch(e.keyCode){
			// ignore the following keys
			case 9: // tab
				return false;
			case 16: // shift
				return false;
			case 20: // capslock
				return false;
			default: // any other keyup actions will trigger 
				var maxlength = jQuery(this).attr('maxlength'); // get maxlength value
				var inputlength = jQuery(this).val().length; // get the length of the text
				if ( inputlength >= maxlength ){ // if the text is equal of more than the max length
					jQuery(this).next('input[type="text"]').focus(); // set focus to the next text field
				}
		}
	});
}*/
// the latter var is to prevent the essent.fixHBX.js to be loaded twice...
var fixHBXcheck = false;
/**
* @name classValue
* @desc Plugin to get a value from a className.
* @example $('select').classValue('t');
*/
/**
 * @author info
 * Wilfred Nas
 * http://wnas.nl/
 * wilfred at wnas . nl
 * twitter.com/wnas
 *
 * Plugin to get a value from a className.
 *
 * Usage:
 * calling this:
 *  $('select').classValue('t');
 *  will give you the value you put in the className t:foo aka foo.
 *
 *  usefull if you have a few parameters you want to give to the js.

	BUG / FAULT
	this version only gets the first element, so if you do:
	a:b a:c you only get b.
 */
(function($) {
    $.fn.extend({
        classValue : function(pf) {
			var cn = $(this).attr('class');
			var result = "";
			var test = new String(cn);
			var elementString = new String(pf);
			elementString = elementString + ":";
			var startpos = test.indexOf(elementString, 0);
			if (startpos >= 0){
			    test = test.substr(startpos, test.length);
			    if (test.indexOf(" ", 0) >= 0){
			        test = test.substr(elementString.length, test.indexOf(" ", 0) - elementString.length);
			    }
			    else{
			        test = test.substr(elementString.length, test.length - elementString.length);
			    }
			    result = test;
			}
			return result;
        }
    });
})(jQuery);

/**
 * 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;
    }
};

/**
 * Flash (http://jquery.lukelutman.com/plugins/flash)
 * A jQuery plugin for embedding Flash movies.
 * 
 * Version 1.0
 * November 9th, 2006
 *
 * Copyright (c) 2006 Luke Lutman (http://www.lukelutman.com)
 * Dual licensed under the MIT and GPL licenses.
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.opensource.org/licenses/gpl-license.php
 * 
 * Inspired by:
 * SWFObject (http://blog.deconcept.com/swfobject/)
 * UFO (http://www.bobbyvandersluis.com/ufo/)
 * sIFR (http://www.mikeindustries.com/sifr/)
 * 
 * IMPORTANT: 
 * The packed version of jQuery breaks ActiveX control
 * activation in Internet Explorer. Use JSMin to minifiy
 * jQuery (see: http://jquery.lukelutman.com/plugins/flash#activex).
 *
 **/ 
;(function(){
	
	
/**
	$$ = var
**/
var $$;

/**
 * 
 * @desc Replace matching elements with a flash movie.
 * @author Luke Lutman
 * @version 1.0.1
 *
 * @name flash
 * @param Hash htmlOptions Options for the embed/object tag.
 * @param Hash pluginOptions Options for detecting/updating the Flash plugin (optional).
 * @param Function replace Custom block called for each matched element if flash is installed (optional).
 * @param Function update Custom block called for each matched if flash isn't installed (optional).
 * @type jQuery
 *
 * @cat plugins/flash
 * 
 * @example $('#hello').flash({ src: 'hello.swf' });
 * @desc Embed a Flash movie.
 *
 * @example $('#hello').flash({ src: 'hello.swf' }, { version: 8 });
 * @desc Embed a Flash 8 movie.
 *
 * @example $('#hello').flash({ src: 'hello.swf' }, { expressInstall: true });
 * @desc Embed a Flash movie using Express Install if flash isn't installed.
 *
 * @example $('#hello').flash({ src: 'hello.swf' }, { update: false });
 * @desc Embed a Flash movie, don't show an update message if Flash isn't installed.
 *
**/
$$ = jQuery.fn.flash = function(htmlOptions, pluginOptions, replace, update) {
	
	// Set the default block.
	var block = replace || $$.replace;
	
	// Merge the default and passed plugin options.
	pluginOptions = $$.copy($$.pluginOptions, pluginOptions);
	
	// Detect Flash.
	if(!$$.hasFlash(pluginOptions.version)) {
		// Use Express Install (if specified and Flash plugin 6,0,65 or higher is installed).
		if(pluginOptions.expressInstall && $$.hasFlash(6,0,65)) {
			// Add the necessary flashvars (merged later).
			var expressInstallOptions = {
				flashvars: {  	
					MMredirectURL: location,
					MMplayerType: 'PlugIn',
					MMdoctitle: jQuery('title').text() 
				}					
			};
		// Ask the user to update (if specified).
		} else if (pluginOptions.update) {
			// Change the block to insert the update message instead of the flash movie.
			block = update || $$.update;
		// Fail
		} else {
			// The required version of flash isn't installed.
			// Express Install is turned off, or flash 6,0,65 isn't installed.
			// Update is turned off.
			// Return without doing anything.
			return this;
		}
	}
	
	// Merge the default, express install and passed html options.
	htmlOptions = $$.copy($$.htmlOptions, expressInstallOptions, htmlOptions);
	
	// Invoke $block (with a copy of the merged html options) for each element.
	return this.each(function(){
		block.call(this, $$.copy(htmlOptions));
	});
	
};
/**
 *
 * @name flash.copy
 * @desc Copy an arbitrary number of objects into a new object.
 * @type Object
 * 
 * @example $$.copy({ foo: 1 }, { bar: 2 });
 * @result { foo: 1, bar: 2 };
 *
**/
$$.copy = function() {
	var options = {}, flashvars = {};
	for(var i = 0; i < arguments.length; i++) {
		var arg = arguments[i];
		if(arg == undefined) continue;
		jQuery.extend(options, arg);
		// don't clobber one flash vars object with another
		// merge them instead
		if(arg.flashvars == undefined) continue;
		jQuery.extend(flashvars, arg.flashvars);
	}
	options.flashvars = flashvars;
	return options;
};
/*
 * @name flash.hasFlash
 * @desc Check if a specific version of the Flash plugin is installed
 * @type Boolean
 *
**/
$$.hasFlash = function() {
	// look for a flag in the query string to bypass flash detection
	if(/hasFlash\=true/.test(location)) return true;
	if(/hasFlash\=false/.test(location)) return false;
	var pv = $$.hasFlash.playerVersion().match(/\d+/g);
	var rv = String([arguments[0], arguments[1], arguments[2]]).match(/\d+/g) || String($$.pluginOptions.version).match(/\d+/g);
	for(var i = 0; i < 3; i++) {
		pv[i] = parseInt(pv[i] || 0, 10);
		rv[i] = parseInt(rv[i] || 0, 10);
		// player is less than required
		if(pv[i] < rv[i]) return false;
		// player is greater than required
		if(pv[i] > rv[i]) return true;
	}
	// major version, minor version and revision match exactly
	return true;
};
/**
 *
 * @name flash.hasFlash.playerVersion
 * @desc Get the version of the installed Flash plugin.
 * @type String
 *
**/

$$.hasFlash.playerVersion = function() {
	// ie
	try {
		try {
			// avoid fp6 minor version lookup issues
			// see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
			var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
			try { axo.AllowScriptAccess = 'always';	} 
			catch(e) { return '6,0,0'; }				
		} catch(e) {}
		return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
	// other browsers
	} catch(e) {
		try {
			if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
				return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
			}
		} catch(e) {}		
	}
	return '0,0,0';
};
/**
 *
 * @name flash.htmlOptions
 * @desc The default set of options for the object or embed tag.
 *
**/
$$.htmlOptions = {
	height: 240,
	flashvars: {},
	pluginspage: 'http://www.adobe.com/go/getflashplayer',
	src: '#',
	type: 'application/x-shockwave-flash',
	width: 320		
};
/**
 *
 * @name flash.pluginOptions
 * @desc The default set of options for checking/updating the flash Plugin.
 *
**/
$$.pluginOptions = {
	expressInstall: false,
	update: true,
	version: '6.0.65'
};
/**
 *
 * @name flash.replace
 * @desc The default method for replacing an element with a Flash movie.
 *
**/
$$.replace = function(htmlOptions) {
	this.innerHTML = '<div class="alt">'+this.innerHTML+'</div>';
	jQuery(this)
		.addClass('flash-replaced')
		.prepend($$.transform(htmlOptions));
};
/**
 *
 * @name flash.update
 * @desc The default method for replacing an element with an update message.
 *
**/
$$.update = function(htmlOptions) {
	var url = String(location).split('?');
	url.splice(1,0,'?hasFlash=true&');
	url = url.join('');
	var msg = '<p>This content requires the Flash Player. <a href="http://www.adobe.com/go/getflashplayer">Download Flash Player</a>. Already have Flash Player? <a href="'+url+'">Click here.</a></p>';
	this.innerHTML = '<span class="alt">'+this.innerHTML+'</span>';
	jQuery(this)
		.addClass('flash-update')
		.prepend(msg);
};
/**
 *
 * @desc Convert a hash of html options to a string of attributes, using Function.apply(). 
 * @example toAttributeString.apply(htmlOptions)
 * @result foo="bar" foo="bar"
 *
**/
function toAttributeString() {
	var s = '';
	for(var key in this){
		if(typeof this[key] != 'function'){
			s += key+'="'+this[key]+'" ';
		};
	}
	return s;		
};
/**
 *
 * @desc Convert a hash of flashvars to a url-encoded string, using Function.apply(). 
 * @example toFlashvarsString.apply(flashvarsObject)
 * @result foo=bar&foo=bar
 *
**/
function toFlashvarsString() {
	var s = '';
	for(var key in this){
		if(typeof this[key] != 'function'){
			s += key+'='+encodeURIComponent(this[key])+'&';
		};
	}
	return s.replace(/&$/, '');		
};
/**
 *
 * @name flash.transform
 * @desc Transform a set of html options into an embed tag.
 * @type String 
 *
 * @example $$.transform(htmlOptions)
 * @result <embed src="foo.swf" ... />
 *
 * Note: The embed tag is NOT standards-compliant, but it 
 * works in all current browsers. flash.transform can be
 * overwritten with a custom function to generate more 
 * standards-compliant markup.
 *
**/
$$.transform = function(htmlOptions) {
	htmlOptions.toString = toAttributeString;
	if(htmlOptions.flashvars) htmlOptions.flashvars.toString = toFlashvarsString;
	return '<embed ' + String(htmlOptions) + '/>';		
};

/**
 *
 * Flash Player 9 Fix (http://blog.deconcept.com/2006/07/28/swfobject-143-released/)
 *
**/
if (window.attachEvent) {
	window.attachEvent("onbeforeunload", function(){
		__flash_unloadHandler = function() {};
		__flash_savedUnloadHandler = function() {};
	});
}
	
})();
/*
 * @name jQuery.delegate
 * @desc a small and handy function to enable event delegation
 * 
 * does not work with complex selectors but it's fast.
 *
**/
// dan webb
/*
jQuery.delegate = function(rules) {
	return function(e) {
		var target = $(e.target);
		for (var selector in rules){
			if (target.is(selector)) {return rules[selector].apply(this, $.makeArray(arguments));}
		};
	};
};

*/
/*
	using it is simple

	$('#thing').click($.delegate({
	  '.quit': function() {  },//quit stuff inside brackets
	  '.edit': function() {  } // edit stuff inside brackets
	}));

	see it's origin here...
	http://www.danwebb.net/2008/2/8/event-delegation-made-easy-in-jquery
	thanks dann
*/
/*-------------------------------------------------------------------- 
 * javascript method: "pxToEm"
 * by:
   Scott Jehl (scott@filamentgroup.com) 
   Maggie Wachs (maggie@filamentgroup.com)
   http://www.filamentgroup.com
 *
 * Copyright (c) 2008 Filament Group
 * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
 *
 * Description: Extends the native Number and String objects with pxToEm method. pxToEm converts a pixel value to ems depending on inherited font size.  
 * Article: http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/
 * Demo: http://www.filamentgroup.com/examples/pxToEm/	 	
 *							
 * Options:  	 								
 		scope: string or jQuery selector for font-size scoping
 		reverse: Boolean, true reverses the conversion to em-px
 * Dependencies: jQuery library						  
 * Usage Example: myPixelValue.pxToEm(); or myPixelValue.pxToEm({'scope':'#navigation', reverse: true});
 *
 * Version: 2.0, 08.01.2008 
 * Changelog:
 *		08.02.2007 initial Version 1.0
 *		08.01.2008 - fixed font-size calculation for IE
--------------------------------------------------------------------**/

Number.prototype.pxToEm = String.prototype.pxToEm = function(settings){
	//set defaults
	settings = jQuery.extend({
		scope: 'body',
		reverse: false
	}, settings);
	
	var pxVal = (this == '') ? 0 : parseFloat(this);
	var scopeVal;
	var getWindowWidth = function(){
		var de = document.documentElement;
		return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
	};	
	
	/* When a percentage-based font-size is set on the body, IE returns that percent of the window width as the font-size. 
		For example, if the body font-size is 62.5% and the window width is 1000px, IE will return 625px as the font-size. 	
		When this happens, we calculate the correct body font-size (%) and multiply it by 16 (the standard browser font size) 
		to get an accurate em value. */
				
	if (settings.scope == 'body' && $.browser.msie && (parseFloat($('body').css('font-size')) / getWindowWidth()).toFixed(1) > 0.0) {
		var calcFontSize = function(){		
			return (parseFloat($('body').css('font-size'))/getWindowWidth()).toFixed(3) * 16;
		};
		scopeVal = calcFontSize();
	}
	else { scopeVal = parseFloat(jQuery(settings.scope).css("font-size")); };
			
	var result = (settings.reverse == true) ? (pxVal * scopeVal).toFixed(2) + 'px' : (pxVal / scopeVal).toFixed(2) + 'em';
	return result;
};

/*-------------------------------------------------------------------- 
 * JQuery Plugin: "EqualHeights"
 * by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
 *
 * Copyright (c) 2008 Filament Group
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Description: Compares the heights or widths of the top-level children of a provided element 
 		and sets their min-height to the tallest height (or width to widest width). Sets in em units 
 		by default if pxToEm() method is available.
 * Dependencies: jQuery library, pxToEm method	(article: 
		http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/)							  
 * Usage Example: $(element).equalHeights();
  		Optional: to set min-height in px, pass a true argument: $(element).equalHeights(true);
 * Version: 2.0, 08.01.2008
--------------------------------------------------------------------**/

$.fn.equalHeights = function(px) {
	$(this).each(function(){
		var currentTallest = 0;
		$(this).children().each(function(i){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
		});
		if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
		// for ie6, set height since min-height isn't supported
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
		$(this).children().css({'min-height': currentTallest}); 
	});
	return this;
};

/**
	Namespace: essent
	
	author:
	- Wilfred Nas
	- wilfred@wnas.nl
	- http://wnas.nl
	- twitter.com/wnas

**/

/** komt dit in beeld? */
var essent = function () {

	/*
		Function: essent.tools
		
		some tools for common usage in other functions
	*/
	var tools = function () {
		/**
		* config is the place for private variables
		* @desc put variables in a object literal
		* @example foo : bar,
		*/
		var config = {
			// name: value pairs
		};
		/*
			Sub: essent.tools.consool
			
			consool is our console.log emulator for ie and other non-console browsers.
			
			Use like this:
			> @example essent.consool( arg );
		*/
		
		var consool = function (foo) {
			if ( !window.console ){		
				$('body').append('<p id="console"></p>');
				$('#console').text(foo);
			}
			else {
				console.log( foo );
			}
		};
		return {
			consool: consool
		};
	}();
	/*
		Function: essent.tools.fontSmooth
		
		Check to see if font-smoothing is on in IE.
		
	*/
	var fontSmooth = new function(){

	   // I use me instead of this.  For reasons why, please read:
	   // http://w3future.com/html/stories/callbacks.xml
	   var me = this;

	   me.hasSmoothing = function(){

	      // IE has screen.fontSmoothingEnabled - sweet!
	      if (typeof(screen.fontSmoothingEnabled) != "undefined") {
	         return screen.fontSmoothingEnabled;
	      } else {
			
	         try {

	            /** Create a 35x35 Canvas block. */
	            var canvasNode = document.createElement('canvas');
	            canvasNode.width = "35";
	            canvasNode.height = "35";

	            /** 
				* @lends fontSmooth
				* @class canvasNode.style
				* We must put this node into the body, otherwise
	            * Safari Windows does not report correctly. 
				*/
	            canvasNode.style.display = 'none';
	            document.body.appendChild(canvasNode);
	            var ctx = canvasNode.getContext('2d');

	            /** draw a black letter 'O', 32px Arial.*/
	            ctx.textBaseline = "top";
	            ctx.font = "32px Arial";
	            ctx.fillStyle = "black";
	            ctx.strokeStyle = "black";

	            ctx.fillText("O", 0, 0);

	            // start at (8,1) and search the canvas from left to right,
	            // top to bottom to see if we can find a non-black pixel.  If
	            // so we return true.
	            for (var j = 8; j <= 32; j++) {
	               for (var i = 1; i <= 32; i++) {

	                  var imageData = ctx.getImageData(i, j, 1, 1).data;
	                  var alpha = imageData[3];

	                  if (alpha != 255 && alpha != 0) {
	                     return true; // font-smoothing must be on.
	                  }
	               }

	            }

	            // didn't find any non-black pixels - return false.
	            return false;
	         }
	         catch (ex) {
	            // Something went wrong (for example, Opera cannot use the
	            // canvas fillText() method.  Return null (unknown).
	            return null;
	         }
	      }
	   };

	   me.insertClasses = function(){
	      var result = me.hasSmoothing();
	      var htmlNode = document.getElementsByTagName('html')[0];
	      if (result == true) {
	         htmlNode.className += " fs-true";
	      } else if (result == false) {
	            htmlNode.className += " fs-false";
	      } else { // result == null
	            htmlNode.className += " fs-unknown";
	      }
	   };

	}();

	/**
	* @class popup
	* @desc a generic function to open links in a popup window
	* @example $('a.popup').essent.popup();
	* is being called by event delegation
	*/
	var popup = function (uri,w,h) {
		/** is w is undefined fall back to 640 */
		if ( w === '') { 
			w = '640'; 
		}
		/** if he is undefined, fall back to 480 */
		if ( h === '') { 
			h= '480';
		}
		window.open(uri,'essent', "width="+w+", height="+h);
	};
	
	/**
	* @class pageList
	* @desc simple function to activate pagination
	* @example $('#nieuwsoverzicht').pagination();
	* @requires essent.pagination.js
	*/
	var pagelist = function () {
		var config = {
			pl: $('.pageList'),
			sc : 'js/essent.pagination.js',
			sort : $('select.sortable')
		};
		var init = function (t) {
			/** if we have the need for this */
			if ( config.pl.length !== 0 ){
				/** we get the script with ajax */
				$.getScript(config.sc, function () {
					/** and call the function to do stuff */
					pagination.init( t );
					//setTimeout('sortable()',100)
				});
			}
		};
		/** @return init to the global namespace. */
		return  { 
			init: init
		//	sortable:sortable
		};
	}();
	
	/**
	* @class heleen
	* @desc build heleen
	* @example some code
	*/
	var heleen = function () {
		var config = {
			heleen : $('#heleen'),
			textfield : $('#heleen-zoek').val(),
			btn : $('#heleen-submit'),
			w : $('#wrapper'),
			heleenB : '#heleenbig'
		//	uri : 'essent.nl/content/thuis/klantenservice/vraag_en_antwoord/index.jsp?allterms='
		};

		var init = function () {
			$('#heleen-zoek').focus( function() { $('#heleen-submit').addClass('focused');});
			$('#heleen-zoek').blur( function() { $('#heleen-submit').removeClass('focused');});
			// on submit of the heleen form
			if( !($('input#heleen-zoek').attr('placeholder'))){
				$('#heleen-zoek').attr('placeholder','Stel uw vraag kort & bondig');
				$.getScript('js/essent.placeholder.js');
			}
			$('form.heleen').submit( function() {
			// for every item with the placeholder attribute
				$('[placeholder]', this).each(function() {
					// set the var $input to this
					var $input = $(this);
					// Clear the value if it is still the placeholder					
					if ( $input.val() == $input.attr('placeholder') ) {
						$input.val('');
					}
					return true;
				});
				// get the value of the question
				var v =  $('#heleen-zoek').val();
				//alert('before build stuff')
				// build stuff
				if ( $('#heleenC').length === 0 ){
					// if there is no heleenC on the page
					buildStuff( v );
				} else {
					// show the heleen if she is on the page already..
					$('#heleenC').show();
					et_dl.ask($('#heleen-zoek').val());
				}
				// cancel default action
				return false;
			});
			// voor bjorn to check stufff
			// if there is a big heleen on the page ( klantenservice )
			if ( $(config.heleenB).length !== 0 ) {
				// load heleen into the big heleen, local path
				// $(config.heleenB).load('heleen/heleen.html');
				// for real live situations replace with:
				 $(config.heleenB).load('++/system/heleen.jsp');
			}
		};
		// build the stuff
		var buildStuff = function (v) {
		//	alert('in build stuff')
			// build the container for heleen
			config.w.prepend('<div id="heleenC"></div>');		
			// get the action, which should be the path to heleen.
			var ur = $('#search form.heleen').attr('action');
			// load the heleen page.
			$('#heleenC').load( ur , function() {
				// once we loaded heleen, we bind the click on the close button to hiding it...
				$('#heleenC #close').bind('click',function(){
				//	alert('clicked...');
					$('#heleenC').hide();
				});
			});
						// wait a bit.
			setTimeout( function () {
				// set the span's for the faq's
				$('#heleenC dl.faq dt').append('<span></span>');
				// set the value of the question...
				$('#vraag').val(v);
			},0);
		};
	
		return { 
			init:init 
		};
	}();
	

	
	/**
	* @class autotab
	* @desc simple way to enable autotab in form fields
	* @example jQuery('input.autoTab ').autotab();
	* @requires jquery autotab plugin
	**/
	var autoTabf = function () {
	//	$('input.autoTab').autoTab();
	};
	var faq = function () {
		$('dl.faq dt').append('<span></span>');
	};
	/**
	* @class init
	* @desc call other javascript stuff
	*/
	var init = function () {
		jQuery.ajaxSetup({ cache: true });
		login();
	//	pagelist.init();
		heleen.init();
		equalH();
	//	steps();
		faq();
		autoTabf();
		fixImages();
		checkVideo();
	};
	var equalH = function () {
		$('.section-equal').equalHeights();
	};
	
	var fixImages = function(){
		var $im = $('.img-l, .img-r');
		$im.each( function () {
			var w = $(this).find('img').width();
			$(this).width(w);
		});
	};
	/**
	 * @class steps
	 * @author wilfred nas
	 * @desc a simple function to build a 'step' list for forms. We do this by adding the number of the list element inside a span in it.
	 * {@code $('ol.steps').steps(); }
	 */
	var steps = function () {
	//	$('ol.steps').steps();
	};
	
	/*
	
		Function: login
		
		all of the stuff needed to login, including showing and hiding the div and saving the name and stuff in a cookie
	*/
	var login = function () {
		$('body.particulier .subhome #login, body.mkb .subhome #login, body.grootzakelijk .subhome #login').addClass('open-add');
		$('body.particulier .subhome #login h4.login, body.mkb .subhome #login h4.login, body.grootzakelijk #login h4.login').after('<div class="login-module" id="form-login"></div>');
		$('body.particulier .subhome #form-login, body.mkb .subhome #form-login').load($('h4.login a').attr('href')+' #login-component form',function(){getLoginCookie();});
		$('body.particulier .subhome #login, body.mkb .subhome #login,  body.grootzakelijk .subhome #login').toggleClass('open');
		if( $('#login.open').length !== 0  ) {
		//	console.log('open login component');
			getLoginCookie();
		}
		var redirectButton = function () {
			var h = $('.login a').attr('href');
			$('body').delegate('#loginSec','click',function(){ window.open(h);return false;});
		};
		
		var loadGZlogin = function () {
			// see place for 
			// ++/system/
			$('#login .login-module').load('grootzakelijk-login-extras.html');
		};
		
		if ( $('#login-component').length !== 0 ){
		//	console.log('#login-component')
			getLoginCookie();
		}
		
			if( ($('body.grootzakelijk .subhome').length !== 0) ){
				loadGZlogin();
				redirectButton();
				$('#login h4 a').click( function(){
					$('#login').toggleClass('open');return false;
				});
			}
		
		$('#login .login').click( function () {
			// if there is no #form-login
			if ( $('#form-login').length == 0 ){
				// get the class of the body to differentiate between particulier and others
				// build the div to receive the login form
				$('#login .login').after('<div class="login-module" id="form-login"></div>');
			}
			var bodyClass = $('body').attr('class');
			loadLogin(bodyClass);
			if( $('body.mkb').length !== 0 ){
				$('input[name="ERROR"]').attr('value','zakelijk');
			}
		
				
			$('#login').toggleClass('open');
			// don't follow the link.
			return false;
		});
		
		
		var loadLogin = function (bodyClass) {
			// get the link target.
			var tar = $('h4.login a').attr('href');
			// load the login form.
			if( ($('body.grootzakelijk .entree, body.grootzakelijk .article').length !== 0) ){
				loadGZlogin();
				redirectButton();
				doLoginStuff(bodyClass);
			} else {
				$('#form-login').load(tar+' #login-component form',function(){
					doLoginStuff(bodyClass);
				});
			};
		
			
			return false;
		};
		var doLoginStuff = function (bodyClass) {
			// get hbx...
			_hbPageView("inloggen mijn essent ",bodyClass);
			// get the cookie
			if( $.cookie('essentlogin') ){
				var cookieVal = $.cookie('essentlogin').split('|');
				//alert(cookieVal);
				$('#ess-tbun').val(cookieVal[0]);
				$('#ess-tbpw').val(cookieVal[1]);
			}
		};
	};
	 /*
		Function: checkRememberCheckbox
	*/
	$('body').delegate('#essent-login','submit',function(event){
		// stop the normal behaviour of the form
		event.preventDefault();
		// set or delete the cookie with the login information
		setDeleteLoginCookie();
		// get the script for login and go to work...
		$.getScript('js/essent.login.js');
	});
	
	/*
		Function: setDeleteLoginCookie
	*/
	var setDeleteLoginCookie = function() {
		var config = {
			cookieName : 'essentlogin',
			cookieOptions : { path: '/', expires: 365, domain: document.domain.split( "." ).slice( -2 ).join( "." )}
		};
	//	alert('in setDeleteLoginCookie');
		if( $('#remember:checked').length !== 0 ){
	//		alert('checked')
			saveLogin(config.cookieName,config.cookieOptions);
		}
		else {
		//	alert('no rememebredkeked')
			deleteLogin(config.cookieName,config.cookieOptions);
		};
	};
	
	/*
		Function: saveLogin
		
		Saves the name and password after checking the 'remember' checkbox
		
		first we go and get the value of the name and password fields and put it in some vars
		>var name= $('#ess-tbun').val();
		>var pass= $('#ess-tbpw').val();
		we than create a cookie with those values and set it to be valid for x weeks
		>$.cookie('essent-login', name + '|' + pass );
	*/
	var saveLogin = function ( cookieName,options ) {
		var n= $('#ess-tbun').val();
		var p= $('#ess-tbpw').val();
		var $cookieVal = n+'|'+p;
	//	alert('saveLogin = '+$cookieVal+' name = '+cookieName+' options '+options)
		$.cookie( 'essentlogin' , $cookieVal,options );
	};
	
	/*
		Function: deleteLogin
		
		delete the cookie we set for saving the name and password value for logging in...
	*/
	var deleteLogin = function( cookieName,options ){
		$.cookie('essentlogin', null,options);
		return false;
	};
	
	/*
		Function: getLoginCookie
		
		get the information of the cookie set by checking the remember checkbox, if it is present
		
		see if the cookie is present.
		>if( $.cookie('essent-login') ){
		if it is, get the value of the coookie
		>var cookieVal = $.cookie('essent-login').split('|');
		prefill the name and password fields
		>	$('#ess-tbun').val(cookieVal[0]);
		>	$('#ess-tbpw').val(cookieVal[1]);

	*/
	
	var getLoginCookie = function () {
		if( $.cookie('essentlogin') ){
			var $cookieVal = $.cookie('essentlogin').split('|');
		//	alert('getLoginCookie = '+$cookieVal)
			$('#ess-tbun').val($cookieVal[0]);
			$('#ess-tbpw').val($cookieVal[1]);
			return false;
		}
	};
	
	/**
	 Function: html5
	 * @author wilfred nas
	 * @desc function to detect html5 features. we use a written input to do this.
	**/
	/*
		Function: html5
		
		adds html5 support to browsers that need it...
		
		The only thing we add for now is placeholder..
	*/
	var html5 = function() {
		// build an input element.
		// Create a new element to test for html5 attributes
		document.createElement('abbr');
	 	var i = document.createElement('input');
		// Check if "placeholder" attribute is available
		if ( !('placeholder' in i) ) {
			$.getScript('js/essent.placeholder.js');
		}
		else {
			$('[placeholder]').addClass('default');
			$('[placeholder]').focus(function(){
				$(this).removeClass('default');
			});
		};
	
		// Check if "autofocus" attribute is available
		if ( !('autofocus' in i) ) {
			// do autofocus stuff
		}
		// Check if "required" or "pattern" attributes are available
		if ( !('required' in i && 'pattern' in i) ) {
			// do required and pattern stuff
		}
	};
	var checkVideo = function() {
		// make video play when opening in essentbox.
		$('a.essentbox').click( function() {
			var t = $(this).attr('href');
			var vid = $(t).find('video');
			if( vid.length !== 0 ){
				/* 
					autoplay works in:
						osx
							firefox the first time
					
					does not work in :
						osx
							safari 5
							opera 10
				*/
				vid.attr('autoplay','autoplay');
			}
		
		});
	};

	return { 
		init:init,
		tools: tools,
		html5: html5,
		fontSmooth: fontSmooth,
		popup:popup,
		pagelist:pagelist
	};
}();
essent.init();
essent.html5();
essent.pagelist.init('#nieuwsoverzicht');


/*
	function: click
	 
	summary: makes sure that a whole html block is linkable to the href of the first a href found in the block
*/
$('body').delegate('.click','click', function(event){
	// get the href of the first button in the black: not only used on landing pages but also on subhome
	var e = $(this).find("a.btn").attr("href");
	if (e == undefined) { e = $(this).find("a:first").attr("href"); }
	/*
		call to function <fixHBX>.js
		
		we first check to see if we are in a spotlight.
	*/
	var par = $(this).closest('.spotlight');
	// if we are:
	if ( par ){
		// we set the link clicked to be our origin var.
		var origin = $(this).find('h3 a');
		// if the script isn't loaded
		if ( fixHBXcheck == false ){
			// get the script needed and
			$.getScript('js/essent.fixHBX.js',function(){ 
				// call the init function carrying the origin and the tag spotlight...
				fixHBX.init( origin,'spotlight' );
			});
		} else {
			// if we already have the script, just call the function and stuff.
			fixHBX.init( origin,'spotlight' );
		}
	}
	// go to that location...
	window.location=e;
});

/*
	function for adding hover to all of the .click boxes.
*/
$("body").delegate(".click", "hover", function(e){
	$(this).toggleClass("hover");
		var label = $(this).classValue('label');
		if ( label != '' ) { $(this).toggleClass("label-"+label+"-hover"); }
});


$("#nav ul.menu li").hover(
  	function () {
		$(this).parent().parent().removeClass("hover"); return false;
	}
);

$('body').delegate('.popUp','click', function(){
	// go to the essent.popup script
	essent.popup($(this).attr('href'),$(this).classValue('w'),$(this).classValue('h'));
	// ignore the default action
	return false;
});

$('body').delegate('a.newWindow','click',function(){
	// open a new window from the href attribute
	window.open(this.getAttribute('href'));
	// ignore the call to go to the new page...
	return false;
});

// toggle stuff
$('body').delegate('.toggleStuff','click',function(){
	// get the href ( to an id on the page )
	var l = $(this).attr('href');
	// toggle the hidden class on the target id
	$('#'+l).toggleClass('hidden');
	// show that we toggled stuff ( for css )
	$(this).toggleClass('toggled');
	// don't really follow the link
	return false;
});

// VEELGESTELDE VRAGEN
/*
	Function: faq
	
	small function to toggle the faq's
	
	it is being done with event delegation, so that it is present on the generated heleen as well
	>$('body').delegate('dl.faq dt','click', function(){
	First we get the next dd from the list
	>var antwoord = $(this).next('dd');
	then we need the class of the clicked item ( this )
	>var a = $(this).attr('class');
	If this is active
	>if (a == 'active') { 
	We slide the answer back up and remove the class .active
	>	$(antwoord).slideUp('400');
	>	$('dl.faq dt, dl.faq dd').removeClass('active');
	If it is not active
	>else {
	We remove the active class from all dt's ( just to be sure )
	>$('dl.faq dt').removeClass('active');
	and collapse all the answers
	>$('dl.faq dd.active').slideUp('400');
	We go ahead and set active on the current question
	>$(this).addClass('active');
	And slide the correct answer open.
	>$(antwoord).slideDown('600').addClass('active');
	
	Full code
	
	(code)
	$('body').delegate('dl.faq dt','click', function(){
		var antwoord = $(this).next('dd');
		var a = $(this).attr('class');
		// KLIKT MEN OP HUIDIGE ACTIEVE ITEM OF EEN ANDER?
		if (a == 'active') { 
			$(antwoord).slideUp('400');
			$('dl.faq dt, dl.faq dd').removeClass('active');
		} else { 
			$('dl.faq dt').removeClass('active');
			$('dl.faq dd.active').slideUp('400');
			$(this).addClass('active');
			$(antwoord).slideDown('600').addClass('active');
		}
	});
	(end)
*/
$('body').delegate('dl.faq dt','click', function(){
	var antwoord = $(this).next('dd');
	var a = $(this).attr('class');
	// KLIKT MEN OP HUIDIGE ACTIEVE ITEM OF EEN ANDER?
	if (a == 'active') { 
		$(antwoord).slideUp('400');
		$('dl.faq dt, dl.faq dd').removeClass('active');
	} else { 
		$('dl.faq dt').removeClass('active');
		$('dl.faq dd.active').slideUp('400');
		$(this).addClass('active');
		$(antwoord).slideDown('600').addClass('active');
	}
});

$('body').delegate('a.showvideo', 'click', function(){
	$(this).parent().parent().find('div.flash').show();
	$(this).parent('div.section').hide();
	return false;
});
/*
$('body').delegate('#heleenC #close','click', function(){
//	alert(' 	');
	$('#heleenC').hide('slow').remove();
	return false;
});
*/
if ( jQuery('table.tochart').length !== 0 ){
		jQuery.getScript('js/table2chart.js');
}
if ( jQuery('table.toline').length !== 0 ){
		jQuery.getScript('js/table2line.js');
}
if ( jQuery('table.tobar').length !== 0 ){
		jQuery.getScript('js/table2bar.js');
}

	
// ETALAGE OP SUBHOMES
if ( jQuery('#etalage').length !== 0 ){
	jQuery.getScript('js/essent.etalage.js');
}




/**
	* flashEn
	* @author Maarten van Oudenniel
	* @desc description of code
	* @param parameters.
	* @example $('foo').flashEn();
**/
var flashEn = function () {
	var config = {
		fl : $('.flash'),
		src : 'http://oudenniel.com/essent/player.swf' // location of player
	};
	var init = function (fl) {
		// check of er flash is
		// ga iets doen
		// on the lightbox pages
		if ( !fl ){ fl = config.fl; }
		if ( fl.length !== 0 ){
			fl.each( function () {
				var flID = $(this).attr('id');
				// WE HALEN DE VARIABELEN OP
				// sets a fault on chrome...
				// Uncaught TypeError: Cannot call method 'lastIndexOf' of undefined
			
				if (getComments(this)[0]) {
					var length = (getComments(this)[0]).lastIndexOf("\"");
					var start = 17; // essent.flash = "
					var url = (getComments(this)[0]).substring(start,length);	
				}
				else {
					return false;
				}
				doStuff( flID, url);	
			});
		}
	};
	var doStuff = function ( flID, url ) {

		// lees flash vars uit.
		// bouw flash ding...
		var param = url.split('|');
		var width = param[0];
		var height = param[1];
		var src = param[2];
		var flashvars = param[3];

   		$('#'+flID).flash(null, { version: 9 }, function(htmlOptions) {
	        htmlOptions.src = src;
	        htmlOptions.width = width;
	        htmlOptions.height = height;
			htmlOptions.flashvars = flashvars;
			htmlOptions.wmode = 'opaque';
			htmlOptions.allowfullscreen = 'true';
			htmlOptions.allowScriptAccess = 'always';
	        this.innerHTML = '<div class="alt">'+this.innerHTML+'</div>';
	        $('#'+flID).addClass('flash-replaced').prepend($.fn.flash.transform(htmlOptions));
	    });
	};
	var getComments = function (node) {
		var c = new Array(); //create an array.
		
		  if (node.nodeType == 8) { //if the current DOM node is a comment.

		  	if(((node.nodeValue).substring(1,13)) == 'essent.flash'){//only the flashvars comments we are interrested in.

   
		c[c.length] = node.nodeValue; //add it's text to the array.
		    }
		  } else if (node.childNodes != null) { //Otherwise, if it has children
		    for (var i=0; i < node.childNodes.length; i++) { //iterate through each child
		      c = c.concat(getComments(node.childNodes.item(i))); //add it's comments too.
		    }
		  }
		  return c; //return the array.
	};
	return {
		init: init
	};
}();
flashEn.init();











if ( $('.tabs').length !== 0 ){
	
	var h = '';
	var j = document.location.toString().split('#tab-');
	if ( j[1] ) { h = j[1]; }
	jQuery.getScript('js/jquery.tabs.js',function(e) { 
	//	alert($(e.target).text()+' tekst van de link');
		$('.tabs').tabs(h); 
	});
}
/*
if ( $('table.sortable') !== 0 ){
	$.getScript('js/jquery.tablesorter.min.js', function() { $('table.sortable').tablesorter()})
}
*/

if ( jQuery('a.essentbox').length !== 0 ){
	$.getScript('js/jquery.fancybox-1.3.1.js',function() {
			$('a.essentbox').fancybox();
		//	$.fancybox.resize
			
	});
};
$('a.fancybox').click(function(){
	alert('fancybox');
	var h = $(this).attr('href');
	console.log(h);
	$('body').append('<div id="fancybox"></div>');
	$('#fancybox').load(h);
	return false;
});
$('p:empty').remove();
//$.fancybox.resize

var fancy = function () {
//	alert('fancy function')
	$('a.essentbox').fancybox(
	/*	'titlePosition'	: 'over',
		'autoDimensions': 'true'*/
		// for more options see http://fancybox.net/api
	);
};
if ( $('#klantenbalie').length !== 0 ){
	$.getScript('js/essent.klantenbalie.js');
};
if ( $('.essent-form.validate').length !== 0 ){
	$.getScript('js/essent.form.js',function () {
		essent.eform.init();
	});
};


/**
	JavaScript Lint
	0 error(s), 1 warning(s)

	388: warning: anonymous function does not always return a value
	  };
	..^

**/

