var esmart = {
	timeout: undefined,
	shadediv: undefined,
	shadowon: true,
	shadow: function(id) {
			var div = document.getElementById(id);
			var html = div.innerHTML;
			
			var shade = document.createElement('DIV');
			shade.innerHTML=html;
			shade.style.position='absolute';
			shade.style.marginLeft='1px';
			shade.style.marginTop='-1px';
			
			var els = div.getElementsByTagName('A');
			for (var i=0;i<els.length;i++) {
				els[i].style.color='#666666';
				els[i].onmouseover=null;
			}

			div.insertBefore(shade,div.childNodes[0]);
		},
	getpos: function(obj) {
			var x=y=0;
			if (obj.offsetParent) {
				do {
					x += obj.offsetLeft;
					y += obj.offsetTop;
				} while (obj=obj.offsetParent);
			}
			return [x,y];
		},
	hideall: function(except) {
			var els = document.getElementsByTagName('DIV');
			for (var i=0;i<els.length;i++)
			if (els[i].id.match(/^popup/)!=null && els[i]!=except) {
				els[i].style.display='none';
			}
		},
	mover: function(a,id) {
			var popup = document.getElementById('popup'+id);
			if (popup) {
				esmart.hideall(popup);
				var xy = esmart.getpos(a);
				popup.style.top=xy[1]+'px';
				popup.style.left=(xy[0]+15)+'px';
				popup.style.display='block';
				if (esmart.shadowon)
					esmart.shade(popup.parentNode,xy[0]+15,xy[1],popup.offsetWidth,popup.offsetHeight);
				document.documentElement.onmouseover=esmart.mout;
			}
		},
	delayedmout: function() {
			esmart.hideall(null);
			esmart.unshade();
		},
	mout: function(e) {
			var targ = undefined;
			if (!e) var e = window.event;
			if (e.target) targ = e.target;
			else if (e.srcElement) targ = e.srcElement;
			if (targ.nodeType==3) targ = targ.parentNode;
			if (targ) {
				clearTimeout(esmart.timeout);
				do {
					if ((targ.id && (targ.id.match(/^popup/)!=null || targ.id=='menu')) || (targ.className && (targ.className=='popup' || targ.className=='popupmenu'))) break;
				} while (targ=targ.parentNode);
				/*if (targ)
					esmart.log(targ.nodeName+' '+targ.className+' '+targ.id+' '+targ.innerHTML);*/
				if (!targ) {
					esmart.timeout=setTimeout(esmart.delayedmout,500);
				}
			}
		},
	log: function(txt) {
			var l = document.getElementById('log');
			l.innerHTML=txt;
		},
	unshade: function() {
			if (esmart.shadediv) esmart.shadediv.parentNode.removeChild(esmart.shadediv);
			esmart.shadediv=undefined;
		},
	shade: function(obj,x,y,width,height) {
			esmart.unshade();
			esmart.shadediv = document.createElement('DIV');
			esmart.shadediv.className='shade';
			esmart.shadediv.style.background='black';
			esmart.shadediv.style.top=(y+3)+'px';
			esmart.shadediv.style.left=(x+3)+'px';
			esmart.shadediv.style.width=width+'px';
			esmart.shadediv.style.height=height+'px';
			obj.parentNode.insertBefore(esmart.shadediv,obj);
		}
};

function ToggleContent (d) {
	d = document.getElementById(d);
	d.style.display = d.style.display=='block' ? 'none' : 'block';
}

jQuery.fn.autofieldset = function() {
	return this.each(function() {

		$(this).submit(function(event) {
		
			//event.preventDefault();
			//$(this).find('INPUT[type=submit]').attr({disabled:'disabled'});
		
			});
	
		$(this).find('FIELDSET').each(function() {
			
			var fnd = 0;
			$(this).find('INPUT[type=text],SELECT')
				.focus(function() {
					$(this).closest('FIELDSET').next('FIELDSET').delay(250).slideDown();
					$(this).closest('FIELDSET').find('INPUT[type=text],SELECT').unbind('focus');
					})
				.each(function() {
					if ($(this).val()!='') fnd++;
					})
				;
			if (fnd==0) $(this).hide();

			});
		$(this).find('FIELDSET').first().show();

		$(this).find('.removefieldset')
			.click(function(event) {
				event.preventDefault();
				if (confirm('Weet u het zeker?'))
					$(this).closest('div').remove();
				})
			;
		$(this).find('.addfieldset').click(function(event) {
			event.preventDefault();
			var div = $(this).closest('fieldset').children('div').last();
			div = $(div).clone(true).insertAfter(div);
			$(div).find('INPUT,SELECT').val('');
			$(div).find('INPUT[type=text],SELECT').first().focus();
			});

		})
		;
};

jQuery.fn.fieldmsg = function(err,color) {
	this.each(function() {
	
		$(this).prev('span').remove();
		
		if (err) {
			$(this).before('<span class="e">'+err+'</span>');
			var span = $(this).prev('span');
			var p = $(this).position();
			$(span).css('left',p.left);
			$(span).css('top',p.top+$(this).outerHeight());
			$(span).css('color',color);
			$(span).fadeIn();
		}

		});
	return this;
};

function cvbank_postfield(action,field) {
	$(field).prev('span').remove();
	$.post(window.location.href,{action:action, name:field.name, value:field.value},function(res) {
		$('head').append('<script type="text/javascript">'+res+'</script>');
		});
}

$(document).ready(function() {
		$('a[rel=ga]').click(function() {
			_gaq.push(['_trackEvent',$(this).text(),'click']);
			});
	});


