var site = {
	initialize: function() {
		var a = $('submenusContainer').getHeight();
		var b = $('contentContainer').getHeight();
		$('content').style.height = (b - a - 10) +'px';
	}
}

var appointment = {
	update: function(elm, treatment) {
		var qs = $('afspraakForm').serialize();
		//console.log(qs);
		if(treatment) {
		var qs = "treatmentID="+$F(elm.down('td').next('td').down('select')) + "&detailID="+$F(elm.down('tr').next('tr').down('td').next('td').down('select'));
		} else {
		var qs = "treatmentID="+$F(elm.down('td').next('td').down('select'));
		}
		//console.log(qs);
		new Ajax.Updater(elm, 'site/about_the_salons/_afspraak_form.php?ajax=true', { method: 'post', parameters: qs, onComplete: function(){
			//appointment.price();
		}
		} );		
	},
	price: function() {
		var prijs = 0;
		$$('.prijs').each(function(elm, index) {
			prijs += parseFloat($F(elm));
		});
		prijs = prijs.toString().replace(".",",");
		
		$('afspraakPrijs').update(prijs);
	},
	getTreatment: function() {
	new Ajax.Request('site/about_the_salons/_afspraak_form.php?ajax=true', { method: 'post', parameters: '', onComplete: function(transport) {
		$('treats').insert( { before: transport.responseText } );
		//appointment.price();
	}
	} );
}
}

var imageList = {
	'images': null,
	'index': 0,
	'fadeTimeout': null,
	'nextTimeout': null,
	
	initialize: function(current, images) {
		this.images = images;
		
		//Switch to first image
		if ($('mainImageSwitcher') != null) {
			$('mainImageSwitcher').hide();
			$('mainImageSwitcher').src = 'cms_img/main_'+ images[this.index].file;
			this.fadeTimeout = setTimeout("$('mainImageSwitcher').appear(); $('lightboxHref').href = 'cms_img/large_"+ images[this.index].file +"';"+
											"document.observe('dom:loaded', function () { document.lightbox.updateImageList() });", 300);
			
		}
		
		new Ajax.Updater('', 'site/_set_image.php', { method: 'post', parameters: 'file='+ images[this.index].file } );
		
		//Create a periodical executer
		if(images.length > 1) {
			this.nextTimeout = setTimeout("imageList.next();", 3000);
		}
	},
	
	next: function() {
		this.index++;
		if(this.index == this.images.length) this.index = 0;
		
		$('mainImage').style.backgroundImage = 'url('+ $('mainImageSwitcher').src +')';
		$('mainImageSwitcher').hide();
		$('mainImageSwitcher').src = 'cms_img/main_'+ this.images[this.index].file;
		
		this.fadeTimeout = setTimeout("$('mainImageSwitcher').appear(); $('lightboxHref').href = 'cms_img/large_"+ this.images[this.index].file +"'; "+
										"document.observe('dom:loaded', function () { document.lightbox.updateImageList() });", 2000);
		this.nextTimeout = setTimeout("imageList.next();", 7000);
		
		new Ajax.Updater('', 'site/_set_image.php', { method: 'post', parameters: 'file='+ this.images[this.index].file } );
	},
	
	'lastImageData': null,
	
	click: function(imageData) {
		//Clear autoimages timeouts
		clearTimeout(this.fadeTimeout);
		clearTimeout(this.nextTimeout);
		
		$('mainImage').style.backgroundImage = 'url('+ $('mainImageSwitcher').src +')';
		$('mainImageSwitcher').hide();
		
		//Set new image in session
		new Ajax.Updater('', 'site/_set_image.php', { method: 'post', parameters: 'file='+ imageData.file } );
		
		//Set thumb
		$(imageData.id).src = 'cms_img/small_'+ imageData.file;
		$(imageData.id).onmouseout = function() {};
		
		//Set new image
		$('mainImageSwitcher').src = 'cms_img/main_'+ imageData.file;
		$('lightboxHref').href = 'cms_img/large_'+ imageData.file;
		document.observe('dom:loaded', function () { document.lightbox.updateImageList() });
		this.fadeTimeout = setTimeout("$('mainImageSwitcher').appear();", 300);
		
		//Reset old thumb
		if(this.lastImageData && $(this.lastImageData.id) && this.lastImageData.file != imageData.file) {
			$(this.lastImageData.id).src = 'cms_img/small_bw_'+ this.lastImageData.file;
			var file = this.lastImageData.file;
			$(this.lastImageData.id).onmouseout = function() { this.src = 'cms_img/small_bw_'+ file; }
		}
		
		this.lastImageData = imageData;
	},
	
	initializeScroll: function() {
		$('imageList').observe('mousemove', imageList.scroll);
	},
	
	scroll: function(e) {
		var height = $('pager').getHeight();
		var trueHeight  = $('imageList').getHeight();
		
		var y = Event.pointerY(e) - $('imageList').positionedOffset().top - $('imageList').getOffsetParent().positionedOffset().top;
		
		if(y < 60) y = 0;
		y -= 60;
		if(y > (height - trueHeight)) y = (height - trueHeight);
		
		//Try catch is workaround for senseless IE js error
		try { $('pager').style.marginTop = '-'+ y +'px'; } catch(err) {} 
	}
}
var player = null;

function playerReady(obj)
{
	player = document.getElementById(obj.id);
	player.addModelListener('STATE', 'stateMonitor');
};

function stateMonitor(obj)
{
	if(obj.newstate == 'COMPLETED')
	{
		$('movieContainer').hide();
	}
};

function disableContextMenu(element) {
    element.oncontextmenu = function() {
        return false;
    }
}

function showVideo(video) {
	new Effect.Fade('menu',{
		duration : 0.5,
		afterFinish : function() {new Effect.Appear('video_menu',{duration : 1});}
	}
	);
	playVideo(video);
}

function playVideo(video) {
	$('movieContainer').show();
	$('contentContainer').hide();
	var so = new SWFObject('swf/player.swf','mpl','807','449','9');
	so.addParam('allowscriptaccess','always');
	so.addParam('allowfullscreen','true');
	so.addParam('flashvars','&file='+video+'&controlbar=none&autostart=true');
	so.write('player');
}

function hideVideo() {
	new Effect.Fade('video_menu',{
		duration : 0.5,
		afterFinish : function() {
			new Effect.Appear(
				'menu',{
					duration : 0.5,
					afterFinish : function() { $('contentContainer').show();}
				});
		}
	}
	);
} 


function validateOrderForm() {
	if($("order_form")) {
		if (!$("algemene_check").checked) {
			alert("Gaat u akkoord met onze algemene voorwaarden?");
			return false;
		} 
		
	}
}

disableContextMenu(document);
