$(document).ready(function () {

	var $top_link = $('#top_link').hide();
	var appleDevice = ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) != null;

	$('.info').hide();
	$('.panel').hover(
		function() {
			$(this).find(".info").fadeIn(300);
		},
		function() {
			$(this).find(".info").fadeOut(300);
		}
	);

	$('#header').localScroll();
	if (!appleDevice) {
		$('#top_link_container').localScroll();
	}

	// Blog feed
	
	var i = 1;

	$.get("http://poly.ie/blog/?feed=rss2", function(d) {
		$(d).find('item').each(function() {
			if (i <= 3) {
				var $item = $(this);
				var title = $item.find('title').text();
				var link = $item.find('link').text();
				var description = $item.find('description').text();
				
				var html = "<div class=\"entry\">";
				html += "<h3 class=\"postTitle\"><a href=\"" + link + "\">" + title + " &rsaquo;</a><\/h3>";
				html += "<p>" + description + " <a href=\"" + link + "\">more &rsaquo;</a></p>";
				html += "</div>";
				
				$('#blog_content').append($(html));  
				i++;
			}
		});
	});
 	
	// Back to top link
	
	var at_top = true;
	$(window).scroll(function() {
		if ($(window).scrollTop() > 0) {
			if (at_top == true) {
				$top_link.fadeIn(300);
				position = $(window).height() - 45 + $(window).scrollTop();
				$top_link.css('top', position + 'px');
				at_top = false;
			}
			else {
				position = $(window).height() - 45 + $(window).scrollTop();
				$top_link.css('top', position + 'px');
			}
		}
		else {
			if (at_top == false) {
				$top_link.fadeOut(300);
				at_top = true;
			}
		}
	});

	$('#slides').slides();
});

