// Random Mootools Stuff for Site Naam
window.addEvent('domready', function()
{
	
	// Fade New Photo's in
	if ($('photoviewer'))
	{
		var objPhotoviewer = new Photoviewer();
	};
	
	// Type Text in Licenseplate
	if ($('licenseplate'))
	{
		var objLicensePlate = new LicensePlate();
	};
	
});


var LicensePlate = new Class(
{
	elWrapper: null,
	elTextWrapper: null,
	strText: null,
	intLength: null,
	
	intCurrent: 1,
	intDelay: 300,
	
	initialize: function()
	{
		this.elWrapper = $('licenseplate');
		this.elTextWrapper = this.elWrapper.getElement('a');
		this.strText = this.elWrapper.getElement('a').get('text');
		this.elWrapper.getElement('a').set('text', '');
		this.intLength = this.strText.length;
		
		this.elWrapper.addEvents(
		{
			click:function(event)
			{
				event.preventDefault();
				window.open(this.getElement('a').get('href'));
			}
		});
		
		this.showNext.bind(this).delay(this.intDelay);
	},
	
	showNext: function()
	{
		
		this.elTextWrapper.set('text', this.strText.substr(0, this.intCurrent) + '|');
		
		if (this.intCurrent == this.intLength)
		{
			this.intCurrent = 0;		
			this.showNext.bind(this).delay(5000);
		}
		else
		{
			this.intCurrent++;		
			this.showNext.bind(this).delay(this.intDelay);
		}
	}
	
});

var Photoviewer = new Class(
{
	
	elWrapper: null,
	arrItems: null,
	intItems: null,
	
	intCurrent: 0,
	intDelay: 6000,
	
    initialize: function()
	{
		this.elWrapper = $('photoviewer');
		this.arrItems = this.elWrapper.getElements('li');
		this.intItems = this.arrItems.length;
		
		this.arrItems.setStyles(
		{
			'opacity': 0
		});
		
		this.arrItems[this.intCurrent].setStyles(
		{
			'opacity': 1
		});
		
		this.showNext.bind(this).delay(this.intDelay);
    },

	showNext: function()
	{
		this.arrItems[this.intCurrent].fade(0);
		
		if (this.intCurrent == (this.intItems - 1))
		{
			this.intCurrent = 0;
		}
		else
		{
			this.intCurrent++;
		}
		
		this.arrItems[this.intCurrent].fade(1);
		
		this.showNext.bind(this).delay(this.intDelay);
	}

});


window.addEvent('domready', function()
{	
	var arrItems = $$('.hoverimage');
	arrItems.each(function(elImage, intKey)
	{
		if (intKey < 1)
		{
			var elLargeImage = new Element('img',
			{
				'id': 'largeimage',
				'src': elImage.get('rel')
			});
			elLargeImage.inject($('resultimage'));
		};
		elImage.addEvents(
		{
			mouseenter:function()
			{
				$('largeimage').set('src', elImage.get('rel'));
			}
		});
	});
	
});
