function wc()
{
	if(window.console)
	{
		for(var i = 0; i < arguments.length; i++)
		{
			window.console.log(arguments[i]);
		}
	}
}



$().ready(function()
{
	

	$(".rss-article-list a").attr("target","_blank");
	
	var home = $('#page.homepage');
	
	if(home.length)
	{
		$('div.visual', home).flash(
		{
			swf: BASE_URL+'swf/luchtletters.swf?aaa',
			height: 250,
			width: 1020,
			wmode: 'opaque'
		});
	}
	else
	{	
		$('#page div.visual').flash(
		{
			swf: BASE_URL+'swf/luchtletters_small.swf',
			height: 125,
			width: 1020,
			wmode: 'opaque'
		});
	}
	
	// ----------------------------------------------------------------------------
	
	$('div.content div.body h5').each(function(){
		
		$(this).addClass('toggable').css({cursor: 'pointer'});
		
		$('~ *', this).each(function(){
							
			if(this.tagName.indexOf('H') == 0) return false;
			
			$(this).hide();
			
		});
	});
	
	$('div.content div.body h5').toggle(
		function() {
			
			$(this).addClass('open');
			
			// alle sliblings tot aan de volgende H5 uitklappen
			$('~ *', this).each(function(){
								
				if(this.tagName.indexOf('H') == 0) return false;
				
				$(this).slideDown('fast');
				
			});
			
		},
		function() {
		
			$(this).removeClass('open');
			
			// alle sliblings tot aan de volgende H5 inklappen
			$('~ *', this).each(function(){
								
				if(this.tagName.indexOf('H') == 0) return false;
				
				$(this).slideUp('fast');
				
			});
		}
	);
	
	// ----------------------------------------------------------------------------
	
	if($('#map').length)
	{
		var address = $('#map').text(); //'Middenweg 6, 4782 PM Moerdijk';
		
		wc(address);
		
		var myOptions = {
			
			zoom: 14,
			
			disableDefaultUI: true,
			
			//center: myLatlng,
			
			mapTypeId: google.maps.MapTypeId.ROADMAP
		}
		
		var infowindow_contents = $('#map').html();
		
		//wc(infowindow_contents);
		
		var map = new google.maps.Map($('#map')[0], myOptions);
	
		var geocoder = new google.maps.Geocoder();
		
		var directionsDisplay = new google.maps.DirectionsRenderer();
		
		directionsDisplay.setMap(map);
		
		var directionsService = new google.maps.DirectionsService();
		
		geocoder.geocode(
			
			{'address': address},
			
			function(results, status)
			{
				if (status == google.maps.GeocoderStatus.OK)
				{
					// wc(results);
					// wc(results[0].geometry.location);
					
					map.setCenter(results[0].geometry.location);
					
					map.setZoom(14);
					
					var marker = new google.maps.Marker({
						map: map, 
						position: results[0].geometry.location
					});
					
					//calcRoute(results[0].geometry.location, 'rotterdam');
					
					var infowindow = new google.maps.InfoWindow({
					
						content: infowindow_contents,
						
						maxWidth: 400
						
					});
									
					// infowindow.open(map, marker);
				
				}
				else
				{
					wc("Geocode was not successful for the following reason: " + status);
				}
			}
		);
	}
});

// ----------------------------------------------------------------------------

function getFancyboxConfig()
{
	var isIE = !$.support.opacity;
	
	return {
	
		hideOnContentClick: false,
		
		cyclic: true,
		
		margin: 20,
		
		centerOnScroll: true,
		
		overlayOpacity: 0.6,
		
		overlayColor: '#000',
		
		speedIn: 600, 
		
		speedOut: 200, 
		
		overlayShow: true,
		
		showCloseButton: true,
		
		titlePosition: 'inside',
		
		titleFormat: fancyTitle,
		
		onStart: function() {
			
			if(isIE) $('object').css({visibility: 'hidden'});
		},
		onCleanup: function() {
		
			if(isIE) $('object').css({visibility: 'visible'});
		},
		
		foo: 'bar'
	};
}

// ----------------------------------------------------------------------------

function fancyTitle(title, currentArray, currentIndex, currentOpts)
{
	return '<div id="fancydescription">' + (title && title.length ? '<h4>' + title + '</h4>' : '' ) + '</div>';
	//return '<div id="fancydescription">' + (title && title.length ? '<b>' + title + '</b><br/>' : '' ) + (currentArray.length > 1 ? '<span id="fancypagecount"><a href="javascript:;" onclick="$.fancybox.prev();">&#8249;&#8249; previous </a> &#160; image ' + (currentIndex + 1) + ' of ' + currentArray.length + ' &#160; <a href="javascript:;" onclick="$.fancybox.next();"> next &#8250;&#8250;</a></span>' : '') +'</div>';
}

