/*
Copyright (c) 2008 Ylab, www.ylab.nl
*/
var msie, msie6, urlprefix, imgext;

function doIFR(){
	if(!!sIFR){
    var sIFRprops = {
      sFlashSrc: '../css/maiandra.swf',
      sColor: '#003cb9',
      nPaddingTop: 0,
      nPaddingBottom: 0,
      sWmode:  'Transparent',
      sFlashVars: 'textalign=left'
    };
    sIFRprops.sSelector = 'h1';
    try{;
    	sIFR.replaceElement(named(sIFRprops));
    }
    catch(e){
    }
  }
}

jQuery(document).ready(function($){
	var sFolder, bActive;
	var aChannelCodes = ['vrijbergen', 'basis', 'voortgezet', 'actueel'];
	var aCanvasClasses = $('#canvas').attr('class').split(' ');
	if($.inArray('intranet', aCanvasClasses) > -1){
		 aChannelCodes[3] = 'intranet';
	}

	msie  = $.browser.msie;
	msie6 = $.browser.msie && $.browser.version < 7;
	imgext = msie6 ? '.gif' : '.png';
	urlprefix = $('#logo img')[0].src.replace('logo.gif', '');
	doIFR();

	//replace menu text with images
	$('#menu a').each(function(i){
		//todo:better logic
		if(!bActive){
			bActive = $.inArray(aChannelCodes[i], aCanvasClasses) > -1;
			sFolder =  bActive ? 'active' : 'normal';
		}
		else{
			sFolder = 'normal';
		}
		this.innerHTML = '<img src="' + urlprefix + sFolder + '/menu-' + aChannelCodes[i] + imgext + '" alt="' + this.innerHTML + '" />';
	});

	//hover menu
	$('#menu img').hover(function(){
		this.src = this.src.replace('normal/', 'hover/');
	}, function(){
		this.src = this.src.replace('hover/', 'normal/');
	});

	//push down menu
	$('a img,.click').mousedown(function(){
		this.src = this.src.replace('normal/', 'down/');
	}).mouseup(function(){
		this.src = this.src.replace('down/', 'normal/');
	}).mouseout(function(){
		this.src = this.src.replace('down/', 'normal/');
	});

	$('.login input').focus(function(){
		if(this.value==this.defaultValue){
			$(this).css({ color:'#000'});
			this.value='';
		}
	}).blur(function(){
		if(!this.value){
			$(this).css({color:'#aaa'});
			this.value=this.defaultValue;
		}
	}).css({color:'#aaa'});

	$('#submenu').hide().slideDown();

	//preload images
	try{
		(new Image).src='../graphics/hover/menu-vrijbergen'+imgext;
		(new Image).src='../graphics/hover/menu-basis'+imgext;
		(new Image).src='../graphics/hover/menu-voortgezet'+imgext;
		(new Image).src='../graphics/hover/menu-actueel'+imgext;
		(new Image).src='../graphics/hover/menu-intranet'+imgext;
	}catch(err){}
});
