$(function() {
		   
	// Flickr Settings
	var search = 'tiltshift';
	var key = '68e54c919b8fb1c98857ccde6d46636b';
	var queryString = window.location.search.replace(/\?q=([^\&]+)/,'$1');
	if(queryString.length > 2) {
		search = queryString;
	}

	$('.fsSearch').find('input[type=text]').focus(function() {
		if($(this).attr('value') == 'search') {
			$(this).attr('value','');
		}
	}).blur(function() {
		if($(this).attr('value') == '') {
			$(this).attr('value','search');
		}
	});
	
	$('.fsInfo').toggle(
		function() {
			$('.fsTitle,.fsCaption').show();
			$(this).find('a').addClass('active');
		},
		function() {
			$('.fsTitle,.fsCaption').hide();
			$(this).find('a').removeClass('active');
		}
	);
	
	$("#imageList").flickr({     
	    api_key: key,  
	    type: 'search',
		tags: search,
		sort: 'relevance',
		size: 'o',
		per_page: 100,
	    loadFirst: function() {
			$('#imageList ul').fsGallery({
				delay:0,
				fade:1,
				onLoad : function() {
					var c = $('.fsCaption').css('visibility','hidden');
					var t = $('#fsImage td img:not(.init)').attr('alt');
					$('.fsTitle').text(t);
					document.title = 'FS Gallery: '+t;
					$.getJSON('http://api.flickr.com/services/rest/?format=json&jsoncallback=?&api_key='
					+ key
					+ '&method=flickr.photos.getInfo'
					+ '&photo_id='+$('#fsImage td img:not(.init)').attr('id'), function(info){
						var content = info.photo.description._content.replace(/<("[^"]*"|'[^']*'|[^'">])*>/gi,"");
						if(content.length > 0) {
							c.html(content).css('visibility','visible');
						}
					});
				}
			});
		}
	});

	// Hide and Show "More Content"
	$('.more-content').hide();
	$('.show-more').click(function() {
		$(this).toggleClass('show-less');
		$(this).next().slideToggle(400);
	});
	
	/*
		Begin jQuery UI Functions
	*/
	// This adds the ability to move the card box around
	$('#card').draggable({ handle: '#card-header', axis: 'x', containment: 'body', scroll: false, grid: [20,20] });
	// This adds a tab show/hide effect
	$('#card-content').tabs();
	// This creates an effect to collapse containers, leaving 1 open at a time
	$('#card-content .accordion').accordion();
			
});

