var myListener = new Object();
var isplaying = 0;
function getFlashObject(){
	return document.getElementById("myFlash");
}
$.videocontrol = function(){
	isplaying = 1;
	$(".playcontrol").playbutton();
	$(".stopcontrol").click(function(){
		getFlashObject().SetVariable("method:stop", "");
		$.stopbutton();
	});
};

jQuery.fn.playbutton = function(){
 $(this).each(function(){
	 $(this).css("background-image","url(\"/images/pause.png\")");
 	 $(this).toggle(
		function () {
				isplaying = 0;
				getFlashObject().SetVariable("method:pause", "");
				$(this).css("background-image","url(\"/images/play.png\")");
			
		},
		function () {
				isplaying = 1;
				getFlashObject().SetVariable("method:play", "");
				$(this).css("background-image","url(\"/images/pause.png\")");
		}
	);
 });
};
$.stopbutton = function(){
	if(isplaying == 1){
		$(".playcontrol").trigger('click');
	}
};

$(document).ready(function() {
if(!$.cookie("showvideo")){
		//video overlay
		var api = $("#videobox").overlay({
			expose: {
				// you might also consider a "transparent" color for the mask
				color: '#333',
				// load mask a little faster
				loadSpeed: 200,
				// very transparent
				opacity: 0.9
			},
			// disable this for modal dialog-type of overlays
			closeOnClick: false,
			onClose: function() {
				getFlashObject().SetVariable("method:stop", "");
			},
			// load it immediately after the construction
			api: true
		});
		api.load();
		myListener.onInit = function(){
			getFlashObject().SetVariable("method:setUrl", "http://www.partygewinnen.de/video/bb_hausparty_koeln_2011.flv");
			getFlashObject().SetVariable("method:play", "");
			$.cookie("showvideo", "1");
		};
		myListener.onClick = function(){ };
		myListener.onKeyUp = function(pKey){ };
		myListener.onFinished = function(){
			api.close();
		};
		myListener.onUpdate = function(){ };
		$.videocontrol();
		$("#videobox").mouseenter(function(){
			$("#videobox .close").show();
			$(".playcontrol").show();
			$(".stopcontrol").show();
		}).mouseleave(function(){
			$("#videobox .close").hide();
			$(".playcontrol").hide();
			$(".stopcontrol").hide();
		});

	}

});

