﻿var OnLoad = {
	fns: [],
	add: function(fn) {
		this.fns.push(fn);
	},
	get: function() {
		return this.fns;
	},
	exec: function() {
		for (var i in this.fns) {
			this.fns[i]();
		}
	}
};
window.onload = function() {OnLoad.exec();};

var version = '?v=1';
var px = 5;
var d;
var s;
var imagePath = "img/fotos/";
var images = [];
var bigImageEl;
var activeImage = {
	i: null,
	el: null
};

OnLoad.add(function() {
	d = document.getElementById("col1_content");
});

function scroll(up) {
	if (d)
	{
		scrollCancel();
		var y = d.scrollTop;
		
		if (up)
			y-=px;
		else
			y+=px;
		
		if( y <= d.scrollHeight-d.offsetHeight+px && y >= 0-px)
			d.scrollTop = y;
		
		s = setInterval("scroll(" + up + ")", 50);
	}
}
function scrollCancel() {
	clearInterval(s);
}

function createImageTable(images, size) {
	var iLen = images.length;
	var len = iLen;
	var result = "<table class='gallery'><tr>";
	var sz = '';
	if (size && size.w >= 0) sz += " width='"+size.w+"'";
	if (size && size.h >= 0) sz += " height='"+size.h+"'";
	
	while((len % 6) !== 0) {
		len++;
	}
	
	for (var i = 0; i < len; i++)
	{
		if ((i%6) === 0 && i > 0)
			result += "</tr><tr>";
		if (i < (iLen-1)) {
			result += "<td><img src='" + imagePath + "small/" + images[i] + version + "'"+sz+" onmouseover='mouseOverImage(this, " + i + ")' onmouseout='mouseOutImage(this, " + i + ")' " /*+ "onclick='showImage(this, " + i + ")'" */+ " alt='' /></td>";
		}
		else
			result += "<td>&nbsp;</td>";
	}
	result += "</tr></table>";

	d.innerHTML = result;
}

function mouseOverImage(el, i) {
	el.src = imagePath + "small_color/" + images[i] + version;
	showImage(el, i);
}

function mouseOutImage(el, i) {
	if(activeImage.i === null || activeImage.i !== i)
		el.src = imagePath + "small/" + images[i] + version;
}

function showImage(el, i) {
	if(activeImage.i !== null)
	{
		var oldEl = activeImage.el;
		var oldI = activeImage.i;
		activeImage.el = null;
		activeImage.i = null;
		
		mouseOutImage(oldEl, oldI);
	}
	activeImage.i = i;
	activeImage.el = el;
	bigImageEl.innerHTML = "<img src='" + imagePath + "big/" + images[i] + "' alt='' />";
}

function logoClick() {
	window.location.href='index.html';
}

function videoClick(nr) {
	nr = nr || 1;
	window.location.href='video.html?play='+nr;
}

function fotosClick() {
	window.location.href='fotos.html';
}

function getVar(varname) {
	var v=location.search.substring(1, location.search.length).split('&');
	var getVars = new Array();

	for(var i=0; i<v.length; i++){
		var temp = v[i].split('=');
		getVars[temp[0]] = temp[1];
	}
	
	return getVars[varname] || null;
}

OnLoad.add(function() {
	var h = document.getElementById('header');
	var cnt = document.createElement('div');
	var line = document.createElement('div');
	var img = document.createElement('div');
	cnt.style.position = 'absolute';
	cnt.style.top = '100px';
	cnt.style.left = '600px';
	cnt.style.width = '72px';
	cnt.style.height = '45px';
	cnt.style.border = '1px solid #FFFFFF';
	cnt.style.padding = '1px';
	cnt.style.cursor = 'pointer';
	cnt.onclick = function() {videoClick(2);};
	
	img.id = 'logo-video2';
	img.style.background = 'url("img/VIDEO_2.jpg") #000000';
	img.style.width = '100%';
	img.style.height = '100%';
	img.alt = 'UV-Flachbettdruck';
	img.title = 'UV-Flachbettdruck';
	
	line.style.position = 'absolute';
	line.style.top = '150px';
	line.style.left = '660px';
	line.style.width = '1px';
	line.style.height = '24px';
	line.style.borderLeft = '1px solid #FFFFFF';
	line.style.padding = '1px';
	
	cnt.appendChild(img);
	h.appendChild(cnt);
	h.appendChild(line);
});




