if (document.images)
	{
	image1_on = new Image();
	image1_on.src = "./img/home/photographers_index_on.gif";
	image1_off = new Image();
	image1_off.src = "./img/home/photographers_index_off.gif";

	image2_on = new Image();
	image2_on.src = "./img/home/production_index_on.gif";
	image2_off = new Image();
	image2_off.src = "./img/home/production_index_off.gif";
	}

function swapImg(img,stat) {
	if (document.images)
		{
		(stat == "on") ? (document.getElementById(img).src = eval(img + "_on.src")) : (document.getElementById(img).src = eval(img + "_off.src"));
		}
	}

function preloadImages() {
	if (document.images)
		{
		for (var i = 0; i < preloadImages.arguments.length; i++)
			{
			(new Image()).src = preloadImages.arguments[i];
			}
		}
	}

function showImprint() {
	imprint = window.open("./imprint.htm","imprint","'toolbars=0,location=0,scrollbars=1,statusbars=0,menubars=0,resizable=0,width=500,height=350,left=50,top=50");
	}

function checkSubmit() {
	check = confirm("Are you sure you want to submit the information?");
	return check;
	}
	
function loadPh(ph) {
	oID = "#lnav-" + ph + "-kl";
	self.location.href = $(oID).attr('href');
	}

function loadStory(st, stdiv) { // ajax aufruf liefert story html
	$('#story-slider').slider({ value: 0 });
	storySlide(0,0);
	$("#story").load('buildcontent.php', { story : st }, function() {
		$("div.thumbdiv").removeClass("thumbdiv-high");
		$(stdiv).addClass("thumbdiv-high");
		if ($("#story").attr("scrollWidth") - $("#story").width() <= 0) {
			$('#story-slider').hide();
			}
			else $('#story-slider').show();
		getPDFfromSession();
		});
	}

function loadMovie(mv, stdiv) { // ajax aufruf liefert movie html
	$("#story").load('buildcontent.php', { movie : mv }, function() {
		$("div.moviediv").removeClass("thumbdiv-high");
		$(stdiv).addClass("thumbdiv-high");
		});
	}

function storySlide(e, ui) {
	var maxScroll = $("#story").attr("scrollWidth") - $("#story").width();
	$("#story").attr({scrollLeft: ui.value * (maxScroll / 100)});
	}

function thumbSlide(e, ui) {
	var maxScroll = $("#thumbrow").attr("scrollWidth") - $("#thumbrow").width();
	$("#thumbrow").attr({scrollLeft: ui.value * (maxScroll / 100)});
	}

function loadPDF() {
	$.post('lib/session.php', { action:'pdf'}, function(data, success) {
		if (data.images.length < 1) { self.location.reload(); }
		$("#story").html(data.html);
		$('#story-slider').slider({ value: 0 });
		storySlide(0,0);
		if ($("#story").attr("scrollWidth") - $("#story").width() <= 0) {
			$('#story-slider').hide();
			}
			else $('#story-slider').show();
		$("#thumbrow").html("<div class=\"pdf-text\">Your bookmarked images</div>");
		$("#thumb-slider").hide();
		pdfMarker(data.images);
		}, "json");
	}

function pdfMarker(images) {
	$("#story img").each(function () {
		l=this.src.split("/");
		if(images.match(l[l.length-1])) $(this.nextSibling).removeClass("add").addClass("remove"); 
		});
	}

function getPDFfromSession() { 
	$.post('lib/session.php', { action:'get' }, function(data) {
		if(data.length > 0 && $("#story").html() !== null) { $("#lnav-pdf").show(); }
			else { $("#lnav-pdf").hide(); }
		pdfMarker(data);
		});
	}

function add2pdf(imgID) {
	$("#story img").each(function () {
		$(this.nextSibling).removeClass("remove").addClass("add"); 
		});
	$.post('lib/session.php', { action:'set', image:imgID }, function(data) {
		getPDFfromSession();
		});
	}
	
function makePDF() {
	$.post('lib/session.php', { action:'get' }, function(data) {
		oForm = document.forms.pdf;
		oForm.images.value = data;
		oForm.submit();
		});
	}

function pdfHandler(oID,stat) {
	if (stat == 1) {
		$("#" + oID + " div.add2pdf").fadeIn();
		}
		else {
			$("#" + oID + " div.add2pdf").fadeOut();
			}
	}

function updateDB(ph,cat,ser) { // neue sortierung in db schreiben
	var strURL = 'dbupdater.php';
	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest) 
		{
		self.xmlHttpReq = new XMLHttpRequest();
		}
			// IE
			else if (window.ActiveXObject) 
			{
			self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
			}
	self.xmlHttpReq.open('POST', strURL, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.setRequestHeader("Pragma", "no-cache");
	self.xmlHttpReq.setRequestHeader("Cache-Control", "must-revalidate");
	self.xmlHttpReq.setRequestHeader("If-Modified-Since", document.lastModified);
	self.xmlHttpReq.onreadystatechange = confirmUpdate;
	self.xmlHttpReq.send('ph=' + ph + '&cat=' + cat + '&' + ser);
	}

function confirmUpdate() { // update bestŠtigen
	if (self.xmlHttpReq.readyState == 4) 
		{
		//var data = eval('(' + self.xmlHttpReq.responseText + ')');
		var data = self.xmlHttpReq.responseText;
		alert(data);
		}
	}

function showStat(ph, oID) {
	window.status = ph + " / story no. " + oID;
	}
