/// ----------------------------------
///
/// @author Michelle Chua
/// ----------------------------------

// @TODO - add hover events for highlighting img when hovering on sidebar
// and viceversa

// ----------------------------------
/// Event handlers
// ----------------------------------
$(document).ready(function() {
	handlePlatform();
});

$(window).scroll(function() {
	handlePlatform();
});

$(window).resize(function() {
	handlePlatform();
});


function handleFooterVisibility()
{
	var docHeight = $(document).height();
	var winHeight = $(window).height();
	var winScrollTop = $(window).scrollTop();

	if(docHeight - winHeight - winScrollTop < 5 || docHeight < winHeight)
	{
		$("#footer").fadeIn();
	}
	else 
	{
		$("#footer").fadeOut();
	}
}

function handleSideNavPos()
{
	var winScrollTop = $(window).scrollTop();
	var contentY = $("#content").offset().top;
	var margin = 20;

	if(contentY >= winScrollTop)
	{
		$("#side").css({"position":"absolute", "top": contentY + "px"});
	}
	else
	{
		$("#side").css({"position": "fixed", "top": "20px"});
	}
}

function handlePlatform()
{
	var isMobile = navigator.userAgent.match(/(iPhone)|(iPad)|(iPod)|(android)|(webOS)/i);

	if(isMobile)
	{

		var contentWidth = $("#content").width();
		$("#all").css({"padding": "0 20px"});
		$("#side").css({"position": "absolute", "left": contentWidth + "px", "margin": "8px 0 0 10px"});
		
		// Hide footer
		$("footer").css({"display": "none"});
	}
	else
	{
		handleFooterVisibility();
		handleSideNavPos();
	}
}



