// kenna JS

document.write('<div id="overlay"></div>');

$(document).ready(function(){
	
	// Top Link
	$(window).scroll(function() {
		if ($(window).scrollTop() > 100) {
			$("#top").fadeIn();
		}
		else {
			$("#top").fadeOut();
		};
	});
	
	$("#top").live("click", function(e) {
		e.preventDefault();
		
		$("body, html").animate({
			scrollTop : 0
		}, "slow");
		
		return false;
	});
	
	
	// Home Slider
	function homeSlider() {
		$("#home-slider img:gt(0)").hide();
		
		setInterval(function () {
			$("#home-slider :first-child").fadeOut(1000)
				.next("img").fadeIn(1000).end().appendTo("#home-slider");
		}, 2000);
	};
	
	homeSlider();
	
	
	// Set Width
	function setWidth() {		
		$("#work-container").css({width: Math.floor($("#page-wrap").width() / 240) * 240});
		$(".pop-up").css({"top" : "50%", "margin-top" : Math.round($(window).scrollTop() - $(".pop-up").height() / 2) + "px", "margin-left" : "-" + $(".pop-up").width() / 2 + "px"});
	};
	
	setWidth();
	
	$(window).resize(function() {
		setWidth();
	});
	
	
	// Isotope
	function isotope() {
		$("#work-container").isotope({
			// options
			itemSelector : ".work-card",
			animationEngine : "best-available",
			masonry : { columnWidth : 240 }
		});
		
		$("#employees-container").isotope({
			// options
			itemSelector : ".employee-card",
			animationEngine : "best-available",
			layoutMode : "fitRows"
		});
	};
	
	isotope();
	
	
	// Work Filter
	$("#work-nav a").live("click", function(e) {
		e.preventDefault();
		
		var selector = $(this).attr("data-filter");
		$("#work-container").isotope({ filter: selector });
		
		return false;
	});
	
	
	// Work Details
	$(".work-card a").live("click", function(e) {
		e.preventDefault();
		
		var workTitle = $(this).children().attr("data-title");
		var workClient = $(this).children().attr("data-client");
		
		var techRaw = $(this).children().attr("data-icons");
		var techSubstr = techRaw.split(', ');
				
		var scrollHeight = $(window).scrollTop();
				
		$(this).clone().addClass("pop-up").appendTo("body").css({
			"margin-top" : Math.round(scrollHeight - $(".pop-up").height() / 2) + "px",
			"margin-left" : "-" + $(".pop-up").width() / 2 + "px",
			"position" : "absolute",
			"top" : "50%",
			"left" : "50%",
			"z-index" : "1000"
		});
		
		$("body").append('<div class="work-info"><h1>' + workTitle + '</h1><h3>' + workClient + '</h3><img class="close" src="images/close.png" alt="close" /><div class="tech-icons"></div></div>');
		
		for (var i = 0; i < techSubstr.length; i++) {
			if (techRaw.length > 0) {
				$(".tech-icons").append('<img src="images/work/platforms/' + techSubstr[i] + '.png" />');
				
				var $this = $(".tech-icons img").last();
				
				if ($this.attr("src") == "images/work/platforms/analytics.png") {
					$this.attr("alt", "Analytics Platform");
				}
				else if ($this.attr("src") == "images/work/platforms/data.png") {
					$this.attr("alt", "Data Management Platform");
				}
				else if ($this.attr("src") == "images/work/platforms/precision.png") {
					$this.attr("alt", "Precision Marketing Platform");
				}
				else if ($this.attr("src") == "images/work/platforms/animated.png") {
					$this.attr("alt", "Animated Web Graphics Reporting Platform");
				}
				else if ($this.attr("src") == "images/work/platforms/knowledge.png") {
					$this.attr("alt", "Knowledge Management Platform");
				}
				else if ($this.attr("src") == "images/work/platforms/predictive.png") {
					$this.attr("alt", "Predictive Modeling Platform");
				}
				else if ($this.attr("src") == "images/work/platforms/business.png") {
					$this.attr("alt", "Business Intelligence Platform");
				}
				else if ($this.attr("src") == "images/work/platforms/email.png") {
					$this.attr("alt", "E-mail Deployment and Statistics Platform");
				}
				else if ($this.attr("src") == "images/work/platforms/social.png") {
					$this.attr("alt", "Social Business Collaboration Platform");
				}
				else if ($this.attr("src") == "images/work/platforms/content.png") {
					$this.attr("alt", "Content Management Platform");
				}
				else if ($this.attr("src") == "images/work/platforms/lead.png") {
					$this.attr("alt", "Lead Management Platform");
				}
				else if ($this.attr("src") == "images/work/platforms/survey.png") {
					$this.attr("alt", "Survey Management Platform");
				};
			};
		};
		
		$("#overlay").height($("#page-wrap").height()).fadeIn();
				
		setWidth();
	});
	
	
	// Platform Icon Hover
	$(".tech-icons img").live("mouseover", function() {
		var tipText = $(this).attr("alt");
		$("body").append('<div id="tool-tip">' + tipText + '</div>');
	});
	
	$(".tech-icons img").live("mousemove", function(e) {
		$("#tool-tip").css({
			'top' : e.pageY + 10,
			'left' : e.pageX - 180
		});
	});
	
	$(".tech-icons img").live("mouseout", function() {
		$("#tool-tip").remove();
	});
	
		
	// Overlay Close
	$("#overlay, a.pop-up, .close").live("click", function(e) {
		e.preventDefault();
		
		$("#overlay").fadeOut();
		$(".pop-up, .work-info").remove();
	});
		
});


// Maps
function initializeMap(lat, lng, zoomSet, mapName) {
	var location = new google.maps.LatLng(lat, lng);
	var marker;
	var map;
    var mapOptions = {
    	zoom: zoomSet,
    	mapTypeId: google.maps.MapTypeId.ROADMAP,
    	center: location
    };

    map = new google.maps.Map(document.getElementById(mapName), mapOptions);
          
    marker = new google.maps.Marker({
    	map:map,
    	draggable:true,
    	animation: google.maps.Animation.DROP,
    	position: location
    });
};
