var popupStatus = 0;

$(document).ready(function(){
	if($('form#euroscore').length){	
		$("#popupContactClose").click(function(){  
			disablePopup();  
		}); 
			
		$("#backgroundPopup").click(function(){  
			disablePopup();  
		}); 
	}
});

function loadPopup(id){ 
	centerPopup(id);
	if(popupStatus==0){
		$.post("ajax/ajax_popup.php?do=setText", {
			"id": id
		}, function(data){
			$("#popupContact").html(data);
			$("#backgroundPopup").css({  
				"opacity": "0.7"  
			});  
			$("#backgroundPopup").fadeIn("slow");  
			$("#popupContact").fadeIn("slow");  
			popupStatus = 1;
		});  
	}  
} 

function disablePopup(){  
	if(popupStatus==1){  
		$("#backgroundPopup").fadeOut("slow");  
		$("#popupContact").fadeOut("slow");  
		popupStatus = 0;  
	}  
}  


function centerPopup(id){        
	$("#popupContact").css({  
		"position": "absolute",
		"top": "290px",
		"left": "20px"
	});  
} 

function switchContent(akt_id, direction){
	var prev = akt_id-1;
	var next = akt_id+1;
	if(prev<1){
		prev = 6;
	}
	if(next>6){
		next = 1;	
	}
	$.post("ajax/ajax_ajax.php?do=switchContent", {
			"akt_id": akt_id,
			"direction": direction
		}, function(data){
			if(direction == "right"){
				$("#content_hidden").css("left","800px");
				$("#content").css("left","0px");
				$('#content_hidden').show().html(data);
				$("#content").stop().animate({"left":"-800px"});
				$("#content_hidden").stop().animate({"left":"0px"}, function(){
					$("#content").css("left","0px");
					$("#content").html(data).show();
					$("#content_hidden").hide().css("left","800px");
					$('#content_hidden').html('');
				});
				$("#m_"+akt_id).removeClass("on");
				$("#m_"+next).addClass("on");
				$('#content_pfeil_links').attr("href", "javascript:switchContent("+next+",'left');");
				$('#content_pfeil_rechts').attr("href", "javascript:switchContent("+next+",'right');");
			}else{
				$("#content_hidden").css("left","-800px");
				$("#content").stop().animate({"left":"0px"});
				$('#content_hidden').show().html(data);
				$("#content").stop().animate({"left":"800px"});
				$("#content_hidden").stop().animate({"left":"0px"}, function(){
					$("#content").css("left","0px");
					$("#content").html(data).show();
					$("#content_hidden").hide().css("left","800px");
					$('#content_hidden').html('');
				});
				$("#m_"+akt_id).removeClass("on");
				$("#m_"+prev).addClass("on");
				$('#content_pfeil_links').attr("href", "javascript:switchContent("+prev+",'left');");
				$('#content_pfeil_rechts').attr("href", "javascript:switchContent("+prev+",'right');");
			}
		}); 
}
