$(function(){
	
	// external links
	$("a[rel='external']").click(function(){window.open(this.href); return false});
	
	// dropmenu
	var oSnelmenu = new DickerFisch('#snelmenu',{Effect:0});
	
	// hide/show telefonisch reserveren uitlegjes
	$(".telResToggleButton").click(function(){
		voorstellingId = $(this).attr("id").substr(18);
		$("#telResToggleItem"+voorstellingId).toggle();
		return false;
	});
	
	sDefaultTxt = 'zoek...';
	$("#formZoeken-zoek").focus(function(){
		if (this.value == sDefaultTxt)
			this.value = '';
	});
	$("#formZoeken-zoek").blur(function(){
		if (this.value == '')
			this.value = sDefaultTxt;
	});
		
	// audiofragmenten
	if ($('#bodyAgenda').length) {
		if ($('#audioFragmenten').length) {
			if (typeof swfobject != 'undefined'  && swfobject.hasFlashPlayerVersion('7')) {
				$('#audioFragmenten .mediafragment').click(function() {
					$(this).siblings().removeClass('active');
					$('#audioplayer').remove();
					var sUri = $(this).find('a').attr('href');
					var oUri = parseUri(sUri);
					if (oUri.domain != '')
						sFile = oUri.protocol + '://' + oUri.domain + oUri.path;
					else
						sFile = oUri.path;
					
					$('#audioFragmenten').append('<div id="audioplayer"></div>');

					var so = swfobject.createSWF({
						data:"/flash/audioplayer.swf?playMe=true&myFile=" + sFile,
						width: '125', height: '10'}, { bgcolor: '#ffffff' }, 'audioplayer'); 
	    			if (so) {
						$(this).addClass('active');
						return false;
					}
				})
				.hover(
					function(){	$(this).addClass('hover') },
					function(){	$(this).removeClass('hover') }
				);
			}			
		}
	}
	
});



function addLoadEvent(func)
{
	var oldonload = window.onload;
	if(typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

/* parseUri JS v0.1, by Steven Levithan (http://badassery.blogspot.com)
*/
function parseUri(sourceUri){
    var uriPartNames = ["source","protocol","authority","domain","port","path","directoryPath","fileName","query","anchor"];
    var uriParts = new RegExp("^(?:([^:/?#.]+):)?(?://)?(([^:/?#]*)(?::(\\d*))?)?((/(?:[^?#](?![^?#/]*\\.[^?#/.]+(?:[\\?#]|$)))*/?)?([^?#/]*))?(?:\\?([^#]*))?(?:#(.*))?").exec(sourceUri);
    var uri = {};
    
    for(var i = 0; i < 10; i++){
        uri[uriPartNames[i]] = (uriParts[i] ? uriParts[i] : "");
    }

    if(uri.directoryPath.length > 0){
        uri.directoryPath = uri.directoryPath.replace(/\/?$/, "/");
    }
    
    return uri;
}
