$(document).ready(function() {
	/* ------------------------------------------------- */
	/* MAKE ALL MODAL WINDOWS > MODAL :)
	/* ------------------------------------------------- */
		if($.browser.msie)
		{
			$('div.modal').draggable({containment:'window', refreshPositions:true});
		}
		else
		{
			$('div.modal').draggable({opacity:0.75, containment:'window', refreshPositions:true});
		}
	/* ------------------------------------------------- */
	/* OPEN/CLOSE MODAL WINDOW
	/* ------------------------------------------------- */
		$('div.modal a.btn-close').click(function(e) {
			e.preventDefault();
			var box = $(this).parent();
			if(box.hasClass('closed')) {
				box.removeClass('closed');
			} else {
				box.addClass('closed');
			}
		});
	/* ------------------------------------------------- */
	/* INIT TOGGLE
	/* ------------------------------------------------- */
		$('div.thumbnails').hide();
	/* ------------------------------------------------- */
	/* SCROLLABLE MODAL WINDOWS
	/* ------------------------------------------------- */
	if($('div.dynamic').size() > 0)
	{
		// +++++++++++++++++++++++++++++++++++++++++++++ */
		// DYNAMISCHE THUMBSTRIP
		// ********************************************* */
		api = $('div.content').scrollable({
				size:1,
				items:'div.content-wrapper',
				next:'a.btn-next',
				prev:'a.btn-prev',
				globalNav:true,
				clickable:false
			}).mousewheel({api:true});
			
		$('div.content div.content-wrapper div.content-item:first').each(function() {
			setupPhotobtns($(this));
		});
			
		api.onSeek = function(event, index) {
			setupPhotobtns(this.getVisibleItems());
		}
	} else if ($('div.thumbnails').size() > 0) {
		// +++++++++++++++++++++++++++++++++++++++++++++ */
		// NIET DYNAMISCHE THUMBSTRIP
		// ********************************************* */
		if($('#bomen-en-struiken').size() > 0)
		{
			$('div.content').scrollable({
					size:1,
					items:'div.content-wrapper',
					next:'a.btn-next',
					prev:'a.btn-prev',
					globalNav:true,
					clickable:false
			}).mousewheel().navigator({navi:'ul.submenu',naviItem:'a', activeClass:'active'});
		} else {
			$('div.content').scrollable({
					size:1,
					items:'div.content-wrapper',
					next:'a.btn-next',
					prev:'a.btn-prev',
					globalNav:true,
					clickable:false
			}).mousewheel();
		}
		
		$('div.modal #btn-fotos').unbind('click').click(function(e) {
			e.preventDefault();
			$('div.thumbnails').slideToggle(1000,function() { if(!$('div.thumbnails').data('sliderActive')) { $('div.thumbnails').slider(); }});
			$('div.thumbnails').unbind('cbox_next').bind('cbox_next', function(){ $("div.thumbnails a.active").removeClass('active').next().addClass('active'); });
			$('div.thumbnails').unbind('cbox_prev').bind('cbox_prev', function(){ $("div.thumbnails a.active").removeClass('active').prev().addClass('active'); });
		});
		
	} else {
		// +++++++++++++++++++++++++++++++++++++++++++++ */
		// GEEN THUMBSTRIP
		// ********************************************* */
		$('div.content').scrollable({
				size:1,
				items:'div.content-wrapper',
				next:'a.btn-next',
				prev:'a.btn-prev',
				globalNav:true,
				clickable:false
		}).mousewheel();
		$('div.modal #btn-fotos').hide();
	}
	
	/* ------------------------------------------------- */
	/* GEEN SCROLLABLE NODIG
	/* ------------------------------------------------- */
	if($('div.content div.content-wrapper div.content-item').size() < 2) { $('a.btn-next').addClass('disabled'); $('a.btn-prev').addClass('disabled'); }
		
	/* ------------------------------------------------- */
	/* EXTERNAL LINKS
	/* ------------------------------------------------- */
		$('a.external').each(function() {
			$(this).click(function(e) {
				e.preventDefault();
				window.open($(this).attr('href'));
			});
		})
		
	/* ------------------------------------------------- */
	/* INIT GOOGLE MAPS
	/* ------------------------------------------------- */
		if($('#map-canvas').size() > 0) { gMap(); }
		
});

/* ------------------------------------------------- */
/* GOOGLE MAPS PART
/* ------------------------------------------------- */
	function gMap() {
		var geocoder = new google.maps.Geocoder();
		var latlng = new google.maps.LatLng(-34.397, 150.644);
		var myOptions = {
			zoom: 16,
			center: latlng,
			mapTypeControl: false,
			mapTypeId: google.maps.MapTypeId.HYBRID
		};
		map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
		
		if (geocoder) {
			geocoder.geocode({'address':'Berg 26, 9860 Oosterzele'},
				function(results, status) {
					if (status == google.maps.GeocoderStatus.OK) {
						map.setCenter(results[0].geometry.location);
						var marker = new google.maps.Marker({map:map, position:results[0].geometry.location, icon:'img/gmap-flag.png'});
					} else {
						alert("Geocode was not successful for the following reason: " + status);
					}
				});
		}
	}

