// JavaScript Document
jQuery.fn.loadContent = function(options){$(this).removeClass("loadContent"); $(this).addClass("pointer"); return $(this).click(function(){ url = $(this).attr('href'); $("div#content").load(url); return false; }); };

jQuery.fn.loadTopDiv = function(options){ $(this).removeClass("loadTopDiv"); $(this).addClass("pointer"); return $(this).click(function(){ url = $(this).attr('href'); if("none" == $("div#topDiv").css('display')){ $('div#topDiv').load(url); $('div#topDiv').slideDown(); }	else{ $("div#topDiv").slideUp(); } return false; }); };

jQuery.fn.pagination = function(options){ $(this).removeClass("pagination"); $(this).addClass("pointer"); var settings = { "target" : $("div#content") }; $.extend(settings, options);	return $(this).bind('click',function(){ url = $(this).attr('href');	$(settings.target).customLoad(url); return false; }); };

jQuery.fn.loading = function(){ jQuery(this).html("<div align=\"center\"><img src=\"/memento/img/images/loadingAnimation.gif\" /></div>"); };

jQuery.fn.customLoad = function(url, options, func){ $(this).bind("ajaxStart", function(){ 
$(this).html("<div align=\"center\"><img src=\"/memento/img/images/loadingAnimation.gif\" /></div>"); }); $(this).bind("ajaxStop", function(){ $(this).unbind("ajaxStart"); }); return $(this).load(url, options, func); }; 

$.fn.box = function(){ return this.each(function(index){ $(this).removeClass("box").addClass("module"); $(this).children("div.heading").corner("top 5px"); $(this).children("div.value").corner("bottom 5px"); }); };

$.fn.hasCheckBoxSelection = function(id){ var hasSelection = false;	$("form#" + id + " input[@type=checkbox]").each(function(){ if(this.checked) hasSelection = true; }); return hasSelection; };

$.fn.chbHelper = function(id, command){ if(command == "ALL"){ $("form#" + id + " input[@type=checkbox]").each(function(){ this.checked = true; }); } else if(command == "NONE"){ $("form#" + id + " input[@type=checkbox]").each(function(){ this.checked = false; }); }	else if(command == "TOGGLE"){ $("form#" + id + " input[@type=checkbox]").each(function(){ this.checked = !this.checked; }); }return; };

$.fn.rating = function(obj){command = $(obj).attr('command');	url = $(obj).attr('href');	new_command = "";
new_html = ""; if(command == "WATCH"){ url = url + 'rating:1'; new_command = 'UNWATCH';	new_html = "UnWatch";}			else if(command == "UNWATCH"){url = url + 'rating:0'; new_command = 'WATCH'; new_html = "Watch"; } $("div#message_for_user").load(url); $(obj).html(new_html);	$(obj).attr('command', new_command);};
	

function close_parent(obj){$(obj).parent().hide();return false;};

function deleteKey(obj){url = $(obj).attr('url'); $(obj).parent().load(url, function(){$(obj).parent().remove();}); return false; };

$.fn.overlabel = function() {
    this.each(function(index) {
        var input = $(this); 
		var title = input.attr('title');
		var value = input.attr('value');
		if(typeof value == "undefined"){
			$(this).attr('value', title);	
		}
	    input.blur(function () {
			v = input.attr('value');
			if(typeof v == "undefined")
				$(this).attr('value', input.attr('title'));
		});
		input.focus(function(){
			v = input.attr('value');
			if(v == input.attr('title'))
				$(this).attr('value', "");
		});
    });
};

$.fn.checkOverLabel = function(){ var isOk = true; this.children("input.overlabel").each(function(index){ var input = $(this); if(input.attr('value') == input.attr('title')) isOk = false; }); return isOk; };

function togglePreview(obj, options){
	var settings = {txtOpen: "Open", txtClose: "Close"}; jQuery.extend(settings, options); command = $(obj).attr('command'); object = $(obj).attr('object'); 
	if("OPEN" == command){ $(object).slideDown("slow"); $(obj).html(settings.txtClose); $(obj).attr('command', 'CLOSE'); }	else if("CLOSE" == command){ $(object).slideUp("slow"); $(obj).html(settings.txtOpen);	$(obj).attr('command', 'OPEN'); }	return false; };	
