// JavaScript Document

var intervalID1 = false;
var intervalID2 = false;
var intervalID3 = false;
var intervalID4 = false;
var intervalTimer = 5000;

$(document).ready(function() {
	
	_form();
	
	$('<input type="hidden" name="sid" value="'+$("META[name='sid']").attr('content')+'" />').prependTo('FORM');
	
	$('a[rel="extern"]').attr('target', '_blank');
	
//	Confirm link

	$("a.confirm").click(function() {
		if (confirm($(this).attr('title'))) {
			return true;							 
		}
		else {
			return false;
		}
	});
	
	
//	Menu

	if ($.browser.msie && $.browser.version.substr(0,1) == '6') {
		$("#menu > UL > LI, #submenu > UL > LI").hover(function() {
			$("UL",this).show();
		},
		function() {
			$("UL",this).hide();
		});
	}

	// HEADER
	if($('.slides > li').length > 1){		
		intervalID1 = setInterval(function(){slider(false)}, intervalTimer);
	}
	
	// HEADER
	if($('.slides2 > li').length > 1){		
		intervalID3 = setInterval(function(){slider2(false)}, intervalTimer);
	}
	
	// FOTOREPORTAGE
	if($('.carousel > li').length > 1){		
		intervalID2 = setInterval(function(){carousel(false)}, intervalTimer);
	}
	
	
//	Lightbox
	
	$('.fotoalbum a').lightBox();
	
//	Rating


	$(".rating A.star").click(function() {
		var _length = $(this).parent().children().length;
		var _current = $(this).nextAll().length;
		var _qty = _length - _current - 1;
		
		$(".rating A.star IMG").attr('src', '/images/common/star-empty.png');
		
		for (var i=0;i<= _qty;i++) {
			$(".rating A.star").eq(i).children('img').eq(0).attr('src', '/images/common/star-full.png');
		}
		
		var _qty = $(".rating A.star IMG[src='/images/common/star-full.png']").length;
		$("#form-score").val(_qty);
		
		
		return false;
	});
	
	
// Popup link

	$("a.popup").click(function() {
		
		window.open($(this).attr('href'),'popup','width=500,height=500,scrollbars=yes,toolbar=no,location=no');
		
		return false;
	});
	
//	Verwijder plaatje

	$("A#deleteImage").click(function() {
		$("#image").val('0');
		$("#imageSrc").attr('src', $(this).attr('href'));
		return false;
	});

	
//	FCK Editor

	$("TEXTAREA.fck").fck({waitFor:1, path: '/script/fckeditor/',toolbar:'Custom', height:'300px', width:'100%' });


// Blocks

	$("UL.block > LI > A").click(function() {
		if ($(this).parent().is('.active')) {
			$(this).parent().removeClass('active');
		}
		else {
			$(this).parent().addClass('active');
		}
		return false;
	});
	
//	Breadcrumb 

	$("#breadcrumb UL LI:first").css('margin-left','0');
	
	
// Home lijst

	$("#home #cats LI:odd").css('margin-top','30px');	
		
	
// Nieuws carousel

	 
	
// Kalender carousel
	$("ul.marquee").marquee({showSpeed: 1, scrollSpeed: 15});

// Sponsor carousel

	 $('#sponsors ul').jcarousel({
        auto: 2,
        wrap: 'last',
		scroll: 1,
		animation: 'slow'
     });

//	Zoeken

	$("#search-input").focus(function() {
		if ($(this).val() == $(this).attr('alt')) {
			$(this).val('');	
		}
	});
	
	
	$("#search-input").blur(function() {
		if ($(this).val() == '') {
			$(this).val($(this).attr('alt'));	
		}
	});
	
	$("#search-form").submit(function() {
		var _filter = 0;
		var _val = $("#search-input").val();
		
		if($("input:checked").length > 0){
			_filter = $("input:checked").val();
		}

		if (_val > '') {
			location = $(this).attr('action')+base64_encode(_val)+'/'+_filter;	
		}		
		
		return false;	
	});
	
// Google maps aanroepen

	gmaps();
	gmapsSmall();


});



