// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
if (typeof BoPunkten == "undefined") { 
	BoPunkten = {
		Classes: {} 
	};
}

BoPunkten.l10n = {
	translate: function(string) {
		return BoPunkten.l10n.Phrases[string] ? BoPunkten.l10n.Phrases[string] : string;
	},
	add: function(string, localized) {
		BoPunkten.l10n.Phrases[string] = localized;
	},
	Phrases: { }
};
String.prototype.t = function(){
	return BoPunkten.l10n.translate(this);
};

/**
* @class Basic toggler class
* @constructor 
* @param  {Object}   el                  An element which's content you want to be able to hide and show
* @param  {Hash}     options             Hash with options. Optional. The options are as follows:
* @param  {String}   options ['prefix']  Prefix for classname. Prepended to "closed". Default: "";
*/
BoPunkten.Classes.Toggler = function(el,options){
	if(!el){ return false; }
	this.el        = $(el);
	this.options   = options || {};
	this.className = this.options.prefix ? this.options.prefix + "closed closed" : "closed";
	this.closed    = this.el.hasClass(this.className);
}
BoPunkten.Classes.Toggler.prototype = {
	/**
	* Runs the open() or the close() function
	*/
	toggle: function(){
		if(this.closed){
			this.open();
		}else{
			this.close();
		}
	},
	/**
	* Shows content and sets cookie
	*/
	open: function(){
		this.el.removeClass(this.className);
		this.closed = false;
	},
	/**
	* Hides content and sets cookie
	*/
	close: function(){
		this.el.addClass(this.className);
		this.closed = true;
	}
}

$(document).ready(function() {
	// Clickable table rows with :hover effect
	if ($("table.overview tbody tr").find("a[class!='delete']").length >= 1) {
		$("table.overview tbody tr").click(function() {
			window.location = $(this).find("td[class!='photo']").children("a")[0].href;
		}).addClass("hover");
	}
	// Add class "even" on every second table row
	$("table.overview tbody tr:even").addClass("even");
	// Search area
	$("#specify-date").hide();
	$("#indate_later").click(function() {
		$("#specify-date").show();
	});
	// Hide notices on click
	$(".notice").click(function(){
		$(this).fadeOut();
	});
});