/*
 * lia_functions.js UTF-8
 * v 0.5
 * 
 */


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() {
			$.lia.log("Anzahl a[rel=external]:", "count");
			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) {
					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 (typeof $(this).attr('title') != 'undefined') {
					$(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.log($("a[rel=external]"));
		$.lia.log("", "groupEnd");
	},
	
	// Externe Links auszeichnen
	mark_external_links : function() {
		$.lia.log("$.lia.mark_external_links()", "group");
	
		// PDFs
		$("a[href*=.pdf]").each(function() {
			$.lia.log($(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.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");
		
		additional_txt = "[öffnet in einem Pop-up]";
		
		$("a[rel*=popup]").each(function() {
			$.lia.log("Anzahl a[rel=popup]:", "count");
			
			if (typeof $(this).attr('title') != 'undefined') {
				$(this).attr('title', $(this).attr('title')+additional_txt);
			}
			else {
				$(this).attr('title', additional_txt);
			}
			
			/*$.lia.log($(this).attr('rel'));*/
			
			regex = new RegExp(/(\d+)x(\d+)/);
			rel = $(this).attr('rel');
			
			get_popup_values = regex.exec(rel);
			/*$.lia.log(get_popup_values);
			$.lia.log(rel);
			$.lia.log(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.log(get_popup_values[1]);
			$.lia.log(popup_width);
			$.lia.log(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.log($("a[rel*=popup]"));
		$.lia.log("", "groupEnd");
	},
	
	popup_window : function(url, popup_width, popup_height) {
		this.log("$.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() {
		$.lia.log("$.lia.dummy_links()", "group");
		$("a.no-click").each(function() {
			$.lia.log("Anzahl a.no-click:", "count");
			$(this).attr('title', "Dieser Link ist zur Zeit deaktiviert");
			$(this).click(function() {
				return false;
			});
		});
		$.lia.log($("a.no-click"));
		
		$.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");
	}
	
};
