$(document).ready(function(){
	
	$("#slides").cycle({
		timeout: 5000,
		speed: 2000
	});
	
	$("#imp").gallery({
		interval: 5500,
		height: '500px',
		width: '900px',
		showOverlay: false,
		thumbHeight: 56,
		thumbWidth: 100,
		easing: 'easeOutQuad',
		toggleBar: false
	});
	
			
	$(".over").hover(function(){
		
		source = $(this).attr('src').split('.');
		newSource = source[0]+'_over.'+source[1];
		
		$(this).attr('src',newSource)
		
	},function(){
		
		source = $(this).attr('src').split('_over');
		newSource = source[0]+source[1];
		
		$(this).attr('src',newSource)
		
	});
	
	$('.clickhome').click(function(){
		window.location = '/';
	});
	
	$('.clickinter').click(function(){
		window.location = 'http://www.amsterdam.intercontinental.com';
	});
	
	$('.menucard tr[class*="dish"]').hover(function(){
		
		cla = '.menucard tr.'+$(this).attr('class');
		$(this).find('td.description').css('border-bottom', 'solid #ccc 1px');
		$(this).find('td').css('background-color', '#e3e3e3');
		$(cla).find('td.description').css('border-bottom', 'solid #ccc 1px');
		$(cla).find('td').css('background-color', '#e3e3e3');
		
	},function(){
		
		cla = '.menucard tr.'+$(this).attr('class');
		$(this).find('td.description').css('border-bottom', 'solid #ddd 1px');
		$(this).find('td').css('background-color', 'transparent');
		$(cla).find('td.description').css('border-bottom', 'solid #ddd 1px');
		$(cla).find('td').css('background-color', 'transparent');
				
	});
	
	$('input[type=text], textarea').focus(
		function(){
			$(this).css('border-color','#000');
		}
	);
	
	$('input[type=text], textarea').blur(
		function(){
			$(this).css('border-color','#fff');
		}
	);
	
	
	// impressie stuff
	
	$(".galleryBar img").fadeTo(100,0.5);
	
	$("#imp_thumbs img").click(function(){
		
		$("#imp").children().css('display','none');
		
		idfind = $(this).attr('id');
		idfind = "#"+idfind.replace("_thumb","");
		
		$(idfind).css('display','block');
		
		
	});
	
	$(".galleryBar img").hover(function(){
		$(this).stop(true,false).fadeTo(50,1);
	},function(){
		$(this).stop(true,false).fadeTo(500,0.5);
	});
	
	$(".galleryBar").hover(function(){
		$(this).css('background-image','url(img/1px33350pct.png)');
	},function(){
		$(this).css('background-image','none');
	});
		
});
	
function nextThumb(){
	
}

var sizefactor = 0.1;
var speedfactor = 0.1;

var width = 0;
var speed = 50;
var direction = 0;
var prevDirection = 0;
var margin = 0;
var scroll = true;
var maxL = 0;

$(document).ready(function(){
	
	followMouse();
	
});

function scrolling(){
	
	if (scroll) {
	
		prevMargin = margin;
				
		margin = (speed * direction) + margin;
		
		if (!(margin >= 20 && direction > 0)
			&&
			!(margin < maxL && direction < 0)) {
				
			$("#imp_thumbs").stop(true, false).animate({
				marginLeft: margin / 7
			}, {
				duration: 200,
				easing: 'swing'
			});
			
		}
		else {

			margin = prevMargin;
		}
		
	}
				
}

function followMouse(){

	maxL = -1*(($('#imp_thumbs').children().length)*400)+500;
	
	$('#imp_thumbs_container').mousemove(function(e){
        
		var x = e.pageX - this.offsetLeft;
		
		// check which side to scroll to
		if(x >= 800){
			
			// go right
			direction = -1;
			scroll = true;
			
		}else if(x <= 100){

			//go left
			direction = 1;
			scroll = true;
			
		}else if(x >= 100&&x<=800){
				direction = 0;
				scroll = false;
			}
		
		scrolling();
				
    });
	
	$('#imp_thumbs_container').mouseleave(function(e){
		
		scroll = false;
		
	});
	
}