// ----------------------------------------------------------------------------

function getFlowPlayerConfig(url, autoHide_enabled)
{
	//return {"clip":{"url": url, 'onBufferEmpty': function(){ return false; } }};
	
	autoHide_enabled == undefined ? autoHide_enabled = true : autoHide_enabled = false;
	
	return {"clip":{"url": url },"screen":{"height":"100pct","top":0},"plugins":{"controls":{"borderRadius":"0px","timeColor":"#ffffff","bufferGradient":"none","slowForward":true,"backgroundColor":"rgba(0, 0, 0, 0)","volumeSliderGradient":"none","slowBackward":false,"timeBorderRadius":20,"time":true,"progressGradient":"none","height":26,"volumeColor":"#007ac3","tooltips":{"marginBottom":5,"volume":true,"scrubber":true,"buttons":false},"opacity":1,"fastBackward":false,"timeFontSize":12,"bufferColor":"#a3a3a3","volumeSliderColor":"#ffffff","border":"0px","buttonColor":"#ffffff","mute":true,"autoHide":{"enabled":autoHide_enabled,"hideDelay":500,"mouseOutDelay":500,"hideStyle":"fade","hideDuration":400,"fullscreenOnly":false},"backgroundGradient":"none","width":"100pct","sliderBorder":"1px solid rgba(128, 128, 128, 0.7)","display":"block","buttonOverColor":"#ffffff","fullscreen":true,"timeBgColor":"rgb(0, 0, 0, 0)","scrubberBarHeightRatio":0.2,"bottom":0,"stop":false,"zIndex":1,"sliderColor":"#000000","scrubberHeightRatio":0.6,"tooltipTextColor":"#ffffff","sliderGradient":"none","timeBgHeightRatio":0.8,"volumeSliderHeightRatio":0.6,"timeSeparator":" ","name":"controls","volumeBarHeightRatio":0.2,"left":"50pct","tooltipColor":"rgba(0, 0, 0, 0)","playlist":false,"durationColor":"#b8d9ff","play":true,"fastForward":true,"timeBorder":"0px solid rgba(0, 0, 0, 0.3)","progressColor":"#007ac3","scrubber":true,"volume":true,"volumeBorder":"1px solid rgba(128, 128, 128, 0.7)","builtIn":false}}};
}

// ----------------------------------------------------------------------------

function startFlowPlayer(flowplayer, url, title)
{
	wc(' -- startFlowPlayer --');
	
	var video_w = 640;			
	var video_h = 368;
	
	if(url)
	{				
		if(flowplayer && flowplayer.length)
		{
			wc('-- play video in page embedded flowplayer --');
			
			// wc(url, flowplayer);
			
			flowplayer.flowplayer(
				
				'swf/flowplayer/flowplayer-3.2.2.swf',
				
				getFlowPlayerConfig(url, false)
				
			);
		}
		else
		{
			// trap video pleerert in fancybox
			
			wc('-- play video in fancybox overlay --');
			
			wc(flowplayer);
			
			$.fancybox(
				
				$('<div/>')
					.css({ width: video_w, height: video_h, overflow: 'hidden' })
					.flowplayer(
						'swf/flowplayer/flowplayer-3.2.2.swf',
						getFlowPlayerConfig(url)
					)
				,
				
				$.extend({
				
					'title': title,
					
					//'autoDimensions': false,
					'autoScale': false,
					
					'width': video_w,
					'height': video_h,
					
					//'transitionIn': 'none',
					//'transitionOut': 'none',

					'onCleanup': function(){
						
						wc('-- fancybox onCleanup --');
						
						$f().unload();
					},
					
					'onClosed': function(){
						
						wc('-- fancybox onClosed --');
												
					},
					
					'foo': 'bar'
					},
					
					getFancyboxConfig()
				)					
			);
		}
	}
}

// ----------------------------------------------------------------------------

/**
 * @see http://github.com/NV/placeholder.js
 */
jQuery.fn.textPlaceholder = function () {

    return this.each(function(){

        var that = this;

        if (that.placeholder && 'placeholder' in document.createElement(that.tagName)) return;

        var placeholder = that.getAttribute('placeholder');
        var input = jQuery(that);

        if (that.value === '' || that.value == placeholder) {
            input.addClass('text-placeholder');
            that.value = placeholder;
        }

        input.focus(function(){
            if (input.hasClass('text-placeholder')) {
                this.value = '';
                input.removeClass('text-placeholder')
            }
        });

        input.blur(function(){
            if (this.value === '') {
                input.addClass('text-placeholder');
                this.value = placeholder;
            } else {
                input.removeClass('text-placeholder');
            }
        });

        that.form && jQuery(that.form).submit(function(){
            if (input.hasClass('text-placeholder')) {
                that.value = '';
            }
        });

    });

};

// ----------------------------------------------------------------------------
	

