$(document).ready(function() {
	$('body').addClass('hasJQ');
	// tidy up the nav output through the blogroll feature
	$('#top_nav li:eq(0)').addClass('first');
	checkFormField();
	jumpMenus();
});


// gets the keywords input fields default value and checks
// before submission that it has been changed.
function checkFormField() {
	var defVal = $('#keywords').val();
	formClear();
	$('#search_form').submit(function () {
		if ($('#keywords').val() == defVal) {
			return false;
		};
	});
};

// Is called from the checkFormField function
function formClear () {
	var textContent = $('#keywords').val();
	$('#keywords').focus(function() {
		if (this.value == textContent) {
			$(this).val('');
		};
	}).blur(function() {
		if (this.value == '') {
			$(this).val(textContent);
		};
	});
};

function jumpMenus () {
	var jumper = $('select.jump_menu');
	jumper.change(function() {
		location.href=this.options[this.selectedIndex].value;
	});
};

function jsonFlickrApi(rsp) {
	if (rsp.stat != "ok"){
		// If this executes, something broke!
		return;
	}
	var s = "";
	//this loop runs through every item and creates HTML 
	// Use rsp.photos.photo.length in the loop to get all matching the search
	for (var i=0; i < 30; i++) {
		photo = rsp.photos.photo[ i ];
		//notice that "t.jpg" is where you change the
		//size of the image
		t_url = "http://farm" + photo.farm + 
		".static.flickr.com/" + photo.server + "/" + 
		photo.id + "_" + photo.secret + "_" + "s.jpg";
		p_url = "http://www.flickr.com/photos/" + 
		photo.owner + "/" + photo.id;  
		s +=  '<a href="' + p_url + '">' + '<img alt="'+ 
		photo.title + '"src="' + t_url + '"/>' + '</a>';
	}
	document.writeln(s); 
	//this tells the JavaScript to write 
	//everything in variable "s" onto the page
}
