/*
* Initialise KeepCup
*/
$(document).ready(function() {

	$('input.hint').inputHint();


	if($('body').prettyPhoto) {
		$("a[rel^='prettyPhoto']").prettyPhoto({ social_tools:'',
												 default_width:450,			// inline default width
												 default_height:450,		// inline default height
												 default_width_video:800,   // video default width
												 default_height_video:450,  // video default width
												 overlay_gallery:false});
	}

	$('.blog.slider').each(function() {
		var l_jBlogSlider = $(this),
			l_jBlogEntriesHolder = $('.blog_entries', l_jBlogSlider),
			l_jBlogEntries = $('.blog_entry', l_jBlogEntriesHolder),
			l_index = 1,
			l_count = l_jBlogEntries.length,
			l_jNextButton = $('a.next', l_jBlogSlider),
			l_jPrevButton = $('a.prev', l_jBlogSlider);
		if(l_jBlogEntries.is('.count1')) {
			// do nothing
		} else {

			// show a particular item
			var l_showItem = function(p_item) {

				// wrap and record the index
				p_item = parseInt(p_item);
				if(p_item > l_count) p_item = 1;
				if(p_item < 0) p_item = l_count - 1;
				l_index = p_item;
				
				// show the item
				var l_x = ((l_index - 1) * 214);
				l_jBlogEntriesHolder.parent().animate({scrollLeft:l_x});

				// hide/show the buttons
				if(l_index == 1) l_jPrevButton.not('.disabled').addClass('disabled');
				else l_jPrevButton.removeClass('disabled');
				if(l_index == l_count) l_jNextButton.not('.disabled').addClass('disabled');
				else l_jNextButton.removeClass('disabled');
			}

			// show the next item
			l_jNextButton.click(function() {
				if(l_jNextButton.is('.disabled')) return false;
				l_showItem(l_index + 1);
			});

			// show the previous item
			l_jPrevButton.click(function() {
				if(l_jPrevButton.is('.disabled')) return false;
				l_showItem(l_index - 1);
			});

			// show the first item
			l_showItem(1);

		}

	});

});
