/*
	===============
	escher.js
	===============
	www.escher-illustration.de

	Global site scripts

	------------------------
	Author : 	Stefan Schaden
	Created: 	July 9 2008
	Revised: 	Aug 26 2008
				March 31 2010
	------------------------
*/

var resizeactive;

/*
	setCaption(newText)
	========================
	Change image caption text according to function argument.
	To be called by thumbnail mouse event.

	TO DO: assign getElementByIds to variables
*/

function setCaption(newText) {

	var descriptionBits = newText.split("#");			// split description into title and details
	var title = descriptionBits[0];
	var details = descriptionBits[1];
	var nl = details.replace(/\<br\>/g, "\n");			// replace HTML breaks by "\n"
	details = nl;

	//~ var textlength = document.getElementById("captionBottom").firstChild.nodeValue.length;
	var textlength = document.getElementById("captionBottom").firstChild.length;
	document.getElementById("captionBottom").firstChild.deleteData(0, textlength);
	document.getElementById("captionBottom").firstChild.nodeValue = title;

	textlength = document.getElementById("imgDescription").firstChild.nodeValue.length;
	document.getElementById("imgDescription").firstChild.deleteData(0, textlength);
	textlength = document.getElementById("imgDescription").lastChild.nodeValue.length;
	document.getElementById("imgDescription").lastChild.deleteData(0, textlength);
	document.getElementById("imgDescription").firstChild.nodeValue = details;
}


/*
	swapImage(image, description)
	===============================
	Change image caption text according to function argument.
	To be called by thumbnail mouse event.
*/

function swapImage(image, description) {
	//~ alert(document.BIG.src);
	document.BIG.src = image;
	document.getElementById("BIG").style.display = "none";
	//~ document.getElementById("captionBottom").style.display = "none";
	new Effect.Appear('BIG', {duration: 3.8});
	setCaption(description);
	//~ new Effect.Appear('captionBottom', {duration: 6.0});
	//~ new Effect.BlindDown('captionBottom', { duration: 4.0} );
	new Effect.BlindDown('captionBottom', { duration: 4.0} );
	//~ new Effect.SlideDown('captionBottom', { duration: 6.0} );
}

/*
	fadeTitleImages()
	===============================
	Title page only: image fade-in
*/

function fadeTitleImages() {

	document.titleAnimation1.src = "images/titlepage/sessel_down_anim.gif";
	document.titleAnimation2.src = "images/titlepage/selbst_sieger_base.gif";

	document.getElementById("hoverbox1").style.display = "none";
	new Effect.Appear('hoverbox1', {duration: 4.8});
	document.getElementById("hoverbox2").style.display = "none";
	new Effect.Appear('hoverbox2', {duration: 4.8});

	document.getElementById("caption1").style.display = "none";
	new Effect.Appear('caption1', {duration: 4.8});
	document.getElementById("caption2").style.display = "none";
	new Effect.Appear('caption2', {duration: 4.8});


	document.getElementById("top").style.display = "none";
	new Effect.Appear('top', {duration: 3.8});
	document.getElementById("leftTitleImg").style.display = "none";
	new Effect.Appear('leftTitleImg', {duration: 7.8});
	document.getElementById("rightTitleImg").style.display = "none";
	new Effect.Appear('rightTitleImg', {duration: 7.8});
}

/*
	splashPage()
	===============================
	Title page only: image fade-in
*/

function splashPage() {
	ie_for_mac_no_thanks();
	if (navigator.appName === 'Microsoft Internet Explorer')
		return;
	//~ document.getElementById("titleText").style.display = "none";
	//~ new Effect.Appear('titleText', {duration: 4.8});
	document.getElementById("splashPageContent").style.display = "none";
	new Effect.Appear('splashPageContent', {duration: 4.8});

}


function swapImage_old(image, description) {
	Effect.BlindDown('BIG', { duration: 3});
	Effect.SlideDown('captionBottom', { duration: 2} );
	document.BIG.src = image;
	setCaption(description);
}


/*
	morphImage()
	===============================
	Resize main image on mouseover event
	Parameters currently unused
*/