/* ------------------------------------------------- */
/* SETUP PHOTOS
/* ------------------------------------------------- */
	setupPhotobtns = function(el) {
		var item	= el.attr('id');
		var data	= item.split('-');
		// CLOSE OTHER STRIPS
		$('div.thumbnails:visible').slideToggle(250);
		if(data[2] == 'false')
		{
			$('div.modal #btn-fotos').hide();
		}
		else
		{
			$('div.modal #btn-fotos').fadeIn('fast');
			$('div.modal #btn-fotos').unbind('click').click(function(e) {
				e.preventDefault();
				var strip = $('#strip-' + data[1]);
				strip.slideToggle(1000,function() { if(!strip.data('sliderActive')) { strip.slider(); }});
				$().unbind('cbox_next').bind('cbox_next', function(){ $("#strip-" + data[1] + " a.active").removeClass('active').next().addClass('active'); });
				$().unbind('cbox_prev').bind('cbox_prev', function(){ $("#strip-" + data[1] + " a.active").removeClass('active').prev().addClass('active'); });
			});
		}
	}

/*
	DELAY FUNCTION
*/
$.fn.delay = function( time, name ) {

    return this.queue( ( name || "fx" ), function() {
        var self = this;
        setTimeout(function() { $.dequeue(self); } , time );
    } );

};

/*
	SLIDER FUNCTION
*/
(function($) {
	
	$.slider = function(el, options) {
		// To avoid scope issues, use 'base' instead of 'this'
		// to reference this class from internal events and functions.
		var base = this;
		var moveNextInterval;
		var totalWidth;
		var direction;
		// Access to jQuery version of element
		base.$el = $(el);
		// init class
		base.init = function() {
			// Cache existing DOM elements for later 
			base.$wrapper		= base.$el.find('div.items');
			base.$items			= base.$el.find('div.items a');
			base.$images		= base.$items.find('img').hide();
			base.$item			= base.$items.find(':first');
			base.$next			= base.$el.find('a.next');
			base.$prev			= base.$el.find('a.prev');
			base.$close			= base.$el.find('#close-btn');
			// Setup wrapper
			base.setup();
		}
		// Setup wrapper function
		base.setup = function() {
			totalWidth = 0;
			var i = 0;
			var delay = 100;
			base.$items.each(function() {
				var $item	= $(this);
				var $image	= $(this).find('img');
				var $dummy	= $('<img />').attr('src', $image.attr('src'));
				totalWidth += $item.width();
				if($.browser.msie)
				{
					$image.delay(i * delay).fadeIn('fast', function() { $item.css('background-image','none') }); i++;
				}
				else
				{
					$dummy.unbind().one('load', function() { $image.delay(i * delay).fadeIn('fast', function() { $item.css('background-image','none') }); i++; });
				}
				
				$item.colorbox({transition:'fade', overlayClose:false, speed:500, title:'<span>' + $item.attr('title') + '</span>',transition:'elastic',previous:'<span>previous</span>', next:'<span>next</span>', close:'<span>close</span>', current:'beeld {current} van {total}'});
				$item.click(function() {
					$('a.active').removeClass('active');
					$(this).addClass('active');
				});
			});
			
			base.$close.click(function(e) {
				e.preventDefault();
				$.fn.colorbox.close();
				base.$el.slideToggle(1000);
			});
			
			base.$wrapper.width(totalWidth);
			base.setupNavigation();
		}
		
		base.setupNavigation = function() {
			var windowWidth	= $(window).width();
			base.$next.hover(function() {
				base.$wrapper.animate({'left':(windowWidth - totalWidth)}, 250 * base.$items.size(), 'linear');
			}, function() {
				base.$wrapper.stop(true,false);
			});
			
			base.$prev.hover(function() {
				base.$wrapper.animate({'left':0}, 250 * base.$items.size(), 'linear');
			}, function() {
				base.$wrapper.stop(true,false);
			});
			base.$el.data('sliderActive', true);
		}
		// Trigger the initialization
		base.init();
	}
	
	$.fn.slider = function(options){
		return this.each(function(i) {
			(new $.slider(this, options));
		});
    };
	
})(jQuery);

/*
	SUPERSIZED SETTINGS AND INIT
*/
$(function(){
	$.fn.supersized.options = {  
		startwidth: 1920,
		startheight: 1280,
		vertical_center: 0,
		slideshow: 0,
		navigation: 0,
		transition: 0, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
		pause_hover: 0,
		slide_counter: 1,
		slide_captions: 1,
		slide_interval: 3000
	};
    $('#supersize').supersized();
});
