// -----------------------------------------------------------------------------
// 2011-06-18

function trace(s) {
  //try { console.log(s) } catch (e) { alert(s) }
};

trace('2011-06-18: ' + 1);

function hideGallery() {
trace('hideGallery');
	var g = document.getElementById('gallery');
	if (g) { trace('ok'); g.style.display = 'none' }
}

function showGallery() {
trace('showGallery');
	var g = document.getElementById('gallery');
	if (g) { trace('ok'); g.style.display = '' }
}
// -----------------------------------------------------------------------------
var cHash;
var hashTimer

function processHash() {
	var tHash = window.location.hash;
	var a, li;
	
	if (tHash || cHash) {
		tHash = tHash.replace('#section_', 'content_');
		
		if (tHash != cHash) {
			cHash = tHash;
			if (cHash.length == 0) { cHash = "content_home" }
			
			$("#" + cHash).click();
			
			a = document.getElementById(cHash);
			li = a.parentNode;
			
			$(a).animate({ opacity: 1, marginTop: "0px"}, 0 );
			$(li).addClass("active");
			$(li).siblings().removeClass("active");
			$(li).siblings().children().animate({ opacity: 0, marginTop: "0px"}, 240 );
		}
	}
}

setInterval("processHash()", 500);
// -----------------------------------------------------------------------------
function debug(e) {
	document.title += "," + e;
}

//debug("#");

function contentItem(h, o) {
	this.height = h;
	this.offset = o;
	
	offset = offset + h;
	
	this.hpx = function() { return this.height + 'px' }
	this.opx = function() { return this.offset + 'px' }
	this.opx2 = function() {
		var tmp = this.offset - 200;
		if (tmp < 0) { tmp = 200 }
		return tmp + 'px';
	}
}

var heightS = 395; // Small
var heightM = 790; // Medium
var heightL = 1350; // Large

var offset = 0;

var contentHome = new contentItem(heightS, offset);
var contentVoorraad = new contentItem(heightL, offset); // Large
var contentNapbovag = new contentItem(heightS, offset);
var contentRoute = new contentItem(heightS, offset);
var contentOpeningstijden = new contentItem(heightS, offset);
var contentFinanciering = new contentItem(heightS, offset);
var contentGarantie = new contentItem(heightS, offset);
var contentAutonieuws = new contentItem(heightM, offset); // Medium
var contentContact = new contentItem(heightS, offset);

var animationLengthL = 2000;
var animationLength = 0;
var animationLengthS = 0;

var scrollDistance = 100;

function scrollDistances(grid, item) {
	var x0, x1, x2, x3;
	var y0, y1, y2, y3;
	var t;
	
	x0 = grid.scrollLeft();
	x3 = parseInt(item.css('left')) - 35;
	if (!x3) { x3 = 0 }
	if (x3 < 0) { x3 = 0 }
	if ((Math.abs(x3 - x0)) > (2 * scrollDistance)) {
		if (x0 < x3) {
//alert(0);
			x1 = x0 + scrollDistance;
			x2 = x3 - scrollDistance;
		} else {
//alert(1);
			x1 = x0 - scrollDistance;
			x2 = x3 + scrollDistance;
		}
	} else {
//alert(2);
		x1 = Math.floor(x0 + ((x3 - x0) / 2));
		x2 = Math.ceil(x0 + ((x3 - x0) / 2));
		if ((x1 < 0) && (x1 > x2)) { t = x1; x1 = x2; x2 = t }
	}
	
	y0 = grid.scrollTop();
	y3 = grid.scrollTop() + item.offset().top - 205;
	if (!y3) { y3 = 0 }
	if (y3 < 0) { y3 = 0 }
	if ((Math.abs(y3 - y0)) > (2 * scrollDistance)) {
		if (y0 < y3) {
			y1 = y0 + scrollDistance;
			y2 = y3 - scrollDistance;
		} else {
			y1 = y0 - scrollDistance;
			y2 = y3 + scrollDistance;
		}
	} else {
		y1 = Math.floor(y0 + ((y3 - y0) / 2));
		y2 = Math.ceil(y0 + ((y3 - y0) / 2));
		if ((y1 < 0) && (y1 > y2)) { t = y1; y1 = y2; y2 = t }
	}
	
	if ((Math.abs(x3 - x0) > 0) && (Math.abs(y3 - y0) > 0)) {
		y1 = y0;
		x2 = x3;
	}
	
	this.x0 = x0 + 'px';
	this.x1 = x1 + 'px';
	this.x2 = x2 + 'px';
	this.x3 = x3 + 'px';
	
	this.y0 = y0 + 'px';
	this.y1 = y1 + 'px';
	this.y2 = y2 + 'px';
	this.y3 = y3 + 'px';
}

