// JavaScript Document

$(document).ready(function() {
	
	_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();
		});
	}
	
	
//	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').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 _val = $("#search-input").val();
		if (_val > '') {
			location = $(this).attr('action')+base64_encode(_val);	
		}		
		return false;	
	});
	
// Google maps aanroepen

	gmaps();
	gmapsSmall();


});



//	Google maps
	
var gmaps	=	function(){
	
	var content = $('#jmap').html();
	
	$('#jmap').jmap('init', {
		'mapType':'map',
		'mapZoom':12,
		'language': "nl",
		'mapEnableType': false,
		'mapEnableDoubleClickZoom': true,
		'mapEnableScrollZoom': false,
		'mapEnableSmoothZoom': true,
		'mapCenter':[51.893576,5.092463], 
		'mapShowjMapsIcon':false
	}, function (map, element, options){
		
	}).append(content);
	
	
	 $('#jmap').jmap('AddMarkerLayer',{
                'feedUrl':'/almanak/xml',
                'pointIcon': {
                    'iconShadow': 'none',
                    'iconShadowSize': {'width':0,'height':0}
                }
      }, function(thisMap, markers, options){
		  
		  		$(".checked").each(function() {
					
					var layer = $(this).attr('href');
					 for(var i=0; i<markers.length; i++){                        
                        if (typeof markers[i] == 'object') {
							if(markers[i].layer == layer){
								markers[i].show();
								$('<div class="almanak-'+layer+'">'+markers[i].html+'<div class="dotted-line"></div></div>').appendTo('#almanak');
							}    
						}
                    }
					
															  
				});
                
                $(".coords").click(function() {
					var layer = $(this).attr('href');
					
					if ($(".almanak-"+layer).length > 0) {
						$(".almanak-"+layer).remove();
					}
					
						
                    for(var i=0; i<markers.length; i++){
                    	if (typeof markers[i] == 'object') { 
                        	if(markers[i].layer == layer){
                        
								if( $(this).is('.checked') ){								
									markers[i].hide();
								}
								else{
									markers[i].show();
									$('<div class="almanak-'+layer+'">'+markers[i].html+'<div class="dotted-line"></div></div>').appendTo('#almanak');
								}
							}
                        }                        
                    }
					
					if ($(this).is(".checked")) {
						$(this).removeClass('checked');
					}
					else {
						$(this).addClass('checked');
					}
					
					return false;				
				});
		
		return false;
	});
}


var gmapsSmall = function() {
	var _x = $("#jmaps .x").text();
	var _y = $("#jmaps .y").text();
	var _i = $("#jmaps .info").html();
	$("#jmaps").html('');
		
	$('#jmaps').jmap('init', {
		'mapType':'map',
		'mapZoom':12,
		'language': "nl",
		'mapEnableType': false,
		'mapEnableDoubleClickZoom': true,
		'mapEnableScrollZoom': false,
		'mapEnableSmoothZoom': true,
		'mapCenter':[_y,_x], 
		'mapShowjMapsIcon':false
	}, function (map, element, options){
		$('#jmaps').jmap('AddMarker',{'pointLatLng':[_y, _x]});
	});	

}


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