﻿$(document).ready(function(){
	var loc = 'imaginary.com.au'; //(location.hostname.indexOf('www.')===-1) ? location.hostname : location.hostname.substring(4);
	var em = $('a.email').attr('title')+'@'+ loc;
	$('#more').hide();
	$('a[href=#more]').click(function(){
		$('.content, #tech').hide();
		$('#more').fadeIn('slow');
		return false;
	});
	$('a[href=#tech]').click(function(){
		$('.content, #more').hide();
		$('#tech').fadeIn('slow');
		return false;
	});
	$('a[href=#home]').click(function(){
		$('#more, #tech').hide();
		$('.content').fadeIn('slow');
		return false;
	});
	$('a.email').attr('href', 'mailto:'+em).text(em);
    $('label.titleset').each(function(){
        var label = $(this).text();
        $(this).next().attr('title', label).val(label).focus(function(){
            if($(this).val()==label){
                $(this).val('');
            }
        }).blur(function(){
            if($(this).val()==''){
                $(this).val(label);
            }
        });
    }).hide();

	$('#cat').change(function(){
		location.href = "http://"+location.hostname+"/journal/?cat="+$('#cat option:selected').val();
	});

	$('#archives').change(function(){
		location.href = $('option:selected', this).val();
	});
	
	$('dl.accordion').accordion();	
	$('#pagePrint').click(function(){
		window.print();
		return false;
	});
	
	$.ajax({
		url: "/common/include/feed.php",
		dataType: "xml",
		success: function(data){
			var feed = $('feed', data);
			var e = '';
			$('entry', feed).slice(0,10).each(function(i){
				var t = $('title:eq(0)', this).text().substr(5);
				var a = $('link', this).attr('href');
				var c = $('content', this);
				var s = $('td:eq(1) div:eq(2) a:eq(1)', c).text();
				if(s == 'Google Reader') {
					c = 'reader'
				} else if (s== 'Imaginary journal') {
					c = 'blog'
				} else if (a.indexOf('flickr.com') > -1) {
					c = 'photo'
				} else if (s == 'delicious') {
					c = 'bookmark'
				} else if (a.indexOf('youtube') > -1) {
					c = 'video'
				} else if (a.indexOf('vimeo') > -1) {
					c = 'video'
				}
				else {
					c = 'default'
				}
				e += '<li class="'+c+'"><a href="'+a+'" target="_blank">'+t+'</a></li>';
			});
			$('#bio').before('<div class="content"><h2><a href="http://friendfeed.com/eroteme" rel="external">Recent activity</a></h2><ul id="feed">'+e+'</ul></div>');
			$('.content').fadeIn();
		},
		error: function(){
			$('#bio').fadeIn();
		}
	});
	
});