/*
 * jQuery ifixpng plugin
 * (previously known as pngfix)
 * Version 2.0  (04/11/2007)
 * @requires jQuery v1.1.3 or above
 *
 * Examples at: http://jquery.khurshid.com
 * Copyright (c) 2007 Kush M.
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 */
 
 /**
  *
  * @example
  *
  * optional if location of pixel.gif if different to default which is images/pixel.gif
  * $.ifixpng('media/pixel.gif');
  *
  * $('img[@src$=.png], #panel').ifixpng();
  *
  * @apply hack to all png images and #panel which icluded png img in its css
  *
  * @name ifixpng
  * @type jQuery
  * @cat Plugins/Image
  * @return jQuery
  * @author jQuery Community
  */
 
(function($) {

	/**
	 * helper variables and function
	 */
	$.ifixpng = function(customPixel) {
		$.ifixpng.pixel = customPixel;
	};
	
	$.ifixpng.getPixel = function() {
		return $.ifixpng.pixel || 'http://www.hva.nl/images/pixel.gif';
	};
	
	var hack = {
		ltie7  : $.browser.msie && $.browser.version < 7,
		filter : function(src) {
			return "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,sizingMethod=scale,src='"+src+"')";
		}
	};
	
	/**
	 * Applies ie png hack to selected dom elements
	 *
	 * $('img[@src$=.png]').ifixpng();
	 * @desc apply hack to all images with png extensions
	 *
	 * $('#panel, img[@src$=.png]').ifixpng();
	 * @desc apply hack to element #panel and all images with png extensions
	 *
	 * @name ifixpng
	 */
	 
	$.fn.ifixpng = hack.ltie7 ? function() {
    	return this.each(function() {
			var $$ = $(this);
			var base = $('base').attr('href'); // need to use this in case you are using rewriting urls
			if ($$.is('img') || $$.is('input')) { // hack image tags present in dom
				if ($$.attr('src')) {
					if ($$.attr('src').match(/.*\.png([?].*)?$/i)) { // make sure it is png image
						// use source tag value if set 
						var source = (base && $$.attr('src').substring(0,1)!='/') ? base + $$.attr('src') : $$.attr('src');
						// apply filter
						$$.css({filter:hack.filter(source), width:$$.width(), height:$$.height()})
						  .attr({src:$.ifixpng.getPixel()})
						  .positionFix();
					}
				}
			} else { // hack png css properties present inside css
				var image = $$.css('backgroundImage');
				if (image.match(/^url\(["']?(.*\.png([?].*)?)["']?\)$/i)) {
					image = RegExp.$1;
					$$.css({backgroundImage:'none', filter:hack.filter(image)})
					  .children().children().positionFix();
				}
			}
		});
	} : function() { return this; };
	
	/**
	 * Removes any png hack that may have been applied previously
	 *
	 * $('img[@src$=.png]').iunfixpng();
	 * @desc revert hack on all images with png extensions
	 *
	 * $('#panel, img[@src$=.png]').iunfixpng();
	 * @desc revert hack on element #panel and all images with png extensions
	 *
	 * @name iunfixpng
	 */
	 
	$.fn.iunfixpng = hack.ltie7 ? function() {
    	return this.each(function() {
			var $$ = $(this);
			var src = $$.css('filter');
			if (src.match(/src=["']?(.*\.png([?].*)?)["']?/i)) { // get img source from filter
				src = RegExp.$1;
				if ($$.is('img') || $$.is('input')) {
					$$.attr({src:src}).css({filter:''});
				} else {
					$$.css({filter:'', background:'url('+src+')'});
				}
			}
		});
	} : function() { return this; };
	
	/**
	 * positions selected item relatively
	 */
	 
	$.fn.positionFix = function() {
		return this.each(function() {
			var $$ = $(this);
			var position = $$.css('position');
			if (position != 'absolute' && position != 'relative') {
				$$.css({position:'relative'});
			}
		});
	};

})(jQuery);

$(document).ready(function(){
	// apply ifixpng
 	$('img[@src$=.png]').ifixpng();
});

//////////////////////////////////////////////////////////////////////////////////////
// script om png's in IE 5.5-7 goed te tonen - Marion de Groot 23 februari 2007		//
//																					//
// De functies om achtergrondpngtjes correct te tonen zijn in principe generiek:	//
// function initshowPNGbg(), showPNGbg() en filteren(el, s)							//
// je moet alleen zorgen dat verzamel_PNGbg() de gewenste elementen verzamelt;		//
// De functies hoveren() en uitgehoverd() zijn specifiek voor ons menu - dat komt	//
// omdat css psuedo-classes (bv ':hover') niet te scripten zijn met JavaScript		//
//////////////////////////////////////////////////////////////////////////////////////

var achtergrondurl ="";
 
function verzamel_PNGbg(){ 
// maak array van de menu elementen met PNG background		
		var verzameling = new Array(); 
		var a = document.getElementById('menuitems');
		verzameling[0]= a;
		var b = a.getElementsByTagName('a');
		for(var teller=0;teller<b.length;teller++){
		 	verzameling[(teller+1)]=b[teller];
		}
		if(document.getElementById('bottom')){
			var c = document.getElementById('bottom');
		}
		else{
			var c = document.getElementById('bottom2');
		}
		verzameling[(teller+1)]=c;
		return verzameling;
}

function filteren(el, s){		
	if (document.body.filters) {			
		el.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+s+",sizingMethod='crop')";		
		// De volgende if is specifiek gericht op de niet actieve menu-items
		// twee eventhandlers om a:hover na te bootsen
		if(!el.className && el.tagName=='A'){										
			el.onmouseover = hoveren; 
			el.onmouseout = uitgehoverd; 
		}
	}
}

function initshowPNGbg(){
	if(document.getElementById('menuitems')){
		var el_metPNGbg = verzamel_PNGbg();		
		// Fix van IE 5.5 tot 7, 7 zou het goed moeten doen
	 	var version = navigator.appVersion.split("MSIE");
		version = parseFloat(version[1]);		
		if ((version >= 5.5) && (version < 7.0)) {
	  		for(var i=0;i<el_metPNGbg.length;i++){
				var el = el_metPNGbg[i];
				showPNGbg(el);			
			}
		}
	}
}

function showPNGbg(el){	
	var bgImg = el.style.backgroundImage || el.currentStyle.backgroundImage;		
	if(bgImg.match(/^url[("']+(.*\.png)[)"']+$/i)){	
		var s = RegExp.$1;					
		el.style.width = el.offsetWidth+'px';
		el.style.height = el.offsetHeight+'px';				
		el.style.background = 'none';	
		el.style.position = 'relative';	
		el.style.cursor ='pointer';
		achtergrondurl = s;							
		filteren(el, s);				
	}
}

function hoveren(){	
	this.className = "ie5"; // schakelt de a:hover uit	
	var bgurl = achtergrondurl.split('/');
	bgurl.pop();
	bgurl.push('menulink-back.png');
	var hoverbg = bgurl.join('/');
	this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+hoverbg+",sizingMethod='crop')";		
}

function uitgehoverd() {	
	var bgurl = achtergrondurl.split('/');
	bgurl.pop();
	bgurl.push('menu-back.png');
	var bg = bgurl.join('/');	
	this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src="+bg+",sizingMethod='crop')";		
}

if(window.attachEvent)window.attachEvent("onload",initshowPNGbg);

