window.addEvent('domready', function()
{
	mAktiv = 0;

	if($('sqlError'))
		$('sqlError').makeDraggable();

	/* Einblenddauer für Inhaltsbereich */
	rahmen = new Fx.Tween($('iRahmen'), { duration: 500 } );
	
	/* Slimbox sucht nach Bildern */
	Slimbox.scanPage();

	if(rubrik == "home")
	{
		for(var i=1; i<4; i++)
		{
			$("li" + i).set('opacity', 0);
			$("mLi" + i).set('opacity', 0);
			$("lPic" + i).set('opacity', 0);
		}
		$("inhalt").set('opacity', 0);
		intro();
	}
	else
	{
		hideSelect();
		$('menu').style.left = "248px";
		if(browser.substr(0,2) == "ie")
			$('farbleiste').set('opacity', .8);
	}

	/* Wiederverwendbares Request-Element für Inhaltsbereich */
	laden = new Request(
	{
		url: base+'/load.php',
		method: 'get',
		onSuccess: function(response)
		{
			var temp = response.split("|**|");
			$('iRahmen').innerHTML = temp[0];
			document.title = "J. Buchmann Immobilien - " + temp[1];
			rubrik = temp[2];
			Slimbox.scanPage();
			hideSelect();
			rahmen.start('opacity', $('iRahmen').style.opacity, 1)
		}	
	});
});

function hideSelect()
{
	if($('flaeche'))
		$('flaeche').slide('hide');
	if($('standort'))
		$('standort').slide('hide');
}

function intro()
{
	var tarTransp = 1;
	if(browser.substr(0,2) == "ie")
		tarTransp = .8;
	if(!ise)
	{
		var a = 1500;
		var b = 2500;
		var c = 3000;
	}
	else
	{
		var a = 0;
		var b = 0;
		var c = 0;
	}
	var intro = new Fx.Tween($('intro'), { duration: b } );
	var text1 = new Fx.Tween($('introText1'), { duration: a } );
	var text2 = new Fx.Tween($('introText2'), { duration: a } );
	var farbleiste = new Fx.Tween($('farbleiste'), { duration: a } );
	var menu = new Fx.Tween($('menu'), { duration: a } );
	var pic1 = new Fx.Tween($('lPic1'), { duration: a } );
	var pic2 = new Fx.Tween($('lPic2'), { duration: b } );
	var pic3 = new Fx.Tween($('lPic3'), { duration: c } );
	var homeText = new Fx.Tween($('inhalt'), { duration: b } );
	var umenu = new Fx.Tween($('untermenu'), { duration: b } );
	var news = new Fx.Tween($('aText'), { duration: b } );
	var newsBild = new Fx.Tween($('aBild'), { duration: b } );
	menu.set('opacity', 1);
	intro.start('opacity', 0, 1).chain(function()
	{
		text1.start('opacity', 0, 1).chain(function()
		{
			text2.start('opacity', 0, 1).chain(function()
			{
				farbleiste.start('opacity', 0, tarTransp).chain(function()
				{
					menu.start('left', -800, 248).chain(function()
					{
						intro.start('opacity', 1, 0).chain(function()
						{
							$('intro').innerHTML = "";
							$('aktuell').style.backgroundColor = "white";
							pic1.start('opacity', 0, 1);
							pic2.start('opacity', 0, 1);
							pic3.start('opacity', 0, 1);
							homeText.start('opacity', 0, 1);
							umenu.start('opacity', 0, 1);
							news.start('opacity', 0, 1);
							newsBild.start('opacity', 0, 1);
						});
					});
				});
			});
		});
	});
}

function divAnAus(div, force)
{
	var a = document.getElementById(div).style;
	if(force == "ein")
		a.visibility = "visible";
	else if(force == "aus")
		a.visibility = "hidden";
	else if(a.visibility == "hidden")
		a.visibility = "visible";
	else
		a.visibility = "hidden";
}

function markLi(nr, func)
{
	if(nr)
	{
		if(!$("li" + nr).style.opacity)
			var oa = 0;
		else
			var oa = $("li" + nr).style.opacity;
	}
	var oe = 0;
	if(func == "aktiv")
	{
		mAktiv = nr;
		for(var i=1; i<4; i++)
		{
			toa = $("li" + i).style.opacity
			poa = $("lPic" + i).style.opacity
			if(toa == 1 && i == nr)
				continue;
			else
			{
				$("li" + i).tween('opacity', toa, oe);
				$("mLi" + i).tween('opacity', toa, oe);
				if(!nr)
					$("lPic" + i).tween('opacity', poa, 1)
				else if(i != nr)
					$("lPic" + i).tween('opacity', poa, .65)
				else
					$("lPic" + i).tween('opacity', poa, 1)
			}
		}
		if(nr && $("li" + nr).style.opacity != 1)
		{
			oe = 1;
			$("li" + nr).tween('opacity', oa, oe);
			$("mLi" + nr).tween('opacity', oa, oe);
		}
	}
	else if(nr && mAktiv != nr)
	{
		if(func == "hover")
			oe = .65;
		else
			oe = 0;
		$("li" + nr).tween('opacity', oa, oe);
		$("mLi" + nr).tween('opacity', oa, oe);
	}
}

function markTr(o, f)
{
		var hex = $(o).style.backgroundColor;
		var tar = "#EFF1F4";
		if(rubrik == "ladenflaechen")
			tar = "#fff5e5";
		else if(rubrik == "wohnungen")
			tar = "#F2E7E9";
			
		if(hex.substr(0,1) != "#")
			hex = "#" + RGBtoHex(hex);
		if(f)
			$(o).tween('background-color', hex, tar);
		else
			$(o).tween('background-color', hex, "#FFFFFF");
}

function lade(tar)
{
	rahmen.start('opacity', $('iRahmen').style.opacity, 0).chain(function()
	{
		$('iRahmen').innerHTML = "";
		laden.send('v='+tar);
	});
}

function drucken()
{
	window.print();
}

function slideInOut(o, f)
{
	if(o == "flaeche")
		$('standort').slide('out');
	else
		$('flaeche').slide('out');
	$(o).slide(f);
}

function setTitle(o, id, bID)
{
	$('sel' + o).load(base + '/xmlhttp/select.php?rubrik=' + rubrik + '&sel=' + o + '&id1=' + id + '&id2=' + bID);
}

function RGBtoHex(rgb)
{
	if(!rgb)
	{
		var R = 255;
		var G = 255;
		var B = 255;
	}
	else
	{
		var ausdruck = /rgb\(([0-9]*),\s*([0-9]*),\s*([0-9]*)\)/;
		ausdruck.exec(rgb);
		var R = RegExp.$1;
		var G = RegExp.$2;
		var B = RegExp.$3;
	}
	return toHex(R)+toHex(G)+toHex(B)
}

function toHex(N)
{
	if(N==null)
 		return "00";
	N=parseInt(N);
	if(N==0 || isNaN(N))
		return "00";
	N=Math.max(0,N);
	N=Math.min(N,255);
	N=Math.round(N);
 	return "0123456789ABCDEF".charAt((N-N%16)/16) + "0123456789ABCDEF".charAt(N%16);
}
