// jQuery stuff for BakerofBrighton.com
// Author: Alex Goluszko

// Exact text string matching via 
// http://lanitdev.wordpress.com/2009/09/22/jquery-custom-selector-for-selecting-elements-by-exact-text-textequals/

$.expr[':'].textEquals = function(a, i, m) {
	return $(a).text().match("^" + m[3] + "$");};

$('document').ready(function() {
	
	//Add recipe styling to "headers" labeled 'Recipe'
		$("p:textEquals('RECIPE:'), p:textEquals('Recipe:')").addClass('recipe');

	// Pic styling
		$(".full a:has(img[src*='uploads'])").wrap("<div class='pictureBox'></div>").addClass("lightbox");
		
		var imageTitle = $(".entry img[src*='uploads']").attr('title');	
		
		$(".full .pictureBox").append('<span>' + imageTitle + '</span>'); 
		$(".pictureBox span").css( {opacity: 0.7});

		$('#entries .entry a:has(img)').wrap("<div class='pictureBox floatLeft nudged'></div>");

	//Add value to search field, then clear it on focus 
		$("input[type='text']").addClass('hint').focus(function() { 
				$(this).removeClass('hint').val("");
			});	

	// Flickr feed - removes vertically-oriented photos
		var x = 0;
		
		$.getJSON("http://api.flickr.com/services/feeds/photoset.gne?set=72157594244161609&nsid=59576457@N00&lang=en-us&format=json&jsoncallback=?", function(data){
			$.each(data.items, function(i,item){
	
					var picWidth = $(item.description).find('img').attr('width');									  
					var picHeight = $(item.description).find('img').attr('height');									  
											
					var pic = $(item.description).find('img');
						
					if(picWidth > picHeight && x<=3) { 
							$(pic)
								.appendTo(".flickrFeed ul")
								.attr({
									width: "282",
									height: "200"})
								.wrap("<li class='pictureBox column'><a href=" + item.link + " target='_blank'></a></li>");
							$('.flickrFeed li:odd').addClass('floatRight');
							$('.flickrFeed li:even').addClass('floatLeft');
	
							x++;	
					}
				});	
			});

	
});

