/************************************************************************************************************
(C) www.dhtmlgoodies.com, September 2005

This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.

Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.

Thank you!

www.dhtmlgoodies.com
Alf Magne Kalleland

************************************************************************************************************/

// Path to arrow images
var arrowImage = 'images/icons/select_arrow.gif';	// Regular arrow
var arrowImageOver = 'images/icons/select_arrow_over.gif';	// Mouse over
var arrowImageDown = 'images/icons/select_arrow_down.gif';	// Mouse down


var selectBoxIds = 0;
var currentlyOpenedOptionBox = false;
var editableSelect_activeArrow = false;



function selectBox_switchImageUrl()
{
	if(this.src.indexOf(arrowImage)>=0){
		this.src = this.src.replace(arrowImage,arrowImageOver);
	}else{
		this.src = this.src.replace(arrowImageOver,arrowImage);
	}


}

function selectBox_showOptions()
{
	if(editableSelect_activeArrow && editableSelect_activeArrow!=this){
		editableSelect_activeArrow.src = arrowImage;

	}
	editableSelect_activeArrow = this;
	var optionDiv = document.getElementById('selectBoxOptions' + this.id.replace(/[^\d]/g,''));
	if(optionDiv.style.display=='block'){
		optionDiv.style.display='none';
		this.src = arrowImageOver;
	}else{
		optionDiv.style.display='block';
		this.src = arrowImageDown;
		if(currentlyOpenedOptionBox && currentlyOpenedOptionBox!=optionDiv)currentlyOpenedOptionBox.style.display='none';
		currentlyOpenedOptionBox= optionDiv;
	}
}

function selectOptionValue()
{
	var parentNode = this.parentNode.parentNode;
	var textInput = parentNode.getElementsByTagName('INPUT')[0];
	textInput.value = this.innerHTML;
	this.parentNode.style.display='none';
	document.getElementById('arrowSelectBox' + parentNode.id.replace(/[^\d]/g,'')).src = arrowImageOver;
}
var activeOption;
function highlightSelectBoxOption()
{
	if(this.style.backgroundColor=='#316AC5'){
		this.style.backgroundColor='';
		this.style.color='';
	}else{
		this.style.backgroundColor='#316AC5';
		this.style.color='#FFF';
	}

	if(activeOption){
		activeOption.style.backgroundColor='';
		activeOption.style.color='';
	}
	activeOption = this;

}

function createEditableSelect(dest)
{

	dest.className='selectBoxInput';
	var div = document.createElement('DIV');
	div.style.styleFloat = 'left';
	div.style.width = dest.offsetWidth + 16 + 'px';
	div.style.position = 'relative';
	div.id = 'selectBox' + selectBoxIds;
	var parent = dest.parentNode;
	parent.insertBefore(div,dest);
	div.appendChild(dest);
	div.className='selectBox';
	div.style.zIndex = 10000 - selectBoxIds;

	var img = document.createElement('IMG');
	img.src = arrowImage;
	img.className = 'selectBoxArrow';

	img.onmouseover = selectBox_switchImageUrl;
	img.onmouseout = selectBox_switchImageUrl;
	img.onclick = selectBox_showOptions;
	img.id = 'arrowSelectBox' + selectBoxIds;

	div.appendChild(img);

	var optionDiv = document.createElement('DIV');
	optionDiv.id = 'selectBoxOptions' + selectBoxIds;
	optionDiv.className='selectBoxOptionContainer';
	optionDiv.style.width = div.offsetWidth-2 + 'px';
	div.appendChild(optionDiv);

	if(dest.getAttribute('selectBoxOptions')){
		var options = dest.getAttribute('selectBoxOptions').split(';');
		var optionsTotalHeight = 0;
		var optionArray = new Array();
		for(var no=0;no<options.length;no++){
			var anOption = document.createElement('DIV');
			anOption.innerHTML = options[no];
			anOption.className='selectBoxAnOption';
			anOption.onclick = selectOptionValue;
			anOption.style.width = optionDiv.style.width.replace('px','') - 2 + 'px';
			anOption.onmouseover = highlightSelectBoxOption;
			optionDiv.appendChild(anOption);
			optionsTotalHeight = optionsTotalHeight + anOption.offsetHeight;
			optionArray.push(anOption);
		}
		if(optionsTotalHeight > optionDiv.offsetHeight){
			for(var no=0;no<optionArray.length;no++){
				optionArray[no].style.width = optionDiv.style.width.replace('px','') - 22 + 'px';
			}
		}
		optionDiv.style.display='none';
		optionDiv.style.visibility='visible';
	}

	selectBoxIds = selectBoxIds + 1;
}

