$(document).ready(function(){
  $(".menu li ul").css({display: 'none'});
  $(".menu li").hoverIntent(function(){$("ul:first", this).slideDown("fast");}, function(){$("ul", this).fadeOut("normal");});
  $(function() {setInterval( "slideSwitch()", 4000 );});
  $("#query").bind('click',function(){($("#query").val() == "Zoeken...")? $("#query").val(""): $("#query").val(); $("#query").unbind( "click" )
});
  $.localScroll();
  if ($(".ns").length > 0) {
  $.get('./php/rss.php', function(rss){
  	//alert(rss);
                                var titles = rss.getElementsByTagName('title');
                                var links  = rss.getElementsByTagName('link');
                                var feed = "";
                                //var limit = 8;
                                //if (titles.length < 8) limit = titles.length;
                                for (var i = 1; i < titles.length; i++)
                                    feed += "<dt><a href=\"" +links[i].firstChild.nodeValue+ "\">" +titles[i].firstChild.nodeValue+ "</a></dt><dd></dd>";
                                $("#newsScroller").fadeOut("slow", function(){$("#newsScroller").html(feed); $("#newsScroller").fadeIn("slow", vacatureScroll);} );
                                //$(".vacatures").html(feed);
                                 }
                   );
     }
  //adjustPanelHeights();
  });
$(window).load(function () {adjustPanelHeights();});

arrow = new Image(); arrow.src = "../graphics/go-button-over.png";
up = new Image(); up.src = "../graphics/up-button-over.png";
leftLink = new Image(); leftLink.src = "../graphics/left-link-over-bg.png";
back = new Image(); back.src = "../graphics/back-button-over.png";
/// - Vacatures iFrame Construction
function vacatures(){
	//alert(location.href);
	var link = "";
	if (location.href.indexOf('?') != -1) {
		link = "http://ssl1.peoplexs.com/Peoplexs22/CandidatesPortalNoLogin/Vacancy.cfm?CFID=79447&CFTOKEN=84405125&PortalID=643&VacatureID=" +location.href.substr(location.href.indexOf('?') + 1, location.href.length);

		}
	else
		link = "http://ssl1.peoplexs.com/Peoplexs22/CandidatesPortalNoLogin/Vacancies.cfm?CustomerCode=OVE1&PortalID=643";

document.write("<iframe id=\"vacatures\" marginwidth=\"0\" marginheight=\"0\" src=\"" +link+ "\" align=\"middle\" frameborder=\"0\" height=\"600\" scrolling=\"auto\" width=\"100%\"></iframe>");
}


