window.addEvents({
	'domready': function() {
		initMenu();
		initListRollOvers();
		initDiscography();
	},
	'load': function() {
		detectEcardOpener();
		initFooterOverlays();
	}
});



function initMenu() {
	var menuItemsKoppen = $$('div#header li span');
	menuItemsKoppen.each(function(item) {
		item.getParent('li').setStyle('width', item.getSize().size.x + 30);
	});
}

/**
* initListRollOvers
* starts list item rollover functionallity
*
* @author Rocco Janse <rocco@efocus.nl>
*/

function initListRollOvers() {

	var listItems = $$('div#content ul li');
	var arrIdsToIgnore = new Array('bookmarks', 'discography', 'dtitle', 'dtlist', 'tlist', 'media');

	listItems.each(function(row) {

		var currentListId = row.getParent().getProperty('id');

		if ('-1' == arrIdsToIgnore.indexOf(currentListId)) {

			row.addEvent('mouseenter', function() {
				row.addClass('hover');
			});

			row.addEvent('mouseleave', function() {
				row.removeClass('hover');
			});
		}
	});
}

/**
* inputFocus
* changes textcolor to white on click
*
* @param argElement current input element
* @author Rocco Janse <rocco@efocus.nl>
*/

function inputFocus(argElement) {

	var inputElement = $(argElement);

	inputElement.setStyles({
		'color': '#FFFFFF'
	});

	if (inputElement.value == inputElement.defaultValue) {
		inputElement.value = '';
	}
}

/**
* inputReset
* resets the input on blur
*
* @param argElement current input element
* @author Rocco Janse <rocco@efocus.nl>
*/

function inputReset(argElement) {

	var inputElement = $(argElement);

	if (inputElement.value == '') {

		inputElement.setStyles({
			'color': '#CCCCCC'
		});

		inputElement.value = inputElement.defaultValue;
	}
}

/**
* initDiscography
* starts discography functionallity
*
* @author Rocco Janse <rocco@efocus.nl>
*/

function initDiscography() {

	var listItems = $$('ul#discography li.row');

	listItems.each(function(element) {

		var elementFx = new Fx.Styles(element, { duration: 600, transition: Fx.Transitions.Sine.easeInOut, wait: false });

		element.addEvents({
			'mouseenter': function() {
				element.setStyles({ 'cursor': 'pointer' });
				element.fireEvent('open', 2000);
			},
			'mouseleave': function() {
				elementFx.start({
					'height': 49
				});
			},
			'open': function() {
				elementFx.start({
					'height': element.scrollHeight - 1
				});
			}
		});
	});
}

/**
* initBandOverlays
* starts overlay functionallity
*
* @author Rocco Janse <rocco@efocus.nl>
*/

function initBandOverlays() {

	var bandButtons = $$('a.band');

	bandButtons.each(function(button) {

		var currentButton = button.getProperty('class').split(' ');
		var currentOverlay = $(currentButton[2]);

		currentOverlay.setStyles({ 'opacity': 0, 'display': 'none' });

		var fade = new Fx.Style(currentOverlay, 'opacity', { duration: 300, wait: false });

		button.addEvent('mouseenter', function() {
			currentOverlay.setStyles({ 'opacity': 0, 'display': 'block' });
			fade.start(0, 0.9);
		});
		button.addEvent('mouseleave', function() {
			fade.start(0.9, 0);
			currentOverlay.setStyles({ 'opacity': 0, 'display': 'none' });
		});
	});
}

/**
* initFooterOverlays
* starts overlay functionallity for the footer
*
* @author Rocco Janse <rocco@efocus.nl>
*/

function initFooterOverlays() {

	var bandButtons = $$('a.blofistips');

	bandButtons.each(function(button) {

		var currentButton = button.getProperty('class').split(' ');
		var currentOverlay = $('blofisoverlay_' + currentButton[1]);

		currentOverlay.setStyles({ 'opacity': 0 });

		var fade = new Fx.Style(currentOverlay, 'opacity', { duration: 300, wait: false });

		button.addEvent('mouseenter', function() {
			fade.start(0, 1);
		});
		button.addEvent('mouseleave', function() {
			fade.start(1, 0);
		});
	});
}

