
	var scrolledBefore = false;
	var isiPad = navigator.userAgent.match(/iPad/i) != null;
	var minusScroll = isiPad ? 0 : 70;
	
    

	$(document).ready(function(){

		$(".main_content div").css({top: (($(".main_content").height()-$(".main_content div").height())/2)+"px"}).fadeIn();
	
		if ($.browser.msie && ($.browser.version=="6.0" || $.browser.version=="7.0" && $.browser.version=="8.0")){ 
			
			$('.items article:eq(0)').css({'opacity':''}); 
			$('.columns p').css({'padding-right': '20px'}); 
			$('.columns').columnize({width: 340});
		
		}
		
		$(window).scroll(function() {
			if(scrolledBefore && $(window).scrollTop()) $("#seemore").fadeOut('fast');
			scrolledBefore = true;
		});
		
		if($('#workitems li').length < 9){
			$('.scrollup', $('#workitems').parent().parent()).css({visibility: 'hidden'});
			$('.scrolldown', $('#workitems').parent().parent()).css({visibility: 'hidden'});
		}
		
		if($('#caseitems li').length < 9){
			$('.scrollup', $('#caseitems').parent().parent()).css({visibility: 'hidden'});
			$('.scrolldown', $('#caseitems').parent().parent()).css({visibility: 'hidden'});
		}
				
		$.tools.tabs.addEffect("fadeInOut", function(tabIndex, done) {
		
			var panes = this.getPanes();
			
			this.getPanes().fadeOut(500);
				
			setTimeout(function(){
				panes.eq(tabIndex).fadeIn(500);
				done.call();
			},500);
			
			
		});
				
		$("section:last").addClass('last');
		
		$(".scrollable").scrollable({
			next:'.nright',
			prev:'.nleft',
			onBeforeSeek : function(event, index){
				stopAllPlayers();
				$(".items article").eq(index).animate({opacity: 1}, 1, function(){
					if($.browser.msie) $(this).css({opacity: ''});
				});
				$(".items article").not($(".items article").eq(index)).animate({opacity: 0.2}, 500);
			}
		});
		
		$("ul.worktabs").tabs("div.workpanes > div", {effect: 'fadeInOut', onBeforeClick: function(){
			stopAllPlayers();
		}});
		
		$(".invisibletabs").tabs("div.workpanels > div", {effect: 'fadeInOut'});
		
		$(".invisiblecasetabs").tabs("div.casepanels > div", {effect: 'fadeInOut'});
		
		$(".scrollable").tabs("div.newspanels > div", {effect: 'fadeInOut'});
		
		$(".scrollablefeeds").scrollable({circular: true}).autoscroll({ autoplay: true, interval: 7000 });
		
		$(".main_content").scrollable({circular: true, speed: 750, keyboard: false, touch: false}).autoscroll({ autoplay: true, interval: 7000, autopause: false });
		
		$(".visual_tabs").tabs(".visual_tab_panels > li", {
			effect: 'fade',
			fadeOutSpeed: "slow",
			rotate: true
		}).slideshow();
		
		$(".invisibletabs a").each(function(index)
		{
			$(this).bind("click", function()
			{
				if($(".workpanels .workpanel:eq("+index+") .workpanes img:eq(0)").length)
				{
					$(".workpanels .workpanel:eq("+index+") .workpanes").css(
					{
						'height': $(".workpanels .workpanel:eq("+index+") .workpanes img:eq(0)").height()+"px"
					});
				}
			});
		});
		
		$(".backtowork").bind("click", function(){
			stopAllPlayers();
			$(".invisibletabs a:first").trigger("click");
		});
		
		$(".backtocase").bind("click", function(){
			stopAllPlayers();
			$(".invisiblecasetabs a:first").trigger("click");
		});
		
		$("nav ul li a").bind("click", function(){
			stopAllPlayers();
			$(".invisiblecasetabs a:first").trigger("click");
			$(".invisibletabs a:first").trigger("click");
			$(".scrollable").data("tabs").click(0);
		});
		
		
		/********** EMPLOYEES ***********/
		
		$("ul.employees li").hover(
			function() { 

				var thumbOver = $(this).find("img").attr("src"); 
				
				thumbOver = "http://www.germaine.be/sites/default/files/imagecache/Profielfoto" + thumbOver.substring(thumbOver.lastIndexOf("/"));
								
				$(this).find("a.thumb").css({'background' : 'url("' + thumbOver + '") no-repeat'});

				$(this).find("span").stop().fadeTo('normal', 0 , function() {
					$(this).hide();
				});
			} , function() { 
				$(this).find("span").stop().fadeTo('normal', 1).show();
			}
		);


		$('#workitems a').live("click", function(e){
			e.preventDefault();
			$($(this).attr("rel")).trigger("click");
		});
		
		$('#workitems li').live("mouseenter", function(){
			$("div", this).stop().animate({top: '0px'});
		});
		
		$('#workitems li').live("mouseleave", function(){
			$("div", this).stop().animate({top: '108px'});
		});
		
		$('#caseitems a').live("click", function(e){
			e.preventDefault();
			$($(this).attr("rel")).trigger("click");
		});
		
		$('#caseitems li').live("mouseenter", function(){
			$("div", this).stop().animate({top: '0px'});
		});
		
		$('#caseitems li').live("mouseleave", function(){
			$("div", this).stop().animate({top: '108px'});
		});
		
		$(".workpanels a.scrollup").bind("click", function(){
			if($('#workitems').position().top < 0)
				$('#workitems').stop().animate({top:"+=180px"}); 
		});
		
		$(".workpanels a.scrolldown").bind("click", function(){
			if($('#workitems').position().top > Math.floor((($('#workitems li').length-1)/4)-1)*-180)
				$('#workitems').stop().animate({top:"-=180px"}); 
		});
		
		
		$(".casepanels a.scrollup").bind("click", function(){
			if($('#caseitems').position().top < 0)
				$('#caseitems').stop().animate({top:"+=180px"}); 
		});
		
		$(".casepanels a.scrolldown").bind("click", function(){
			if($('#caseitems').position().top > Math.floor((($('#caseitems li').length-1)/4)-1)*-180)
				$('#caseitems').stop().animate({top:"-=180px"}); 
		});
		
		
		var cases = $('#workitems');

		var $casedata = cases.clone();
		
		$("#workmenu a").each(function(){
		  
			$(this).bind("click", function(e){
								
				if ($(this).attr('data-value') == 'all') {
					var filteredData = $casedata.find('li');
				} else {
					var filteredData = $casedata.find('li.' + $(this).attr('data-value'));
				}
				if($('#workitems').position().top==0){
					cases.quicksand(filteredData);
				}else{
					$('#workitems').stop().animate({top:"0px"}, 500, function(){
						cases.quicksand(filteredData);
					}); 
				}
								
				e.preventDefault();
			});
			
		});
			
		

		var applications = $('#clientitems');

		var $data = applications.clone();
		
		$("#clientmenu a").each(function(){
		  
			$(this).bind("click", function(e){
								
				if ($(this).attr('data-value') == 'all') {
					var filteredData = $data.find('li');
				} else {
					var filteredData = $data.find('li.' + $(this).attr('data-value'));
				}
				
				applications.quicksand(filteredData);
				
				e.preventDefault();
			});
		});
		

		
		/****** SMOOTH SCROLL ********/
		
		function filterPath(string) {
			return string
			.replace(/^\//,'')
			.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
			.replace(/\/$/,'');
		}
	
		var locationPath = filterPath(location.pathname);
		var scrollElem = scrollableElement('html', 'body');
	
		// Any links with hash tags in them (can't do ^= because of fully qualified URL potential)
		$('a[href*=#]').each(function() {

			// Ensure it's a same-page link
			var thisPath = filterPath(this.pathname) || locationPath;
			if (  locationPath == thisPath
				&& (location.hostname == this.hostname || !this.hostname)
				&& this.hash.replace(/#/,'') ) {
	
					// Ensure target exists
					var $target = $(this.hash), target = this.hash;
					if (target && $target.length) {
	
						// Find location of target
						var targetOffset = $target.offset().top-minusScroll;
						$(this).click(function(event) {
	
							// Prevent jump-down
							event.preventDefault();
							
							var $target = $(this.hash), target = this.hash;
							var targetOffset = $target.offset().top-minusScroll;
	
							// Animate to target
							$(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
	
								// Set hash in URL after animation successful
								//location.hash = target;
	
							});
						});
					}else{
						$(this).click(function(event) {
	
							// Prevent jump-down
							event.preventDefault();
	
						});
					}
			}
	
		});
	
		// Use the first element that is "scrollable"  (cross-browser fix?)
		function scrollableElement(els) {
			for (var i = 0, argLength = arguments.length; i <argLength; i++) {
				var el = arguments[i],
				$scrollElement = $(el);
				if ($scrollElement.scrollTop()> 0) {
					return el;
				} else {
					$scrollElement.scrollTop(1);
					var isScrollable = $scrollElement.scrollTop()> 0;
					$scrollElement.scrollTop(0);
					if (isScrollable) {
						return el;
					}
				}
			}
			return [];
		}
		
		
		$(window).resize(resize);
		
		resize();
		
	});
	
	function resize(){
		$("#home").css({'margin-top': ($(window).height()/2)-320});
		var mTop = $(".main_content").css('margin-top').replace("px", "");
		$("#home").height($(window).height()-mTop);
		
		$(".main_content img").css({'top': ($(".main_content").height()-500)});
		$(".main_content div").css({top: (($(".main_content").height()-$(".main_content div").height())/2)+"px"});
	}
	
	function stopAllPlayers(){
	
		$(".workpanes_tab").each(function(){
			if($("div", this).length){
				var id = $("div", this).attr("id");
				if(id.indexOf("_")==-1 && (id.indexOf("video") || id.indexOf("audio")))
					jwplayer(id).stop(); 
			}
			if($("object", this).length){
				var id = $("object", this).attr("id");
				if(id.indexOf("video") || id.indexOf("audio")){
					jwplayer(id).stop(); 
				}
			}
		});
		
	}
	
