var width, height, scrolltop, object_visibility;
object_visibility = ""; // Variable auf einen definierten Wert setzen

function get_window_size() {
	if( typeof( window.innerWidth ) == 'number' ) {
		width=window.innerWidth;
		height=window.innerHeight;
	} else if(document.documentElement && document.documentElement.clientHeight) {
		//IE6 standards compliant mode
		// muss vor der DOM-compliant-Prüfung ausgeführt werden: body.clientHeight gibt Höhe der gesamten Seite aus
		width=document.documentElement.clientWidth;
		height=document.documentElement.clientHeight;
	} else if(document.body && document.body.clientHeight) {
	    //DOM compliant
		width=document.body.clientWidth;
		height=document.body.clientHeight;
	} else {
		// IE + HTML4.0Trans: sonst funktioniert nichts...
		width=document.body.clientWidth;
		height=document.body.clientHeight;
	}
}

function get_scroll_position() {
	//Aktuelle Scrollposition bestimmen und das Vollbild-div an diese Stelle verschieben
	if( typeof( window.pageYOffset ) == 'number' ) {
		scrolltop=window.pageYOffset;
	} else if(document.body && document.body.scrollTop) {
	//DOM compliant
	scrolltop=document.body.scrollTop;
	} else if(document.documentElement && document.documentElement.scrollTop) {
		//IE6 standards compliant mode
		scrolltop = document.documentElement.scrollTop;
	} else {
		// IE + HTML4.0Trans: sonst funktioniert nichts...
		scrolltop=document.body.scrollTop;
	}
}

//katalog version
function showImageFullSize(tabelle_katalogbilder, id, katalog_db, image_nr) {
	get_window_size();
	$.ajax({
		type: 'POST',
		url: '/katalog_image_fullsize.php',
		data: {tabelle_katalogbilder: tabelle_katalogbilder, id: id, katalog_db: katalog_db, image_nr: image_nr, width: width, height: height},
		error: function() {	},
		success: function(response) {
			UnTip();
			get_scroll_position();
			$("body").css("overflow", "hidden"); // Funktioniert im IE7 bei XHTML nicht
			if (object_visibility == "") { // Nur setzen, wenn es noch keinen Wert gab
				object_visibility = $('object').css('visibility') ; // Std: visible; Anzeigeart von Flash-Videos merken
			}
			$('object').css('visibility', 'hidden'); // Flash-Videos ausblenden (liegen sonst immer über dem Vollbild)
			$("#div_vollbild").css("top", scrolltop+"px");
			$("#div_vollbild").html(response);
			$("#div_vollbild").fadeIn("fast");
			if(typeof jQuery.hotkeys == 'undefined') {
				$.getScript('/scripts/jQuery/jquery.hotkeys.js', function() {
					$(document).bind('keydown', 'esc', function (evt){
						closeFullscreen();
						return false;
					});
					$(document).bind('keydown', 'left', function (evt) {
						$('#prev_bild').click();
						return false;
					});
					$(document).bind('keydown', 'right', function (evt) {
						$('#next_bild').click();
						return false;
					});
				});
			}else{
				$(document).bind('keydown', 'esc', function (evt){
					closeFullscreen();
					return false;
				});
				$(document).bind('keydown', 'left', function (evt) {
					$('#prev_bild').click();
					return false;
				});
				$(document).bind('keydown', 'right', function (evt) {
					$('#next_bild').click();
					return false;
				});
			}
		}
	});
}

function closeFullscreen() {
	$("#div_vollbild").fadeOut("fast");
	$("body").css("overflow", "scroll");
	$('object').css('visibility', object_visibility); // Flash-Videos auf alten Zustand zurücksetzen
	$(document).unbind('keydown', 'esc');
	$(document).unbind('keydown', 'left');
	$(document).unbind('keydown', 'right');
}

function set_image_timeout(next_bild, div_id) {
	setTimeout(function() {$('#'+div_id).html(next_bild)}, 2000);
}

$(document).ready(function () { //The fullscreen container should have the body as its parent node so we can position it absolute to the body
	if($("#div_vollbild").length==0) {$("body").append("<div id=\"div_vollbild\"></div>");}
});
