// JavaScript Document

$(function() {
			
	// enable W3C object code syntax
	if ($('#home').length) {
		flashembed("logo", {src: "/swf/Scherer_glowing.swf", w3c: true, wmode: "transparent"});
	}
	
	// Add hover class to hovered menu items.
	var hoveredElem = $('#navigatie li, #prevnext li');
	
	hoveredElem.hover(
		function() {
			$(this).toggleClass('hover', true);
		}, 
		function() {
			$(this).toggleClass('hover', false);
		}
	);
	
	// Scroll the list with brands
	if ($('#scroller').length){
		$("#scroller").scrollable().autoscroll();
	}
	
	// select the thumbnails and make them trigger our overlay 
	$("#navigatie ul ul.pano li a, #hotspots a").overlay({ 
	 
		// each trigger uses the same overlay with the id "gallery" 
		target: '#gallery', 
	 
		// optional exposing effect 
		expose: '#f1f1f1',
							 
		onBeforeLoad: function() {

			// load the pano specified in the trigger
			flashembed("panowrap", {src: this.getTrigger().attr("href"), w3c: true, wmode: "transparent"});
		}
	 
	// let the gallery plugin do its magic! 
	});
	
	// load movies
	if ($('#tvspot1').length) {
		flashembed("spotje", {src: "/swf/scherer_caravan.swf", w3c: true, wmode: "transparent"});
	}
	if ($('#tvspot2').length) {
		flashembed("spotje", {src: "/swf/scherer_garage.swf", w3c: true, wmode: "transparent"});
	}
	if ($('#tvspot3').length) {
		flashembed("spotje", {src: "/swf/scherer_visser.swf", w3c: true, wmode: "transparent"});
	}
	if ($('#tvspot4').length) {
		flashembed("spotje", {src: "/swf/scherer_design_1.swf", w3c: true, wmode: "transparent"});
	}
	if ($('#tvspot5').length) {
		flashembed("spotje", {src: "/swf/scherer_design_2.swf", w3c: true, wmode: "transparent"});
	}

	// load google maps
	if ($('#map').length) {
		$('#map').bMap({
			mapZoom: 11,
			mapCenter:[53.41269,6.72209],
			markers:{"data":[ //How to immediately add markers to the map
				{
					"lat":53.41269,
					"lng":6.72209,
					"zoom":11,
					"title":"Scherer", 
					"body":"Hoofdstraat 140 - 9982 AK Uithuizermeeden"
				}
			]}
		});
	}
	
	
	// slideshows with jquery Tools
	if ($('.slidetabs').length) {
		$(".slidetabs").tabs(".images > div", {
		
			// enable "cross-fading" effect
			effect: 'fade',
			fadeOutSpeed: "slow",
		
			// start from the beginning after the last tab
			rotate: true,
			
			// copy alt tag from image to title in content div
			onClick: function(event, tabIndex) {
				var myPane = this.getCurrentPane();
				var description = $(myPane).contents('img').attr('alt');
				$("#title").html(description);
			}//end onClick
		
		// use the slideshow plugin. It accepts its own configuration
		}).slideshow({
			autoplay: true
		});
		
	}
		

	
	// expand content area when hovered
	function hideScroll(elem){
		w = elem.width() - 10;
		elem.width(w);
		elem.css('overflow','hidden');
	}
	
	var scrollElem = $('#route #content, #modern #content, #textiel #content, #slapen #content, #geschiedenis #content, #mensen #content');
	
	hideScroll(scrollElem);
	
	var leesverderButton = $('#content #leesverder');
	
	leesverderButton.show();
	
	scrollElem.live('mouseenter', function (e) {
		leesverderButton.hide();
		$(this).animate({height: 460}, {duration: 150, queue: false});
		$(this).addClass('expanded dropshadow');
		if($.browser.msie){
			$(this).css("border","1px solid #006fb7");
		}
	});
	
	scrollElem.live('mouseleave', function (e) {
		$(this).animate({height: 190}, {duration: 150, queue: false});
		$(this).removeClass('expanded dropshadow');
		if($.browser.msie){
			$(this).css("border","0px solid #006fb7");
		}
		leesverderButton.show();
	});
	
	// form validation
	$.tools.validator.localize("nl", {
		':email'  		: 'Vul een geldig email adres in.',
		'[required]' 	: 'Vul dit veld a.u.b. in.'
	});
	
	if ($('#nieuwsbrief form').length) {
		$('#nieuwsbrief form').validator({lang: 'nl'});
	}

});
