$(document).ready(function() {
	var currentPreview = 'cuisine';
	
	$('img[usemap]').maphilight();
	
	/* setup the tooltips */
	$('#products a').tooltip({ 
		track: true, 
		delay: 0, 
		showURL: false, 
		showBody: " - ", 
		fade: 250
	});
	$('#products-all a, #products-demonstration a, #products-inspiration a').tooltip({ 
		track: true, 
		delay: 0, 
		showURL: false, 
		showBody: " - ", 
		fade: 250
	});
	$('.hidden').hide();
	
	$('#huis-overlay').mouseover(function(e){
		y = e.pageY;
		x = e.pageX;
		$(this).hide();
		$(document.elementFromPoint(x, y)).mouseover(); 
		$(this).show();
		}).click(function(e){});
	
	$('#house-image #huis .huisarea').click(function(){
		$('.previewimage').hide();
		var thisId = $(this).attr('id');
		thisId = thisId.replace('huis','');
		$('#'+thisId).show();
		$('img[usemap]').maphilight();		
		$('#house-image img#lamaison').attr('src','/img/3d-huis-'+thisId+'-avec.png');
		$('#house-image div').css('background-image','url("/img/3d-huis-'+thisId+'-avec.png")');
		
		var newPostits = $('#'+thisId+' .postitbar').html();
		newPostits = newPostits.split('|');
		for(var i=1; i<=5; i++){
			$('#hovermap'+i).html(newPostits[i-1]);	
		}
		
		currentPreview = thisId;
		return false;
	});
	
	/*
	$('#hovermap1').mouseover(function(e) { $('#'+currentPreview+' #'+currentPreview+'map1').mouseover(); }).mouseout(function(e) { $('#'+currentPreview+' #'+currentPreview+'map1').mouseout(); });
	$('#hovermap2').mouseover(function(e) { $('#'+currentPreview+' #'+currentPreview+'map2').mouseover(); }).mouseout(function(e) { $('#'+currentPreview+' #'+currentPreview+'map2').mouseout(); });
	$('#hovermap3').mouseover(function(e) { $('#'+currentPreview+' #'+currentPreview+'map3').mouseover(); }).mouseout(function(e) { $('#'+currentPreview+' #'+currentPreview+'map3').mouseout(); });
	$('#hovermap4').mouseover(function(e) { $('#'+currentPreview+' #'+currentPreview+'map4').mouseover(); }).mouseout(function(e) { $('#'+currentPreview+' #'+currentPreview+'map4').mouseout(); });
	$('#hovermap5').mouseover(function(e) { $('#'+currentPreview+' #'+currentPreview+'map5').mouseover(); }).mouseout(function(e) { $('#'+currentPreview+' #'+currentPreview+'map5').mouseout(); });
	*/
	$('#hovermap1,#hovermap2,#hovermap3,#hovermap4,#hovermap5').mouseover(function(e) {
		thisId = $(this).attr('id');
		thisId = thisId.replace('hovermap','');
		$('#'+currentPreview+' #'+currentPreview+'map'+thisId).mouseover();
	}).mouseout(function(e) {
		thisId = $(this).attr('id');
		thisId = thisId.replace('hovermap','');
		$('#'+currentPreview+' #'+currentPreview+'map'+thisId).mouseout();
	});	
	
	$('#hovermap1,#hovermap2,#hovermap3,#hovermap4,#hovermap5').click(function(e) {
		thisId = $(this).attr('id');
		thisId = thisId.replace('hovermap','');
		$('#'+currentPreview+' #'+currentPreview+'map'+thisId).click();
		return false;
	});
	
	$('.maparea').click(function(){
		thisId = $(this).attr('id');
		thisId = thisId.replace(currentPreview+'map','');
		parentId = $(this).parent().attr('id');
		parentId = parentId.replace('map','');
		
		if($('#'+parentId+thisId+':visible').length > 0){
			$('.preview-postit').hide();
		}
		else {
			$('.preview-postit').hide();	
			$('#'+parentId+thisId).show();	
		}
		return false;
	});
	$(document).click(function(){
		$('.preview-postit').hide();
   	});
	$('.faq_link').click(function(){
		if($(this).attr('rel')!=""){
			$('#no-faq').hide();
			$('.faq_link').removeClass('active');
			$('.faq_item').hide();
			$(this).addClass('active');
			$('#'+$(this).attr('rel')).show();
		}
		return false;
	});
	/* Video's */
	if($('#idees-de-collage-video').length > 0){
   		flowplayer("idees-de-collage-video", "/flowplayer/flowplayer-3.2.6.swf");
	}
	if($('#demonstration-video').length > 0){
		flowplayer("demonstration-video", "/flowplayer/flowplayer-3.2.6.swf", {
	 	   clip: {autoPlay: false, autoBuffering: true}});
	}
	
	$('#products-demonstration a').click(function(){
		var newSrc = $(this).attr('href');
		$('#demonstration-video').attr('href',newSrc);
		$(document).scrollTop('0');
		flowplayer("demonstration-video", "/flowplayer/flowplayer-3.2.6.swf");
		return false;
	});
	
	$('.demonstration-postit-top a').click(function(){
		var newSrc = $(this).attr('href');
		$('#demonstration-video').attr('href',newSrc);
		$(document).scrollTop('0');
		flowplayer("demonstration-video", "/flowplayer/flowplayer-3.2.6.swf");
		return false;
	});
	
});
