/*
 * lia_lia.js UTF-8
 * $Rev: 7425 $
 * $Date: 2008-10-10 14:56:27 +0200 (Fr, 10 Okt 2008) $
 * 
 */

function lia_init (domain2, ver) {
	
	// private Eigenschaft
	var domain = domain2;
	var ver = ver;
	
	var _equal_height = 0;
	var _equal_height_group;
	
	// private Methode
	function foo () {
		lia.console(domain);
	}
	
	// öffentliche Methode(n)
	var lia = {
	
		// Wrapper für console.log (Ausgabe in der Firebug-Console);
		// lässt den IE nicht abstürzen
		console : function (what, msg_type, lia) {
			
			if (typeof(domain) != 'undefined') {
				if (document.domain != domain) {
					if (typeof(what) != 'undefined') {
						try {
							if (typeof(lia) != 'undefined') {
								what = 'LIA: '+what;
							}
							
							if (typeof(msg_type) != 'undefined') {
								if (typeof(msg_type) == 'object') {
									console.log(what+' (%o)', msg_type);
								}
								eval("console."+msg_type+"(what)");
							}
							else {
								console.debug(what);
							}
						}
						catch(err) {
							
						}
					}
				}
			}
		},
		
		muh : function(alertOrPrint) {
			if (typeof alertOrPrint == 'undefined') {
				lia.console("muh!");
			} else {
				alert("muh");
			}
		
			return false;
		},
		
		// behebt das Flickern von Hintergrund-Bildern im IE(6)
		ie6_noflickr : function() {
			lia.console("lia.ie6_noflickr()", "group");
			try {
				document.execCommand("BackgroundImageCache", false, true);
			} 
			catch (err) {
			}
			
			lia.console("", "groupEnd");
		},
		
		// Externe Links mit Funktion versehen
		external_links : function () {
			f_name = 'lia.external_links()';
			lia.group_start(f_name);
			lia.timer_start(f_name);
			
			o = $("[rel=external]");
			o_length = o.length;
			if (o_length > 0) {
				lia.console("Anzahl a[rel=external]: "+o_length, o);
				
				$("a[rel=external]").each(function() {
					var $this = $(this);
							
					$(this).unbind('click');
					
					if (typeof($("base").attr("href")) != "undefined") {
				  		_base = $("base").attr("href");
					}
					else {
						_base = "";
					}
			
					$(this).click(function()
					{
						if ($(this).attr('href').indexOf('http://') == -1) {
							window.open(_base + $(this).attr('href'), '_blank');
						}
						else {
							window.open($(this).attr('href'), '_blank');
						}
						return false;
					});
			
					if ($(this).attr('class') == 'pdf')
					{
						$(this).attr('title',"PDF-Dokument | öffnet in neuem Fenster").addClass('external');
					}
					else
					{
						additional_txt = "[öffnet in neuem Fenster]";

						if ($(this).attr('title') !== '') {
							$(this).attr('title', $(this).attr('title')+" "+additional_txt);
						}
						else {
							if ($(this).attr('href').indexOf('http://') == -1) {
					   			$(this).attr('title', _base + $(this).attr('href') + " " + additional_txt).addClass('external');
					   		}
							else {
								$(this).attr('title', $(this).attr('href') + " " +additional_txt).addClass('external');
							}
						}				
					}
				});
			}
			lia.timer_end(f_name);
			lia.group_end(f_name);
		},
		
		timer_start : function (timer_name) {
			lia.console(timer_name, 'time');
		},
		
		timer_end : function (timer_name){
			lia.console(timer_name, 'timeEnd');
		},
		
		group_start : function (group_name) {
			lia.console(group_name, 'group');
		},
		
		group_end : function (){
			lia.console('', 'groupEnd');
		},
		
		// Externe Links auszeichnen
		mark_external_links : function() {
			lia.console("lia.mark_external_links()", "group");
		
			// PDFs
			$("a[href*=.pdf]").each(function() {
				lia.console($(this).attr('href')+" = external pdf");
				$(this).attr('rel', 'external');
				$(this).addClass('pdf');
			});
			
			// Links mit http:// in URL
			$("a[href*=http]").each(function() {
				foo = new RegExp(_base);
				
				if ($(this).attr('href').search(foo) == -1) {
					// wenn _base nicht in url
					lia.console($(this).attr('href')+" = external");
					//$(this).css('background','blue');
					$(this).attr('rel', 'external');			
				
				}
			});
		
			this.external_links();
		
			lia.console("", "groupEnd");
		},
		
		popup_links : function() {
			lia.console("lia.popup_links()", "group");
			
			additional_txt = "[öffnet in einem Pop-up]";
			
			$("a[rel*=popup]").each(function() {
				lia.console("Anzahl a[rel=popup]: "+o_length, o);
				
				if (typeof $(this).attr('title') != 'undefined') {
					$(this).attr('title', $(this).attr('title')+additional_txt);
				}
				else {
					$(this).attr('title', additional_txt);
				}
				
				/*lia.console($(this).attr('rel'));*/
				
				regex = new RegExp(/(\d+)x(\d+)/);
				rel = $(this).attr('rel');
				
				get_popup_values = regex.exec(rel);
				/*lia.console(get_popup_values);
				lia.console(rel);
				lia.console(regex);*/
				
				//get_popup_values = $(this).attr('rel').match();
				if (typeof get_popup_values != 'undefined') {
					popup_width = get_popup_values[1];
					popup_height = get_popup_values[2];
				}
				/*lia.console(get_popup_values[1]);
				lia.console(popup_width);
				lia.console(popup_height);*/				
				
				$(this).click(function(){
			 		lia.popup_window($(this).attr('href'), popup_width, popup_height);
			 		//window.open($(this).attr('href'),'_blank'); return false; }
					return false;
				});
			});
			
			lia.console($("a[rel*=popup]"));
			lia.console("", "groupEnd");
		},
		
		popup_window : function(url, popup_width, popup_height) {
			lia.console("lia.popup_window()", "group");
			// Standard-Werte des Pop-up-Fensters
			if (typeof popup_width == 'undefined') {
				popup_width = 790;		
			}
			if (typeof popup_height == 'undefined') {
				popup_height = 760;
			}
	
			window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+popup_width+',height='+popup_height+',screenX=150,screenY=150,top=150,left=150');
			return false;
		},
		
		// Links deaktivieren
		dummy_links : function() {
			f_name = 'lia.dummy_links()';
			lia.group_start(f_name);
			lia.timer_start(f_name);

			o = $(".no_click");
			o_length = o.length;

			if (o_length > 0) {
				lia.console("Anzahl .no_click: "+o_length, o);
				o.each(function() {
					$(this).attr('title', "Dieser Link ist zur Zeit deaktiviert");
					$(this).click(function() {
						return false;
					});
				});
			}
			
			lia.timer_end(f_name);
			lia.group_end(f_name);
		},
		
		equal_height : function(group)
		{
			if ( _equal_height === 0 )
			{
				_equal_height_group = group;
				lia.console(_equal_height_group);
				
				_equal_height = 0;
				
				_equal_height_group.each(function(){
					thisHeight = $(this).height();
					if (thisHeight > _equal_height) {
						_equal_height = thisHeight;
					}
				});
				
				// Timeout für den IE6 bei Verwendung von IE7.js
				if ( typeof(IE7) === 'object' && $.browser.msie && jQuery.browser.version == '6.0' )
				{
					setTimeout(lia.equal_height, 2000);
				}
				else
				{
					_equal_height_group.height(_equal_height);
					_equal_height = 0;
				}
			}
			else
			{
				_equal_height_group.height(_equal_height);
				_equal_height = 0;
			}
		}
		
	};
	
	if (typeof($) === 'undefined')
	{
		return (lia.console('Biblitohek benötigt jQuery', 'error', true));
	}
	
	lia.console('JS-Version: '+ver);
	
	return lia;
	
}
