/* Spotlight anim */
var fxBulletsq1;
var fxBullets = [];
var numEl  = 2;
var curEl  = 1;
var nextEl = 2;

function spotlightAnim() {

	/*
	$('#spotlightsContainer').innerfade({
		speed: 1500,
		timeout: 5000,
		type: 'sequence'
	});
	*/


	numEl = $('#spotlightsContainer').children('.spotlight-blok').length;

	if (numEl > 1)
		setTimeout(function() { startAnim(numEl, curEl); }, 5000);

}


function startAnim(elLength, curEl) {
	/* Determine next fade Element num */
	nextEl = curEl + 1;
	if (nextEl > elLength)
		nextEl = 1;

	/* Perform the animation */
	$('#spotlight-blok-'+curEl).fadeOut(1000);
	$('#spotlight-bullet-'+curEl).animate({backgroundColor: 'rgb(12,216,255)'},1000);
	$('#spotlight-blok-'+nextEl).fadeIn(2000);
	$('#spotlight-bullet-'+nextEl).animate({backgroundColor: 'rgb(255,255,255)'},2000);

	setTimeout(function() { startAnim(elLength, nextEl); }, 7000);
}

/* Show popup */
function showMessage(strTitle, strStamString, index, blnShow, lngEvenementID) {

	if(blnShow) {
		//if(strTitle == "Combiticket uitverkocht" || strTitle == "Busticket uitverkocht"){
		if(false){
			var strSoortText = "Stamtext";

			$.post("/includes/AJAX/request-handler.asp", {
				strActie: 'get-popup-content',
				strStamgegeven: strStamString,
				strSoortText: strSoortText,
				lngEvenementID: lngEvenementID
			}, function(response){
				$('#content-'+index).html(response);
			});
		} else {
			var parentHeight = document.getElementById(index).offsetHeight-9;//$('#'+index).innerHeight();

			$('#msg-'+index).height(parentHeight);
			$('#msg-'+index).html(strTitle).slideDown("fast");
		}
	} else {
		$('#content-'+index).hide();
		$('#msg-'+index).slideUp("fast");
		$('#content-'+index).show();
	}
}


function showPopup(strTitle, strStamString, strSoortText) {
	$('#popupTitle').html(strTitle);
	$('#popupInnerContent').html("Informatie wordt opgehaald, een moment geduld a.u.b.");
	$('#popup').fadeIn('fast');

	$.post("/includes/AJAX/request-handler.asp", {
		strActie: 'get-popup-content',
		strStamgegeven: strStamString,
		strSoortText: strSoortText
	}, function(response){
		$('#popupInnerContent').html(response);
	});

	return false;
}

function showInfoPopup(intOpstapplaatsID) {
	$('#popup #popupTitle').html("Opstapplaats informatie");
	$('#popup #popupInnerContent').html("Informatie wordt opgehaald, een moment geduld a.u.b.");
	$('#popup').fadeIn('fast');

	$.post("/includes/AJAX/request-handler.asp", {
		strActie: 'get-opstapplaats-info',
		intOpstapplaatsID: intOpstapplaatsID
	}, function(response){
		$('#popup #popupInnerContent').html(response);
	});

	return false;
}


/* Show small popup */
/*
function showSmallPopup(strTitle, strStamString, strSoortText, lngEvenementID) {
	$('#smallpopupTitle').html(strTitle);
	$('#smallpopupInnerContent').html("Informatie wordt opgehaald, een moment geduld a.u.b.");
	$('#smallpopup').fadeIn('fast');

	$.post("/includes/AJAX/request-handler.asp", {
		strActie: 'get-popup-content',
		strStamgegeven: strStamString,
		strSoortText: strSoortText,
		lngEvenementID: lngEvenementID
	}, function(response){
		$('#smallpopupInnerContent').html(response);
	});

	return false;
}
*/

