$(document).ready(function($){
    
		menuFade();
    slideShow(4000);  
    $('#gallery a').lightBox();
		$('ul#mikkola_calendar').hide();
    setCalendar();
		$('#randomimage').css({'opacity': 0.5});
});

function formcheck_gastenboek()
{
	if (document.formname.nm.value=="")
	{
		alert("Gelieve je naam in te vullen.");
		document.formname.nm.focus();
		return false
	}
	if (document.formname.bn.value!="")
	{
		if (document.formname.bn.value.indexOf("@")==-1 || document.formname.bn.value.indexOf(".")==-1 || document.formname.bn.value.length<6) 
		{
			alert("gelieve je e-mailadres correct in te vullen.");
			document.formname.bn.focus();
			return false
		}
	}
	else
	{
		alert("gelieve je e-mailadres in te vullen.");
			document.formname.bn.focus();
			return false
	}
	if (document.formname.comments.value=="")
	{
		alert("Gelieve een bericht in te vullen.");
		document.formname.comments.focus();
		return false
	}
}

function formcheck_contact()
{
	if (document.formname.ab.value=="")
	{
		alert("Gelieve je naam in te vullen.");
		document.formname.ab.focus();
		return false
	}
	if (document.formname.bem.value!="")
	{
		if (document.formname.bem.value.indexOf("@")==-1 || document.formname.bem.value.indexOf(".")==-1 || document.formname.bem.value.length<6) 
		{
			alert("Er zit een fout in je email adres.");
			document.formname.bem.focus();
			return false
		}
	}
	else
	{
		alert("Gelieve je email adres in te vullen.");
		document.formname.bem.focus();
		return false
	}
	if (document.formname.message.value=="")
	{
		alert("Gelieve een bericht of vraag in te vullen.");
		document.formname.message.focus();
		return false
	}
}

var firstTime=true;

function menuFade() {
    $('#main_nav li, #main_nav2 li').removeClass('hover');
    $('#main_nav li a, #main_nav2 li a').append('<span class="hover"></span>').each(function () {
        var $span = $('> span.hover', this).css('opacity', 0);
        $(this).hover(function () {
            $span.stop().fadeTo(300, 1);
        }, function () {
            $span.stop().fadeTo(700, 0);
        });
    });
}

function slideShow(speed) {  
    //append a LI item to the UL list for displaying caption  
    $('ul.slideshow').append('<li id="slideshow-caption" class="caption"><div class="slideshow-caption-container"><h3></h3></div></li>');  
	
    //Set the opacity of all images to 0  
    $('ul.slideshow li').css({
        opacity: 0.0
    });  
			
    //Get the first image and display it (set it to full opacity)  
    $('ul.slideshow li:first').css({
        opacity: 1.0
    });  
			
    //Get the caption of the first image from REL attribute and display it  
    $('#slideshow-caption h3').html($('ul.slideshow a:first').find('img').attr('title'));  
					
    //Display the caption  
    $('#slideshow-caption').css({
        opacity: 0.7, 
        bottom:0
    });  
			
    //Call the gallery function to run the slideshow      
    var timer = setInterval('gallery()',speed);  
			
    //pause the slideshow on mouse over  
    $('ul.slideshow').hover(  
        function () {  
            clearInterval(timer);     
        },    
        function () {  
            timer = setInterval('gallery()',speed);           
        }  
        );  		
}  
	
function gallery() {  
    //if no IMGs have the show class, grab the first image  
    var current = ($('ul.slideshow li.show')?  $('ul.slideshow li.show') : $('#ul.slideshow li:first'));  
	
    //Get next image, if it reached the end of the slideshow, rotate it back to the first image  
    var next = ((current.next().length) ? ((current.next().attr('id') == 'slideshow-caption')? $('ul.slideshow li:first') :current.next()) : $('ul.slideshow li:first'));  
					
    //Get next image caption  
    var title = next.find('img').attr('title');   
    var desc = next.find('img').attr('alt');      
					
    //Set the fade in effect for the next image, show class has higher z-index  
    next.css({
        opacity: 0.0
    }).addClass('show').animate({
        opacity: 1.0
    }, 1000);  
			
    //Hide the caption first, and then set and display the caption  
    $('#slideshow-caption').animate({
        height: '-=40px',
        bottom: '+=0px'
    }, 500, function () {
															 
        //Display the content
        $('#slideshow-caption h3').html(title);
        $('#slideshow-caption').animate({
            height: '+=40px',
            bottom: '0px'
        }, 300);	
    });   
	
    //Hide the current image  
    current.animate({
        opacity: 0.0
    }, 1000).removeClass('show');  
}

function setCalendar(){
		var events = new Array();
		$('ul#mikkola_calendar li').each(function() {
				events[events.length] = {
				 'EventID': $(this).attr('id'),
				 'StartDateTime': $('.datum', this).attr('id'),
				 'Title': "Cross",
				 'URL': "#",
				 'Description': $('.info', this).html()
			 };
		});
		
    var options = {
        onMonthChanging: function(dateIn) {
            $.jMonthCalendar.ReplaceEventCollection(events);
            return true;
        },
        onEventLinkClick: function(event) { 
            setCalendarEvent(event);
            return true; 
        },
        onEventBlockClick: function(event) { 
            setCalendarEvent(event);
            return true; 
        },
        onEventBlockOver: function(event) {
            //alert(event.Title + " - " + event.Description);
            return true;
        },
        onEventBlockOut: function(event) {
            return true;
        },
        navLinks: {
            enableToday: true,
            enableNextYear: true,
            enablePrevYear: true,
            p:'‹ Vorig',
            n:'Volgend ›',
            t:'Nu'
        },
        firstDayOfWeek: 1,
        dragableEvents: false,
        locale: {
            days: ["Zondag", "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"],
            daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
            daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
            months: ["Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December"],
            monthsShort: ["Jan", "Feb", "Maa", "Apr", "Mei", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"],
            weekMin: 'wk'
        }
    };		
		
    $.jMonthCalendar.Initialize(options, events);		
};

function getMaand(maand){
    switch(maand){
        case 0:
            maand="Januari";
            break;
        case 1:
            maand="Februari";
            break;
        case 2:
            maand="Maart";
            break;
        case 3:
            maand="April";
            break;
        case 4:
            maand="Mei";
            break;
        case 5:
            maand="Juni";
            break;
        case 6:
            maand="Juli";
            break;
        case 7:
            maand="Augustus";
            break;
        case 8:
            maand="September";
            break;
        case 9:
            maand="Oktober";
            break;
        case 10:
            maand="November";
            break;
        case 11:
            maand="December";
            break;
    }
    return maand;
}

function setCalendarEvent(event){
    //alert(event.Description);
    var dag=event.StartDateTime.getDate();
    var month=getMaand(event.StartDateTime.getMonth());
    var jaar=event.StartDateTime.getFullYear();
	
    var htmlText='<div class="list_item" style="margin-top: 0;">' + dag + ' ' + month + ' ' + jaar + '</div><p>' + event.Description + '</p>';
	
    if(firstTime==true)
    {
        $('#calendar_event').hide();
        $('#calendar_event').html(htmlText).show(400);
        $('#agenda').animate({
            "margin-top": 0
        },400);
        firstTime=false;
    } else {
        $('#calendar_event').fadeTo(400,0, function() {
            $(this).html(htmlText);
        });
				$('#calendar_event').fadeTo(400,1);
				
    }
}
