// Ipad, Iphone, Ipod and Android support
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/Android/i))) {
	var isTouchScreen = 1;
}else{
	var isTouchScreen = 0;
}

if(isTouchScreen){
	// calculate viewport zoom
	var docHeight = $(window).height();
	var docPerc = (docHeight/600)+0.05;
	//alert(docPerc);
	$('head').append('<meta name="viewport" content="initial-scale='+docPerc.toFixed(2)+'">');
}

$(document).ready(function() {
	
	$('#home .info').load("info.txt");
	
	$('#wineHolder').jScrollPane();
	$('#menuHolder').jScrollPane();
	if(isTouchScreen == 0){
		$("#outer").height(600);
		$("#outer").center();
		$("#outer").css('overflow','hidden');
	} else {
		//change some setting according to scale percentage
		if(docPerc > 1.12){
			$('#imgNav ul li').css('margin-right','11px');
			$('#kids #flamberkesKids').css('left','350px');
			$('.navigation').css('left','390px');
			$('#kids .kidsImgNav li').css('margin-right','17px');
			$('#contact .txt img').width(130);
			$('#home .info').css('right','100px');
		} else {
			$('#imgNav ul li').css('margin-right','15px');
			$('#kids #flamberkesKids').css('left','390px');
			$('#home .info').css('right','60px');
		}
	}
	
	$(".navigation a").click(function(){
		var paneID = $(this).attr('rel');
		var panePos = $("#"+paneID).position();	
		if(isTouchScreen){
			$('html,body').animate({scrollTop : panePos.top+'px'},'slow');
		} else {
			$("#outer").animate({scrollTop : panePos.top+'px'},'slow');
		}
		return false;
	});					
	
	
	$("#route").hover(
		function(){
			$(this).find("#gmaps2").fadeIn();
		},
		function(){
			$(this).find("#gmaps2").fadeOut();
		}
	);
	
	var panePosStart = $("#home").position();	
	
	$("#intro").click(function(){
		if(isTouchScreen){
			$('html,body').animate({scrollTop : panePosStart.top+'px'},'slow');
		} else {
			$("#outer").animate({scrollTop : panePosStart.top+'px'},'slow');
		}
	});
	$("#go").hover(function(){
		if(isTouchScreen){
			$('html,body').animate({scrollTop : panePosStart.top+'px'},'slow');
		} else {
			$("#outer").animate({scrollTop : panePosStart.top+'px'},'slow');
		}
	});
	
	/* SET MENU SUBNAVIGATION */
	var menuNavPos = $('#menu .navigation').position();
	var menuBtnPos = $('#menu .navigation a.active').position();
	$('.menuNav, #menuHolderCont').css('left',menuNavPos.left+menuBtnPos.left+'px');
	
	$('.menuNav a').click(function(){
		$('.menuNav a.active').each(function(){
			$(this).removeClass('active');							  
		});	
		$(this).addClass('active');
		
		var element = this;
		$('#menuHolder').fadeOut('fast',function(){
			$('#menuHolder').load($(element).attr('href'), function() {
				$("#menuHolder").jScrollPaneRemove();
				$("#menuHolder").jScrollPane();			
				$("#menuHolder").css('left','0px');
				$('#menuHolder').fadeIn('fast');
			});
		});
		return false;
	});
	
	
	/* SET WINE SUBNAVIGATION */
	var wineNavPos = $('#wijn .navigation').position();
	var wineBtnPos = $('#wijn .navigation a.active').position();
	$('.wineNav, #wijn .txt').css('left',wineNavPos.left+wineBtnPos.left+'px');
	
	$('.wineNav .subnav a').click(function(){
		$('.wineNav a.active').each(function(){
			$(this).removeClass('active');							  
		});	
		$(this).addClass('active');
		
		var element = this;
		$('#wineHolder').fadeOut('fast',function(){
			$('#wineHolder').load($(element).attr('href'), function() {
				$("#wineHolder").jScrollPaneRemove();
				$("#wineHolder").jScrollPane();
				$('#wineHolder').fadeIn('fast');
			});
		});
		
		$(this).parent().parent().parent().find('a').first().addClass('active');
		return false;
	});
	
	$('.wineNav .parent').click(function(){
		// activate first child
		$('.wineNav a.active').each(function(){
			$(this).removeClass('active');							  
		});	
		$(this).find('a').first().addClass('active');
		
		var element = this;
		$('#wineHolder').fadeOut('fast',function(){
			$('#wineHolder').load($(element).find('a').first().attr('href'), function() {
				$("#wineHolder").jScrollPaneRemove();
			  $("#wineHolder").jScrollPane();
				$('#wineHolder').fadeIn('fast');
			});
		});
		$(this).find('.subnav li a').first().addClass('active');
		return false;
	});
	
	/* SET KIDS TXT */
	var kidsNavPos = $('#kids .navigation').position();
	var kidsBtnPos = $('#kids .navigation a.active').position();
	$('#kids .txt').css('left',kidsNavPos.left+kidsBtnPos.left+'px');
	
	$('.kidsImgNav li').hover(function(){
		$('.kidsImgNav li').each(function(){
			if($(this).hasClass('active')) $(this).removeClass('active');								  
		});
		$(this).addClass('active');
		var animatePos = $(this).find('span').html() * 217;
		// animate to element 
		$('.kidsPhotos ul').animate({left: -animatePos},300);
		
	});
	
	/* SET CONTACT TXT */
	var contactNavPos = $('#contact .navigation').position();
	var contactBtnPos = $('#contact .navigation a.active').position();
	$('#contact .txt').css('left',contactNavPos.left+contactBtnPos.left+'px');
	
	/* PHOTO GALERY */
	$("#imgNav a").click(function(){
		var i = new Image();
        i.src = $(this).attr('href');
		$(i).hide();
		$("#fotoHolder").append(i);
		$(i).load(function() {
			$(i).fadeIn();
			$("#fotoHolder").find('img').first().fadeOut('normal',function(){
			   $(this).remove();
			});
		});
		return false;
	});
	
});

// Center element
jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}

// EMAIL ENCRYPTION
function ogLUMcISPeQJxGZ()
{
	var FtnwDnpzJQXfgGe=["105","x6e","102","111","x40","102","x6c","x61","109","98","x65","x72","x6b","x65","x2e","98","x65"];
	var nhJRVVoJkLLUKjE=['?','s','u','b','j','e','c','t','=','&','c','c','=','&','b','c','c','=','&','b','o','d','y','='];
	var kMpCvknSlVAkaOs=["105","x6e","102","111","64","102","x6c","97","109","x62","x65","114","x6b","x65","46","x62","101"];
	document.write("<a href=\"&#x6d;&#00097;&#x69;&#108;&#000116;&#x6f;&#x3a;");
	for (i=0; i<FtnwDnpzJQXfgGe.length; i++) document.write('&#'+FtnwDnpzJQXfgGe[i]+';');
	for (i=0; i<nhJRVVoJkLLUKjE.length; i++) document.write(nhJRVVoJkLLUKjE[i]);
	document.write('" style="" class="" id="">');
	for (i=0; i<kMpCvknSlVAkaOs.length; i++) document.write('&#'+kMpCvknSlVAkaOs[i]+';');
	document.write('</a>');
}
