function selectFirstItem() {
	document.getElementById('navigationLeft').style.display = "block";
}

function deselectFirstItem() {
	document.getElementById('navigationLeft').style.display = "none";	
}

function setFormField(f, text) {
	if (f.value == text) 
		f.value = '';
}

function resetFormField(f, text) {
	if (f.value == '')
		f.value = text;
}

function setOutlines() {
	var content = document.getElementById('content');
	var middle = document.getElementById('middleContent');
	// Marvin: -40px is de padding die er nog vanaf moet;
	middle.style.height = (content.offsetHeight-40) + 'px';
}

/*function showPhoto(pg_id, file, photoablumid, photografer, message) {
	if(photografer != ""){
		photografer = 'Foto gemaakt door: ' + photografer;
	}
	
	document.getElementById('photoHolder_' + photoablumid).innerHTML = '<img src="/inc/upload/photos/' + pg_id + '/photo_' + file + '" border="0" title="' + photografer + '" />';
	if(message != undefined){
		document.getElementById('textHolder_' + photoablumid).innerHTML = message;
	}
}*/

function highlightSearch(action){
	var tags = getElementsByClassName("searchField");
	if(!tags[1]){
		if(action=="over")tags[0].style.backgroundImage = "url(/inc/img/bg_search_over.png)";
		else tags[0].style.backgroundImage = "url(/inc/img/bg_search.png)";
	}
}

function getElementsByClassName(clss){
	var returnTags = new Array();	
	var tags = document.getElementsByTagName("*");
	for(var i=0;i<tags.length;i++){
		if(tags[i].className&&tags[i].className==clss)returnTags.push(tags[i]);
	}
	return returnTags;
}


function addListener(element, type, expression, bubbling){
	bubbling = bubbling || false;
	
	if(window.addEventListener) { // Standard
		element.addEventListener(type, expression, bubbling);
		return true;
	} else if(window.attachEvent) { // IE
		element.attachEvent('on' + type, expression);
		return true;
	} else return false;
}

function getTargetId(event){
	
	if(event.target) { // FF
		return event.target.id;
	} else if(window.attachEvent) { // IE
		return event.srcElement.id;
	} else return false;
}

/* Photoalbum */
function photoAlbum(arrPhotos, photoPath, pa_id){
	
	/* Constructor : Photoalbum instellingen */
	this.arrPhotos = arrPhotos;
	this.photoPath = photoPath;
	this.photosPerPage = 5;
	this.paId = pa_id;	
	
	// FUNCTIE | Foto groot tonen
	this.showPhoto = function(id){
		var photoHolder = document.getElementById('photoholder_' + this.paId);	
		var photoInfo = document.getElementById('photoinfo_' + this.paId);	
		
		photoHolder.src = this.photoPath+ 'photo_' + this.arrPhotos[id][1];
		
		var photoInfoText = "";
		if(this.arrPhotos[id][2] != ''){
			photoInfoText += this.arrPhotos[id][2];
		}
		if(this.arrPhotos[id][2] != '' && this.arrPhotos[id][3] != ''){
			photoInfoText += " - ";	
		}
		if(this.arrPhotos[id][3] != ''){
			photoInfoText += this.arrPhotos[id][3];
		}
		photoInfo.innerHTML = photoInfoText;
	}
	
	// FUNCTIE | Thumbnails tonen
	this.showThumbs = function(pageId){
		
		// Standaard pagina
		pageId = pageId || 1;
		var loopFrom;
		var loopTo;
		
		var pageCount = Math.ceil(this.arrPhotos.length / this.photosPerPage);

		var photoStrip = document.getElementById('photostrip_'+this.paId);
		
		// Foto strip leegmaken
		photoStrip.innerHTML = "";
		
		// Pagina bereik uitrekenen
		if(this.arrPhotos.length > this.photosPerPage){
			loopFrom = (this.photosPerPage * pageId) - (this.photosPerPage - 1);
			if(pageCount == pageId && (this.arrPhotos.length % this.photosPerPage > 0)){
				loopTo = loopFrom + (this.arrPhotos.length % this.photosPerPage)-1;
			} else {
				loopTo = loopFrom + (this.photosPerPage - 1);								   
			}
		} else {
			loopTo = this.arrPhotos.length;
		}

		// Thumbs uitloopen en afdrukken
		var objAlbum = new photoAlbum(this.arrPhotos, this.photoPath, this.paId);
		for(var i = loopFrom; i <= loopTo; i++){
			
			var photoThumb = document.createElement('img');
			photoThumb.id = "thumb_"+(i-1);
			photoThumb.className = "thumb";
			photoThumb.src = photoPath+'thumb_' + arrPhotos[i-1][1];
			photoThumb.style.cursor = "pointer";
			addListener(photoThumb, 'click', function(e){ 
				photoId = getTargetId(e).split("_");
				photoId = photoId[1];
				objAlbum.showPhoto(photoId); 
			});
			
			photoStrip.appendChild(photoThumb);
		}
		
		// Pagina's uitlopen
		var photoPagesHolder = document.getElementById('photopages_holder_' + this.paId);
		var photoPages = document.getElementById('photopages_' + this.paId);	
		
		// Pagina's Leegmaken
		photoPages.innerHTML = "";
		
		// Checken of er wel pagina's zijn
		if(pageCount > 1){
			for(var i = 1; i <= pageCount; i++){
				var pageLink = document.createElement('span');
				pageLink.id = "link_"+i;
				pageLink.innerHTML = i+" ";
				if(i != pageId){
					pageLink.className = "pageLink";
					pageLink.style.cursor = "pointer";
					addListener(pageLink, 'click', function(e){ 
						pageId = getTargetId(e).split("_");
						pageId = pageId[1];
						objAlbum.showThumbs(pageId); 
					});
				} else {
					pageLink.className = "pageLink selected";
				}
				photoPages.appendChild(pageLink);
			}
		} else { // Anders uitzetten
			photoPagesHolder.style.display = "none";
		}
	}
}