/* Suckerfish menu hover */
sfHover = function() {
	if(document.getElementById("TopNavMenu")) {
		var sfEls = document.getElementById("TopNavMenu").getElementsByTagName("LI");

		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) { window.attachEvent("onload", sfHover); }


/* Controleren op valide postcode invoer */
function checkInput(elem, strFocus) {
	var strInput = elem.value.replace(' ','');
	if (isNaN(strInput))
		strInput = '';

	elem.value = strInput;

	if (strFocus != '') {
		$('#'+strFocus).focus();
	}
}

/********************** Tonen van reclameblokken **********************/

function submitPollForm(strVraag1, strVraag2) {
	if ($('#lngAntwoordID').val() == '') {
		alert('Selecteer een optie voor de vraag "'+strVraag1+'".');
		return false
	}

	else if ($('#lngAntwoord2ID').val() == '') {
		alert('Selecteer een optie voor de vraag "'+strVraag2+'".');
		return false
	}

	else {

		var lngID 			= $('input[name=lngPollID]').val();
		var lngOptieID 	= $('#lngAntwoordID').val();
		var lngOptie2ID = $('#lngAntwoord2ID').val();

		jQuery.post(
			'/includes/AJAX/request-handler.asp',
			{
				strActie		:	'poll_submit',
				lngID				:	lngID,
				lngOptieID	:	lngOptieID,
				lngOptie2ID	:	lngOptie2ID
			},
			function(response){
				//doe niets met de response
			}
		);

		//$('#poll-popup').fadeOut('fast');

		$.post(
			'/includes/AJAX/request-handler.asp',
			{
				strActie:'poll-toon-resultaten',
				lngID:lngID
			},
			function(response) {
				$('#poll-popup #popupInnerContent').html(response);
			}
		);

	}
	return false;
}

function submitPoll( strClassSelector, elemToFade ){
	/* gooi de ids van alle geselecteerde opties in een array*/
	var arrSelectedOptions = $.map( $('input.' + strClassSelector + ':checked'), function (elem, index){ return $(elem).val() });

	if (arrSelectedOptions.length == 0) {
		alert('Selecteer minimaal 1 antwoord');
		return false;
	}

	$.post(
		'/includes/AJAX/request-handler.asp',
		{
			strActie		:	'poll_submit_nieuw',
			strOptieIDs	:	arrSelectedOptions.join(', ')
		},
		function(response){
			$(elemToFade).fadeOut('fast');
		}
	);

	return false;
}

function submitPollEnDisplay(strClassSelector, elemToFade, classToDisplay){
	/* gooi de ids van alle geselecteerde opties in een array*/
	var arrSelectedOptions = $.map( $('input.' + strClassSelector + ':checked'), function (elem, index){ return $(elem).val() });

	if (arrSelectedOptions.length == 0) {
		alert('Selecteer minimaal 1 antwoord');
		return false;
	}

	$.post(
		'/includes/AJAX/request-handler.asp',
		{
			strActie		:	'poll_submit_nieuw',
			strOptieIDs	:	arrSelectedOptions.join(', ')
		},
		function(response){
			$(elemToFade).fadeOut('fast');
			$("."+classToDisplay).show();
		}
	);

	return false;

}


/********************** //Tonen van reclameblokken **********************/


function showToelichtingBetaalmethodetoeslag(strBetaalmethode){

	var strTekst = $('span#strBetaalmethodeToelichtingTekst_' + strBetaalmethode).html();
	$.cursorMessage(strTekst, {hideTimeout:2500});
}




/* functie om elementen uit een array te verwijderen, aangezien deze niet in javascript bestaat */
Array.prototype.remove = function(from, to) {
	var rest = this.slice((to || from) + 1 || this.length);
	this.length = from < 0 ? this.length + from : from;
	return this.push.apply(this, rest);
};

/* Functie om positie in Array te bepalen, IE7 heeft deze functie nog niet */
if (!Array.indexOf) {
	Array.prototype.indexOf = function (obj, start) {
		for (var i = (start || 0); i < this.length; i++) {
			if (this[i] == obj) {
				return i;
			}
		}
		return -1;
	}
}

function accordion(elem)
{
	var iSpeed = 1000;	//ms

	/* Als item al is uitgeklapt: niks doen */
	if ( $(elem).find('.item-text').is(':visible') === false )
	{
		/* Huidige 'column' */
		$(elem).find('.item-header').addClass('active');
		$(elem).find('.item-text').slideDown(iSpeed);

		$(elem).siblings().find('.item-header').removeClass('active');
		$(elem).siblings().find('.item-text').slideUp(iSpeed);

		/* Overige 'columns' resetten */
		$(elem).closest('.routereis-item').siblings().find('.item:last').each(function(){
			accordion( $(this) );
		})
	}
}

$(function(){
	if( navigator.userAgent.indexOf ("MSIE") !=-1 && $('#extLink').length > 0){
		var iframeHideTimeout;
		$('#TopNavMenu').bgiframe();

		$('#TopNavMenu *')
		.mouseover( function(){
			clearTimeout( iframeHideTimeout );
			iframeHideTimeout = setTimeout( "$('#extLink').hide()", 200 );
		})
		.mouseout( function(){
			clearTimeout( iframeHideTimeout );
			iframeHideTimeout = setTimeout( "$('#extLink').slideDown(250)", 200 );
		});
	}

	/* Als we op een vliegticket pagina zitten, maak een fancybox van de foto's */
	if ($(".link-hotel-meerfotos").length) {
		$(".link-hotel-meerfotos").fancybox();
	}

	$('.routereis-item .item').click(function(event){
		accordion($(this));
	})

	$('.routereis-item .item-header')
		.mouseenter(function(event){
			$(this).addClass('mouseover');
		})
		.mouseleave(function(event){
			$(this).removeClass('mouseover');
		});

	/* De carrousel voor pagina's met zelfde template */
	$("#templatebar").tinycarousel({
		start:1,
		display:1,
		axis:"x",
		controls:true,
		pager:false,
		interval:false,
		intervaltime:0,
		animation:true,
		duration:1000,
		callback:null
	});
});
