/*
 * jQuery Beukenrode Conferentiecentrum controls
 */

$(document).ready(function(){
	var carousel = $("#carousel").size();
	if (carousel) {
		$('#carousel').galleryScroll({
			btPrev: 'a.link-prev',
			btNext: 'a.link-next',
			holderList: 'div.gallery',
			scrollElParent: 'ul',
			scrollEl: 'li',
			slideNum: false,
			duration : 1000,
			step: false,
			circleSlide: true,
			disableClass: 'disable',
			funcOnclick: null,
			slideNum:'div.swicher',
			autoSlide: 5000
		});
	}
	
	var photoGallery = $("#photogallery").size();
	if (photoGallery) {	
		$("#photogallery a").fancybox({
		});
	}

	var filmBeukenrode = $(".film-beukenrode").size();
	if (filmBeukenrode) {	
		$(".film-beukenrode").fancybox({
			'width'					: 439,
			'height'				: 300,
			'autoScale'			: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'type'					: 'iframe',
			'centerOnScroll': true
		});
	}

	var open720500 = $(".open720500").size();
	if (open720500) {		
		$(".open720500").fancybox({
			'width'					: 720,
			'height'				: 500,
			'autoScale'			: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'type'					: 'iframe',
			'titleShow'			:	false
		});
	}
	
	var open720275 = $(".open720275").size();
	if (open720275) {		
		$(".open720275").fancybox({
			'width'					: 720,
			'height'				: 275,
			'autoScale'			: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'type'					: 'iframe',
			'titleShow'			:	false
		});
	}
		
	var roomGallery = $("a.roomGallery").size();
		if (roomGallery) {
		$("a.roomGallery").fancybox();
	}
	
	var externalLinks = $(".main-container a").size();
	if (externalLinks) {
		$('.main-container a').filter(function() {
			return this.hostname && this.hostname !== location.hostname;
		}).addClass('externalLink').attr("target","_blank");
	}
	
	var titles = $(".image-list").size();
	if (titles) {
		$(".image-list [title]").colorTip({color:'yellow'});
	}
	
	var contactForm = $("#contact").size();
	if (contactForm) {
		var container = $('div.errorbox');
		var validator = $("#contact").validate({
			invalidHandler: function() {
				$(".gmapbox").hide();
			},
			errorContainer: container,
			errorLabelContainer: $("ol", container),
			wrapper: 'li',
			meta: "validate",
			onfocusout: false,
			onkeyup: false,
			onsubmit: true,
		});
	}
	var quickContactForm = $("#quick-contact").size();
	if (quickContactForm) {
		var container = $('div.errorbox');
		var validator = $("#quick-contact").validate({
			invalidHandler: function() {
				$("#text").hide();
			},
			errorContainer: container,
			errorLabelContainer: $("ol", container),
			wrapper: 'li',
			meta: "validate",
			onfocusout: false,
			onkeyup: false,
			onsubmit: true,
		});
	}
	var nieuwsbriefForm = $("#quick-nieuwsbrief").size();
	if (nieuwsbriefForm) {
		var container = $('div.errorbox');
		var validator = $("#quick-nieuwsbrief").validate({
			errorContainer: container,
			errorLabelContainer: $("ol", container),
			wrapper: 'li',
			meta: "validate"
		});
	}
	
	var offerteForm = $("#offerte").size();
	if (offerteForm) {
		var container = $('div.errorbox');
		var validator = $("#offerte").validate({
			invalidHandler: function() {
				$(".gmapbox").hide();
			},
			errorContainer: container,
			errorLabelContainer: $("ol", container),
			wrapper: 'li',
			meta: "validate",
			onfocusout: false,
			onkeyup: false,
			onsubmit: true,
		});
	}
	
	var formDateField = $("#offerte-datum").size();
	if (formDateField) {
		$("#offerte-datum").datepicker({
			minDate: 0,
			dateFormat: 'dd/mm/yy'
		});
	}

	var googleMapDiv = $("#gmap").size();
	if (googleMapDiv) {
		var target = null;
		if (!GBrowserIsCompatible()) {
			return;
		}
		if ((target = document.getElementById("gmap")) == false) {
			return false;
		}
		var point = new GLatLng(52.041082,5.318445);
		var icon = new GIcon();
		icon.image = "http://www.beukenrode.nl/conferentiecentrum/assets/media/images/icn-google-maps_large.png";
		icon.iconSize = new GSize(54, 63);
		icon.iconAnchor = new GPoint(27, 59);
		var map = new GMap2(target);
		map.setCenter(point, 12);
		map.addControl(new GLargeMapControl3D());
		marker = createMarker(point,icon);
		map.addOverlay(marker);
		
	}
});

$(document).unload(function() {
	GUnload();
});
		
function createMarker(point,icon) {
	var marker = new GMarker(point,icon);
	GEvent.addListener(marker, "click", function() {
	});
	return marker;
}

