var Jabroo = {

	textRevertCount : 0,

	init : function() {
	
	 $("img").lazyload({
	     placeholder : "/img/grey.gif",       
	     effect      : "fadeIn"
	 });
	
		// set up font image clicking
	Jabroo.fontImage();
	// set up textRevert on change image text
	Jabroo.textRevert();
	// bind bookmark links
	Jabroo.bookmark();
},

bookmark : function() {

	$(".bookmark-link").live("click", function() {

		if ($(this).hasClass("bookmark-link-remove")) {

			$(this).removeClass("bookmark-link-remove");
			$(this).find('a').html('Bookmark');
		} else {

			// change it back
			$(this).addClass("bookmark-link-remove");

			$(this).find('a').html('Remove bookmark');

		}

		$.post("/user/addfavourite", {
			codelink : $(this).attr('title')
		});

		return false;

	});

},

fontImage : function() {
	
	
	$('.main_font_image_link').click(function() {
		if ($(this).siblings('.font_extra').children().size() == 0) {
			$(this).siblings('.font_extra').load("/index/fontextra", {
				codelink : $(this).attr('id')
			}, function() {
				$(this).slideToggle();
			});
		} else {
			$(this).siblings('.font_extra').slideToggle('fast');
		}

		return false;

	});

},

textRevert : function() {
	$('.textRevert').focus(function() {
		Jabroo.textRevertCount++;
		if (Jabroo.textRevertCount == 1) {
			$(this).attr('title', $(this).val());
			$(this).val('');
		}

		if ($(this).val() == $(this).attr('title')) {
			$(this).val('');
		}
	});
	$('.textRevert').blur(function() {
		val = $(this).val();
		if (val == '') {
			$(this).val($(this).attr('title'));
		}
	});
}
}

$(document).ready(function() {
	Jabroo.init();
});