function changeDate(form){
	var bookingDate = form.bookingDate.value;
	var bookingEnd = form.bookingEnd.value;
	//OPRET ARRAY
	bDA=bookingDate.split(".");
	bEA=bookingEnd.split(".");

	//OPRET ENG FORMAT
	var bDE = parseInt(bDA[2]+bDA[1]+bDA[0]);
	var bEE = parseInt(bEA[2]+bDA[1]+bEA[0]);

	//CHECK OM BOOKINGDATE ER STØRRE END BOOKING END
	if(bDE > bEE){
		//SÆT BOOKINGEND LIG MED BOOKINGSTART
		form.bookingEnd.value=form.bookingDate.value;

		xajax_updateTimeSelect('bookingEndTime',xajax.getFormValues('booking'));

	} else {
		xajax_updateTimeSelect('bookingEndTime',xajax.getFormValues('booking'));

	}
}
function changeEventdate(form){
	var publishDate = form.publishDate.value;
	var expireDate = form.expireDate.value;
	//OPRET ARRAY
	bDA=publishDate.split(".");
	bEA=expireDate.split(".");

	//OPRET ENG FORMAT
	var bDE = parseInt(bDA[2]+bDA[1]+bDA[0]);
	var bEE = parseInt(bEA[2]+bDA[1]+bEA[0]);

	//CHECK OM publishDate ER STØRRE END event END
	if(bDE > bEE){
		//SÆT expireDate LIG MED eventSTART
		form.expireDate.value=form.publishDate.value;

		xajax_updateTimeSelect('expireDateTime',xajax.getFormValues('event'));

	} else {
		xajax_updateTimeSelect('expireDateTime',xajax.getFormValues('event'));

	}
}
function previewImage(path,width,height){
	document.getElementById('imagePreview').innerHTML = '<img style="cursor:pointer;vertical-align:middle;" valign="middle" onclick="xajax_selectImage(\''+path+'\')" src="'+path+'" width="'+width+'px" height="'+height+'px">';

}
function displayImage(path,width,height){
	//FIND POSITION
	var marginLeft = parseInt(width/2);
	var marginTop =  parseInt(height/2);

	document.getElementById('displayImage').innerHTML = '<img title="Klik for at lukke" style="cursor:pointer;vertical-align:middle;" valign="middle" onclick="displayClose();" src="'+path+'" width="'+width+'px" height="'+height+'px">';
	elm = document.getElementById('displayImage');
	elm.style.marginLeft="-"+marginLeft+"px";
	elm.style.marginTop="-"+marginTop+"px";
	elm.style.visibility="visible";
	document.getElementById('container').className='containerBlur';
	hideSelects();

}
function displayClose(){
	document.getElementById('displayImage').style.visibility='hidden';
	document.getElementById('container').className='';
	showSelects()


}
function showSelects(){
	var elements = document.getElementsByTagName("select");
	for (i=0;i< elements.length;i++){
		elements[i].style.visibility='visible';
	}
}

