function showDivForEmail ()
{
	jQuery('#light').css('display', 'block');
	jQuery('#fade').css('display', 'block');
}
function hideDivForEmail ()
{
	jQuery('#light').css('display', 'none');
	jQuery('#fade').css('display', 'none');
}

function showCustomLightBox(divIdentifier)
{
	var sTop = jQuery(window).scrollTop() + (jQuery(window).height() / 6.66);
	
	if(divIdentifier == null)
	{
		jQuery('#thumbnails_div').attr('style', 'display:inline; z-index: 30000; top: '+ sTop + 'px;');
	}
	else
	{
		jQuery('#thumbnails_div'+divIdentifier).attr('style', 'display:inline; z-index: 30000; top: '+ sTop + 'px;');		
	}
	jQuery('#overlay_div').attr('style', 'display:inline; z-index: 10000;').height(jQuery(document).height());

}
function hideCustomLightBox(divIdentifier)
{
	if(jQuery('#overlay_div').length > 0)
	{
		if(divIdentifier == null)
		{
			jQuery('#thumbnails_div').attr('style', 'display:none;');
		}
		else
		{
			jQuery('#thumbnails_div'+divIdentifier).attr('style', 'display:none;');
		}
		jQuery('#overlay_div').attr('style', 'display:none;');

	}
}
var floortypeClass = new Class
(
	{
		initialize: function()
		{
			iCounter = -1;
		
			PR.Form.InputTip.addTips();

			this.setEvents();
		},
		setEvents: function()
		{
			var oShowSamples = $('show_samples');
			var oBtnPrevious = $('button_previous');
			var oBtnNext	 = $('button_next');
			var oPrintSample = $('printSample');
			var oBtnSendEmail = $('sendEmail');
			var oBtnCalculate = $('calculate');

			if(oShowSamples) {
				oShowSamples.removeEvents();
				oShowSamples.addEvent('click', this.showSamples.create({bind: this}));
			}

			if(oBtnPrevious) {
				oBtnPrevious.removeEvents();
				oBtnPrevious.addEvent('click', this.switchSamplePrevious.create({bind: this}));
			}

			if(oBtnNext) {
				oBtnNext.removeEvents();
				oBtnNext.addEvent('click', this.switchSampleNext.create({bind: this}));
			}

			if(oPrintSample) {
				oPrintSample.removeEvents();
				oPrintSample.addEvent('click', this.printSample.create({bind: this}));
			}
			
			if(oBtnSendEmail) {
				oBtnSendEmail.removeEvents();
				oBtnSendEmail.addEvent('click', this.sendEmail.create({bind : this}));
			}
			
			if(oBtnCalculate) {
				oBtnCalculate.removeEvents();
				oBtnCalculate.addEvent('click', this.calculate.create({bind : this}));
			}
			
		},
		
		showSamples: function (oEvent) 
		{
			iCounter 				= 0;
			var divCollection 		= $('collection_img');
			var divSamples 			= $('samples');

			// Show first element
			this.addSample(iCounter,divSamples,'hidden');
			this.showSample(iCounter);
			
			// Get second element, but with class hidden for preloading
			this.addSample( (iCounter+1) ,divSamples,'hidden');

			// Get second element, but with class hidden for preloading
			this.addSample( (aSamples.length-1) ,divSamples,'hidden');
			
			// Collection div hidden
			divCollection.addClass('hidden');
			
			// Sample div show
			divSamples.removeClass('hidden');
		},
		
		switchSampleNext: function (oEvent)
		{
			var divCollection = $('collection_img');
			var divSamples = $('samples');

			// destroy images
			iNumber = iCounter - 1;
			if ( iNumber < 0 )
			{
				iNumber = (aSamples.length-1);
			}
			if ( $('collection' + iNumber))
			{
				this.destroySample(iNumber);
			}
			
			// Set current collection item hidden
			this.preloadSample(iCounter);

			iCounter++;
			
			if ( iCounter == aSamples.length )
			{
				iCounter = 0;
			}
			
			// Set next collection item visible
			this.showSample(iCounter);

			// Get second element, but with class hidden for preloading
			iPreload = iCounter + 1;
			if ( iPreload == aSamples.length )
			{
				iPreload = 0;
			}
			
			this.addSample(iPreload,divSamples,'hidden');
		},

		switchSamplePrevious: function (oEvent)
		{
			var divCollection = $('collection_img');
			var divSamples = $('samples');

			// destroy images
			iNumber = iCounter + 1;
			if ( iNumber == aSamples.length )
			{
				iNumber = 0;
			}
			if ( $('collection' + iNumber))
			{
				this.destroySample(iNumber);
			}
			
			this.preloadSample(iCounter);
			
			iCounter--;

			if ( iCounter < 0 )
			{
				iCounter = aSamples.length-1;
			}
			
			this.showSample(iCounter);
						
			// Get second element, but with class hidden for preloading
			iPreload = iCounter - 1;
			if ( iPreload < 0 )
			{
				iPreload = aSamples.length-1;
			}			
			
			// Get second element, but with class hidden for preloading
			this.addSample( iPreload ,divSamples,'hidden');
		},
		
		addSample: function (iCounter, sampleDiv, visible )
		{
			var sImageUrl = aSamples[iCounter]['url'];
			var sImageName = aSamples[iCounter]['name'];
						
			var sample = new Element('img', {'id': 'collection' + iCounter, 'class': visible, 'alt': sImageName, src: sImageUrl} );
			
			sampleDiv.grab(sample,'top');
		},
		
		destroySample: function(iSample)
		{
			var sCurrentCollectionItem = 'collection' + iSample;
			$(sCurrentCollectionItem).addClass('hidden');
			$(sCurrentCollectionItem).destroy();
		},
		
		showSample: function(iSample)
		{
			var sampleExplanation	= $('sample_explanation');
			var sImageName 			= aSamples[iCounter]['name'];
			var downloadLink 		= $('download_sample');
			
			var sNextCollectionItem = 'collection' + iSample;
			$(sNextCollectionItem).removeClass('hidden');
			
			var span = new Element('span');

			downloadLink.set('href', aSamples[iCounter]['download']);
			sampleExplanation.set('text',sImageName);
			sampleExplanation.grab(span);			
		},
		
		preloadSample: function(iSample)
		{
			var sCollectionItem = 'collection' + iCounter;
			$(sCollectionItem).addClass('hidden');
		},
		
		printSample: function ()
		{
			var sImageUrl = aSamples[iCounter]['url'];
			
			pwin = window.open(sImageUrl,"_blank");
			setTimeout("pwin.print()",100);
		},
		
		sendEmail: function(oEvent)
		{
			var oBtn = $(oEvent.target);
			var oForm = $(oBtn.get('rel'));
	
			var validator = oForm.retrieve('validation');			
			if( validator!=null && !validator.doValidate() ){
				
			} else {		
				oForm.send();
				var oDiv = $('emailForm');
				oDiv.set('style', 'display:none');
				var oDiv = $('emailFormThanx');
				oDiv.set('style', 'display:block');
			}
			
			return false;
		},
		
		calculate: function(oEvent)
		{
			sSquareMeters = $('tbl_collection_square_meters').value;
			sSquareMeters = sSquareMeters.replace(',','.');
			iSquareMeters = parseFloat(sSquareMeters);
			
			sWidth 	= $('width').value;
			sWidth	= sWidth.replace(',','.');
			iWidth 	= parseFloat(sWidth);

			if (isNaN(iWidth) || iWidth < 0)
			{
				sErrorMessage = 'De breedte is geen geldige nummerieke waarde';
				
				$('result').empty();
				
				$('calculate_error').empty();
				$('calculate_error').appendText(sErrorMessage);
				$('calculate_error').addClass('errors');
				
				return;
			}
			
			sLength	= $('length').value;
			sLength	= sLength.replace(',','.');
			iLength = parseFloat(sLength);

			if (isNaN(iLength) || iLength < 0)
			{
				sErrorMessage = 'De lengte is geen geldige nummerieke waarde';
				
				$('result').empty();
				
				$('calculate_error').empty();
				$('calculate_error').appendText(sErrorMessage);
				$('calculate_error').addClass('errors');
				
				return;			
			}

			iTotalSquareMeters = iWidth * iLength;
			
			iParcel 		= (iTotalSquareMeters / iSquareMeters) * 1.05;
			iParcelRound 	= Math.ceil(iParcel);
			
			$('result').empty();
			$('result').appendText(iParcelRound);
			
			$('calculate_error').removeClass('errors');
			$('calculate_error').empty();
		}
		
	}
);

function floortypeInit()
{
	floortypeObj = new floortypeClass();
};

function printSample (sImageUrl)
{
			
	pwin = window.open(sImageUrl,"_blank");
	setTimeout("pwin.print()",100);
};



var floortypeObj;

window.addEvent('domready', floortypeInit);

