///////////////////////////////////////////////////////////////////////////////
// Text //////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

var path2images = "";
var path2bgimages = "files/bgimg/";

//////////////////////////////////////////////////////////////////////////////////////////
//   Slide Show based on Shuffler v1.0 by
//   Carl Camera
//   http://iamacamera.org 
// SetOpacity Function by
//   Richard Rutter
//   http://clagnut.com
// License: Creative Commons Attribution 2.5  License
//   http://creativecommons.org/licenses/by/2.5/
//////////////////////////////////////////////////////////////////////////////////////////

var slide = new Array();
var slideText = new Array;
var slidePreloaded = new Array();
var slideCount = 0;
function slideshow(direction)
{
	if(slidePreloaded.length < (slideCount+1))
		slidePreload(); // preload the first image
	
	var theImg = element("slidepic");
	var theText = element("slide_text");
	var theDiv = element("slide");
	var theCount = element("slidecounter");
	
	if(direction == "forward") 
	{
		slideCount++;
		if(slideCount > slide.length-1) slideCount = 0;
	}
	if(direction == "back")
	{
		slideCount--;
		if(slideCount < 0) slideCount = slide.length-1;
	}
	
	if(!direction) 
		theImg.src = slidePreloaded[slideCount].src; 
	else
	{	
		theDiv.style.backgroundImage='url('+slidePreloaded[slideCount].src+')';
		slideFade()
	}
		
	theText.innerHTML = slideText[slideCount];
	theCount.innerHTML = "<span>" + (slideCount+1) +" / "+ slide.length + "</span>";
	slidePreload(); // call again to preload the rest
}

var slideFirstPic = true;
function slidePreload() 
{	
	if(slide.length > 0 && slidePreloaded.length < 2)
	{
		for(var i=0;i<slide.length;i++)
		{
			slidePreloaded[i] = new Image();
			slidePreloaded[i].src = path2images + slide[i];
			if(slideFirstPic == true)
			{
				slideFirstPic = false;
				break;
			}
		}
	}
}

var slideFadeSeconds = 0.5;
var slideOpacity = 100;
function slideFade()
{
  	var theImg = element("slidepic");
	
  	// determine delta based on number of fade seconds
	// the slower the fade the more increments needed
        var fadeDelta = 100 / (30 * slideFadeSeconds);

	// fade top out to reveal bottom image
	if (slideOpacity < 2*fadeDelta ) 
	{
		slideOpacity = 100;
		// stop the rotation if we're done
		theImg.src = slidePreloaded[slideCount].src;
	}
	else
	{
		slideOpacity -= fadeDelta;
		setOpacity(theImg,slideOpacity);
		setTimeout("slideFade()",30);  // 1/30th of a second
	}
  }

function setOpacity(obj, opacity) 
{
	opacity = (opacity == 100)?99.999:opacity;
	
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
  }
  


//////////////////////////////////////////////////////////////////////////////////////
// Generate Links //////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////

function genLink(destUrl,idx)
{
	switch(idx)
	{
		case 0: //self
			location.href=destUrl;
			break;
		
		// blank
		case 1: 
			var newWindow = window.open(destUrl,'_blank');
			newWindow.focus();
			break;
		
		// TNT normal
		case 2:
			var newWindow= window.open(destUrl,'visio3D','width=800,height=450');
			newWindow.focus();
			break;
		
		// TNT breit mit GR
		case 3:
			var newWindow= window.open(destUrl,'visio3D','width=990,height=450');
			newWindow.focus();
			break;
			
		// Immo360 normal
		case 4:
			var newWindow= window.open(destUrl,'visio360','width=1050,height=480');
			newWindow.focus();
			break;
		
		// Immo360 breit mit GR
		case 5:
			var newWindow= window.open(destUrl,'visio360','width=1050,height=480');
			newWindow.focus();
			break;
			
		// Slideshow
		case 6:
			var newWindow= window.open(destUrl,'visio360','width=640,height=520');
			newWindow.focus();
			break;
		
		default:
			location.href=destUrl;
			break;
	}
}

function openWin(destUrl,features,name)
{
		if(!name) { name = ""; }
		var newWindow= window.open(destUrl,name,features);
}

///////////////////////////////////////////////////////////////////////////////
// Toggle FAQ //////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

function toggleall(direction) 
{
	var styleprop = "";
	if(direction == "open") {
		styleprop = "block";
		imgprop = path2bgimages + "faq_minus.gif";
		element("faq_show_all").style.display = 'none';
		element("faq_hide_all").style.display = styleprop;
	}
	else
	{
		styleprop = "none";
		imgprop = path2bgimages + "faq_plus.gif";
		element("faq_show_all").style.display = 'block';
		element("faq_hide_all").style.display = styleprop;
	}
		
	var i = 0;
	while(element('tree'+i) != null) 
	{
		element('tree'+i).style.display = styleprop;
		element('img_tree'+i).src = imgprop;
		i++;
	}
}

function toggle(obj) 
{
	if(element(obj).style.display == "block") 
	{
		element(obj).style.display = "none";
		element("img_"+obj).src = path2bgimages + "faq_plus.gif";
	}
	else
	{
		element(obj).style.display = "block";
		element("img_"+obj).src = path2bgimages + "faq_minus.gif";
	}
}

///////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

function element(id)
{
	return document.getElementById(id);
}


function changeToActive(host) {
	var myClass='FRactive'
	if(host.className.substring(host.className.length-(myClass.length), host.className.length)!=myClass) {
		host.className+=" "+myClass;
	}
}
function changeToInactive(host) {
	var myClass='FRactive'
	if(host.className.substring(host.className.length-(myClass.length), host.className.length)==myClass) {
		host.className=host.className.substring(0, host.className.length-(myClass.length+1));
	}
}



// ###################################################################

function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		 obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj.attachEvent( "on"+type, function() { obj["e"+type+fn](); } );
	}
}

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj["e"+type+fn] );
		obj["e"+type+fn] = null;
	}
}

//addEvent(window,"load",test);








