// run the code in the markup!
$(function() {
	$('code.jquery').each(function() {
		eval($(this).text());
	});
	
	/* loginForm AJAX */
	$('#login').colorbox({ href: '/libs/content.php?check=loginform', innerHeight: 300 } ,function() { 
			$('.focus').focus();
	});
	
	/* loginform Ajax script */
	$("input[name='submit_login']").live('click',function(event){
		$('#loginError').slideUp();
		$.post('/libs/content.php?check=login', {pid: $('body').attr('id'), user_name: $('input[name=loginname]').val(), user_pass: $('input[name=password]').val(), redirect: $('input[name=redirect]').val(), remind: $('#remind:checked').val() }, function(data){
			if(data.success) {
				if(data.redirect) {
					location.href=data.redirect;
				}
				else
					location.href=window.location.pathname;
			}
			else {
				$('#loginError').html(data.message).fadeIn();	
			}
		
		}, 'json');
		event.preventDefault();
	});
	
	/* logout Ajax script */
	$('#logout').click(function(event) { 
		var host = window.location.host;
		$.post('/libs/content.php?check=logout', { host: host }, function(data){
			if(data.success && data.cookie) {
				alert("U bent nu veilig uitgelogd en uw gegevens worden niet meer onthouden op deze computer.");
				location.href=window.location.pathname;
			}
			else if(data.success && !data.cookie) {
				alert("U bent nu veilig uitgelogd.");
				location.href=window.location.pathname;
			}
			else {
				location.href=window.location.pathname;
			}
		
		}, 'json');
		event.preventDefault();
	});	
	
	/* lost password AJAX */
	$('#lostpassword').live('click', function(e) {
		e.preventDefault();
		$.fn.colorbox({ href:$(this).attr('href'), open:true, width: '400' } ,function() { 
			$('.focus').focus();
			$('form[name=contentForm]').submit(function() {
				var action = $(this).attr('action');
				$.post(action, { email_address : $("input[name='email_address']").val() }, function(data){
					if(data.success) {
						$('#result').attr('style','text-align:center;padding:5px;background-color:#99FF00;').html('Het nieuwe wachtwoord is verstuurd!').fadeIn();
						setTimeout(function() {
							$.fn.colorbox.close();
						}, 2500); 
					}
					else if(data.notvalid) {
						$('#result').attr('style','color:#FFFFFF;text-align:center;padding:5px;background-color:#FF0000;').html('Vul een geldig e-mail adres in!').fadeIn();
					}
					else if(data.unknownuser) {
						$('#result').attr('style','color:#FFFFFF;text-align:center;padding:5px;background-color:#FF0000;').html('Dit e-mail adres is onbekend...').fadeIn();
					}
				}, 'json');
				return false;
			});
			return false;
		});									  									  
	});
	
	/* bookmarking */
	$("a.jQueryBookmark").click(function(e){
		e.preventDefault(); // this will prevent the anchor tag from going the user off to the link
		var bookmarkUrl = this.href;
		var bookmarkTitle = this.title;
		if (window.sidebar) { // For Mozilla Firefox Bookmark
			window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
		} else if( window.external || document.all) { // For IE Favorite
			window.external.AddFavorite( bookmarkUrl, bookmarkTitle);
		} else if(window.opera) { // For Opera Browsers
			$("a.jQueryBookmark").attr("href",bookmarkUrl);
			$("a.jQueryBookmark").attr("title",bookmarkTitle);
			$("a.jQueryBookmark").attr("rel","sidebar");
		} else { // for other browsers which does not support
			 alert('Uw browser bied hiervoor geen ondersteuning. Probeer met uw browser een bladwijzer te maken.');
			 return false;
		}
	});

	/* colorbox loading content from images link with alt and group */
	$("a.showContent").live('click', function(e){
		$.fn.colorbox({ href: $(this).attr('href'), title: $(this).find("img").attr('alt'), rel: $(this).attr('rel'), next:'volgende', previous: 'vorige', close: 'sluiten', current: "{current} van {total}" });
		e.preventDefault();
	});
	/* colorbox loading content from inline div html without title (scrolling false */
	/* $("a.showInline").live('click', function(e){
		$.fn.colorbox({ inline: true, href: $(this).attr('href'), rel: $(this).attr('rel'), next:'volgende', previous: 'vorige', close: 'sluiten', current: "{current} van {total}", scrolling: false });
		e.preventDefault();
	}); */
	
	$("a.showInline").colorbox({ inline:true, next:'volgende', previous: 'vorige', close: 'sluiten', current: "{current} van {total}", rel: 'group', scrolling: false });
	
	$("#Content img").css('cursor','pointer');
	
	$("#Content img[class!='link']").colorbox({ href: function(){ 
		var srcPath = $(this).attr('src');
			if(srcPath.indexOf(".thumbs/")) {
				srcPath = srcPath.replace(".thumbs/","");
			}
			return srcPath; 
		} , next:'volgende', previous: 'vorige', close: 'sluiten', current: "{current} van {total}", rel: 'group' });
	
});
