/** -- Functions -------------------------
 * 
 * elm(id)                            
 * toggleFaq(id)                      
 * toggleWord(id)                     
 * switchImage(name)                  
 * openKeyWordDescBox(id)             
 * closeKeyWordDescBox(id)            
 * switchVideo(file, titel, tekst)    
 * scrollTo(selector)                 
 * 
 * 
**/


// elm(id)
function elm(id)
{
  return document.getElementById(id);
}


// toggleFaq(id)
function toggleFaq(id)
{
	questionElement = elm('faq_question_'+id);
	
	if (questionElement.className=="open")
	{
		questionElement.className = "";
	}
	else
	{
		questionElement.className = "open";
	}
	$('#awnser_'+id).slideToggle('fast');
}


// toggleWord(id)
function toggleWord(id)
{
	wordElement = elm('word_'+id);
	
	if(wordElement.className=="open")
	{
		wordElement.className = "";
	}
	else
	{
		wordElement.className = "open";
	}
	$('#description_'+id).slideToggle('fast');
}


// switchImage(name)
function switchImage(name)
{
	var mainImage = elm('mainImage');
	var fakeImage = elm(name);
	var fakeWidth = fakeImage.width;
	var fakeHeight = fakeImage.height;
	
	var comment = fakeImage.alt;
	
	//alert("Width: "+fakeWidth+" Height: "+fakeHeight);
	
	mainImage.src='/images/fotos/'+name;
	elm('galery_photo_title').innerHTML = comment;
	
	if (fakeWidth > fakeHeight)
	{
		mainImage.style.width = '95%';
		mainImage.style.height = 'auto';
	}
	else
	{
		mainImage.style.height = '95%';
		mainImage.style.width = 'auto';
	}
}


// openKeyWordDescBox(id)
function openKeyWordDescBox(id)
{
	$('#'+id).append("<div class='word_description_box'><div>"+$('#'+id).attr("desc")+"</div></div>");
}


// closeKeyWordDescBox(id)
function closeKeyWordDescBox(id)
{
	$('#'+id+' div').remove();
}


// switchVideo(file, titel, tekst)
function switchVideo(file, titel, tekst)
{
	player.sendEvent('LOAD','/images/video/'+file);
	elm('titleBox').innerHTML = titel ;
	elm('descriptionBox').innerHTML = tekst;
}

// scrollTo(selector) -- gratefully nicked from http://jtauber.com/blog/2008/04/28/auto-scrolling_is_jquery/
function scrollTo(selector) {
	var targetOffset = $(selector).offset().top;
	$('html,body').animate({scrollTop: targetOffset}, 500);
}
