﻿$(document).ready(function() {

	// Welcome
	$.getJSON('http://www.geoplugin.net/json.gp?jsoncallback=?', function(location) {
		if (location != null) {
			var welcome = " It's always good to have visitors from " + location.geoplugin_countryName + ".";
			$('#welcome').append(welcome);
		};
	});

	// Flickr
	$('#photos').append('<ul id="feed"></ul>');

	$('#feed').jflickrfeed({
		feedapi: 'photos_public.gne',
		limit: 14,
		qstrings: {
			id: '10289959@N07'
		},
		itemTemplate:
		'<li>' +
			'<a rel="flickr" href="{{image_b}}" title="{{title}}">' +
				'<img src="{{image_s}}" alt="{{title}}" />' +
			'</a>' +
		'</li>'
	}, function(data) {
		$('#photos a').colorbox(
		{
			maxWidth: "94%",
			maxHeight: "94%"
		});
	});

	// LastFM
	$('#sidebar div#lastfm').lastFM({
		username: 'DanDiplo',
		apikey: 'ca1599876cde298491941da8577de666',
		number: 3,
		artSize: 'medium',
		noart: '/images/noartwork.gif',
		onComplete: function() {
			$('#sidebar div#lfm_wrapper').fadeIn('slow');
		}
	});

	// Tweets
	$("#tweets").jCarouselLite({
		vertical: true,
		visible: 3,
		auto: 7000,
		speed: 1500,
		easing: "swing"
	});

	// Header animation
	$('#header #header-text strong a').animate({ color: '#8edee4' }, 10000);
	$('#header #header-text strong a span').animate({ color: '#fff' }, 10000);

	// Random Quote
	$("#reload-quote-link").show();

	$("#reload-quote-link").click(function(event) {
		event.preventDefault();
		getQuote();
	});

	function getQuote() {
		$('#quote-body').load('/RandomQuote.ashx', function() {
			$(this).hide();
			$(this).fadeIn(2000);
		});
	}

	// LoveFilm Watched

	$.getJSON("/LoveFilmProxy.ashx",
		function(data) {

			var html = '';

			$.each(data.rented.children, function(i, item) {

				var ct = item.rented_item.children[0].catalog_title;
				var title = ct.title.clean.replace(" - Blu-ray", "");
				var year = ct.production_year;
				var studio = ct.studio;
				var synopsis = ct.links[2].children.synopsis.synopsis_text;
				var image = ct.links[6].children.artworks.children[0].artwork.children[1].image;
				var link = ct.links[8].href;

				if (year != '') {
					title += " (" + year + ")";
				}

				html += '<a href="' + link + '" class="new-window">';
				html += '<span class="wrap">';
				html += '<span class="m_art"><img src="' + image.href + '" alt="cover" /></span>';
				html += '<span class="m_song">' + title + '</span>';
				if (synopsis != undefined) {
					html += '<span class="m_artist">' + synopsis + '</span>';
				}
				html += '</span>';
				html += '</a>';


			});

			$("#lovefilm_wrapper").show();
			$("#lovefilm").append(html).fadeIn(2000);

		});


});

