$(document).ready(function(){
	$('input.button').hover(
		function() {
			$(this).css({
				border: "#666 1px solid"
			});
		},
		function() {
			$(this).css({
				border: "#ccc 1px solid"
			});
		}
	);
	
	/**
	 *	Admin paneel
	 */	 	
	
	$('.sluit_admin_paneel').click(function(){
		tb_remove();
	});
	
	/**
	 *	Module contact:
	 */	 	
	
	$('#contactform').submit(function() {
		$('#contact_proces').show();
		$('#contactform').hide();
		$('#contact_result').hide();
		$.get("/ajax/contact_formulier_verzenden", { 'contact': "Verzenden", naam: $('#naam').val(), email: $('#email').val(), onderwerp: $('#onderwerp').val(), bericht: $('#bericht').val() },
			function(data) {
				$('#contact_result').show();
				$('#contact_result').html(data);
				$('#contact_proces').hide();
				$('#contactform').show();
			}
		);
		return false;
	});
	
	// EditPanel:
	
	/**$('.editInPanel').click(
		function() {
			$('.editPanel').remove();
			var titel = $(this).attr('title');
			$(this).parent().append('<div class="editPanel"><!--<a href="javascript:closeEditPanel();">Paneel sluiten</a>--><div class="editPanelTitel">'+titel+'</div><div class="editPanelContent"></div></div>');
			$('.editPanelContent').load($(this).attr('href'), function() {
				$('.editPanel').slideDown('slow');								
			});
			return false;
		}
	); */
	
	// Blog:
	
	$('.blogSearch input').keyup(
		function() {
			var q = $(this).val();
			var url = $('.blogSearch').attr('action');
			$.ajax({
				type: "GET",
				url: url+q,
				success: function(msg){
					$('#leftBig').html(msg);
				}
			});
		}
	);
	
	// Gebruikers:
	
	$('.users').flexigrid({
		height:'auto',
		striped: true,
	});
	
	// Muziek:
	
	$('.listenTrack').click(
		function() {
			$('.trackTitel').html($(this).attr('title'));
			$('#track').html('<embed src="'+$(this).attr('href')+'" height="30" autostart="true" width="300" style="background-color: #ff0090;"></embed>');
			return false;
		}
	);
	
	// Fotoalbum:

	$("#thumbs a").click(function(){
		$("#largeImg").hide();
		$('#loadingImage').show();
	
		var largePath = $(this).attr("href");
		var largeAlt = $(this).attr("title");
		
		$("#largeImg").attr({ src: largePath, alt: largeAlt });
		$("#largeImg").one("load",function() {
			$('#loadingImage').hide();
			$("#foto").css({
				'text-align': 'center'
			});
			$("#largeImg").fadeIn(1000);
		});
		
		$("h2 em").html(" (" + largeAlt + ")"); 
		return false;
	});
	
	$('.galNavArrow').css({
		opacity: '.5',
		filter: 'alpha(opacity=50)',
		'-moz-opacity': '.5'
	});
	
	$('.galNavArrow').hover(
		function() {
			$(this).css({
				opacity: '1',
				filter: 'alpha(opacity=100)',
				'-moz-opacity': '1'
			});
		},
		function() {
			$(this).css({
				opacity: '.5',
				filter: 'alpha(opacity=50)',
				'-moz-opacity': '.5'
			});
		}
	);
	
	// Edit fotoalbum:
		
	$('.subTitle').keyup(function() {
		var url = $(this).attr('title');
		var val = $(this).val();
		
		$.post(url, { titel: val },
  			function(data){
    			//alert("Data Loaded: " + data);
    			$('.albumTitel').html(val);
  			}
		);
		return false;
	});
	
	$('.albumBeschrijving').keyup(function() {
		var url = $(this).attr('title');
		var val = $(this).val();
		
		$.post(url, { tekst: val },
  			function(data){
    			//alert("Data Loaded: " + data);
    			$('.albumTekst').html(val);
  			}
		);
		return false;
	});
	
	$(".editThumb .delete").click(function() {
		if (confirm("Weet je zeker dat je deze foto wilt verwijderen? Dit kan niet ongedaan worden gemaakt.")) {
		
			var url = $(this).attr('title');
			var foto = $(this).attr('alt');
			
			$.post(url, { foto: foto },
  				function(data) {
    				//alert("Data Loaded: " + data);
    				
  				}
			);
			
			$(this).parents('.editThumb').animate({ opacity: 'hide' }, "slow");
		}
	});
	
	//
});

function closeEditPanel() {
	tb_remove();
}

function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' moet een emailadres bevatten.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is verplicht.\n'; }
    } if (errors) alert('Er zijn fouten opgetreden:\n'+errors);
    document.MM_returnValue = (errors == '');
} }

// File uploader

function startUpload(){
	$('#f1_upload_process').show();
	$('#fl_upload_form').hide();
	$('#fl_upload_result').hide();
	return false;
}

function stopUpload(data) {
	// Resultaat weergeven
	$('#fl_upload_result').show().html(data+'<br /><p><a href="javascript: history.go(0);">Vernieuw de pagina om de nieuwe foto\'s te kunnen zien.</a></p>');
	$('#f1_upload_process').hide();
	$('#fl_upload_form').show();
	$('#file').attr("value","");
	$('#track').attr("value","");
	return false;
}

function broncode_opslaan(broncode, bestand) {
	$.post("ajax/ajax.broncode.php", { broncode: broncode, bestandsnaam: bestand });
}
