﻿var popupvideoStatus = 0;
var popupvideoStatus2 = 0;

function loadpopupvideo(){
	if(popupvideoStatus==0){
		$("#backgroundpopupvideo").css({
			"opacity": "0.8"
		});
		$("#backgroundpopupvideo").fadeIn("slow");
		$("#popupvideoCart").fadeIn("slow");
		popupvideoStatus = 1;
	}
}

function disablepopupvideo(){
	if(popupvideoStatus==1){
		$("#backgroundpopupvideo").fadeOut("slow");
		$("#popupvideoCart").fadeOut("slow");
		popupvideoStatus = 0;
		popupvideoStatus2 = 0;
	}
}

function centerpopupvideo(){
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupvideoHeight = $("#popupvideoCart").height();
	var popupvideoWidth = $("#popupvideoCart").width();
	$("#popupvideoCart").css({
		"position": "fixed",
		"top": windowHeight/2-popupvideoHeight/2,
		"left": windowWidth/2-popupvideoWidth/2
	});
	
	$("#backgroundpopupvideo").css({
		"height": windowHeight
	});
	
}

$(document).ready(function(){
	$(".buttonpopupvideo").click(function(){
		var dvd = $(this).attr("class").substr(19);
		if ( popupvideoStatus2 != 1 ) {
			popupvideoStatus2 = 1;
			$.get("popup_film.php?dvd="+dvd,function(data) {
				$(".footer").prepend(data);
				centerpopupvideo();
				loadpopupvideo();
				$(".new_div").fadeOut();			
				$("#popupvideoCartClose").click(function(){
				disablepopupvideo();
				$(".new_div").fadeIn();			
				});

				$(document).keypress(function(e){
					if(e.keyCode==27 && popupvideoStatus==1){
						disablepopupvideo();
					}
				});
			});
			return false;
		}
	});

	
	$(".buttonpopupvideo2").click(function(){
		var dvd = $(this).attr("class").substr(20,8);
		var scene = $(this).attr("class").substr(28);
		if ( popupvideoStatus2 != 1 ) {
			popupvideoStatus2 = 1;		
			$.get("popup_video.php?dvd="+dvd+"&scene="+scene,function(data) {
				$(".footer").prepend(data);
				centerpopupvideo();
				loadpopupvideo();
				$(".new_div").fadeOut();			
				$("#popupvideoCartClose").click(function(){
				disablepopupvideo();
				$(".new_div").fadeIn();			
				});

				$(document).keypress(function(e){
					if(e.keyCode==27 && popupvideoStatus==1){
						disablepopupvideo();
					}
				});
			});
			return false;
		}
	});
});
