/*
 * lia_functions.js
 * v 0.4
 * 08.05.2008 vr: Idee umgesetzt
 * 
 */

jQuery.lia = {
	
	// Wrapper für console.log (Ausgabe in der Firebug-Console);
	// lässt den IE nicht abstürzen
	log : function(what, msg_type) {
		if (typeof(what) != 'undefined') {
			try {
				if (typeof(msg_type) != 'undefined') {
		   		eval("console."+msg_type+"(what)");
			   }
			   else {
			   	console.debug(what);
			   }
			}
			catch(err) {
				
			}
		}
	},
	
	muh : function(alertOrPrint) {
		if (typeof alertOrPrint == 'undefined') {
			this.log("muh!");
		} else {
			alert("muh");
		}
	
		return false;
	},
	
	// behebt das Flickern von Hintergrund-Bildern im IE(6)
	ie6_noflickr : function() {
		$.lia.log("$.lia.ie6_noflickr()", "group");
		try {
			document.execCommand("BackgroundImageCache", false, true);
		} 
		catch (err) {
		}
		
		$.lia.log("", "groupEnd");
	},
	
	// Externe Links mit Funktion versehen
	external_links : function () {
		//this.log("$.lia.external_links()", "group");
		$("a[rel=external]").each(function()
		{
			var $this = $(this);
			
/* 			$.lia.log(typeof(this));
			$.lia.log(typeof($(this)));
			$.lia.log(typeof($this));
			$.lia.log($this, "dir");
			$.lia.log(typeof(this) == "object2", "assert");			 */
			
			$(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) && $(this).attr('href').indexOf('https://') == -1)
				{
					window.open(_base + $(this).attr('href'), '_blank');
				}
				else
				{
					window.open($(this).attr('href'), '_blank');
				}
				return false;
			});
	
			if ($(this).attr('class') == 'pdf') {
				if (typeof $(this).attr('title') != 'undefined') {
					$(this).attr('title',"PDF-Dokument ("+$(this).attr('title') +") | öffnet in neuem Fenster").addClass('external');
				}
				else {
					$(this).attr('title',"PDF-Dokument | öffnet in neuem Fenster").addClass('external');
				}
	
			} else {
				
				additional_txt = "[öffnet in neuem Fenster]";
				
				if (typeof $(this).attr('title') != 'undefined') {
					$(this).attr('title', $(this).attr('title') + " " + additional_txt);
				}
				else {
					if ( ($(this).attr('href').indexOf('http://') == -1) && $(this).attr('href').indexOf('https://') == -1)
					{
			   			$(this).attr('title', _base + $(this).attr('href') + " " + additional_txt).addClass('external');
			   		}
					else
					{
						$(this).attr('title', $(this).attr('href') + " " +additional_txt).addClass('external');
					}
				}				

			}
	
		});
		//$.lia.log("", "groupEnd");
	},
	
	// Externe Links auszeichnen
	mark_external_links : function() {
		//$.lia.log("$.lia.mark_external_links()", "group");
	
		// PDFs
		$("div#content a[href^='.pdf']").each(function()
		{
			//$.lia.log($(this).attr('href')+" = external pdf");
			$(this).attr('rel', 'external');
			$(this).addClass('pdf');		
		});
		
		// Links mit http:// in URL
		$("div#content a[href^='http']").each(function()
		{
			foo = new RegExp(_base);
			
			if ($(this).attr('href').search(foo) == -1)
			{
				// wenn _base nicht in url
				//$.lia.log($(this).attr('href')+" = external");
				//$(this).css('background','blue');
				$(this).attr('rel', 'external');			
			
			}
		});
	
		this.external_links();
	
		//$.lia.log("", "groupEnd");
	},
	
	popup_links : function() {
		//this.log("$.lia.popup_links()", "group");
		$("a[rel=popup]").each(function()
		{
			$(this).click( function() { window.open($(this).attr('href'),'_blank'); return false; } );
			//alert(typeof $(this).attr('title') == 'undefined');
		});
		
		//$.lia.log("", "groupEnd");
	},
	
	// Links deaktivieren
	dummy_links : function() {
		//$.lia.log("$.lia.dummy_links()", "group");
		$("a.noclick").each(function()
		{
			$(this).attr('title', "Dieser Link ist zur Zeit deaktiviert");
			$(this).click(function() {
				return false;
			});
		});
		
		//$.lia.log("", "groupEnd");
	},
	
	// Elemente mit CSS-Klasse "hidden" verstecken
	hide_items : function() {
		//this.log("$.lia.hide_items()", "group");
		$(".hidden").each(function()
		{
			$(this).hide();
		});
		
		//$.lia.log("", "groupEnd");
	}
	
};

// extension for creating elements with jQuery
jQuery.extend({ createElement : function(elementName) { return jQuery(document.createElement(elementName)); } });
