$(document).ready(function () {


	//
	// PROFILE PICTURE
	//
	$("#userProfileImg img").load(function () {
		var profilePic = $(this);
		var profilePicWidth = profilePic.width();
		var profilePicHeight = profilePic.height();
		var profilePicWidthHalf = null,
			profilePicLandscapeMath = null,
			profilePicAspectRatio = null;

		if (profilePicWidth > profilePicHeight) {
			profilePicAspectRatio = "landscape";
			if (profilePicHeight < 60) {
				profilePicLandscapeMath = 60 / profilePicHeight;
				profilePicWidth = Math.ceil(profilePicWidth * profilePicLandscapeMath);
				profilePicWidthHalf = -((profilePicWidth / 2) - 30);
			}

		} else {
			profilePicAspectRatio = "portrait";
		}

		if (profilePicAspectRatio === "landscape") {
			$(profilePic).css({
				height: "60px",
				marginLeft: profilePicWidthHalf + "px"
			});
		} else if (profilePicAspectRatio === "portrait") {
			$(profilePic).css({
				width: "60px"
			});
		}

	});











	//
	// tooltip
	//
	$(".tooltip,.tooltip2").hover(function () {
		// get element position and tooltip content
		elementOffset = $(this).offset();
		elementTitle = $(this).attr("title");
		elementWidth = $(this).width();
		// put content in tooltip THEN get its width
		$("#tooltip").html(elementTitle);
		tooltipWidth = $("#tooltip").width();
		// show tooltip
		$("#tooltip").css({ left: elementOffset.left - ((tooltipWidth / 2) - (elementWidth / 3)), top: elementOffset.top - 28 }).stop(true, true).fadeIn(150);
		// kill default title
		$(this).attr("title", "");
	}, function () {
		// kill kill
		$("#tooltip").stop(true, true).delay(150).fadeOut(150);
		// reset title attr
		$(this).attr("title", elementTitle);
	});






	//
	// image media window title
	//
	$("#embeddedPlayer h1").hide();
	$("#embeddedPlayer").hover(function () {
		$("#embeddedPlayer h1").fadeIn(100);
	}, function () {
		$("#embeddedPlayer h1").fadeOut(100);
	});










	// media grid scrollable
	// current page in scroller
	var curScrollPage = 1;
	// how many elements in the scroller?
	var howManyScrollerElements = $(".mediaGrid ul.playlist li").length;
	var elementsPerScrollerPage = 5.5;
	var totalScrollerPages = Math.ceil(howManyScrollerElements / elementsPerScrollerPage);
	// nav buttons
	$(".mediaGrid .earLeft").click(function () {
		if (curScrollPage > 1) {
			$(".mediaGrid ul.playlist").stop(true, true).animate({
				left: '+=750'
			}, 400);
			curScrollPage--;
		}
	});
	$(".mediaGrid .earRight").click(function () {
		if (curScrollPage >= 1 && curScrollPage < totalScrollerPages) {
			$(".mediaGrid ul.playlist").stop(true, true).animate({
				left: '-=750'
			}, 400);
			curScrollPage++;
		}
	});

	/*var player = document.getElementById("km_player");
	$(".playlist li a").not("#playlistGrid").click(function () {
		var id = $(this).parent().attr("id");
		player.setCurrentItemById(id);
	});*/


	// internal only
	var likesLinkText = $("a#iconLikes").html();
	$("a#iconLikes").hover(function () {
		$(this).html("Like this");
	}, function () {
		$(this).html(likesLinkText);
	});

	$("a#iconLikes").click(function () {
		$(this).html("Submitting...");
		return false;
	});









});
