function GetObj(objectId)
{
	return document.getElementById(objectId);
}

function isObj(obj)
{
	if(obj) return true;
	return false;
}

function checkInput(obj, value)
{
	if(obj)
	{
		setMessage("");
		
		if(obj.value == value)
		{
			obj.value = "";
		}
		else if(obj.value == "")
		{
			obj.value = value;
		}
		else
		{
			cleanMessage();
		}
	}
}

function isEmpty(obj)
{
	if(obj.value == "") return true;
	return false;
}

function isEmail(obj)
{
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	if (filter.test(obj.value)) return true;
	return false;
}

function isPostcode(obj)
{
	var filter = /^[1-9]{1}[0-9]{3}[a-zA-Z]{2}$/;
	
	if (filter.test(obj.value)) return true;
	return false;
}

function isSameAsTitle(obj)
{
	if(obj.value == obj.title) return true;
	return false;
}

function focusObject(obj)
{
	obj.focus();
}

function setMessageById(value, messageId)
{
	objMessage = document.getElementById(messageId);
	
	if(objMessage)
	{
		objMessage.innerHTML = value;
	}
}

function setMessage(value, objectId)
{
	objMessage = document.getElementById(objectId);
		
	if(objMessage)
	{
		objMessage.innerHTML = value;
	}
	else
	{
		
		objMessage = document.getElementById('message');
		
		if(objMessage)
		{
			if(value != "")
			{
				objMessage.innerHTML = value;
			}
		}
	}
}

function cleanMessage()
{
	objMessage = document.getElementById('message');
		
	if(objMessage)
	{
		objMessage.innerHTML = "";
	}
}

function VerstuurContactFormulier(formObj)
{
	objComment	= document.getElementById('comment');
	objName 	= document.getElementById('name');
	objEmail 	= document.getElementById('email');
	
	if(objComment && objName && objEmail)
	{
		if(isEmpty(objName) || isSameAsTitle(objName))
		{
			focusObject(objName);
			setMessage("U bent vergeten uw <strong>naam</strong> in te vullen!");
			return;
		}
		
		if(isEmpty(objEmail) || isSameAsTitle(objEmail))
		{
			focusObject(objEmail);
			setMessage("U bent vergeten uw <strong>e-mailadres</strong> in te vullen!");
			return;
		}

		if(!isEmail(objEmail))
		{
			focusObject(objEmail);
			setMessage("Het opgegeven <strong>e-mailadres</strong> is onjuist!");
			return;
		}
		
		if(isEmpty(objComment) || isSameAsTitle(objComment))
		{
			focusObject(objComment);
			setMessage("U bent vergeten uw <strong>vraag/opmerking</strong> in te vullen!");
			return;
		}
		
		formObj.submit();
	}
}

function createQuery(formOject)
{
	var pairs = new Array();
	
	if(formOject)
	{
		for(var i=0; i<formOject.elements.length; i++)
		{
			if ((name = formOject.elements[i].name) && (value = formOject.elements[i].value))
			{
				if(formOject.elements[i].type == "checkbox")
				{
					if(formOject.elements[i].checked)
						pairs.push(encodeURIComponent(name) + "=" + encodeURIComponent(value));	
					else
						pairs.push(encodeURIComponent(name) + "=" + encodeURIComponent("off"));	
				}
				else
				{
					pairs.push(encodeURIComponent(name) + "=" + encodeURIComponent(value));	
				}
			}
		}
	}

	return pairs.join("&");
}

var iDuration		= 500;
var iSleep			= 5000;
var bScrolling		= true;
var iIntervalId		= 0;

var bMenuIsShown 	= true;
var bStartShown 	= false;
var bStartHide 		= false;
var bIsSleeping 	= false;
var bIsFading		= false;

function ShowMenu()
{
	bStartShown = true;
		
	$('#HeaderHolder').animate(
		{'top':'-100px'},
		{
			duration:iDuration,
			queue:true
		});
	
	$('#HeaderMenu').animate(
		{'top':'0px'},
		{
			duration:iDuration,
			queue:true,
			complete: function(){
				bStartShown = false;
				bMenuIsShown = true;
			}
		});
}

function _ShowMenu()
{
	Log('ShowMenu');
	bStartShown = true;
		
	$('#HeaderHolder').animate(
		{'top':'-100px'},
		{
			duration:iDuration,
			queue:true,
			complete: function() {
				$('#HeaderMenu').animate(
					{'top':'0px'},
					{
						duration:iDuration,
						queue:true,
						complete: function(){
							bStartShown = false;
							bMenuIsShown = true;
						}
					});
			}
		});
}

function HideMenu()
{
	Log('HideMenu');
	bStartHide = true;
		
	$('#HeaderMenu').animate(
		{'top':'-100px'},
		{
			duration:iDuration,
			queue:true,
			complete: function() {
				$('#HeaderHolder').animate(
					{'top':'0px'},
					{
						duration:iDuration,
						queue:true,
						complete: function(){
							bStartHide = false;
							bMenuIsShown = false;
						}
					});
			}
		});
}

