iWeerlocaties_cur = 0;

$(document).ready(function() {
	/** TABBLADEN **/
	$('.tabs .tab').bind('mouseenter', function(event) {
		$(this).addClass('active');
	});
  
	$('.tabs .tab').bind('mouseleave', function(event) {
		if(!$(this).hasClass('open')) {
			$(this).removeClass('active');
		}		
	});
	
	$('.tabs .tab').bind('click', function(event) {
		// Bij het huidige item de open class erafhalen
		$(".tabs .tab").each(function (i) {
			$(this).removeClass('open');
			$(this).removeClass('active');
		});
		
		$(this).addClass('open');
		$(this).addClass('active');
		
		// Verbergen
		$("#omschrijving .act_omschrijving").each(function (i) {
			$(this).hide();
		});
		$("img.act_afbeelding").each(function (i) {
			$(this).hide();
		});
		$(".act_acties").each(function (i) {
			$(this).hide();
		});
		
		// Tonen
		$("#acties" + this.id.substring(3)).show();
		$("#afbeelding" + this.id.substring(3)).show();
		$("#omschrijving" + this.id.substring(3)).show();
		
		getLocaties(this.id.substring(3));
		
	});

	
	
	/****** Activeiten pagina *******/
	
	$('#activiteiten .activiteiten .item').bind('click', function(event) {
		// geklikte nummer
		nummer = this.id.substring(4);
		
		// alle activiteiten blokken weer op de normale hoogte zetten
		$('#activiteiten .activiteiten').height(171);
		
		// Welk blok zit deze activiteit in?
		blok = Math.ceil(nummer / 4);
		$('#activiteiten' + blok).height(300);
		
		// items inactief maken
		$('#activiteiten .activiteiten .item').removeClass('active');
		
		// item actief maken		
		$('#item' + nummer).addClass('active');
		
		// items inactief maken
		$('#activiteiten .activiteiten .omschrijving').hide();
		
		// item actief maken		
		$('#omschrijving' + nummer).show();
		
		// Naar het anker toe schuiven
		$.scrollTo($('#item' + nummer), {duration:500});
		
		hoogte_omschrijving = $('#omschrijving' + nummer).height();
		hoogte_item = 171;
		hoogte_nieuw = hoogte_omschrijving + hoogte_item;
		$('#activiteiten' + blok).height(hoogte_nieuw);
		
		
	});
	
	// Locaties ophalen voor de actieve tab
	$('.tabs .tab').each(function() {
		if($(this).hasClass('open')) {
			getLocaties(this.id.substring(3));		
		}
	});

});

function roundedCorners() {
	// ronde hoeken op afbeeldingen	
	$.fn.corner.defaults.useNative = false;
	$('#locaties > .item > .afbeelding').each(function() {
		$(this).corner("7px");
	});

	// Slide buttons
	$('.btn_links').bind('click', function(event) {
		slideBackward();
	});
	$('.btn_rechts').bind('click', function(event) {
		slideForward();
	});
}

function getLocaties(ActiviteitID) {
	$('#locaties_content').html('<p>&nbsp;</p><pstyle="padding-left: 10px;"><img src="/images/loading.gif" /><br/>Locaties worden opgehaald</p>');
	$.get('/home/locaties/' + ActiviteitID + '.htm', function(data) {
	  $('#locaties_content').html(data);
	  initSlide();
	  roundedCorners();
	});
}

function getWeer(sLocatie) {
	$.get('/home/weer/' + sLocatie + '.htm', function(data) {
		
		if(data == "0") {
			alert('Deze locatie werd helaas niet gevonden.');
		} else {
			if(iWeerlocaties_cur == 4) {
				// onderste erafhalen
				$('#weer_locaties tr:last').remove();
				
				iWeerlocaties_cur --;
			}
			
			$('#weer_locaties').prepend(data);
			iWeerlocaties_cur++;
		}
		
	});
}

function zoekWeer() {
	// locatie uit de value halen
	locatie = urlencode($('#weerlocatie').val());
	if(locatie != "" && locatie != "Zoeken") {
		var found = false;
		// Hebben we deze al?
		$('.weerlocatiezichtbaar').each(function() {
			if(locatie.toLowerCase() == $(this).val().toLowerCase()) {
				found = true;

			}
		});
		
		if(found == false) {
			getWeer(locatie);
			$('#weerlocatie').val("Zoeken");
		}
	}
	
}



