$(function(){
	$('#button-tell-a-friend').overlay({
		target : '#overlay'
	});

	/**
	 * Hoofdmenu
	 */
	$('#top-menu .knop').hover(function(){
		$(this).find('.submenu:eq(0)').stop(true, true).slideDown();
	},function(){
		$(this).find('.submenu:eq(0)').slideUp();
	});

	$('.subitem').hover(function(){
		$(this).find('.submenu').stop(true,true).fadeIn();
	},function(){
		$(this).find('.submenu').hide();
	});

	$('.submenu > .submenu').hover(null,function(){
		$(this).fadeOut();
	});

	//Nieuw inladen live beelden
	$('#right-menu-news').click(function(){
		$('#player').load('live.php');
	});

	/**
	 * Links menu
	 */
	$('#left-menu .item').hover(function(){
		$(this).find('.hover').stop(true, true).fadeIn();
	},function(){
		$(this).find('.hover').fadeOut();
	});
	$('.submenu').hide();
	$('#left-menu .item .hover').hide();

	/**
	 * Vergroot glas
	 */
	$('.zoom')
		/*.hover(function(){
			$(this).find('.zoom-icon').stop(true, true).fadeIn();
		},function(){
			$(this).find('.zoom-icon').stop(true, true).fadeOut();
		})*/
		.fancybox()
		.append('<img class="zoom-icon" src="http://www.derooijehoeven.nl/images/magnifier_zoom_in.png">')

	/**
	 * Debug
	 * TODO opbokken
	 */
	$('a[href=#]').css('text-decoration', 'line-through');
});

/* Laat alle plaatjes op de huidige pagina in een overzicht zien met de bijbehorende
 * hoogtes en breedtes
 */
function showimages()
{
	var build = '<div id="img_overzicht">';

	$('img').each(function(){
		build+= '<img src="'+$(this).attr('src')+'"><br><br>';
	});

	$('body').html(build);

	$('img').each(function(){
		$(this).after(' <b>Breedte:</b> ' + $(this).width() + 'px, <b>Hoogte:</b> ' + $(this).height() + 'px, <b>Url:</b> ' + getPath($(this).attr('src') ) );
	});
}

function getPath( url )
{
	var hostname = 'http://' + window.location.hostname + '/derooijehoeven.blhuisvesting.nl';
	var location = window.location.href;

	if( url.indexOf(hostname) !== -1 ) {
		return url.replace(hostname, '');
	}
	var newUrl = window.location.pathname + url;

	return newUrl.replace('/derooijehoeven.blhuisvesting.nl','');
}

function createGallery(element)
{
	var pointer = 0;
	var gallerij = [];
	var gallery = $(element).get();

	$('img', gallery).hide();
	$('img:first', gallery).show();

	$('img', gallery).each(function(){
		gallerij.push($(this).attr('src'));
	});

	setInterval(function(){
		pointer++;
		if( pointer > gallerij.length-1 ) {
			pointer = 0;
		}

		$('img:first', gallery).ImageSwitch({
			Type: 'FadeIn',
			NewImage: gallerij[pointer],
			Speed: 2000
		});
	},4000);
}