var oldItem = $('#overlay_home');
var newItem;
// -----------------------------------------------------------------------------
function slideNext(u, stopAfterNext) {
//document.title += "1";
//alert(u);
	if (stopAfterNext) { stopSliding() }
	
	$('#section_0').css('opacity', 1);
	
	if ($('#section_1').css('opacity') > 0.5) {
		$('#section_0').css('background-image', $('#section_1').css('background-image'));
	}
	
	$('#section_1').css('opacity', 0);
	$('#section_1').css('background-image', 'url("' + u + '")');
	
	$('#section_1').animate( { opacity: 1 }, animationLengthL, function() {
//alert(u);
		$('#section_0').css('background-image', 'url("' + u + '")');
		$('#section_1').css('opacity', 0);
		
		if (stopAfterNext) {
//document.title += "a";
			stopSliding();
		} else {
//document.title += "A";
			continueSlidingAfter(u);
		}
	});
}

var slidesInt;
var slidesArr = new Array('graphics/home2.jpg', 'graphics/voorraad_bg.jpg', 'graphics/napbovag_bg2.jpg', 'graphics/route_bg2.jpg', 'graphics/openingstijden_bg2.jpg', 'graphics/financiering_bg2.jpg', 'graphics/garantie_bg2.jpg', 'graphics/voorraad_bg.jpg');
var slidesI = 0;

function continueSlidingAfter(u) {
//document.title += "2";
	slidesI = 0;
	
	for (var i = 0; i < slidesArr.length; i++) {
		if (slidesArr[i] == u) { slidesI = i + 1 }
	}
	
	if (slidesI >= slidesArr.length) { slidesI = 0 }
	
	//slidesInt = setTimeout('slideNext()', animationLengthL * 3, slidesArr[slidesI])
}

