
function newCrossdomainIframe(url, containerNumber, callback){
	var iframeContainer = "#iframecontainer" + containerNumber;
	$(iframeContainer).empty();
	var socket = new easyXDM.Socket({
	    remote: url,
	    container: document.getElementById("iframecontainer" + containerNumber),
	    onReady:  function(){
			socket.postMessage(url);
		},
	    onMessage: function(message, origin){
	    //	alert(message);
	    	var dimensions = message.split(",");
	    	//alert(dimensions[0]);
	    	var iFrameHeight = (parseInt(dimensions[0]));
	    	var iFrameWidth = (parseInt(dimensions[1]) + 20)
	    	this.container.getElementsByTagName("iframe")[0].style.height = iFrameHeight + "px";
			this.container.getElementsByTagName("iframe")[0].style.width = iFrameWidth + "px";
			
			// make the slidingtabs view bigger to fit the iframe
			var iframe = '#' + ("iframecontainer" + containerNumber);
			var st_view = $(iframe).parent().parent();
			
		//	alert(st_view.height());
		//	alert(parseInt(dimensions[0]));
	    	st_view.css('height', iFrameHeight);
	    }
	});
}

/* horizontal sliding tabs functionality, also loading iframes when needed */
$(document).ready(function() {
	// tabs page button active classes logic
	$('.tab_buttons li a').click(function() {
		var li = $(this).parent();
		$('.tab_buttons li').removeClass('active active-before');
		li.prev().addClass('active-before'); 
		li.addClass('active');

		var iframeId = $(this).attr('id');
		var iframeContainerId = iframeId.replace('iframe', '');

		
		var iframeUrl = $(this).attr('name');
		
		if ( $.browser.msie && parseFloat($.browser.version) < 8.0) {
			// fix for ie7
			if(iframeUrl != undefined){
				newCrossdomainIframe(iframeUrl, iframeContainerId);
			}
		}
		else {
			// only load an iframe if it was set
			if(iframeUrl.length > 0){	
				newCrossdomainIframe(iframeUrl, iframeContainerId);
			}
		}
	});
	
	// Horizontal tabs
	if($('div#st_horizontal .st_view').length > 1 || $('#iframecontainer').length >= 0 ) {
		bAutoHeight = true;
	} else {
		bAutoHeight = false;
	}
	$('div#st_horizontal').slideTabs({  				
		contentAnim: 'slideH',
		contentAnimTime: 600,
		autoHeight: bAutoHeight,
		contentEasing: 'easeInOutExpo',
		tabsAnimTime: 400			
	});
});

/* accordion functionality for frequently asked questions */

$(document).ready(function() {
	$('.accordion-title').click(function() {
		var question = $(this);
		var answer = $(this).next();
		var st_view = $('.st_view');	
		st_viewHeight = st_view.height();
		answerHeight = answer.height();
		
		if(answer.css('visibility') == 'hidden') {
			answer.css('visibility', 'visible');
			answer.css('position', 'relative');
			answer.css('display', 'none');
		}

		if(question.hasClass('hide')){
			// show the answer for this question
			// +height of the answer for stview			
			answer.slideDown('slow');
			
			question.removeClass('hide').addClass('show');
			st_view.animate({
				height: (st_viewHeight + answerHeight)
			}, 'slow');
		}
		else{
			// hide the answer for this question
			// -height of the answer for stview
			answer.slideUp('slow');
			question.removeClass('show').addClass('hide');
			st_view.animate({
				height: (st_viewHeight - answerHeight)
			}, 'slow');
		}
	});
});

/* clear email adres field */
$(document).ready(function() {
	// tabs page button active classes logic
	$('.emailField').click(function() {
		if($(this).val() == 'emailadres'){
			$(this).val('');
		}
	});
});
