/**
 * @author koenbuekenhout
 */
jQuery(document).ready(function(){
	loadFlickrImages("45756509@N02");
	$("td[rel]").overlay({
		effect: 'apple',
		expose: {
			color: '#333',
			loadSpeed: 200,
			opacity: 0.5
		}
	}); 
	highlightMenu();
});

function highlightMenu() {
	$("table.menu tr td").hover( 
	    function() { 
			$(this).addClass('highlight'); 
	    },  
	    function() { 
			$(this).removeClass('highlight');
	    } 
	); 
}

function activateLightBox() {
	$('#image_gallery a:first').click();
}

function loadFlickrImages(flickrid) {
	// Request the JSON and process it
	$.ajax({
		type:'GET',
		url:"http://api.flickr.com/services/feeds/photos_public.gne",
		data:"id="+flickrid+"&lang=en-us&format=json&jsoncallback=?",
		success:function(feed) {
			// Create an empty array to store images
			var thumbs = [];
			var flyers = [];

			// Loop through the items
			for(var i=0, l=feed.items.length; i < l && i < 16; ++i) 
			{
				// Manipulate the image to get thumb and medium sizes
				var img = feed.items[i].media.m.replace(
					/^(.*?)_m\.jpg$/, 
					'<a href="$1.jpg" title="' + feed.items[i].title + '"></a>'
				);

				if(feed.items[i].tags != null && feed.items[i].tags == "flyer") {
					// Add the new element to the flyer array
					flyers.push(img);	
				} else {
					// Add the new element to the array
					thumbs.push(img);
				}
			}

			// Display the thumbnails on the page
			$('#image_gallery').html(thumbs.join(''));
			
			//Set the lightbox on the images
			$('#image_gallery a').lightBox({
				fixedNavigation:true,
				overlayOpacity: 0.5
			});
			
			//If a flyer exists, load and show the flyer.
			if(flyers.length > 0) {
				loadFlyer(flyers);
			}
		},
		dataType:'jsonp'
	});
}

function loadFlyer(flyers) {
	// Display the thumbnails on the page
	$('#flyer_gallery').html(flyers.join(''));
	
	//Set the lightbox on the images
	$('#flyer_gallery a').lightBox({
		overlayOpacity: 0.5
	});
	$('#flyer_gallery a:first').click();
}

function loadDrinks(){
	var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
	if (is_chrome) {
		$("#menu_drinks").html("Door een probleem in Goolge Chrome wordt de kaart in een apart venster geopend. Dit probleem zou verholpen worden in de volgende versie van Goolge Chrome.");
		window.open('drinks.pdf');
	} else {
		$("#menu_drinks").html("<iframe src='drinks.pdf#toolbar=0'></iframe>");
	}
}

function loadFood() {
	var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
	if (is_chrome) {
		$("#menu_food").html("Door een probleem in Goolge Chrome wordt de kaart in een apart venster geopend. Dit probleem zou verholpen worden in de volgende versie van Goolge Chrome.");
		window.open('food.pdf');
	} else {
		$("#menu_food").html("<iframe src='food.pdf#toolbar=0'></iframe>");
	}
}

function loadTakeAway() {
	$("#menu_take_away").html("<iframe src='meeneem.pdf#toolbar=0'></iframe>");
}

function loadFacebook() {
	FB.init("285e8ebe39bf9449bc20acb8b2a24119");
}

function loadContact() {
	setTimeout('initializeMap();', 2000)
}

function initializeMap() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map"));
	map.addControl(new GMapTypeControl());
	map.addControl(new GSmallMapControl());
	map.setCenter(new GLatLng(50.96354, 4.72465), 13);
	
	var marker = new GMarker(new GLatLng(50.96354, 4.72465));
	map.addOverlay(marker);
  }
}