function morphImage(direction, resizeWidth, resizeHeight) {

var fancy = 0;

//~ alert(navigator.userAgent);
//~ alert(navigator.userAgent);
//~ alert(document.BIG.src);

//~ alert('Resize to: ' + 'width: ' + resizeWidth + ' height: ' + resizeHeight)
//~ $('BIG').morph('width:' + resizeWidth + 'px; ' + 'height: ' +  resizeHeight + 'px');
//~ return;

// 31.03.2010: added images: "experiment (freie)", "irrgarten" (buch)

var imagename;

if (document.BIG.src.match(/(max_und_moritz|irrgarten|experiment)(_big)*\.jpg$/g)) 	{

	//~ alert("#" + imagename + "#");

	imagename = RegExp.$1;		// 1st match: image name without file extension, may also contain suffix "_big"

		if (direction === 'grow') {

 			if (navigator.userAgent.indexOf("Safari") > -1 || navigator.appName === 'Microsoft Internet Explorer') {
				return;
				//~ document.BIG.src = 'images/gallery/full/max_und_moritz_big.jpg';
			}

			if (resizeactive === 1) return;
			resizeactive = 1;

				if (fancy === 0) {
					//~ document.BIG.src = 'images/gallery/full/max_und_moritz_big.jpg';
					document.BIG.src = 'images/gallery/full/' + imagename + '_big.jpg';
					resizeactive = 0;
					return;
				}

			document.getElementById("BIG").style.display = "none";
			document.getElementById("captionBottom").style.display = "none";
			new Effect.Appear('BIG', {duration: 0.3});
			//~ document.BIG.src = 'images/gallery/full/max_und_moritz_big.jpg';
			document.BIG.src = 'images/gallery/full/' + imagename + '_big.jpg';
			resizeactive = 0;
		}

		else if (direction === 'shrink') {

			if (navigator.userAgent.indexOf("Safari") > -1  || navigator.appName === 'Microsoft Internet Explorer') {
				return;
			}

			if (fancy === 0) {
					//~ document.BIG.src = 'images/gallery/full/max_und_moritz.jpg';
					document.BIG.src = 'images/gallery/full/' + imagename + '.jpg';
					resizeactive = 0;
					return;
			}

			if (resizeactive === 1) return;
			resizeactive = 1;

			document.getElementById("captionBottom").style.display = "none";
			new Effect.Appear('BIG', {duration: 1.8});
			new Effect.Appear('captionBottom', {duration: 1.8});
			//~ document.BIG.src = 'images/gallery/full/max_und_moritz.jpg';
			document.BIG.src = 'images/gallery/full/' + imagename + '.jpg';

			//~ alert(navigator.appName);
			resizeactive = 0;
		}
	}
} // end function


function closepopup() {
	if (document.getElementById) {
		//~ document.getElementById("popup").style.display="none";
		document.getElementById("bilddesmonats").style.display="none";
		return false;
	}
else return true;
}

function openpopup() {
	if (document.getElementById) {
		//~ document.getElementById("popup").style.display="none";
		document.getElementById("bilddesmonats").style.display="block";
		return false;
	}
else return true;
}

function closeausstellung() {
	if (document.getElementById) {
		//~ document.getElementById("popup").style.display="none";
		document.getElementById("ausstellung").style.display="none";
		return false;
	}
else return true;
}

function closekalender() {
	if (document.getElementById) {
		//~ document.getElementById("popup").style.display="none";
		document.getElementById("kalender").style.display="none";
		return false;
	}
else return true;
}


/*
	ie_for_mac_no_thanks()
	===============================
	Disallow IE for Mac
	Tested for 5.2, supposed to work for earlier releases too

	User Agent: Mozilla/4.0 (compatible; MSIE 5.23; Mac_PowerPC)
	App Name: Microsoft Internet Explorer
*/

function ie_for_mac_no_thanks() {

	if (navigator.userAgent.indexOf("MSIE") > -1  && navigator.userAgent.indexOf("Mac_PowerPC") > -1 ) 	{
		document.writeln('Sie verwenden Internet Explorer für Macintosh-Computer. Dieser Browser ist veraltet.<br>');
		document.writeln('www.escher-illustration.com kann mit diesem Browser leider nicht angezeigt werden.<br>');
		document.writeln('Bitte verwenden Sie einen aktuellen Browser.<br><br>');

		document.writeln('You are using Internet Explorer for Macintosh computers. This browser is outdated.<br>');
		document.writeln('We are sorry that www.escher-illustration.com cannot be displayed by this browser.<br>');
		document.writeln('Please update your browser.<br><br>');

		document.writeln("Empfohlen & kostenlos:<br>recommended & free:<br><br> <a href='http://www.mozilla-europe.org/de/firefox/'\
		target='_new'><img src='images/bg/firefox.jpg' border=\"0\"' ></a>");
	}
	//~ stop();

	return;
}


