var g_roller;
var g_roller_count = 0;
var g_showDetail_activePicture = 1;
var g_lastWindowHeight = -1;

function open_window(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable)
{
  toolbar_str = toolbar ? 'yes' : 'no';
  menubar_str = menubar ? 'yes' : 'no';
  statusbar_str = statusbar ? 'yes' : 'no';
  scrollbar_str = scrollbar ? 'yes' : 'no';
  resizable_str = resizable ? 'yes' : 'no';
  popup = window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
  popup.focus();
}

function open_popup(url) {
	open_window('popup', url, 20, 20, 620, 510, 0, 0, 0, 1, 0);
}

function showContent(contentNo) {
	// alle Contents verstecken
	for (var i = 1; i <= 10; i++) {
		var j = 1;
		while (true) {
			var ref = document.getElementById("cont"+i+"_"+j);
			if (ref != null)
				ref.className="cHidden";
			else break;
			j++;
		}
	}
	// selektierten Content anzeigen
	var j = 1;
	while (true) {
		var ref = document.getElementById("cont"+contentNo+"_"+j);
		if (ref != null)
			ref.className="";
		else break;
		j++;
	}
}

function switchContentTemporarly(showContentNo, hideContentNo, duration) {
	switchContent(showContentNo, hideContentNo);
	window.setTimeout(switchContent, duration, hideContentNo, showContentNo);
}

function switchContent(showContentNo, hideContentNo) {
	// selektierten Content verstecken
	var j = 1;
	while (true) {
		var ref = document.getElementById("cont"+hideContentNo+"_"+j);
		if (ref != null)
			ref.className="cHidden";
		else break;
		j++;
	}
	// selektierten Content anzeigen
	var j = 1;
	while (true) {
		var ref = document.getElementById("cont"+showContentNo+"_"+j);
		if (ref != null)
			ref.className="";
		else break;
		j++;
	}
}

function rollHor(direction, maxOffset) {
	g_roller = window.setInterval("doRollHor("+direction+", "+maxOffset+")", 50);
}
function stopRoll() {
	window.clearInterval(g_roller);
	g_roller_count = 0;	// Dynamisierung der Scrollweite zuruecksetzen
}
function doRollHor(direction, maxOffset) {
	var scrollDistance;
	var areaToScroll;
	var offset;
	var scrollWidth = 4;	// default Scrollweite
	g_roller_count += 1;	// Anzahl der Durchlaeufe
	// Dynamisierung der Scrollweite
	if ((g_roller_count > 10) &&  (g_roller_count <= 20))
		scrollWidth = 8;
	if ((g_roller_count > 20) &&  (g_roller_count <= 30))
		scrollWidth = 16;
	if ((g_roller_count > 30))
		scrollWidth = 16;
	scrollDistance = direction * scrollWidth;
	areaToScroll = document.getElementById("scrollArea");
	offset = parseInt(areaToScroll.style.left) + scrollDistance;
	if (offset > 0) offset = 0;
	if (offset < maxOffset) offset = maxOffset;
	areaToScroll.style.left = offset + "px";
}

function showDetail(id) {
	var detailPicture;
	var oldPreviewPicture;
	var actPreviewPicture;
        var pictureType = ".png";
	if (g_showDetail_activePicture != id) {
		oldPreviewPicture = document.getElementById("pic"+g_showDetail_activePicture);
		oldPreviewPicture.src = "../resource/kollektion/f"+g_showDetail_activePicture+pictureType;
		actPreviewPicture = document.getElementById("pic"+id);
		actPreviewPicture.src = "../resource/kollektion/f"+id+"s"+pictureType;
		detailPicture = document.getElementById("detail");
		detailPicture.src = "../resource/kollektion/d"+id+pictureType;
		g_showDetail_activePicture = id;
		actPreviewPicture.blur(); // entfernt den gestrichelten Rahmen im IE. Muss am Ende der Funktion stehen, weil der Safari nach Aufruf von blur() die Abarbeitung der Funktion abbricht.
	}
}

function checkHeightForCenteredDisplay(areaHeight, checkInterval){
	doCheckHeightForCenteredDisplay(areaHeight);
	if (checkInterval > 0) {	// laufend ueberpruefen
		window.setInterval("doCheckHeightForCenteredDisplay("+areaHeight+")", checkInterval);
	}
}

function doCheckHeightForCenteredDisplay(areaHeight){
	var actHeight = innerWindowHeight();
	if (g_lastWindowHeight != actHeight) {
		var area = document.getElementById("verticalCentered");
		if (actHeight < areaHeight) {	// Hoehe nicht ausreichend
			area.className = "verticalCenteredFallback";
		} else {			// Hoehe ist ausreichend
			area.className = "verticalCenteredDefault";
		}
		g_lastWindowHeight = actHeight;
	}
}

// von QuirksMode.com
// Ermitteln der inneren Hoehe und Breite des Fensters
function innerWindowWidth() {
	var x;
	if (self.innerHeight) {		// all except Explorer
		x = self.innerWidth;
		return x;
	}
	if (document.documentElement && document.documentElement.clientHeight) {	// Explorer 6 Strict Mode
		x = document.documentElement.clientWidth;
		return x;
	}
	if (document.body) {		// other Explorers
		x = document.body.clientWidth;
		return x;
	}
	return x;
}

function innerWindowHeight() {
	var y = 0;
	if (self.innerHeight) {		// all except Explorer
		y = self.innerHeight;
		return y;
	} 
	if (document.documentElement && document.documentElement.clientHeight) {	// Explorer 6 Strict Mode
		y = document.documentElement.clientHeight;
		return y;
	} 
	if (document.body) {		// other Explorers
		y = document.body.clientHeight;
		return y;
	}
	return y;
}
