var debug = function() { };
jQuery(document).ready(function() {

	/**
	 * auto popups
	*/
	$('a.popup').click(function(event) {

		// we have a default size
		var width 		= 400;
		var height 		= 400;
		var scrolling 	= '1';

		if (this.rev) {
			var rev = this.rev.split(" ");

			// which can easily be overridden
			if (rev[0].split('x').length == 2) {
				var parts = this.rev.split('x');
				width 	= parts[0];
				height	= parts[1];
			}

			if ($.grep(rev, function(val) { val == 'noscroll' })) scrolling = '0';
		};

		var target = (typeof(this.target) == 'undefined' || this.target == "") ? 'Popup' + Math.round(Math.random() * 100) : this.target;
		var win = window.open(this.href, target, 'status=1,toolbar=0,location=0,menubar=0,directories=0,resizeable=1,scrollbars='+scrolling+',height=' + height + ',width=' + width);
		if (win) win.focus();

		return false;
	});

	$('a.hover').each(function(i, el) {
		el 	= $(el);
		img = el.find('img');
		if (img) {
			var offSrc 	= img.attr('src');
			var onSrc	= offSrc.replace('off.', 'on.');

			el.hover(function() {
				el.find('img').attr('src', onSrc);
			}, function() {
				el.find('img').attr('src', offSrc);
			});
		};
	});
	/**
	 * loginbox should display name when logged in
	*/
	$('#top').each(function(i, el) {

		var myId = $.cookie('firstName') ? 'loggedin' : 'not_loggedin';
		var my = $('#' + myId);
		if ($.cookie('firstName')) {
			
			var html = my.html();
			html = html.replace('#[Name]', $.cookie('firstName'));
			my.html(html);

			if ($.cookie('userId')) {
				$('.showTo' + $.cookie('userId')).show();
			}

			$('.hideToLogin').hide();

		} else {
		}

		my.show();
	});
	/**
	 * a bit of fancier display of the pager
	*/
	$('div.pager').each(function(i, el) {

		var list = $(el).find('div.l');
		list.each(function(index, div) {
			if (index != list.length - 1) $(div).after(' | ');
		});

	});

});

