function linkchecker(url) {
  var curl = replaceChars(url,"&amp;","kaufmund");
  curl = replaceChars(curl,"&","kaufmund");
  curl = replaceChars(curl,"+","EinPlus");
  var _location = replaceChars(window.location.href,"#","");
  var cUrl = "http://www.modellskipper.de/linkcheck.php?location=" + _location + "&link=" + curl;
  var cWindow = window.open(cUrl);
  if (!cWindow.opener) cWindow.opener = self;
  if (cWindow.focus != null) cWindow.focus();
}

function replaceChars(text,suche,ersetze) {
  out = suche;
  add = ersetze;
  temp = text;
  while (temp.indexOf(out)>-1) {
    pos= temp.indexOf(out);
    temp = "" + (temp.substring(0, pos) + add + temp.substring((pos + out.length), temp.length));
  }
  return temp;
}

var speed = 20;
var interval = 10000;
var index = oldIndex = 0;

function Bildwechsel() {
	createBackgroundContainer(document.getElementById('image'));
	setTimeout('startFading()', interval);
}

function createBackgroundContainer(element) {
	var image = document.createElement('img');
	image.setAttribute('id', 'image');
	image.setAttribute('src', element.src);
	image.setAttribute('alt', element.alt);
	image.style.width = element.width + 'px';
	image.style.height = element.height + 'px';
	image.style.margin = '0';

	var backgroundContainer = document.createElement('span');
	backgroundContainer.setAttribute('id', 'backgroundContainer');
	backgroundContainer.style.display = 'block';
	backgroundContainer.style.padding = '0';
	backgroundContainer.style.width = element.width + 'px';
	backgroundContainer.style.height = element.height + 'px';
	backgroundContainer.appendChild(image);

	var parent = element.parentNode;
	parent.replaceChild(backgroundContainer, element);
}

function startFading() {
	var image = document.getElementById('image');
	index = Math.round(Math.random() * Bilderanzahl-1);
	while (oldIndex == index) {
		index = Math.round(Math.random() * Bilderanzahl-1);
	}
	oldIndex = index;
	var bild="zufallsbilder/"+index +".jpg"

	var backgroundContainer = document.getElementById('backgroundContainer');
	backgroundContainer.style.backgroundImage = "url('" + document.getElementById('image').src + "')"

	image.style.opacity = 0;
  image.setAttribute('src', bild);

	for (var i = 0; i < 100; i++) {
		setTimeout('fadeIn(' + i + ')', speed*i);
	}
	setTimeout("startFading()", interval);
}

function fadeIn(i) {
	document.getElementById('image').style.opacity = i/100;
}

function kontakt(projekt,thema) {
  Tip('<iframe src=\'http://www.modellskipper.de/kontaktformular.php?thema=' + thema + '&projekt=' + projekt + '\' width=\'480\' height=\'320\' frameborder=\'0\' scrollbars=\'no\'></iframe>', TITLE,'',BGCOLOR,'#ffffff',BORDERCOLOR,'#8080ff',CLOSEBTN, true, CLOSEBTNTEXT, 'Schlie&szlig;en',  CLOSEBTNCOLORS,'', FADEIN, 300, FADEOUT, 300, OFFSETX, -250, OFFSETY, +20, PADDING, 0, SHADOW, false ,STICKY, true, CLICKCLOSE,false ,WIDTH,480  ,DELAY,0)
}

function kontaktformular() {
  Tip('<iframe src=\'http://www.modellskipper.de/kontaktformular.php?referenz='+ SiteReferenz + '\' width=\'480\' height=\'320\' frameborder=\'0\' scrollbars=\'no\'></iframe>', TITLE,'',BGCOLOR,'#ffffff',BORDERCOLOR,'#8080ff',CLOSEBTN, true, CLOSEBTNTEXT, 'Schlie&szlig;en',  CLOSEBTNCOLORS,'', FADEIN, 300, FADEOUT, 300, OFFSETX, -250, OFFSETY, +20, PADDING, 0, SHADOW, false ,STICKY, true, CLICKCLOSE,false ,WIDTH,480  ,DELAY,0)
}

