var thumbID;
var imageSet = new Array();
var switchOff=0;

function showContent()
{
	if(thumbID){
		showItem(thumbID,'content');
	}
}


function showItem(id,type,loadImg)
{
	
	if((type=='mainImage'))
		switchOff=1;				

	var divType = type + 'Item';
	
	var ourDiv = document.getElementById(type + id);
	
	var area = document.getElementById(type);
	
	var children = area.childNodes;

	

	for(var j = 0;j<children.length;j++)
	{
		if(
			(children[j].className==divType)&&
			(children[j].alt=='on')&&
			(children[j].id != type + id)
		)
		{
			
			switch(type)
			{
				case 'content':
					$(".contentContent").hide();
					$(children[j]).slideUp("fast");					
					children[j].alt='off';
					toggleFlash(children[j],2);
					$(".contentContent").show();
				break;
				case 'teaser':
					
				break;
				case 'headline':
					$(children[j]).fadeOut("fast");
					
					
					children[j].alt='off';
					
					
					var idstring = children[j].id;
					
					var contentID = idstring.replace('headline','');
					
					var contentDiv = document.getElementById('content' + contentID);
					
					contentDiv.alt='off';
					
					$(contentDiv).slideUp("fast");
					
					toggleFlash(contentDiv,2);
					
				
				break;
				case "thumbContainer":
					$(children[j]).css(
					 { borderColor:"#fa0"}
					);

					
					children[j].alt='off';
				break;
				case 'mainImage':
					$(children[j]).fadeOut("fast");
					children[j].alt='off';
				break;
			}
		}
		
	}
	
	
	if(ourDiv.alt!='on')
	{
		switch(type)
		{
			case 'content':
				$(".contentContent").hide();
				$(ourDiv).slideDown("slow");
				ourDiv.alt='on';
				toggleFlash(ourDiv,1);
				switchOff=1;	
				$(".contentContent").show();
			break;
			case 'headline':
				ourDiv.alt='on';
				$(ourDiv).fadeIn("slow");
				thumbID = id;
				
				if(!loadImg)
					showItem(id,'mainImage');
			 //    showContent(id);
			break;
			case 'thumbContainer':
			
				ourDiv.alt='on';
				
				$(ourDiv).css(
				 { borderColor:"#fff"}
				);

				
			break;
			default:
				ourDiv.alt='on';
				$(ourDiv).fadeIn("slow");
		}
		
	}
	else
	{
		
		switch(type)
		{
			case 'content':
				$(ourDiv).slideUp('fast');
				toggleFlash(ourDiv,2);
				ourDiv.alt='off';
				switchOff=0;	
				initSwitch();
			break;
			case 'headline':
			/*
				var contentDiv = document.getElementById('content' + id);
				$(contentDiv).slideUp('fast');
				toggleFlash(contentDiv,2);
				$(ourDiv).fadeOut('fast');
				contentDiv.alt='off';
				ourDiv.alt='off';
			*/
			break;
			case "thumbContainer":
				$(ourDiv).css(
				 { borderColor:"#fa0"}
				);
				
				
				ourDiv.alt='off';

			break;
			case 'teaser':
			
			
				$(ourDiv).animate({ 
				        width:"0",marginLeft:"240px"
				   }, 'slow','linear');
				 
					ourDiv.alt='off';

			break;
			default:
				ourDiv.alt='off';
				$(type + id).hide();
		}
	}
	 
	//	ourDiv.style.display='none';
	
}
	
function initSwitch()
{
	
	if(imageSet.length<1)
	{
		var area = document.getElementById('mainImage');
		
		var children = area.childNodes;
		
		var j=0;
		
		for(var k=0;k<children.length;k++)
			if(children[k].className=='mainImageItem')
			{
				imageSet[j] = children[k];
				j++;
			}
				
		setTimeout('switchImage(0,0)',0);
	}
	else
	{
		//alert(currID);
		setTimeout('switchImage('+ (thumbID) + ','+ (thumbID - 1) + ')',8000);
	}
}

var currID=0;			

function switchImage(id,lastID)
{
	if(switchOff==0)
	{
		id = id % (imageSet.length);
	
		$(imageSet[lastID]).fadeOut("fast");
		$(imageSet[id]).fadeIn("slow");
		
		imageSet[id].alt='on';
		imageSet[lastID].alt='off';
		
		var nextID = id + 1;			
		var dataID = imageSet[id].id.replace('mainImage','');
		var currID=id;			
		
		showItem(dataID,'headline',true);
		showItem(dataID,'thumbContainer',true);
		
		setTimeout('switchImage(' + nextID + ',' + id + ')',8000);
	}
	else
	{
		var currID=lastID;			
		return false;
	}
	
}


function loadFlash(item,format)
{
	item.style.display = format;
}


function toggleFlash(item,action)
{
	var div=false;
	var wrapper = item.getElementsByTagName('EMBED');
	
	for(j=0;j<wrapper.length;j++)
		if (wrapper[j].tagName == 'EMBED')
		{
			var div = wrapper[j];

			switch(action)
			{
				case 1:
				//	setTimeout('loadFlash(div,\'block\')',1000);
				break;
				case 2:
					//loadFlash(div,'none');
				break;
			}
		}
}


function setTeasers()
{
	var type = 'thumbContainer';
	var area = document.getElementById(type);
	var children = area.childNodes;
	var divType = 'thumbContainer';

	for(var j = 0;j<children.length;j++)
	{
		//easeOutElastic
		//easeOutBack
		//easeOutSine
		//easeOutCirc
		//easeOutQuint
		//easeOutExpo
			 $(children[j]).hover(
			      function () {
			      	
			      	if(!$(this).attr("timestamp"))
			      		$(this).attr("timestamp",0);
			      	
			      	myDate = new Date();
			      	
			      	if(myDate.getTime() - $(this).attr("timestamp")  > 750)
			      	{
			      		
			      		$(this).attr('timestamp',myDate.getTime());
				      	$(this).css(
						 { borderColor:"#fc0"}
						);
				        $(this).animate({ 
								width:"302px",left:"0"
						  }, '8000','easeOutBack' );
					}
			      }, 
			      function () {
						$(this).css(
						 { borderColor:"#fa0"}
						);
						 $(this).animate({
						       width:"91px",left:"211px"
						},'slow','easeOutBack');
			      }
			    );
	}
	
	
}