/* popup */

function previewImage(url) {
	document.body.style.height = "100%";
	var overlayDiv = document.createElement('div');
	overlayDiv.id = "overlay";
	
	var version = navigator.userAgent;
	var findFirefox = version.indexOf('Firefox');
	var findIE6 = version.indexOf('MSIE 6');
	
	if (findIE6 != -1) {
	   overlayDiv.style.position = "absolute";
	   overlayDiv.style.height = document.body.clientHeight;
	   overlayDiv.style.width = document.body.clientWidth;
	} 
	else {
	   overlayDiv.style.height = "100%";
	   overlayDiv.style.position = "fixed";
	   overlayDiv.style.width = "100%";
	}
	
	document.body.style.overflow = "visible";
	
	overlayDiv.style.background = "#FFF none repeat scroll 0 0";
	overlayDiv.style.top = "0";
	overlayDiv.style.left = "0";
	overlayDiv.style.right = "0";
	overlayDiv.style.bottom = "0";
	overlayDiv.style.opacity = ".85";
	overlayDiv.style.filter = "alpha(opacity=85)";
	overlayDiv.style.zIndex = "1";
	
	document.body.appendChild(overlayDiv);
	
	var popUpDiv = document.createElement('div');
	popUpDiv.id = 'imagePreview';
	if (findIE6 != -1) {
		popUpDiv.style.position = "absolute";
	} else {
		popUpDiv.style.position = "fixed";
	}
	popUpDiv.style.top = "50%";
	popUpDiv.style.marginTop = "-160px";
	popUpDiv.style.left= "50%"; 
	popUpDiv.style.width = "512px"; 
	popUpDiv.style.height = "438px";
	popUpDiv.style.marginLeft = "-261px";
	popUpDiv.style.padding = "0px";
	popUpDiv.style.backgroundColor = "#FFFFFF";
	popUpDiv.style.border = "1px solid #f22709";
	popUpDiv.style.zIndex = "2";
	//popUpDiv.style.display = "none";
	
	document.body.appendChild(popUpDiv);
	/*
	var closeDiv = document.createElement('div');
	closeDiv.id = "videoClose";
	closeDiv.style.marginTop = "5px";
	closeDiv.style.width = "466px";
	closeDiv.style.textAlign = "center";
	
	var closeA = document.createElement('a');
	closeA.style.color = "#000000";
	closeA.style.fontWeight = "bold";
	closeA.style.textDecoration = "none";
	closeA.href = "javascript:hidePreview();";
	closeA.innerHTML = "Sluiten...";
	
	closeDiv.appendChild(closeA);
	
	popUpDiv.appendChild(closeDiv);
	*/
	Spry.Utils.updateContent('imagePreview', url);
}

function hidePreview() {
	document.body.removeChild(document.getElementById('overlay'));
	document.body.removeChild(document.getElementById('imagePreview'));
}

