jQuery(document).ready(function(){

	jQuery("#popup_closer, #popupToolbar .close").click(
		function () {
			hidePopup();
		}
	);
	
	var popY = jQuery("body").height() - 71;
	jQuery("#popupinhalt, #popup_closer").css("top", "-"+popY+"px");
	
	

	
	if(browser() > 8){
		var myvid = document.getElementById("video");
		myvid.addEventListener('ended', videoEnded);
	}
	
	popupResize();
});

jQuery(window).resize(function() {
  popupResize();
});

function popupResize(){
	jQuery("#popup_closer").css("height", jQuery("body").height() - jQuery("#wrapper .top").height());
}



function videoEnded(){
	if(plattform() != "iPad"){
		jQuery("#popupVideo .overlayEnd").css("display", "block");
		jQuery("#popupVideo .box1").animate({
	    	opacity: 1
	  	}, 500, function() { 
	  		jQuery("#popupVideo .box2").animate({
	    		opacity: 1
	  		}, 500, function() {  
	  			jQuery("#popupVideo .box3").animate({
	    			opacity: 1
	  			}, 500, function() {  });
	  		});
	  	});
	}else{
		jQuery("#popupVideo .box1").animate({
	    	opacity: 1
	  	}, 500, function() { 
	  		jQuery("#popupVideo .box2").animate({
	    		opacity: 1
	  		}, 500, function() {  
	  			jQuery("#popupVideo .box3").animate({
	    			opacity: 1
	  			}, 500, function() {  });
	  		});
	  	});
	}
}

function playPauseVideo(){
	var myvid = document.getElementById("video");
	
	if(jQuery("#popupVideo .overlayEnd").css("display") != "none"){
		if(plattform() != "iPad"){
			jQuery("#popupVideo .box1, #popupVideo .box2, #popupVideo .box3").animate({
    			opacity: 0
  			}, 750, "easeInOutExpo", function() {  
  				jQuery("#popupVideo .overlayEnd").css("display", "none");
  			});
		}else{
			jQuery("#popupVideo .box1, #popupVideo .box2, #popupVideo .box3").animate({
    			opacity: 0.3
  			}, 750, "easeInOutExpo", function() {  
  				
  			});
		}
	}
	myvid.play();
}

function toContact(){
	window.location = "http://www.dartwork.de/kontakt/anfahrt/";
}

function moreInfo(){
	window.location = "http://www.dartwork.de/agentur/dart-prozess/";
}




function showPopup(){
	jQuery("#popupinhalt, #popup_closer").css('display', "block");
  	jQuery("#popupinhalt, #popup_closer").stop().animate({
    	opacity: 1,
    	top: "71px"
  	}, 1000, "easeOutExpo", function() {  });
  	
  	if(browser() > 8) playPauseVideo();
	
}

function hidePopup(){
  	var screenHeight = jQuery("body").height() - 71;
  	screenHeight = -screenHeight;
  	jQuery("#popupinhalt, #popup_closer").stop().animate({
    	opacity: 0,
    	top: screenHeight
  	}, 600, "easeOutExpo", function() { 	jQuery("#popupinhalt, #popup_closer").css('display', "none");  });
  	
  	if(browser() > 8){
	  	var myvid = document.getElementById("video");
	 	
		if (myvid.paused != true){
			myvid.pause();
		}
  	}
	if(plattform() != "iPad"){
		jQuery("#popupVideo .overlayEnd").css("display", "none");
		jQuery("#popupVideo .box1, #popupVideo .box2, #popupVideo .box3").css("opacity", 0);
	}else{
		jQuery("#popupVideo .box1, #popupVideo .box2, #popupVideo .box3").css("opacity", 0.3);
	}
}