function HideContact()
{
	$('#ContactCloser').fadeOut(function()
		{
			$('#ContactHolder').hide();
		});
	
	/*$('#ContactHolder').animate(
		{'top':'-150px'},
		{
			duration:iDuration,
			queue:true,
			complete: function(){
				$('#ContactCloser').hide();
			}
		});*/
}

function ShowContact()
{
	//Log('ShowContact');

	$('#ContactCloser').fadeIn(function()
	{
		$('#ContactCloser').show();
		$('#ContactHolder').show();
	});
	
	
	/*$('#ContactHolder').animate(
		{'top':'250px'},
		{
			duration:iDuration,
			queue:true,
			complete: function(){
				// $('#ContactCloser').show();
				
			}
		});*/
}

function HoverMenu()
{	/* SHOW THE MENU */
	Log('HoverMenu : ' + bMenuIsShown + bStartShown + bStartHide + bIsSleeping);
	
	if(bMenuIsShown == false)
	{
		if(bStartShown == false && bStartHide == false)
		{
			ShowMenu();
		}
		else
		{
			if(bIsSleeping)
			{
				bIsSleeping = false;
			}
		}
	}
	else
	{
		if(bIsSleeping)
		{
			bIsSleeping = false;
		}
	}
}

function LeaveMenu()
{	/* HIDE THE MENU */
	Log('LeaveMenu : ' + bMenuIsShown + bStartShown + bStartHide + bIsSleeping);
	
	if(bIsSleeping == false)
	{
		if(bStartShown == false)
		{
			bIsSleeping = true;
			
			setTimeout(function()
			{
				if(bIsSleeping)
				{
					bIsSleeping = false;
					
					if(bMenuIsShown == true && bStartShown == false && bStartHide == false)
					{
						HideMenu();
					}
				}
			}, 2000);
		}
	}
}

function replaceAll(text, strA, strB)
{
    return text.replace( new RegExp(strA,"g"), strB );    
}

function LoadImage(sImage, iPhotoId, fCallback)
{
	/* set the photo id */
	iCurrentPhoto = iPhotoId;
	
	if(bVideoShow == true)
	{
		$('#VideoContainer').html('');
		$('#VideoCloser').hide();
		bVideoShow = false;
	}

	if(bIsFading == false)
	{
		/* START FADING */
		bIsFading = true;
		
		/* DEFINE THE BACKGROUND */
		var sImageUrl = "url(" + sImage + ")";
		
		/* Replace the spaces with %20 */
		sImageUrl = replaceAll(sImageUrl," ","%20");
		
		var oPhotoOne = document.getElementById('PhotoOne'); /* BOTTOM */
		var oPhotoTwo = document.getElementById('PhotoTwo'); /* TOP */
		
		if(oPhotoOne && oPhotoTwo)
		{
			/* SYNC THE BACKGROUNDS */
			oPhotoTwo.style.backgroundImage = oPhotoOne.style.backgroundImage;
			
$('#PhotoTwo').fadeIn(function() {
				var tempImage = new Image();
				
				/* wait while image is loading */
				tempImage.onload = function()
				{
					oPhotoOne.style.backgroundImage = sImageUrl;
					
					$('#PhotoTwo').fadeOut(function() {
						/* STOP FADING */
						bIsFading = false;
						
						if(fCallback != undefined)
						{
							fCallback.apply();
						}
					});
				}
				
				// Load the new image
				tempImage.src = sImage;
			});
		}
	}
	else
	{
		if(fCallback != undefined)
		{
			fCallback.apply();
		}
	}
}

$(document).ready(function()
{
	//LeaveMenu();
});

function Log(sValue)
{
	/*var oObj = document.getElementById('Log');
	
	if(oObj)
	{
		oObj.innerHTML = sValue + "<br>" + oObj.innerHTML;
	}*/
}

function SlideTo(iScrollTo, iNumber)
{
	//$('.Thumbnail a').removeClass('ThumbnailActive');
	//$('#tm_' + iNumber).addClass('ThumbnailActive');
	$('#PortfolioSlider').animate({'scrollLeft':iScrollTo + 'px'},{duration:iDuration,queue:true});
}

function Next(iTo)
{
	var iMaxWidth 				= $('#PortfolioSliderTable').width();
	iScrollPanelWidth			= 40;
	var iScrollLeft				= $('#PortfolioSlider').scrollLeft();
	var iScrollTo 				= iScrollLeft + iScrollPanelWidth;
	var iTo						= iTo;

	if(iScrollTo >= iMaxWidth)
	{
		iScrollTo = 0;
		iTo = 0;
	}

	SlideTo(iScrollTo, iTo);
}

function Back()
{
	SlideTo(0, 0);
}

var bVideoShow = false;

