$(function(){
	
	$('.show_floating_box').click(function(){
		$('.floating_box').remove();
		url = $(this).attr('href');
		title = $(this).attr('title');
		$.ajax({
			url: url,
			cache: false,
			success: function(html){
				obj = document.createElement("div");
				$(obj).
				addClass('floating_box').
				append('<span class="floating_box_inner"><div class="handle"><h3>'+title+'</h3><a href="javascript: void(0)">Fenster schliessen</a><div class="clear"></div></div><div class="cnt">'+html+'</div></span>');
				$(obj).find('.handle a').click(function(){
					$(this).parent().parent().parent().fadeOut().remove();
				});
				$('#content').append(obj);
				updateFloatingBox();
				$(obj).fadeIn();
			}
		});
		$(this).blur();
		return false;
	});

});

function updateFloatingBox() {
	
	$('.update_floating_box').click(function(){
		$('.floating_box_inner').remove();
		url = $(this).attr('href');
		title = $(this).attr('title');
		$.ajax({
			url: url,
			cache: false,
			success: function(html){
				obj = document.createElement("span");
				$(obj).
				addClass('floating_box_inner').
				append('<div class="handle"><h3>'+title+'</h3><a href="javascript: void(0)">Fenster schliessen</a><div class="clear"></div></div><div class="cnt">'+html+'</div>');
				$(obj).find('.handle a').click(function(){
					$(this).parent().parent().parent().fadeOut().remove();
				});
				$('.floating_box:eq(0)').append(obj);
				updateFloatingBox();
			}
		});
		return false;
	});

}



Array.prototype.random = function () {
  return this[Math.floor(Math.random() * this.length)];
}

function showRandomContainer() {
	var ekb_container = new Array('family_cnt', 'car_cnt', 'health_cnt', 'seniors_cnt', 'appreciation_cnt', 'privilege_cnt');	
	var which = ekb_container.random();
/*	
	for (i=0; i<ekb_container.length; i++) {
		if (document.getElementById(ekb_container[i])!= null) {
			var hide = document.getElementById(ekb_container[i]).style.display = 'none';	
		}
	}
*/	
	if (document.getElementById(which)!= null) {
		document.getElementById(which).style.display = 'block';
	
		if (which == 'family_cnt') {
			var hide = document.getElementById('family_l2').style.display = 'none';
		} else if (which == 'health_cnt') {
			var hide = document.getElementById('health_l2').style.display = 'none';
		} else if (which == 'car_cnt') {
			var hide = document.getElementById('car_l2').style.display = 'none';
		} else if (which == 'seniors_cnt') {
			var hide = document.getElementById('seniors_l2').style.display = 'none';
		} else if (which == 'appreciation_cnt') {
			var hide = document.getElementById('work_l2').style.display = 'none';
		} else if (which == 'privilege_cnt') {
			var hide = document.getElementById('house_l2').style.display = 'none';
		} 
		
	}
}

