/* 
 * (c) 2011-2012 Peters Web Solutions, Herbert Peters
 */
$(document).ready(function($){
	var abx = $('#auth-box');
	$('li.auth-handle a').removeClass((loggedIn ? 'auth-in' : 'auth-off')).addClass((loggedIn ? 'auth-off' : 'auth-in'));
		
	if (loggedIn) {
		$('#auth-in', abx).hide();
		$('#auth-off', abx).show();
	}
	else {
		$('#auth-in', abx).show();
		$('#auth-off', abx).hide();
	}
	// Update language links
	if (jQuery.isFunction(jQuery.deparam)){
		var loc = jQuery.deparam.querystring(document.location.search);
		$('a.lg').each(function(){
			if (typeof _pageNoByLang == 'object'){
				lng = jQuery.deparam.querystring(this.href);
				if (lng.l && _pageNoByLang[lng.l]) loc.p = _pageNoByLang[lng.l];
			}
			this.href=jQuery.param.querystring(this.href,loc,1)+document.location.hash;
		});
	}
});

(function($) {
		$.extend( {
// finds the link element, pushes the url unto the state
// returns the anchor (0) and url (1) as array
	pwsolGetURL: function(e) {
	// Find the anchor
	var a = $(e.target), ahref/*, state = {}, id = a.closest('.bb').attr('id')*/;
	// If target not link => <li><a></a><span></span><span></span></li> or <a><img/></a> or <li><a></a></li> or <a><span></span></a>
	// initial check for is('img') is because IE8 reports a href for an image
	if (e.target.href === undefined || a.is('img'))	{
		// Clicked on a 'gap' e.g <li> element?
		if (a.is('li')) {
			a = a.children('a');
		}
		else {
			if (a.is('span'))	{
				a = (a.parent().is('a') ? a.parent() :  $(a.siblings('a')));
			}
			else {
				a = a.is('img') ? a.parent() : $('a',a);
			}
		}
	}
	ahref = a.attr('href');
//				state[id] = url.replace( /^#/, '' );
//				$.bbq.pushState(state);
	return [a,
					// Get the url from the link's href attribute, stripping any leading #.
					/*$o.ajaxPage+*/'?' + $.param.querystring(ahref),
					// Query Parameter
					$.deparam.querystring(ahref)];
	},
	pwsolErr: function(d) {
		if ($.isFunction($.pnotify)) {
			if (typeof d == 'string') {d= {pnotify_text: d}}
			d.pnotify_type = 'error';
			$.pnotify(d);
		}
	},
	pwsolMsg: function(d) {
		if ($.isFunction($.pnotify)) {
			if (typeof d == 'string') {d= {pnotify_text: d}}
			$.pnotify(d);
		}
	},
	pwsolRemoveWhitespace: function(str){return str.replace(/[\s\xA0]+/,'');}
});
})(jQuery);