//	Google maps
	

var gmaps	=	function(){

	var selector = "#jmap";
	
	if( $(selector).length > 0 ){
	
		var markers = new Array();
		var center = new Array();
		
		// SET MARKERS
		$('#almanak .marker').each(function(i, value){
			var latLong = $(this).find('.location').text().split(',');	 
			var content = $(this).find('.content').html();
			
			if(latLong[0] && latLong[1]){
						
				center = latLong;
			
				markers[i] = {
					'id': $(this).attr('id'),
					'latitude': latLong[0], 
					'longitude': latLong[1],
					'title': $(this).find('a').text(), 
					'html': $(this).find('.html').html(), 
					'draggable': false
				};
				
			}
			
		});
					
		if(markers.length > 0){
			
			var content = $(selector).html();
	
			$(selector).jmap('init', {
				'mapType':'map',
				'mapControl':'zoom3D',
				'mapZoom':12,
				'language': "nl",
				'mapEnableType': true,
				'mapEnableDoubleClickZoom': true,
				'mapEnableScrollZoom': false,
				'mapEnableSmoothZoom': true,
				'mapEnableStreetview': true,
				'mapCenter':[center[0],center[1]], 
				'mapShowjMapsIcon':false
			}, function (map, element, options){
				
				$(markers).each(function(){
					$(selector).jmap('AddMarker',{
						'pointLatLng':[this.latitude, this.longitude],
						'pointHTML':this.html
						
					});
				});
				
			}).append(content);
		}
	}
}	


var gmapsSmall = function() {
	
	var selector = "#jmaps";

	if( $(selector).length > 0 ){

		var markers = new Array();
		var _x = $(selector+" .x").text();
		var _y = $(selector+" .y").text();
			
		if(_x && _y){
		
			markers[0] = {
				'id':'marker-1',
				'latitude': _y,
				'longitude': _x
			};
			
			// SET MAP WITH MARKERS
			
					
			var content = $(selector).html();
			
			$(selector).jmap('init', {
				'mapType':'map',
				'mapControl':'zoom3D',
				'mapZoom':12,
				'language': "nl",
				'mapEnableType': true,
				'mapEnableDoubleClickZoom': true,
				'mapEnableScrollZoom': false,
				'mapEnableSmoothZoom': true,
				'mapEnableStreetview': true,
				'mapCenter':[_y,_x], 
				'mapShowjMapsIcon':false
			}, function (map, element, options){
				
				$(markers).each(function(){
					$(selector).jmap('AddMarker',{'pointLatLng':[this.latitude, this.longitude]});
				});
				
			}).append(content);
		}
	}
}

var slider = function(next){
		
	var total = $('.slides > li').length;
	var current = parseInt($('.slides .active').removeClass('active').fadeOut(750).attr('id').replace('slide-',''));
	
	if(!next){
		next = current + 1;
	}
	
	if(next > total){
		next = 1;	
	}
	
	$('.slides-nav a').removeClass('active');
	$('a[href=#slide-'+next+']').addClass('active');
	$('#slide-'+next).addClass('active').fadeIn(750);
	
}

var slider2 = function(next){
		
	var total = $('.slides2 > li').length;
	var current = parseInt($('.slides2 .active').removeClass('active').fadeOut(750).attr('id').replace('slide2-',''));
	
	if(!next){
		next = current + 1;
	}
	
	if(next > total){
		next = 1;	
	}
	
	$('.slides-nav a').removeClass('active');
	$('a[href=#slide2-'+next+']').addClass('active');
	$('#slide2-'+next).addClass('active').fadeIn(750);
	
}

var carousel = function(){

	$('.carousel > .first').animate({marginTop: '-112px'}, 500, function(){
	
		$('.carousel').append( $(this).removeClass('first').css('marginTop','0px') );
		$('.carousel li:eq(0)').addClass('first');
	});
}


var debug = function (text) {
	if ($.browser.mozilla && typeof(console) != 'undefined') {
		console.info(text);
	}
}