/**
* toggleSendForm
* toggles send ecard form in shadowbox
*
* @author Rocco Janse <rocco@efocus.nl>
*/

function toggleSendForm() {

	var sendForm = $('sendform');

	if (sendForm.status != 'open') {
		var fade = new Fx.Style(sendForm, 'opacity', { duration: 300 }).set(0);
		sendForm.setStyles({ 'display': 'block' });
		fade.start(0, 0.9);
		sendForm.status = 'open';
	} else {
		var fade = new Fx.Style(sendForm, 'opacity', { duration: 300 }).set(0.9);
		fade.start(0.9, 0).chain(function() {
			sendForm.setStyles({ 'display': 'none' });
			sendForm.status = 'closed';
		});
	}
}

/**
* detectEcardOpener
* detects get var from querystring to open ecard shadowbox automatically
*
* @author Rocco Janse <rocco@efocus.nl>
*/

function detectEcardOpener() {

	var url = 'PhotoViewer.aspx';
	var firstPart = false;
	var secondPart = false;

	// detect querystring
	var queryString = location.search.substring(1, location.search.length);

	if (queryString.length != 0) {
		queryString = queryString.replace(/\+/g, ' ');

		// split querystring
		var queryArguments = queryString.split('&');

		for (var i = 0; i < queryArguments.length; ++i) {

			// detect var we need (ex. &card=1)
			var queryPair = queryArguments[i].split('=');

			if (queryPair[0] == 'Id' && queryPair[1] != null) {
				firstPart = true;
				url += '?gId=' + queryPair[1];
			}

			if (queryPair[0] == 'card' && queryPair[1] != null) {
				secondPart = true;
				url += '&page=' + queryPair[1];
			}

		}

		if (firstPart != false && secondPart != false) {

			// detect is shadowbox is defined
			try { var exists = (Shadowbox != undefined) }
			catch (e) { var exists = false }

			// if defined, open shadowbox
			if (exists) {
				Shadowbox.open({
					type: 'iframe',
					content: url,
					width: 573,
					height: 480
				});
			} else {
				return;
			}
		}

	} else {
		return;
	}
}

/**
* startPlay
* plays sounds via flashplayer
*
* @author Rocco Janse <rocco@efocus.nl>
* @param string sound name of current soundfile to play
*/

var isPlaying = false;
var prevSound;

function startPlay(sound) {

	var soundPlayer = $('soundplayer');
	var soundButton = $('soundbutton').getElement('span.black-text');

	if (isPlaying == false) {

		soundPlayer.SetVariable('startsound', 'ja');
		isPlaying = true;
		soundButton.innerHTML = 'Track stoppen';

	} else {

		soundPlayer.SetVariable('startsound', 'nee');
		isPlaying = false;
		soundButton.innerHTML = 'Track beluisteren';
	}

	if (prevSound != sound) {

		soundPlayer.SetVariable('startsound', 'ja');
		isPlaying = true;
		soundButton.innerHTML = 'Track stoppen';
	}

	soundPlayer.SetVariable('geluid', sound);
	prevSound = sound;
}

/**
* hideTimeline()
* reduces the timeline height
*
* @author Rocco Janse <rocco@efocus.nl>
*/

function hideTimeline() {
	blofTimeline.hide();
}

/**
* showTimeline()
* extends the timeline height
*
* @author Rocco Janse <rocco@efocus.nl>
*/

function showTimeline() {
	blofTimeline.show();
}

/**
* mainTimeline
* class to extend of reduce div height of timeline
*
* @author Rocco Janse <rocco@efocus.nl>
*/

var mainTimeline = new Class({
	initialize: function(state) {

		this.timeline = $('timeline');

		if (!this.timeline) {
			return false;
		}
		if (this.timeline) {
			this.elementFx = new Fx.Styles(this.timeline, { duration: 900, transition: Fx.Transitions.Expo.easeInOut, wait: false });
		}
		if (!state) {
			this.show();
		}
	},
	hide: function() {
		this.elementFx.start({
			'height': 140
		});
	},
	show: function() {
		this.elementFx.start({
			'height': 330
		});
	}
});