$(document).ready(function() {	

	/*$("#nav li a, .infobutton").click(function() {
		$.ajax({
			url: '/ajax-main',
			data: { datatype : $(this).attr('id') },
			type : 'post',
			dataType: 'json',
			success: function(data) {
				$("#textbox").html(data.textbox);
				$("#pagetitle").html(data.title);		
			}
		});	
	}); */
           						
	$("#nav a, .prev, .next, #special-menu a").click(function() {
		loaderHeaderText(this) 
	});
	
	if($('#hofleverancier').length > 0) {
		loaderHeaderText('#special-menu a');		
	}
	
	if($('#contact').length > 0) {
		loaderHeaderText("a#Contact");		
	}
	
	// Google Maps voor Contact
	$('#map_canvas').googleMaps( {		
		markers: {
            latitude: 	52.018087,
            longitude: 4.65685,
            info: {
                layer: '#address',
				popup: false
            }			
        }		
	});
	
	$('#nav > li').bind('mouseover', nav_open);
	$('#nav> li').bind('mouseout',  nav_timer);
});

function loaderHeaderText(target) {
	$.ajax({
		url: '/ajax-main',
		data: { datatype : $(target).attr('rel') },
		type : 'post',
		dataType: 'json',
		success: function(data) {
			$("#textbox").html(data.textbox);
			$("#pagetitle").html(data.title);
			if (data.infobutton != '') {
				$('.infobutton').fadeOut(300, function() {
					$(".infobutton").html(data.infobutton);
				});
			}
		}
	});	
}

function loadSubText(target) {
	$.ajax({
		url: '/ajax-main',
		data: { datatype : $(target).attr('rel') },
		type : 'post',
		dataType: 'json',
		success: function(data) {
			$("#textbox").html(data.textbox);
			$("#pagetitle").html(data.title);
			if (data.infobutton != '') {
				$('.infobutton').fadeOut(300, function() {
					$(".infobutton").html(data.infobutton);
					$(".infobutton").fadeIn(300);
				});
			}
		}
	});	
}


function Animate2id(id, ease) { 
	$('.infobutton').fadeOut(300);
    var animSpeed = 1500; 
    var easeType = ease ? ease : "easeInOutExpo";

	$("#container-ease").stop();
	$('.prev, .next').hide();
    $("#container-ease").animate({"left": -($(id).position().left)}, animSpeed, easeType, function() {
		$('.prev, .next').fadeIn(500);
		$('.infobutton').fadeIn(300);
	});
	return false;
}

var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function nav_open() {
	nav_canceltimer();
	nav_close();
	ddmenuitem = $(this).find('ul').css('visibility', 'visible');
}

function nav_close() {
	if(ddmenuitem) {
		ddmenuitem.css('visibility', 'hidden');
	}
}

function nav_timer() {
	closetimer = window.setTimeout(nav_close, timeout);
}

function nav_canceltimer() {
	if(closetimer) {
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

document.onclick = nav_close;