function LoadVideo(sVideoId)
{
	sVideoId = '12356189';
	
	var sTemplate = '<object id="Video" width="723" height="420">' + 
							'<param name="allowfullscreen" value="true" />' + 
							'<param name="allowscriptaccess" value="always" />' + 
							'<param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=' + sVideoId + '&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=efede9&amp;fullscreen=1&amp;autoplay=1&amp;show_like=0" />' + 
							'<embed src="http://vimeo.com/moogaloop.swf?clip_id=' + sVideoId + '&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=efede9&amp;fullscreen=1&amp;autoplay=1&amp;show_like=0" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="723" height="420"></embed>' + 
						'</object>';
	
	if(bVideoShow == false)
	{
		LoadImage('images/video/background.gif', 0, function()
		{
			bVideoShow = true;
			$('#VideoContainer').html(sTemplate);
			$('#VideoCloser').show();
			
		});
	}
	else
	{
		$('#VideoContainer').html(sTemplate);
		$('#VideoCloser').show();
	}
}

function HideVideo()
{
	ResetPhoto();
}

function LoadImages(sPage, sSubPage, sChildPage)
{
	var sUrl = 'autoviewer.php?page=' + sPage + '&subpage=' + sSubPage + '&childpage=' + sChildPage;
	
	sUrl = sUrl.replace(/\s/g,"%20");
	
	$('#PhotoViewer').load(sUrl);
	/*
	var sUrl = 'portfolioslider.php?page=' + sPage + '&subpage=' + sSubPage + '&childpage=' + sChildPage;

	sUrl = sUrl.replace(/\s/g,"%20");
	
	$('#PortfolioSlider').load(sUrl, function()
		{
			LoadImage(GetFirstLargeImage(),0);
		});*/
}

function GetFirstLargeImage()
{
	var sReturn = '';
	
	var oImage = document.getElementById('img_0');
	
	if(oImage)
	{
		sReturn = oImage.src;
		
		sReturn = sReturn.replace('small','large');
	}
	
	return sReturn;
}

var iSteps 			= 0;
var iSliding 		= false;
var iPausePerStep 	= 25;
var iStepDevider 	= 10;

function SlideRight()
{
	if(iSliding == true)
	{
		//LogMouse('Slide right ' + iSteps + ' ' + $('#PortfolioSlider').scrollLeft());
		
		$('#PortfolioSlider').scrollLeft($('#PortfolioSlider').scrollLeft() + iSteps);
		
		/*$('#PortfolioSlider').animate(
			{
				'scrollLeft': ($('#PortfolioSlider').scrollLeft() + iSteps) + 'px'
			},{duration:100,queue:true});*/
		
		setTimeout(function()
		{
			SlideRight();
		}, 50);
	}
}

function SlideLeft()
{
	if(iSliding == true)
	{
		//LogMouse('Slide left ' + iSteps + ' ' + $('#PortfolioSlider').scrollLeft());
		
		$('#PortfolioSlider').scrollLeft($('#PortfolioSlider').scrollLeft() - iSteps);
		
		/*$('#PortfolioSlider').animate(
			{
				'scrollLeft': ($('#PortfolioSlider').scrollLeft() - iSteps) + 'px'
			},{duration:100,queue:true});*/
		
		setTimeout(function()
		{
			SlideLeft();
		}, 50);
	}
}

function Show(sId)
{
	$('#' + sId).fadeIn('fast');
}

function Hide(sId)
{
	$('#' + sId).fadeOut('fast');
}

var bShow = false;
var sCurrentId = '';

function TShow(sId)
{
	bShow = true;
	sCurrentId = sId;
	$('#' + sId).fadeIn('fast');
}

function THide(sId)
{
	bShow = false;
	setTimeout(function()
		{
			if(bShow == false || sCurrentId != sId)
			{
				$('#' + sId).fadeOut('fast');
			}
		}, 150);
}

var iCurrentPhoto = 0;

function GetPhotoUrlByLinkObject()
{
	var sReturn = '';
	var oLink 	= document.getElementById('tm_' + iCurrentPhoto);
	
	if(oLink)
	{
		var sLink = oLink.href;
		var aLink = sLink.split('\'');
		
		if(aLink[1] != undefined)
		{
			sReturn = aLink[1];
		}
	}
	
	return sReturn;
}

function GetTotalImages()
{
	var iReturn = 0;
	
	var oObject = document.getElementById('iTotalImages');
	
	if(oObject)
	{
		iReturn = oObject.value;
	}
	
	return iReturn;
}

function ResetPhoto()
{
	iCurrentPhoto = 0;
	
	var sImageUrl = GetPhotoUrlByLinkObject();
	
	LoadImage(sImageUrl, iCurrentPhoto);
}

function NextPhoto()
{
	iCurrentPhoto++;
	
	if(iCurrentPhoto >= GetTotalImages())
	{
		iCurrentPhoto = 0;
	}
	
	var sImageUrl = GetPhotoUrlByLinkObject();
	
	LoadImage(sImageUrl, iCurrentPhoto);
}

function PreviousPhoto()
{
	iCurrentPhoto--;
	
	if(iCurrentPhoto < 0)
	{
		iCurrentPhoto = (GetTotalImages() - 1);
	}
	
	var sImageUrl = GetPhotoUrlByLinkObject();
	
	LoadImage(sImageUrl, iCurrentPhoto);
}

function LoadSubmenu(sMenuItem)
{
	$('#submenu').load('submenu.php?page=' + sMenuItem);
}

// HeaderMenu - HeaderHolder
