(function($) {
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(jQuery.browser.msie)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
})(jQuery);

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 != "")
			{
				scroll(0,0);
				objMessage.innerHTML = value;
			}
		}
	}
}

function cleanMessage()
{
	objMessage = document.getElementById('message');
		
	if(objMessage)
	{
		objMessage.innerHTML = "";
	}
}

function VerstuurInschrijving(formObj)
{	
	objName 	= document.getElementById('id-name');
	objStreet	= document.getElementById('id-street');
	objZipcode	= document.getElementById('id-zipcode');
	objCity 	= document.getElementById('id-city');
	objEmail	= document.getElementById('id-emailaddress');
	objPhone	= document.getElementById('id-phone');
	
	if(objName && objStreet && objZipcode && objCity && objEmail && objPhone)
	{
		if(IsEmpty(objName) || IsSameAsTitle(objName))
		{
			focusObject(objName);
			alert("U bent vergeten uw naam in te vullen!");
			return;
		}
		
		if(IsEmpty(objEmail) || IsSameAsTitle(objEmail))
		{
			focusObject(objEmail);
			alert("U bent vergeten uw e-mailadres in te vullen!");
			return;
		}
		
		if(!IsEmail(objEmail))
		{
			focusObject(objEmail);
			alert("Het opgegeven e-mailadres is onjuist!");
			return;
		}
		
		if(IsSameAsTitle(objStreet)) 	objStreet.value = '';
		if(IsSameAsTitle(objZipcode)) 	objZipcode.value = '';
		if(IsSameAsTitle(objCity)) 		objCity.value = '';
		if(IsSameAsTitle(objPhone)) 	objPhone.value = '';
		
		formObj.submit();
	}
}

/* Impressie */
function GetScreenHeight()
{
	return $(window).height();
}

function ResizeImpressie()
{
	$('.ImpressieImage').css('height',((GetScreenHeight() * 0.75) - 125) + 'px');
}

function HideLoader()
{
	$('#IdLoader').hide();
}

function ShowLoader()
{
	$('#IdLoader').show();
}

function LoadImage(sMain, sSub, iPos)
{
	$('#IdImpressiePanel').show();
	$('#IdImpressie').hide();
	ShowLoader();

	var sUrl = 'impressie.php?mainpage=' + sMain + '&subpage=' + sSub + '&pos=' + iPos;
		
	$('#IdImpressie').load(sUrl, function()
	{
		HideLoader();
		ResizeImpressie();
		$('#IdImpressie').show();
		
		/* Start automatically the impressie show */
		StartImpressieAfterLoad();
	});
}

var bImpressieRunning = false;
var iImpressiePause	= 5000;

function StartImpressieAfterLoad()
{
	if(bImpressieRunning == false)
	{
		bImpressieRunning = true;
		
		setTimeout(function(){
			RunImpressie();
		}, iImpressiePause);

		$('#start-slide').hide();
		$('#stop-slide').show();
	}
}

function StartImpressie()
{
	if(bImpressieRunning == false)
	{
		bImpressieRunning = true;
		RunImpressie();

		$('#start-slide').hide();
		$('#stop-slide').show();
	}
}

function RunImpressie()
{
	if(bImpressieRunning == true)
	{
		Next(true);
		
		setTimeout(function(){
			RunImpressie();
		}, iImpressiePause);
	}
}

function StopImpressie()
{
	if(bImpressieRunning == true)
	{
		bImpressieRunning = false;

		$('#stop-slide').hide();
		$('#start-slide').show();
	}
}


function CloseImpressie()
{
	StopImpressie();
	$('#IdImpressiePanel').hide();
	$('#IdImpressie').hide();
}

/* Handle resize on resize action */
$(window).resize(function(){ResizeImpressie();});

function UpdateLabel()
{
	$('#Counter').html(GetCounter());
}


function GetCounter()
{
	var obj = document.getElementById('IdCurrent');
	
	return obj.value;
}

function NextCounter()
{
	var obj = document.getElementById('IdCurrent');
	
	obj.value = parseInt(obj.value) + 1;
}

function PrevCounter()
{
	var obj = document.getElementById('IdCurrent');
	
	obj.value = parseInt(obj.value) - 1;
}

function ResetNext()
{
	var obj = document.getElementById('IdCurrent');
	
	obj.value = 1;
}

function ResetPrev()
{
	var obj = document.getElementById('IdCurrent');
	var objTotal = document.getElementById('IdTotal');
	
	obj.value = parseInt(objTotal.value);
}


function ImageExits()
{
	var oImage = document.getElementById('image-' + GetCounter());

	if(oImage) return true;
	return false;
}

function ButtonPrev(bSamePage)
{
	StopImpressie();
	Prev(bSamePage);
}

function Prev(bSamePage)
{
	$('#image-' + GetCounter()).css({zIndex:99}).fadeOut( function(){
		PrevCounter();		
		UpdateLabel();
		
		if(ImageExits() == true)
		{
			$('#image-' + GetCounter()).css({zIndex:90}).fadeIn(function(){
				$(this).css('filter','');
			});
		}
		else
		{
			if(bSamePage)
			{
				ResetPrev();
				UpdateLabel();
				$('#image-' + GetCounter()).css({zIndex:90}).fadeIn(function(){
					$(this).css('filter','');
				});
			}
			else
			{
				LoadCategory('prev');
			}
		}
		
	});
}


function ButtonNext(bSamePage)
{
	StopImpressie();
	Next(bSamePage);
}

function Next(bSamePage)
{
	$('#image-' + GetCounter()).css({zIndex:99}).fadeOut( function(){
		NextCounter();
		UpdateLabel();
		
		if(ImageExits() == true)
		{
			$('#image-' + GetCounter()).css({zIndex:90}).fadeIn(function(){
				$(this).css('filter','');
			});
		}
		else
		{
			if(bSamePage)
			{
				ResetNext();
				UpdateLabel();
				$('#image-' + GetCounter()).css({zIndex:90}).fadeIn(function(){
					$(this).css('filter','');
				});
			}
			else
			{
				LoadCategory('next');
			}
		}
	});
}