function stopSliding() {
//document.title += "3";
	clearTimeout(slidesInt);
}
// -----------------------------------------------------------------------------
// SLIDING FUNCTIONS
jQuery(function($){
//alert(0);
slidingState = 'sliding';
//document.title += '_';
	//slideNext('graphics/home2.jpg');
	
//alert(1);
	/**
	 * Most jQuery.localScroll's settings, actually belong to jQuery.ScrollTo, check it's demo for an example of each option.
	 * @see http://www.freewebs.com/flesler/jQuery.ScrollTo/
	 * You can use EVERY single setting of jQuery.ScrollTo, in the settings hash you send to jQuery.LocalScroll.
	 */
	
	/*var target = $('#slider').get(0);//the scrolled div*/
	/**
	 * restart the scroll position to ( 0, 0 ) (Firefox doesn't reset it)
	 * could use $(target).scrollTo( 0, {axis:'xy'));
	 * but this needs to be quick(synchronous), to reset before $.localScroll.hash() begins
	 */
	/*target.scrollLeft = target.scrollTop = 0;*/
	
	//scroll initially if there's a hash (#something) in the url 
	/*$.localScroll.hash({
		target: target, //could be a selector or a jQuery object too.
		axis:'xy',//the default is 'y'
		queue:true,
		duration:animationLength
	});*/
	
	/*var $last = $([]);//save the last link*/
	
	/**
	 * NOTE: In the former version of the demo, I called $('#navigation').localScroll()
	 * Now I want to also affect the >> and << links, so I'll use $.localScroll() instead
	 */
	/*$.localScroll({
		target: target,//could be a selector or a jQuery object too.
		axis:'xy',//the default is 'y'
		queue:true,
		duration:animationLength,
		
		hash:true,
		onBefore:function(e, anchor, $target ){
			//'this' is the clicked link
			this.blur();//remove the awful outline
			$target.animate( { opacity: 0 }, 1000 );
		}
	});*/
	
	$.scrollTo.defaults.axis = 'xy';//by default, the scroll is only done vertically ('y'), change it to both.
	
	//this one is important, many browsers don't reset scroll on refreshes
	$('div#overlay').scrollTo( 0 );//reset all scrollable panes to (0,0)
	$('div#slidenav').scrollTo( 0 );//reset all scrollable panes to (0,0)
	$.scrollTo( 0 );//reset the screen to (0,0)
	
	//Target examples bindings
	var $paneTarget = $('#overlay');
	
	var $slideTarget = $('#slidenav');
	//var i=1;
	// =========================================================================
	$('#pijllinks').click(function(){
		var t = $slideTarget.scrollLeft();
		t -= 235;
		if (t < 0) { t = 0 }
		
		$slideTarget.stop().scrollTo( t, animationLengthS, {});
	});

	$('#pijlrechts').click(function(){
		var t = $slideTarget.scrollLeft();
		t += 235;
		if (t > 940) { t = 940 }
		//if (t > 705) { t = 705 } // aangepast op 19-1-2012
		//if (t > 470) { t = 470 } // aangepast op 23-8-2011
		
		$slideTarget.stop().scrollTo( t, animationLengthS, {});
	});
	// =========================================================================
	$('#content_actie1').click(function(){
document.body.style.backgroundImage = "url(graphics/bg-old.gif)";
		$("div#overlay").animate({ height: contentHome.hpx() }, 0);
		$("div#photos").animate({ height: contentHome.hpx() }, 0);
		
		$("div#slidenav").show();
		$("#pijllinks").show();
		$("#pijlrechts").show();
		
		newItem = $('#overlay_home');
		var ds = new scrollDistances($('#overlay'), newItem);
		
		if (ds.x0 != ds.x3) {
			$('#overlay div.item').animate( { opacity: 0 }, 0);
			oldItem.animate( { opacity: 1 }, 0);
			oldItem.animate( { opacity: 0 }, animationLengthS);
			$paneTarget.scrollTo( { top: '0px', left: ds.x1 }, animationLength, {
				onAfter:function(){
					//$paneTarget.scrollTo( { top: '0px', left: ds.x2 }, 0);
					$paneTarget.scrollTo( { top: '0px', left: ds.x3 }, 0);
					newItem.animate( { opacity: 1 }, animationLengthS);
					oldItem = newItem;
				}
			});
		}
	});

	$('#content_actie2').click(function(){
document.body.style.backgroundImage = "url(graphics/bg-old.gif)";
		$("div#overlay").animate({ height: contentHome.hpx() }, 0);
		$("div#photos").animate({ height: contentHome.hpx() }, 0);
		
		$("div#slidenav").show();
		$("#pijllinks").show();
		$("#pijlrechts").show();
		
		newItem = $('#overlay_actie2');
		var ds = new scrollDistances($('#overlay'), newItem);
		
		if (ds.x0 != ds.x3) {
			$('#overlay div.item').animate( { opacity: 0 }, 0);
			oldItem.animate( { opacity: 1 }, 0);
			oldItem.animate( { opacity: 0 }, animationLengthS);
			$paneTarget.scrollTo( { top: '0px', left: ds.x1 }, animationLength, {
				onAfter:function(){
					//$paneTarget.scrollTo( { top: '0px', left: ds.x2 }, 0);
					$paneTarget.scrollTo( { top: '0px', left: ds.x3 }, 0);
					newItem.animate( { opacity: 1 }, animationLengthS);
					oldItem = newItem;
				}
			});
		}
	});

	$('#content_actie3').click(function(){
document.body.style.backgroundImage = "url(graphics/bg-old.gif)";
		$("div#overlay").animate({ height: contentHome.hpx() }, 0);
		$("div#photos").animate({ height: contentHome.hpx() }, 0);
		
		$("div#slidenav").show();
		$("#pijllinks").show();
		$("#pijlrechts").show();
		
		newItem = $('#overlay_actie3');
		var ds = new scrollDistances($('#overlay'), newItem);
		
		if (ds.x0 != ds.x3) {
			$('#overlay div.item').animate( { opacity: 0 }, 0);
			oldItem.animate( { opacity: 1 }, 0);
			oldItem.animate( { opacity: 0 }, animationLengthS);
			$paneTarget.scrollTo( { top: '0px', left: ds.x1 }, animationLength, {
				onAfter:function(){
					//$paneTarget.scrollTo( { top: '0px', left: ds.x2 }, 0);
					$paneTarget.scrollTo( { top: '0px', left: ds.x3 }, 0);
					newItem.animate( { opacity: 1 }, animationLengthS);
					oldItem = newItem;
				}
			});
		}
	});

	$('#content_actie4').click(function(){
document.body.style.backgroundImage = "url(graphics/bg-old.gif)";
		$("div#overlay").animate({ height: contentHome.hpx() }, 0);
		$("div#photos").animate({ height: contentHome.hpx() }, 0);
		
		$("div#slidenav").show();
		$("#pijllinks").show();
		$("#pijlrechts").show();
		
		newItem = $('#overlay_actie4');
		var ds = new scrollDistances($('#overlay'), newItem);
		
		if (ds.x0 != ds.x3) {
			$('#overlay div.item').animate( { opacity: 0 }, 0);
			oldItem.animate( { opacity: 1 }, 0);
			oldItem.animate( { opacity: 0 }, animationLengthS);
			$paneTarget.scrollTo( { top: '0px', left: ds.x1 }, animationLength, {
				onAfter:function(){
					//$paneTarget.scrollTo( { top: '0px', left: ds.x2 }, 0);
					$paneTarget.scrollTo( { top: '0px', left: ds.x3 }, 0);
					newItem.animate( { opacity: 1 }, animationLengthS);
					oldItem = newItem;
				}
			});
		}
	});

	$('#content_actie5').click(function(){
document.body.style.backgroundImage = "url(graphics/bg-old.gif)";
		$("div#overlay").animate({ height: contentHome.hpx() }, 0);
		$("div#photos").animate({ height: contentHome.hpx() }, 0);
		
		$("div#slidenav").show();
		$("#pijllinks").show();
		$("#pijlrechts").show();
		
		newItem = $('#overlay_actie5');
		var ds = new scrollDistances($('#overlay'), newItem);
		
		if (ds.x0 != ds.x3) {
			$('#overlay div.item').animate( { opacity: 0 }, 0);
			oldItem.animate( { opacity: 1 }, 0);
			oldItem.animate( { opacity: 0 }, animationLengthS);
			$paneTarget.scrollTo( { top: '0px', left: ds.x1 }, animationLength, {
				onAfter:function(){
					//$paneTarget.scrollTo( { top: '0px', left: ds.x2 }, 0);
					$paneTarget.scrollTo( { top: '0px', left: ds.x3 }, 0);
					newItem.animate( { opacity: 1 }, animationLengthS);
					oldItem = newItem;
				}
			});
		}
	});

	$('#content_actie6').click(function(){
document.body.style.backgroundImage = "url(graphics/bg-old.gif)";
		$("div#overlay").animate({ height: contentHome.hpx() }, 0);
		$("div#photos").animate({ height: contentHome.hpx() }, 0);
		
		$("div#slidenav").show();
		$("#pijllinks").show();
		$("#pijlrechts").show();
		
		newItem = $('#overlay_actie6');
		var ds = new scrollDistances($('#overlay'), newItem);
		
		if (ds.x0 != ds.x3) {
			$('#overlay div.item').animate( { opacity: 0 }, 0);
			oldItem.animate( { opacity: 1 }, 0);
			oldItem.animate( { opacity: 0 }, animationLengthS);
			$paneTarget.scrollTo( { top: '0px', left: ds.x1 }, animationLength, {
				onAfter:function(){
					//$paneTarget.scrollTo( { top: '0px', left: ds.x2 }, 0);
					$paneTarget.scrollTo( { top: '0px', left: ds.x3 }, 0);
					newItem.animate( { opacity: 1 }, animationLengthS);
					oldItem = newItem;
				}
			});
		}
	});
	
	$('#content_actie8').click(function(){
document.body.style.backgroundImage = "url(graphics/bg-old.gif)";
		$("div#overlay").animate({ height: contentHome.hpx() }, 0);
		$("div#photos").animate({ height: contentHome.hpx() }, 0);
		
		$("div#slidenav").show();
		$("#pijllinks").show();
		$("#pijlrechts").show();
		
		newItem = $('#overlay_actie8');
		var ds = new scrollDistances($('#overlay'), newItem);
		
		if (ds.x0 != ds.x3) {
			$('#overlay div.item').animate( { opacity: 0 }, 0);
			oldItem.animate( { opacity: 1 }, 0);
			oldItem.animate( { opacity: 0 }, animationLengthS);
			$paneTarget.scrollTo( { top: '0px', left: ds.x1 }, animationLength, {
				onAfter:function(){
					//$paneTarget.scrollTo( { top: '0px', left: ds.x2 }, 0);
					$paneTarget.scrollTo( { top: '0px', left: ds.x3 }, 0);
					newItem.animate( { opacity: 1 }, animationLengthS);
					oldItem = newItem;
				}
			});
		}
	});
	// -------------------------------------------------------------------------
	/*$('h1 a').click(function(){
		$paneTarget.stop().scrollTo( '0', animationLength, {
			onAfter:function(){
				$("#gallery").show();
			}
		});
	});*/
	$('#content_home').click(function(){
document.body.style.backgroundImage = "url(graphics/bg-old.gif)";
		$("div#overlay").animate({ height: contentHome.hpx() }, 0);
		$("div#photos").animate({ height: contentHome.hpx() }, 0);
		
		newItem = $('#overlay_home');
		var ds = new scrollDistances($('#overlay'), newItem);
		
//alert(ds.x0 + ':' + ds.y0 + ' - ' + ds.x1 + ':' + ds.y1 + ' - ' + ds.x2 + ':' + ds.y2 + ' - ' + ds.x3 + ':' + ds.y3);
		if ((ds.x0 != ds.x3) || (ds.y0 != ds.y3)) {
			$('#overlay div.item').animate( { opacity: 0 }, 0);
			oldItem.animate( { opacity: 1 }, 0);
			oldItem.animate( { opacity: 0 }, animationLengthS);
slideNext('graphics/home2.jpg');
			$paneTarget.scrollTo( { top: ds.y1, left: ds.x1 }, animationLength, {
				onAfter:function(){
					//$paneTarget.scrollTo( { top: ds.y2, left: ds.x2 }, 0);
					$paneTarget.scrollTo( { top: ds.y3, left: ds.x3 }, 0);
					newItem.animate( { opacity: 1 }, 0, function() {
						$("div#slidenav").show();
						$("#pijllinks").show();
						$("#pijlrechts").show();
					});
					
					oldItem = newItem;
				}
			});
		}
	});

	$('#content_voorraad').click(function(){
//alert(0);
document.body.style.backgroundImage = "url(graphics/bg-new.gif)";
//window.document.flmv2.setVariable("gotoList", "true");
if(window.flmv) {
	window.document["flmv"].SetVariable("gotoList", "true");
} else {
	if(document.flmv) {
		document.flmv.SetVariable("gotoList", "true");
	} else {
		var flmv = document.getElementById('flmv');
		if (flmv) { flmv.setVariable("gotoList", "true") }
	}
}

		$("div#overlay").animate({ height: contentVoorraad.hpx() }, 0);
		$("div#photos").animate({ height: contentVoorraad.hpx() }, 0);
		
		$("div#slidenav").hide();
		$("#pijllinks").hide();
		$("#pijlrechts").hide();
		
		/*$paneTarget.stop().scrollTo( { top: contentVoorraad.opx2(), left: '0px' }, 0, {
			onAfter:function(){
				$paneTarget.scrollTo( { top: contentVoorraad.opx(), left: '0px' }, animationLength)
			}
		});*/

		newItem = $('#overlay_voorraad');
		var ds = new scrollDistances($('#overlay'), newItem);
		
		if ((ds.x0 != ds.x3) || (ds.y0 != ds.y3)) {
			$('#overlay div.item').animate( { opacity: 0 }, 0);
			oldItem.animate( { opacity: 1 }, 0);
			oldItem.animate( { opacity: 0 }, animationLengthS);
slideNext('graphics/voorraad_bg0.jpg', true);
			$paneTarget.scrollTo( { top: ds.y1, left: ds.x1 }, animationLength, {
				onAfter:function(){
					//$paneTarget.scrollTo( { top: ds.y2, left: ds.x2 }, 0);
					$paneTarget.scrollTo( { top: ds.y3, left: ds.x3 }, 0);
					newItem.animate( { opacity: 1 }, 0);
					oldItem = newItem;
//slidesStop();
				}
			});
		}
//slidesStop();
	});

	$('#content_napbovag').click(function(){
document.body.style.backgroundImage = "url(graphics/bg-old.gif)";
		$("div#overlay").animate({ height: contentNapbovag.hpx() }, 0);
		$("div#photos").animate({ height: contentNapbovag.hpx() }, 0);
		
		$("div#slidenav").hide();
		$("#pijllinks").hide();
		$("#pijlrechts").hide();
		
		newItem = $('#overlay_napbovag');
		var ds = new scrollDistances($('#overlay'), newItem);
		
		if ((ds.x0 != ds.x3) || (ds.y0 != ds.y3)) {
			$('#overlay div.item').animate( { opacity: 0 }, 0);
			oldItem.animate( { opacity: 1 }, 0);
			oldItem.animate( { opacity: 0 }, animationLengthS);
slideNext('graphics/napbovag_bg2.jpg');
			$paneTarget.scrollTo( { top: ds.y1, left: ds.x1 }, animationLength, {
				onAfter:function(){
					//$paneTarget.scrollTo( { top: ds.y2, left: ds.x2 }, 0);
					$paneTarget.scrollTo( { top: ds.y3, left: ds.x3 }, 0);
					newItem.animate( { opacity: 1 }, 0);
					oldItem = newItem;
				}
			});
		}
	});

	$('#content_route').click(function(){
document.body.style.backgroundImage = "url(graphics/bg-old.gif)";
		$("div#overlay").animate({ height: contentRoute.hpx() }, 0);
		$("div#photos").animate({ height: contentRoute.hpx() }, 0);
		
		$("div#slidenav").hide();
		$("#pijllinks").hide();
		$("#pijlrechts").hide();
		
		newItem = $('#overlay_route');
		var ds = new scrollDistances($('#overlay'), newItem);
		
//alert(ds.x0 + ':' + ds.y0 + ' - ' + ds.x1 + ':' + ds.y1 + ' - ' + ds.x2 + ':' + ds.y2 + ' - ' + ds.x3 + ':' + ds.y3);
		if ((ds.x0 != ds.x3) || (ds.y0 != ds.y3)) {
			$('#overlay div.item').animate( { opacity: 0 }, 0);
			oldItem.animate( { opacity: 1 }, 0);
			oldItem.animate( { opacity: 0 }, animationLengthS);
slideNext('graphics/route_bg2.jpg');
			$paneTarget.scrollTo( { top: ds.y1, left: ds.x1 }, animationLength, {
				onAfter:function(){
					//$paneTarget.scrollTo( { top: ds.y2, left: ds.x2 }, 0);
					$paneTarget.scrollTo( { top: ds.y3, left: ds.x3 }, 0);
					newItem.animate( { opacity: 1 }, 0);
					oldItem = newItem;
				}
			});
		}
	});

	$('#content_openingstijden').click(function(){
document.body.style.backgroundImage = "url(graphics/bg-old.gif)";
		$("div#overlay").animate({ height: contentRoute.hpx() }, 0);
		$("div#photos").animate({ height: contentRoute.hpx() }, 0);
		
		$("div#slidenav").hide();
		$("#pijllinks").hide();
		$("#pijlrechts").hide();
		
		newItem = $('#overlay_openingstijden');
		var ds = new scrollDistances($('#overlay'), newItem);
		
		if ((ds.x0 != ds.x3) || (ds.y0 != ds.y3)) {
			$('#overlay div.item').animate( { opacity: 0 }, 0);
			oldItem.animate( { opacity: 1 }, 0);
			oldItem.animate( { opacity: 0 }, animationLengthS);
slideNext('graphics/openingstijden_bg2.jpg');
			$paneTarget.scrollTo( { top: ds.y1, left: ds.x1 }, animationLength, {
				onAfter:function(){
					//$paneTarget.scrollTo( { top: ds.y2, left: ds.x2 }, 0);
					$paneTarget.scrollTo( { top: ds.y3, left: ds.x3 }, 0);
					newItem.animate( { opacity: 1 }, 0);
					oldItem = newItem;
				}
			});
		}
	});

	$('#content_financiering').click(function(){
document.body.style.backgroundImage = "url(graphics/bg-old.gif)";
		$("div#overlay").animate({ height: contentRoute.hpx() }, 0);
		$("div#photos").animate({ height: contentRoute.hpx() }, 0);
		
		$("div#slidenav").hide();
		$("#pijllinks").hide();
		$("#pijlrechts").hide();
		
		newItem = $('#overlay_financiering');
		var ds = new scrollDistances($('#overlay'), newItem);
		
		if ((ds.x0 != ds.x3) || (ds.y0 != ds.y3)) {
			$('#overlay div.item').animate( { opacity: 0 }, 0);
			oldItem.animate( { opacity: 1 }, 0);
			oldItem.animate( { opacity: 0 }, animationLengthS);
slideNext('graphics/financiering_bg2.jpg');
			$paneTarget.scrollTo( { top: ds.y1, left: ds.x1 }, animationLength, {
				onAfter:function(){
					//$paneTarget.scrollTo( { top: ds.y2, left: ds.x2 }, 0);
					$paneTarget.scrollTo( { top: ds.y3, left: ds.x3 }, 0);
					newItem.animate( { opacity: 1 }, 0);
					oldItem = newItem;
				}
			});
		}
	});

	$('#content_garantie').click(function(){
document.body.style.backgroundImage = "url(graphics/bg-old.gif)";
$("#overlay_garantie div").animate({ opacity: 0 }, 0);
$("#overlay_garantie div#show").animate({ opacity: 100 }, 0);
		$("div#overlay").animate({ height: contentGarantie.hpx() }, 0);
		$("div#photos").animate({ height: contentGarantie.hpx() }, 0);
		
		$("div#slidenav").hide();
		$("#pijllinks").hide();
		$("#pijlrechts").hide();
		
		newItem = $('#overlay_garantie');
		var ds = new scrollDistances($('#overlay'), newItem);
		
		if ((ds.x0 != ds.x3) || (ds.y0 != ds.y3)) {
			$('#overlay div.item').animate( { opacity: 0 }, 0);
			oldItem.animate( { opacity: 1 }, 0);
			oldItem.animate( { opacity: 0 }, animationLengthS);
slideNext('graphics/garantie_bg2.jpg');
			$paneTarget.scrollTo( { top: ds.y1, left: ds.x1 }, animationLength, {
				onAfter:function(){
					//$paneTarget.scrollTo( { top: ds.y2, left: ds.x2 }, 0);
					$paneTarget.scrollTo( { top: ds.y3, left: ds.x3 }, 0);
					newItem.animate( { opacity: 1 }, 0);
					oldItem = newItem;
				}
			});
		}
	});

	$('#content_autonieuws').click(function(){
document.body.style.backgroundImage = "url(graphics/bg-old.gif)";
$("#overlay_autonieuws div").animate({ opacity: 0 }, 0);
$("#overlay_autonieuws div#show").animate({ opacity: 100 }, 0);
//alert($(window).scrollTop());
		$("div#overlay").animate({ height: contentAutonieuws.hpx() }, 0);
		$("div#photos").animate({ height: contentAutonieuws.hpx() }, 0);

		$("div#slidenav").hide();
		$("#pijllinks").hide();
		$("#pijlrechts").hide();
		
		newItem = $('#overlay_autonieuws');
		var ds = new scrollDistances($('#overlay'), newItem);
		
		if ((ds.x0 != ds.x3) || (ds.y0 != ds.y3)) {
			$('#overlay div.item').animate( { opacity: 0 }, 0);
			oldItem.animate( { opacity: 1 }, 0);
			oldItem.animate( { opacity: 0 }, animationLengthS);
slideNext('graphics/voorraad_bg.jpg');
			$paneTarget.scrollTo( { top: ds.y1, left: ds.x1 }, animationLength, {
				onAfter:function(){
					//$paneTarget.scrollTo( { top: ds.y2, left: ds.x2 }, 0);
					$paneTarget.scrollTo( { top: ds.y3, left: ds.x3 }, 0);
					newItem.animate( { opacity: 1 }, 0);
					oldItem = newItem;
				}
			});
		}
	});

	$('#content_contact').click(function(){
document.body.style.backgroundImage = "url(graphics/bg-old.gif)";
		$("div#overlay").animate({ height: contentContact.hpx() }, 0);
		$("div#photos").animate({ height: contentContact.hpx() }, 0);
		
		$("div#slidenav").hide();
		$("#pijllinks").hide();
		$("#pijlrechts").hide();
		
		newItem = $('#overlay_contact');
		var ds = new scrollDistances($('#overlay'), newItem);
		
		if ((ds.x0 != ds.x3) || (ds.y0 != ds.y3)) {
			$('#overlay div.item').animate( { opacity: 0 }, 0);
			oldItem.animate( { opacity: 1 }, 0);
			oldItem.animate( { opacity: 0 }, animationLengthS);
slideNext('graphics/contact_bg2.jpg');
			$paneTarget.scrollTo( { top: ds.y1, left: ds.x1 }, animationLength, {
				onAfter:function(){
					//$paneTarget.scrollTo( { top: ds.y2, left: ds.x2 }, 0);
					$paneTarget.scrollTo( { top: ds.y3, left: ds.x3 }, 0);
					newItem.animate( { opacity: 1 }, 0);
					oldItem = newItem;
				}
			});
		}
	});
	
	//document.body.onUnload = function() { alert(0) }
	//window.onbeforeunload = function() { alert(0) }
	// =========================================================================
	// Controls the full screen mode
	$("a.fullsize").click(function(){
 	$("div#overlay").slideToggle("fast");
	$(this).toggleClass("active");
		return false;
	});
	
	$('.clearme').example(function() {
		return $(this).attr('title'); 
	});
	
	// -------------------------------------------------------------------------
	// NAVIGATION STUFF
	
	// HIDE THE NAV UNTIL THE PAGE HAS FULLY LOADED
	$("ul.navigation").show();
	
	$("ul.navigation li a").css({ opacity: 0 });
	
	$("ul.navigation li:first").addClass("active").children().css({ opacity: 1, marginTop: "0px"});
	
	$("ul.navigation li").click(
		function(){
			$(this).addClass("active");
			$(this).siblings().removeClass("active");
			$(this).siblings().children().animate({ opacity: 0, marginTop: "0px"}, 240 );
		}
	);
	
	$("ul.navigation li a").hover(
		function(){
			if($(this).parent().hasClass("active")){
			}else{
				$(this).animate({ opacity: 1, marginTop: "0px"}, 240 );
			}
		},
		function(){
			if($(this).parent().hasClass("active")){
			}else{
				$(this).animate({ opacity: 0, marginTop: "0px"}, 100 );
			}
		}
	);
	// -------------------------------------------------------------------------
	
	var myGallerysrc = 'voorraad_cs3_v44f.swf';
	$('#gallery').flash({
		id: "flmv",
		name: "flmv",
		src: myGallerysrc,
		width: 940,
		height: 1218,
		allowscriptaccess: 'always',
		wmode: 'opaque',
		quality: 'high',
		devicefont: 'false',
		bgcolor: '#282828',
		onMouseWheel: 'scrollVoorraad()'},
		{ update: true }
	);
	/*		'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,24,0',
			'width', '900',
			'height', '889',
			'src', 'voorraad_cs3',
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'transparent',
			'devicefont', 'false',
			'id', 'voorraad_cs3',
			'bgcolor', '#ff00ff',
			'name', 'voorraad_cs3',
			'menu', 'true',
			'allowScriptAccess','sameDomain',
			'allowFullScreen','false',
			'movie', 'voorraad_cs3',
			'salign', ''*/
	
	/**
	 *  CONTROL THE NEWS
	 * 
	 */
	 $("#overlay_garantie div").css({ opacity: 0 });
	 $("#overlay_garantie div#show").css({ opacity: 100 });
	 $("#overlay_garantie h6 a").click(
		function(){
			$(this).addClass("garantie_active");
			$(this).parent().siblings("h3").children("a").removeClass("garantie_active");
			$(this).parent().siblings("div").animate({ opacity: 0}, 100 );
			$(this).parent().next("div").animate({ opacity: 1}, 400 );
			return false;
		}
	);
	// -------------------------------------------------------------------------
	/**
	 *  CONTROL FINANCIAL NEWS
	 * 
	 */
	 $("#overlay_autonieuws div").css({ opacity: 0 });
	 $("#overlay_autonieuws div#show").css({ opacity: 100 });
	 $("#overlay_autonieuws h6 a").click(
		function(){
			$(this).addClass("financiallease_active");
			$(this).parent().siblings("h3").children("a").removeClass("financiallease_active");
			$(this).parent().siblings("div").animate({ opacity: 0}, 100 );
			$(this).parent().next("div").animate({ opacity: 1}, 400 );
			return false;
		}
	);
	// -------------------------------------------------------------------------
	$.getFeed({
		url: 'autoweek_nieuws.php',
		success: function(feed) {
			var html = '';
			var txt;
			var br;
			
			var div, imgs, img, title;
			var desc;
			
			for(var i = 0; i < feed.items.length && i < 3; i++) {
				var item = feed.items[i];
				
				div = document.createElement('div');
				div.setAttribute('style', 'clear: both');
				//div.style.clear = 'right';
				//div.innerHTML = item.description;
				desc = document.createElement('div');
				desc.innerHTML = item.description;
				
				imgs = desc.getElementsByTagName('img');
//alert(imgs.length);
				if (imgs.length > 1) {
					img = imgs[0];
					img.width = "120";
					img.setAttribute('style', 'position: relative; border: 2px solid white; float: left; margin: 0px 20px 20px 0px');
					img.style.border = '2px solid white';
					//img.style.height = '100px';
					//img.style.border = '2px solid white';
					//img.float = 'left';
					//img.style.margin = '0px 20px 5px 0px';
					//img.style = 'border: 1px solid white; float: left; margin: 0px 20px 5px 0px';
					//img.setAttribute('class', 'an');
					div.appendChild(img);
					title = document.createElement('b');
					//title.innerHTML = item.title + '<br />';
					txt = document.createTextNode(item.title);
					title.appendChild(txt);
					br = document.createElement("br");
					title.appendChild(br);
					div.appendChild(title);
					div.appendChild(desc)
					//div.insertBefore(title, img.nextSibling);
				}
				
				a = document.createElement('a');
				a.href = item.link;
				a.className = "popupL hvr";
//alert(0);
				a.target = '_blank';
				//a.innerHTML = '<br /><br />Lees verder';
				br = document.createElement("br");
				a.appendChild(br);
				img = document.createElement("img");
				img.src="graphics/leesmeer.gif";
				img.border="0";
				//txt = document.createTextNode('Lees verder');
				a.appendChild(img);
				
				div.appendChild(a);
				
				br = document.createElement("br");
				div.appendChild(br);
				div.appendChild(br);
				div.appendChild(br);
				
				$('#rss_autonieuws').append(div);
//alert(div.innerHTML);
			}
		}
	});
	// -------------------------------------------------------------------------
});

