$(document).ready(function() { 
	$('div#dialog-popup').hide();
	$('div#video-popup').hide();
	$('div#dialog-confirm').hide();
	$('div.widget').corner("10px");
	$('div.widget div.block_loginaccount a').corner("5px");
	$('div.widget input').corner("5px");
	$("div#gallery a").fancybox({
		'titleShow'		: true,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
	$("div#gallery-video a").fancybox({
		'titleShow'		: true,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
});

function openUrlLink(theUrl) {
	window.location=theUrl; 
	return false;
}
function openFormDiv(theUrl, ckeditorField, formTitel) {
	$("#dialog-popup").dialog("destroy");
	$.get(theUrl, function(data) {
		$('#dialog-popup').html(data);
		$("#dialog-popup").dialog({
			resizable: true,
			title: formTitel,
			height: 650,
			width: 650,
			modal: true,
			closeOnEscape: true,
			buttons: false,
			close: function(event, ui) {
				var reloadme = '';
				if ( ckeditorField.length > 1 ) reloadme = 'reload';
				closeFormDiv(ckeditorField, reloadme);
		}
		});
	});
}
function deleteFormDiv(theUrl, btnDelete, btnCancel) {
	$("#dialog-confirm").dialog("destroy");
	$("#dialog-confirm").dialog({
		resizable: true,
		title: 'Dialog Title',
		height:180,
		width:300,
		modal: true,
		closeOnEscape: true,
		buttons: {
			'Ok': function() {
				$.get(theUrl, function(data) {
					setTimeout ("closeFormDiv('', 'reload')", 1000);
				});				
				$(this).dialog('close');
			},
			'Annuleren': function() {
				//$(this).hide('fast');
				$(this).dialog('close');
			}
		}
	});
}
function postFormDiv(theUrl, values, ckeditortoclose, formName) {
	$.ajax({
		  type: 'POST',
		  url: theUrl,
		  async: true,
		  data: values,
		  success: function(msg){ 
				if (msg.substr(0,3) == "OK-") {
					//disable button
    				$('input[type=submit]', $('#'+formName)).attr('disabled', 'disabled')
    				//show message
					$('#messageForm').html(msg.substr(3)).addClass('successmsgForm');
					//Close after 3 seconds
					setTimeout ("closeFormDiv('"+ckeditortoclose+"', 'reload')", 3000);
				} else if (msg.substr(0,4) == "AOK-") {
					//disable button
    				$('input[type=submit]', $('#'+formName)).attr('disabled', 'disabled')
    				//show message
					setTimeout ("closeFormPage('"+msg.substr(4)+"')", 3000);
				} else {$('#messageForm').html(msg).addClass('errormsgForm');}
				$('#messageForm').show('fast'); 
			},
		  error: function(){alert( "An error occurred" );},
		  complete: function(){	}
	});
	return false;
}

function uploadImageDiv(theUrl, formName, values) {
	$.ajaxFileUpload({
        url: 			theUrl+'/'+values, 
        secureuri: 		false,
        fileElementId: 	'fld_file',
        dataType:  		'json',
        success: 		function (data, status) {
    		if(typeof(data.error) != 'undefined') { 
    			if (data.error == '') { 
    				//disable button
    				$('input[type=submit]', $('#'+formName)).attr('disabled', 'disabled')
    				//show message
    				$('#messageForm').html(data.msg).addClass('successmsgForm');
					$('#messageForm').show('fast');
					//Close after 3 seconds
					setTimeout ("closeFormDiv('', 'reload')", 3000);
    			} else {
					$('#messageForm').html(data.error).addClass('errormsgForm');
					$('#messageForm').show('fast');
    			}
    		}
        },
        error: 			function (data, status, e) { 
    			$('#messageForm').html(e + status).addClass('errormsgForm');
    			$('#messageForm').show('fast'); 
        	}
    });
    return false;
}

function closeFormDiv(ckeditorToClose, reloadScreen) {
	if ( reloadScreen != '' ) { window.location=document.location.href;}
	if ( ckeditorToClose != '' ) { var e= CKEDITOR.instances[ckeditorToClose]; e.destroy();	e= null;}
}

function closeFormPage(reloadUrl) {
	window.location=reloadUrl;
}

function showVideo(theUrl, thisWidth, thisHeight, thisTitle) {
	$("#video-popup").dialog("destroy");
	$.fx.speeds._default = 1;
	$.get(theUrl, function(data) {
		$('#video-popup').dialog({
			show: 'blind',
			hide: 'blind',
			resizable: false,
			title: 	thisTitle,
			height: (thisHeight+30),
			width: 	thisWidth,
			dialogClass: 'videoClass',
			modal: true,
			closeOnEscape: true,
			buttons: false
		});
		$('#video-popup').html(data);
	});
}

