/*
  Corné Gabriëls
  Copyright (C) 2007–2009 by Systemantics, Bureau for Informatics

  Systemantics GmbH
  Am Lavenstein 3
  52064 Aachen
  GERMANY

  Web:    www.systemantics.net
  Email:  hello@systemantics.net

  Permission granted to use the files associated with this
  website only on your webserver.

  Changes to these files are PROHIBITED due to license restrictions.
*/



var currentImage = 0;
var duration = 500;
var steps = 10;
var moving = false;
var loaded = false;

function nextImage(offsets) {
	if (!loaded || moving) {
		return;
	}
	moving = true;
	currentImage++;
	if (currentImage==offsets.length) {
		currentImage = 0;
	}
	moveImage(offsets[currentImage], steps);
}

function moveImage(targetX, stepsLeft) {
	if (getObjectLeft('stripe')==-targetX) {
		moving = false;
		return;
	}
	if (currentImage==0) {
		step = -getObjectLeft('stripe')/stepsLeft
	} else {
		step = (-getObjectLeft('stripe')-targetX)/stepsLeft;
	}
	shiftBy('stripe', step, 0);
	stepsLeft--;
	window.setTimeout('moveImage('+targetX+','+stepsLeft+')', duration/steps);
}

function initStripe() {
	loaded = true;
}

function resizeShowcase() {
	// Stretch image width to window width
	var img = getObject('showcaseImage');
	var ww = getInsideWindowWidth();

	if (fitShowcase) {
		// Fit
		var wh = getInsideWindowHeight();
		var iw = parseInt(img.width);
		var ih = parseInt(img.height);
		// Stretch image width to window width
		ih = Math.floor(ih/iw*ww);
		iw = ww;
		if (ih>wh) {
			iw = Math.floor(iw/ih*wh);
			ih = wh;
		}
		img.width = iw+"px";
		img.height = ih+"px";
	} else {
		// Don't fit => just stretch to width
		img.width = ww+"px";
	}
	if (getObject("preview")) {
		shiftTo("preview", 0, Math.max((wh-getObjectHeight("previewImage"))/2-86-50, 0));
	}
}

function initShowcase() {
	window.onresize = resizeShowcase;
	resizeShowcase();
	show("logo");
	show("showcaseImage");
	show("preview");
}

var oldImage = false;

function changeImage(img) {
	if (oldImage) {
		getObject("articleImage"+oldImage).display = "none";
	} else {
		var imgs = getRawObject("article").getElementsByTagName("img");
		for (var i=0; i<imgs.length; i++) {
			if (imgs[i].id) {
				imgs[i].style.display = "none";
			}
		}
	}
	oldImage = img;
	getObject("articleImage"+img).display = "inline";
}

$(function() {
	$(".button").click(function() {
		location.href = $(this).closest(".article").find("a").attr("href");
	});
});
