var bernd = {
	fish : {
		no1: 'url(http://'+document.location.host+'/sitemedia/img/fish1.jpg)',
		no2: 'url(http://'+document.location.host+'/sitemedia/img/fish2.jpg)',
		div: null,
		as: null,
		x: 0,
		subsite: null,
	},
	
	init : function() {
		bernd.fish.subsite = (document.location.pathname).split("/")[1];
		bernd.fish.div = YAHOO.util.Dom.get('topcontainer');
//		bernd.fish.as = YAHOO.util.Dom.getElementsBy(function(o) {return true;}, 'a', 'navi');
//		YAHOO.util.Event.on(bernd.fish.as, 'mouseover', bernd.changeBg);	
		bernd.changeBg();
	},
	
	changeBg : function() {
		var bg = YAHOO.util.Dom.getStyle(bernd.fish.div, 'background-image');
		bg = stripCharacter(bg, '"'); // for opera and safari
		if (bg==bernd.fish.no1 || bg=='')
			YAHOO.util.Dom.setStyle(bernd.fish.div, 'background-image', bernd.fish.no2);
		else
			YAHOO.util.Dom.setStyle(bernd.fish.div, 'background-image', bernd.fish.no1);
		bernd.fish.x += 0.1;
		switch(bernd.fish.subsite) {
			case "refs":
				y = Math.max(Math.tan(bernd.fish.x) * 500, 90);	break;
			case "about":
				y = bernd.fish.x++ * bernd.fish.x++ * bernd.fish.x++ + 500; break;
			default:
				y = Math.floor(Math.random()*5000) + 2000;
		}
		setTimeout(bernd.changeBg, y);
	}
}
YAHOO.util.Event.on(window, 'load', bernd.init);

function stripCharacter(words,character) {
	var spaces = words.length;
	for(var x = 1; x<spaces; ++x)
		words = words.replace(character, "");
	return words;
}

function prelo(bild) {
    var pre_image = new Image();
    pre_image.src = bild;
}
prelo('/sitemedia/img/fish1.jpg');
prelo('/sitemedia/img/fish2.jpg');


// now make clicks on the bottom transparent if over an A-Element
var xy = null;
getElByXY = function(el) {
	el_xy = YAHOO.util.Dom.getRegion(el);
//	console.log(el_xy, ' left: ', el_xy['left'], ' right: ', el_xy['right']);
	if (xy[0] > el_xy['left'] && xy[0] < el_xy['right'] && xy[1] > el_xy['top'] && xy[1] < el_xy['bottom'])
		return true;
	return false;
}
transparentOperation = function(e) {
  	xy = YAHOO.util.Event.getXY(e);
  	var a_el = YAHOO.util.Dom.getElementBy  ( getElByXY, 'A' , 'content' );
  	if (a_el != '') {
//  		console.log(a_el.href);
  		document.location.href = a_el.href;
  	}
}
YAHOO.util.Event.on('bg', 'mousedown', transparentOperation);
