/*
 * tweetable 1.2 - jQuery twitter feed generator plugin
 *
 * Copyright (c) 2009 Philip Beel (http://www.theodin.co.uk/)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Revision: $Id: jquery.tweetable.js 2009-08-20 $ 
 *
 */
(function($){$.fn.tweetable=function(options){var defaults={limit:5,username:'philipbeel',time:false};var options=$.extend(defaults,options);return this.each(function(options){var act=$(this);var api="http://twitter.com/statuses/user_timeline/";var count="?count=";$.getJSON(api+defaults.username+".json"+count+defaults.limit+"&callback=?",act,function(data){$.each(data,function(i,item){if(i==0){$(act).prepend('<ul class="tweetList"><li class="tweet_content_'+i+'">')}else{$('.tweetList').append('<li class="tweet_content_'+i+'">')}$('.tweet_content_'+i+'').append('<span class="tweet_link_'+i+'">'+item.text.replace(/#(.*?)(\s|$)/g,'<span class="hash">#$1 </span>').replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig,'<a href="$&" target="_blank">$&</a> ').replace(/@(.*?)(\s|\(|\)|$)/g,'<a href="http://twitter.com/$1" target="_blank">@$1 </a>$2'));if(defaults.time==true){$('.tweet_content_'+i).append('<small> '+item.created_at.substr(0,16)+', via '+item.source +'</small>')}})})})}})(jQuery);





/*
* Copyright (C) 2009 Joel Sutherland
* Licenced under the MIT license
* http://www.newmediacampaigns.com/page/jquery-flickr-plugin
*
* Available tags for templates:
* title, link, date_taken, description, published, author, author_id, tags, image*
*/
(function($){$.fn.jflickrfeed=function(settings,callback){settings=$.extend(true,{flickrbase:'http://api.flickr.com/services/feeds/',feedapi:'photos_public.gne',limit:20,qstrings:{lang:'en-us',format:'json',jsoncallback:'?'},cleanDescription:true,useTemplate:true,itemTemplate:'',itemCallback:function(){}},settings);var url=settings.flickrbase+settings.feedapi+'?';var first=true;for(var key in settings.qstrings){if(!first)
url+='&';url+=key+'='+settings.qstrings[key];first=false;}
return $(this).each(function(){var $container=$(this);var container=this;$.getJSON(url,function(data){$.each(data.items,function(i,item){if(i<settings.limit){if(settings.cleanDescription){var regex=/<p>(.*?)<\/p>/g;var input=item.description;if(regex.test(input)){item.description=input.match(regex)[2]
if(item.description!=undefined)
item.description=item.description.replace('<p>','').replace('</p>','');}}
item['image_s']=item.media.m.replace('_m','_s');item['image_t']=item.media.m.replace('_m','_t');item['image_m']=item.media.m.replace('_m','_m');item['image']=item.media.m.replace('_m','');item['image_b']=item.media.m.replace('_m','_b');delete item.media;if(settings.useTemplate){var template=settings.itemTemplate;for(var key in item){var rgx=new RegExp('{{'+key+'}}','g');template=template.replace(rgx,item[key]);}
$container.append(template)}
settings.itemCallback.call(container,item);}});if($.isFunction(callback)){callback.call(container,data);}});});}})(jQuery);




$( function() {
	$("#nav li a[href=/give-us-feedback]").attr('target','_blank');
	$('#nav li.here ul').addClass('open');
	nav_highlight();

	
	$('#sflickr').append('<ul id="flickr_embed"></ul>');
	$('#flickr_embed').jflickrfeed({
		limit: 9,
		qstrings: {
			id: '38177794@N02'
		},
		itemTemplate: 
		'<li>' +
			'<a target="_blank" rel="external"><img src="{{image_s}}" alt="{{title}}" /></a>' +
		'</li>'
	});
	
	
	/*
	$('#zrss_facebook').rssfeed('', {
		limit: 5
	});
	*/

	$('#stwitter').append('<div id="twitter_embed"></div');
	$('#twitter_embed').tweetable({username: '', time: true, limit: 4});

	$('#footer #social_links li h2').click( function() {
		if($(this).parent().hasClass('off')) {
			showThis($(this).siblings('div.social'));
		}
		else {
			hideThis($(this).siblings('div.social'));
		}
		
	});
	$('#footer #social_links li').mouseenter( function() {
		showThis($(this).find('div.social'));
	});
	$('#footer #social_links li').mouseleave( function() {
		if(!$(this).hasClass('off')) {
		
			hideThis($(this).find('div.social'));
		}
	});
	
});

// Function to make a social block dissappear
function hideThis(objects) {
	$(objects).animate({
		opacity: 0,
		height: 0,
		paddingTop: 0,
		paddingBottom: 0
	}, {
		queue: false,
		duration: 300,
		complete: function() {
			$(objects).parent().addClass('off');
		}
	});
}

// Function to make a social block appear
function showThis(objects) {
	$(objects).parent().removeClass('off');
	$(objects).animate({
		height: 190,
		opacity: 90,
		paddingTop: 20,
		paddingBottom: 20
	}, {
		queue: false,
		duration: 200
	});

	// PNG fixing
	if($.browser.msie && $.browser.version <= 6) {
			
		$("#logo, #page_header, div.social, #left_block h1, img[src$='.png']").supersleight();
		
	}
}

// Highlight right bit of the nav
function nav_highlight() {
	
	var total_lit = $('#nav li').hasClass('here');
	
	var body_class = $('body').attr('class').split('/');
	
	if(!total_lit && body_class != '') {
		
		$('#nav li>a').each( function() {
		
			if($(this).attr('href') == $('body').attr('class')) {
				
				$(this).parent().addClass('here');
				
			} else if($(this).attr('href').indexOf(body_class[1]) != -1 && total_lit == 0) {
				
				$(this).parent().addClass('here');
				
				total_lit++;
			}
			
			
			
		});

	};
	
	$('#nav li').each( function() {
		
		if($(this).find('ul').size() > 0) {
			
			$(this).find('a:first').click( function() {
				var thislist = $(this).parent().find('ul:first');
				if($(thislist).hasClass('open')) {
					$(this).parent().parent().find('ul').slideUp('fast').removeClass('open');
				}
				else {
					$(this).parent().parent().find('ul').slideUp('fast').removeClass('open');
					thislist.slideDown('fast').addClass('open');
				}

				
				
				
				
				return false;
				
			});
			
		};
		
	});
	
	// Show sub menu if we're on that nav element
	$('#nav li.here ul').show();
	
}