function hideSelects(){
	var elements = document.getElementsByTagName("select");
	for (i=0;i< elements.length;i++){
		elements[i].style.visibility='hidden';
	}
}
function getElm(elm){
	return document.getElementById(elm);
}

	/************************************************************************************************************
	(C) www.dhtmlgoodies.com, October 2005
	
	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
	
	Terms of use:
	You are free to use this script as long as the copyright message is kept intact. However, you may not
	redistribute, sell or repost it without our permission.
	
	Thank you!
	
	www.dhtmlgoodies.com
	Alf Magne Kalleland
	
	************************************************************************************************************/	
	// You can modify these three values
	var slideshow2_noFading = false;	// Just normal show/hide without fading ?
	var slideshow2_timeBetweenSlides = 2500;	// Amount of time between each image(1000 = 1 second)
	var slideshow2_fadingSpeed = 20;	// Speed of fading
	
	
	/* Don't change any of these values */
	var slideshow2_galleryHeigh;	// Height of galery	
	var slideshow2_galleryContainer;	// Reference to the gallery div
	var slideshow2_galleryWidth;	// Width of gallery	
	var slideshow2_slideIndex = -1;	// Index of current image shown
	var slideshow2_slideIndexNext = false;	// Index of next image shown
	var slideshow2_imageDivs = new Array();	// Array of image divs(Created dynamically)
	var slideshow2_currentOpacity = 100;	// Initial opacity
	var slideshow2_imagesInGallery = false;	// Number of images in gallery
	
	function getGalleryImageSize(imageIndex)
	{
		if(imageIndex==slideshow2_imagesInGallery){			
			showGallery();
		}else{
			var imgObj = document.getElementById('galleryImage' + imageIndex);
			var imgWidth = imgObj.width;
			var imgHeight = imgObj.height;
			if(imgWidth>5 && imgHeight>5){						
				var tmpDiv = document.createElement('DIV');
				tmpDiv.id = 'galleryDiv' + imageIndex;
				tmpDiv.style.visibility = 'hidden';
				tmpDiv.className='imageInGallery';
				slideshow2_galleryContainer.appendChild(tmpDiv);
				tmpDiv.appendChild(imgObj);
				imgObj.style.left = Math.round((slideshow2_galleryWidth - imgWidth)/2)  + "px";
				imgObj.style.top = Math.round((slideshow2_galleryHeight - imgHeight)/2)  + "px";
				tmpDiv.style.visibility = 'hidden';
				slideshow2_imageDivs.push(tmpDiv);
				imageIndex++;
				getGalleryImageSize(imageIndex);
			}else{
				setTimeout('getGalleryImageSize(' + imageIndex + ')',10);
			}
		}		
	}
	
	function showGallery()
	{
		if(slideshow2_slideIndex==-1)slideshow2_slideIndex=0; else slideshow2_slideIndex++;	// Index of next image to show
		if(slideshow2_slideIndex==slideshow2_imageDivs.length)slideshow2_slideIndex=0;
		slideshow2_slideIndexNext = slideshow2_slideIndex+1;	// Index of the next next image
		if(slideshow2_slideIndexNext==slideshow2_imageDivs.length)slideshow2_slideIndexNext = 0;
		
		slideshow2_currentOpacity=100;	// Reset current opacity

		// Displaying image divs
		slideshow2_imageDivs[slideshow2_slideIndex].style.visibility = 'visible';
		if(navigator.userAgent.indexOf('Opera')<0){
			slideshow2_imageDivs[slideshow2_slideIndexNext].style.visibility = 'visible';
		}
		
		
		if(document.all){	// IE rules
			slideshow2_imageDivs[slideshow2_slideIndex].style.filter = 'alpha(opacity=100)';
			slideshow2_imageDivs[slideshow2_slideIndexNext].style.filter = 'alpha(opacity=1)';
		}else{
			slideshow2_imageDivs[slideshow2_slideIndex].style.opacity = 0.99;	// Can't use 1 and 0 because of screen flickering in FF
			slideshow2_imageDivs[slideshow2_slideIndexNext].style.opacity = 0.01;
		}		
		

		setTimeout('revealImage()',slideshow2_timeBetweenSlides);		
	}
	
	function revealImage()
	{
		if(slideshow2_noFading){
			slideshow2_imageDivs[slideshow2_slideIndex].style.visibility = 'hidden';
			showGallery();
			return;
		}
		slideshow2_currentOpacity--;
		if(document.all){
			slideshow2_imageDivs[slideshow2_slideIndex].style.filter = 'alpha(opacity='+slideshow2_currentOpacity+')';
			slideshow2_imageDivs[slideshow2_slideIndexNext].style.filter = 'alpha(opacity='+(100-slideshow2_currentOpacity)+')';
		}else{
			slideshow2_imageDivs[slideshow2_slideIndex].style.opacity = Math.max(0.01,slideshow2_currentOpacity/100);	// Can't use 1 and 0 because of screen flickering in FF
			slideshow2_imageDivs[slideshow2_slideIndexNext].style.opacity = Math.min(0.99,(1 - (slideshow2_currentOpacity/100)));
		}
		if(slideshow2_currentOpacity>0){
			setTimeout('revealImage()',slideshow2_fadingSpeed);
		}else{
			slideshow2_imageDivs[slideshow2_slideIndex].style.visibility = 'hidden';			
			showGallery();
		}
	}
	
	function initImageGallery()
	{
		slideshow2_galleryContainer = document.getElementById('imageSlideshowHolder');
		slideshow2_galleryWidth = slideshow2_galleryContainer.clientWidth;
		slideshow2_galleryHeight = slideshow2_galleryContainer.clientHeight;
		galleryImgArray = slideshow2_galleryContainer.getElementsByTagName('IMG');
		for(var no=0;no<galleryImgArray.length;no++){
			galleryImgArray[no].id = 'galleryImage' + no;
		}
		slideshow2_imagesInGallery = galleryImgArray.length;
		getGalleryImageSize(0);		
		
	}
		



