var amountVisible = function(c){
	var a = $(window).scrollTop();
	var b = a + $(window).height();
	var e = c.offset().top;
	var d = e + c.height();
	if(d > a && d < b){
		return d - a
	} else {
		return b - e
	}
};
var fetchMatchingNavItem = function(a){
	return $("#" + $(a).attr("id") + "-link").parent()
};
var setCurrentClass = function(a){
	a.addClass("current");
	a.siblings(".navigation li").removeClass("current")
};
var determineCurrentNodeAndSetNav = function(){
	var a = null;
	var b = $(".slither:in-viewport");
	b.each(function(c){
		var d = $(this);
		if(a == null || amountVisible(d) >= amountVisible(a)){
			a = d
		}
	});
	current_index = $(".slither").index(a);
	setCurrentClass(fetchMatchingNavItem(a))
};
function initialize() {
	var myLatlng = new google.maps.LatLng(51.76150,-0.43997);
	var myOptions = {
		zoom: 13,
		center: myLatlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	var map = new google.maps.Map(document.getElementById("location"), myOptions);
	
	var marker = new google.maps.Marker({
		position: myLatlng, 
		map: map,
		title:"Iguana Creative UK"
	});   
}
$(document).ready(function(){
	initialize();
	var c = $(".slither");
	var b = 0;
	var a;
	$(window).scroll(function(){
		determineCurrentNodeAndSetNav()
	});
	$(".navigation li").click(function(f){
		var d = $(this).children("a").get(0).href.split("#")[1];
		$.scrollTo("#" + d, 800);
		a = $("#"+d);
		b = c.index(a);
		f.preventDefault()
	});
	$(".scroll-link").click(function(g){
		var d = $(this);
		var f = d.attr("href").split("#")[1];
		var h = $($("#" + f + "-link").parent());
		$.scrollTo("#" + f, 800);
		a = $("#" + f);
		b = c.index(a);
		g.preventDefault()
	});
	$(document).keydown(function(d){
		switch(d.keyCode){
			case 39:
				a = c[++b];
				if(a){
					$.scrollTo(a, 800)
				}else{
					b = c.length - 1
				}
				break;
			case 37:
				a = c[--b];
				if(a){
					$.scrollTo(a, 800)
				}else{
					b = 0
				}
			break
		}
	});
	$(".index .cycle").cycle({
		timeout:10000,
		speed:1000,
		pause:1,
		fx: 'scrollLeft',
		pager:".cycle-nav.home"
	});
	$("#what-we-do .cycle").cycle({
		timeout:10000,
		speed:1000,
		pause:1,
		fx: 'scrollLeft',
		pager:".cycle-nav.what-we-do"
	});
    $("#what-we-do .cycle").cycle('pause');

	$("#latest-projects .cycle").cycle({
		timeout:10000,
		speed:1000,
		pause:1,
		fx: 'scrollLeft',
		pager:".cycle-nav.latest-projects"
	});
	$("#ad-campaigns .cycle").cycle({
		timeout:10000,
		speed:1000,
		pause:1,
		fx: 'scrollLeft',
		pager:".cycle-nav.ad-campaigns"
	});	
	$("#online-design .cycle").cycle({
		timeout:10000,
		speed:1000,
		pause:1,
		fx: 'scrollLeft',
		pager:".cycle-nav.online-design"
	});
	$("#print-design .cycle").cycle({
		timeout:10000,
		speed:1000,
		pause:1,
		fx: 'scrollLeft',
		pager:".cycle-nav.print-design"
	});
	$("#pos-exhibitions .cycle").cycle({
		timeout:10000,
		speed:1000,
		pause:1,
		fx: 'scrollLeft',
		pager:".cycle-nav.pos-exhibitions"
	});
});
