Cufon.replace('#menu a, h2.title, #main .post .postoptions a, #main .post .postoptions span, #main .searchresults h2, #main h2.searchresult span, #main div.post h3, #main .content label,');

$.create = function(elm) {return $(document.createElement(elm));};
jQuery(function($){
	if($('div.twitter').length)$.getScript('http://search.twitter.com/search.json?from=_une&rpp=3&result_type=recent&callback=twitterFunction');
	if($('#main .postoptions').length) {
		$('#main .postoptions .twitter a').attr({href:'http://api.tweetmeme.com/share?url=' + location.href});
		$.getScript('http://api.tweetmeme.com/url_info.jsonc?url=' + encodeURIComponent(location.href) + '&callback=tweetCount');
	}

	if($('html.ie6').length) {
		$('h2.title').prepend($.create('span'));
	}
	$('#main').find('.postoptions .print a').click(function() {window.print();return false;});

	var fillTwitter, prepareShowcase, showcaseAnimation, animateShowcase, twitterPost;

	fillTwitter = function(tweets) {
		if(tweets.results && tweets.results.length) {
			tweets = tweets.results;
			var tweetDiv = $('#main').find('div.twitter'),
				textarea = document.createElement('textarea'),
				ilen = tweets.length,
				tweet,from,source,text,i;
			for(i=0;i<ilen;i++) {
				tweet = tweets[i];
				textarea.innerHTML = tweet.source;
				text = ' ' + tweet.text;/*.replace(/#([^ ]+)/g,'<a href="http://twitter.com/search?q=%23' + "$1\">#$1</a>").replace(/@([^ ]+)/g,'<a href="http://twitter.com/' + "$1\">@$1</a>");*/
				from = tweet.from_user;
				source = textarea.value;
				tweetDiv.append($.create('p').append($.create('strong').text(from)).append(text).append($.create('span').html(source)));
			}
		}
	};
	window.twitterFunction = fillTwitter;


	prepareShowcase = function() {
		var slides = $('#showcase').find('.container div');
		if(slides.length > 1) {
			var width = slides.width(),
				slider = $.create('ul'),
				ilen = slides.length,
				i, slide;
			$('#showcase').data('i',0).find('.container').css('width',slides.length * width);
			for(i=0;i<ilen;i++) {
				slide = $.create('a').addClass('ir').data('i',i).click(function() {
					var $this = $(this),
						i = $this.data('i');
					$(this.parentNode.parentNode).find('a').removeClass('active');
					$this.addClass('active');
					$('#showcase').data('i',i).find('.container').animate({
						'marginLeft':(width * i) * -1
					});
					animateShowcase();
				});
				$.create('li').append(slide).appendTo(slider);
			}
			slider.find('a').eq(0).addClass('active');
			$.create('div').addClass('slider').append(slider).appendTo($('#showcase').find('.showcasecontent'));
			animateShowcase();
		}
	};

	showcaseAnimation = function() {
		var showcase = $('#showcase'),
			slides = showcase.find('.slider a');
		if(showcase.data('i') == (slides.length - 1))
			slides.eq(0).click();
		else
			slides.eq(showcase.data('i') + 1).click();
	};

	animateShowcase = function() {
		clearTimeout(window.showcaseTimer);
		window.showcaseTimer = setTimeout(showcaseAnimation,8000);
	};

	prepareShowcase();

	twitterPost = function(obj) {
		if(obj.status == 'failure')
			obj.story.url_count = 0;
		$('#main .postoptions .twitter a').append($.create('span').text(' ' + obj.story.url_count));
	}
	window.tweetCount = twitterPost;


	$('#flickr').find('a').attr('target','_blank');
});