/// - Panel height
function adjustPanelHeights(h) {
if(h)$('.leftPanel').height(h);
if ($('.content').height() < 501 && $(".leftPanel").height() < 501){$('.spacer').height(517 - $('.content').height() + "px"); $(".leftPanel").height("500px")}
else {
($('.content').height() > $(".leftPanel").height() ) ?  $(".leftPanel").height($('.content').height()) :
$(".spacer").height($('.leftPanel').height()- $('.content').height() + 17 + "px");
}
$(".spacer").height($(".spacer").height() + ($('.leftPanel').height()- $('.content').height()));
$(".contentContainer").height($('.leftPanel').height());
$(".contentContainer").height($('.content').height());
$('.leftPanel').height($('.content').height());
}
/// - Slideshow
  function slideSwitch() {
    var $active = $('#slideShow IMG.active');

    if ( $active.length == 0 ) $active = $('#slideShow IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#slideShow IMG:first');
    $next.addClass('noDisplay');
    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .removeClass('noDisplay')
        .animate({opacity: 1.0}, 500, function() {
            $active.removeClass('active last-active');
        });
    $active.animate({opacity: 0.0}, 500, function() {});
}
/// - Vacature Scroll
function vacatureScroll(){
  var height = 0;
  var to = null;
  var theAnimation;
  var newsScroller;
  newsScroller = $('#newsScroller');
  
  var curSet = newsScroller
  .wrap('<div>')
  .children()
  .slice(0,2)
  .each(function(){
	  height += $(this).outerHeight(true);
  });
  
  theAnimation = function(){
	  if( !newsScroller.is(':animated') ){
		  newsScroller.animate({top:-height},1100,"linear",function(){
			  height = 0;
			  curSet = newsScroller
			  .append(curSet)
			  .css('top',0)
			  .children()
			  .slice(0,2)
			  .each(function(){
				  height += $(this).outerHeight(true);
			  });
		  });
	  }
  };
  
  to = setInterval(theAnimation,1);
  
  newsScroller.bind('mouseenter',function(){
	  clearInterval(to);
  })
  .bind('mouseleave',function(){
	  theAnimation();
	  to = setInterval(theAnimation,1);
  });
}
/// - Local Smooth Scroll
;(function( $ ){
	var URI = location.href.replace(/#.*/,'');//local url without hash
	var $localScroll = $.localScroll = function( settings ){
		$('body').localScroll( settings );
	};
	$localScroll.defaults = {
		duration:1000,
		axis:'y',
		event:'click',
		stop:true
	};
	$localScroll.hash = function( settings ){
		settings = $.extend( {}, $localScroll.defaults, settings );
		settings.hash = false;//can't be true
		if( location.hash )
			setTimeout(function(){ scroll( 0, location, settings ); }, 0 );//better wrapped with a setTimeout
	};
	$.fn.localScroll = function( settings ){
		settings = $.extend( {}, $localScroll.defaults, settings );
		return ( settings.persistent || settings.lazy )
				? this.bind( settings.event, function( e ){
					var a = $([e.target, e.target.parentNode]).filter(filter)[0];//if a valid link was clicked.
					a && scroll( e, a, settings );//do scroll.
				})
				: this.find('a,area')//bind concretely, to each matching link
						.filter( filter ).bind( settings.event, function(e){
							scroll( e, this, settings );
						}).end()
					.end();
		function filter(){
			return !!this.href && !!this.hash && this.href.replace(this.hash,'') == URI && (!settings.filter || $(this).is( settings.filter ));
		};
	};
	function scroll( e, link, settings ){
		var id = link.hash.slice(1),
			elem = document.getElementById(id) || document.getElementsByName(id)[0];
		if ( elem ){
			e && e.preventDefault();
			var $target = $( settings.target || $.scrollTo.window() );//if none specified, then the window.
			if( settings.lock && $target.is(':animated') ||
			settings.onBefore && settings.onBefore.call(link, e, elem, $target) === false ) return;
			if( settings.stop )
				$target.queue('fx',[]).stop();
			$target
				.scrollTo( elem, settings )
				.trigger('notify.serialScroll',[elem]);
			if( settings.hash )
				$target.queue(function(){
					location = link.hash;
					// make sure this function is released
					$(this).dequeue();
				});
		}
	};
})( jQuery );
;(function( $ ){
	var $scrollTo = $.scrollTo = function( target, duration, settings ){
		$(window).scrollTo( target, duration, settings );
	};
	$scrollTo.defaults = {
		axis:'y',
		duration:1
	};
	$scrollTo.window = function( scope ){
		return $(window).scrollable();
	};
	$.fn.scrollable = function(){
		return this.map(function(){
			var win = this.parentWindow || this.defaultView,
				elem = this.nodeName == '#document' ? win.frameElement || win : this,
				doc = elem.contentDocument || (elem.contentWindow || elem).document,
				isWin = elem.setInterval;
			return elem.nodeName == 'IFRAME' || isWin && $.browser.safari ? doc.body
				: isWin ? doc.documentElement
				: this;
		});
	};
	$.fn.scrollTo = function( target, duration, settings ){
		if( typeof duration == 'object' ){
			settings = duration;
			duration = 0;
		}
		if( typeof settings == 'function' )
			settings = { onAfter:settings };
		settings = $.extend( {}, $scrollTo.defaults, settings );
		duration = duration || settings.speed || settings.duration;
		settings.queue = settings.queue && settings.axis.length > 1;
		if( settings.queue )
			duration /= 2;
		settings.offset = both( settings.offset );
		settings.over = both( settings.over );
		return this.scrollable().each(function(){
			var elem = this,
				$elem = $(elem),
				targ = target, toff, attr = {},
				win = $elem.is('html,body');
			switch( typeof targ ){
				case 'number':
				case 'string':
					if( /^([+-]=)?\d+(px)?$/.test(targ) ){
						targ = both( targ );
						break;
					}
					targ = $(targ,this);
				case 'object':
					if( targ.is || targ.style )
						toff = (targ = $(targ)).offset();
			}
			$.each( settings.axis.split(''), function( i, axis ){
				var Pos	= axis == 'x' ? 'Left' : 'Top',
					pos = Pos.toLowerCase(),
					key = 'scroll' + Pos,
					old = elem[key],
					Dim = axis == 'x' ? 'Width' : 'Height',
					dim = Dim.toLowerCase();
				if( toff ){// jQuery / DOMElement
					attr[key] = toff[pos] + ( win ? 0 : old - $elem.offset()[pos] );
					if( settings.margin ){
						attr[key] -= parseInt(targ.css('margin'+Pos)) || 0;
						attr[key] -= parseInt(targ.css('border'+Pos+'Width')) || 0;
					}
					attr[key] += settings.offset[pos] || 0;
					if( settings.over[pos] )
						attr[key] += targ[dim]() * settings.over[pos];
				}else
					attr[key] = targ[pos];
				if( /^\d+$/.test(attr[key]) )
					attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max(Dim) );
				if( !i && settings.queue ){
					if( old != attr[key] )
						animate( settings.onAfterFirst );
					delete attr[key];
				}
			});
			animate( settings.onAfter );
			function animate( callback ){
				$elem.animate( attr, duration, settings.easing, callback && function(){
					callback.call(this, target, settings);
				});
			};
			function max( Dim ){
				var attr ='scroll'+Dim,
					doc = elem.ownerDocument;
				return win
						? Math.max( doc.documentElement[attr], doc.body[attr]  )
						: elem[attr];
			};
		}).end();
	};
	function both( val ){
		return typeof val == 'object' ? val : { top:val, left:val };
	};
})( jQuery );

