// site specific functions

addCssClass = function(objectOrId, cssClass) {
	var obj = ((typeof(objectOrId) == 'string') ? document.getElementById(objectOrId) : objectOrId);
	var c = obj.className + ' ';
	if (c.indexOf(cssClass + ' ') == -1) obj.className = c + cssClass;
}	

removeCssClass = function(objectOrId, cssClass) {
	var obj = ((typeof(objectOrId) == 'string') ? document.getElementById(objectOrId) : objectOrId);
	var c = obj.className + ' ';
	obj.className = c.replace(cssClass + ' ', '');
}	

inputReset = function(o) {
	if (o.value == 'Uw e-mailadres') {
		o.value = '';
		removeCssClass(o, 'inactive');
	}
}

createMailto = function(pers, domain, customText) {
	var email = pers + '@' + domain;
	(customText == null) ? lnk = email : lnk = customText;
	document.write('<a href="mailto:'+email+'">'+lnk+'</a>');
}

isEnter = function(e) {
	 var characterCode;
	 if (e && e.which) {           
		e = e; characterCode = e.which;
	 } else { 
		e = event; characterCode = e.keyCode 
	 }
	 return (characterCode == 13);
}

limitChars = function(fld, maxlimit, displayId) {
	if (fld.value.length > maxlimit) {
		fld.value = fld.value.substring(0, maxlimit);
	} else { 
		document.getElementById(displayId).innerHTML = maxlimit - fld.value.length;
	}
}



getMonthNumber = function(m) {
	var months = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
	var month_nrs = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
	var nr = 0;
	for (var i=0; i<months.length; i++) {
		if (months[i] == m) return month_nrs[i];	
	}
	return nr;
}


validateEmail = function(f) {
	return true;
}

initNav = function() {
	$('#nav1 img, img.button').bind("mouseenter", function(e) {
		src = this.src;
		ext = src.substring(src.lastIndexOf('.'), src.length);
		if (src.indexOf('-s' + ext) == -1) this.src = src.replace(ext, '-s'+ext);
	});
	$('#nav1 img, img.button').bind("mouseleave", function(e) {
		src = this.src;
		ext = src.substring(src.lastIndexOf('.'), src.length);
		if (src.indexOf('-s' + ext) != -1) this.src = src.replace('-s'+ext, ext);
	});
	$('#nav1 img.active').unbind();
}

initLinks = function() {
	$('.link-list li, .link-item, .intro-image-block').each(function(e) {
		$(this).bind("click", function(e) {	
			document.location.href = $(this).find('a').attr('href');
		}).css({'cursor':'pointer'});
	});
}

initPhotoOverlays = function() {
	var cnt = 1;
	$('.photos').each(function(e) {
		$(this).find('img').each(function(e) {
			$(this).wrap('<a href="'+$(this).attr('src')+'" rel="sect'+cnt+'" title="'+$(this).attr('alt')+'"></a>')									  
		});
		
		$(this).find('a').each(function(e) {	
			$(this).colorbox({
				 	transition:"elastic", 
					current: "foto {current} / {total}",
					onOpen:function(){ $('object').css('visibility', 'hidden'); },
					onClosed:function(){ $('object').css('visibility', 'visible'); }
			});	
		});
		cnt++;
	});
}

initImages = function() {
	$('img').each(function(e) { 
		$(this).attr('title', $(this).attr('alt'));
		$(this).addClass($(this).attr('align')); 
	});
}

loadTweets = function() {
	username = $('#tweets-username').html();
	$('#tweets-username').hide();
	if ((username != null) && (username != '')) {
		if (username.indexOf('#') == -1) {
			$('#tweets').append('<p class="follow"><a href="http://www.twitter.com/'+username+'" target="_blank">Volg '+username+' op Twitter!</a></p>').show();
			$("#tweets").tweet({
				join_text: "auto",
				username: username,
				count: 6,
				loading_text: "loading tweets...",
				auto_join_text_default: "<br />" 
			});
		} else {
			$("#tweets").tweet({
				join_text: "auto",
				avatar_size: 32,
				count: 6,
				query: username,
				loading_text: "searching twitter...",
				auto_join_text_default: "<br />" 
			});
		}
	} else {
		// hide tweets	
		$('#tweets').hide();
	}
}

$(document).ready(function() {
	initNav();
	initLinks();
	initPhotoOverlays();
	initImages();
	loadTweets();		  							
});




