$(document).ready(function() {

//Hide elements
$('#nutrition, #nutrition img').hide();
$('#health, #health img').hide();
$('#education, #education img').hide();
$('#livelihood, #livelihood img').hide();
$('#detailN, #detailH, #detailE, #detailL').hide();


//Set Atttributes
$('#captions li:eq(3)').css("margin-right", "0");

//Set Cursor to Hand on URL Hover
$('#thumbs img').hover(
function() {
$(this).css("cursor","hand");
},
function() {
$(this).css("cursor","pointer");
}
);


//Gallery click functions with crossfade slideshows
var timer = 0;
timer = setTimeout("slideShow()", 8000);

//Nutrition
$('#thumbs li:eq(0)').click(function() {
clearTimeout(timer);
$('#health, #education, #livelihood').hide();
$('#detailH, #detailE, #detailL').hide();
$('#nutrition, #detailN').fadeIn();

slideShow();

function slideShow() {
var current = $('#nutrition .show');
var next = current.next().length ? current.next() : current.parent().children(':first');

var title = next.attr('title');
var description = next.attr('desc');
$('#detailN #titleHolder').html(title);
$('#detailN #descHolder').html(description);

current.hide().removeClass('show');
next.fadeIn('slow').addClass('show');
timer = setTimeout(slideShow, 8000);
}
return false;
});

//Health
$('#thumbs li:eq(1)').click(function() {
clearTimeout(timer);
$('#nutrition, #education, #livelihood').hide();
$('#detailN, #detailE, #detailL').hide();
$('#health, #detailH').fadeIn();

slideShow();

function slideShow() {
var current = $('#health .show');
var next = current.next().length ? current.next() : current.parent().children(':first');

var title = next.attr('title');
var description = next.attr('desc');
$('#detailH .title').html(title);
$('#detailH .desc').html(description);

current.hide().removeClass('show');
next.fadeIn('slow').addClass('show');
timer = setTimeout(slideShow, 8000);
}
return false;
});

//Education
$('#thumbs li:eq(2)').click(function() {
clearTimeout(timer);
$('#health, #nutrition, #livelihood').hide();
$('#detailN, #detailH, #detailL').hide();
$('#education, #detailE').fadeIn();

slideShow();

function slideShow() {
var current = $('#education .show');
var next = current.next().length ? current.next() : current.parent().children(':first');

var title = next.attr('title');
var description = next.attr('desc');
$('#detailE .title').html(title);
$('#detailE .desc').html(description);

current.hide().removeClass('show');
next.fadeIn('slow').addClass('show');
timer = setTimeout(slideShow, 8000);
}

return false;
});

//Livelihood
$('#thumbs li:eq(3)').click(function() {
clearTimeout(timer);
$('#health, #education, #nutrition').hide();
$('#detailN, #detailH, #detailE').hide();
$('#livelihood, #detailL').fadeIn();

slideShow();

function slideShow() {
var current = $('#livelihood .show');
var next = current.next().length ? current.next() : current.parent().children(':first');

var title = next.attr('title');
var description = next.attr('desc');
$('#detailL .title').html(title);
$('#detailL .desc').html(description);

current.hide().removeClass('show');
next.fadeIn('slow').addClass('show');
timer = setTimeout(slideShow, 8000);
}

return false;
});


//closing tags for document ready function
});

