(function($) {
	$(document).ready(function($){
		/* :: footer :: */
		if (typeof $.fn.stickyFooter == "function") {	
	        $("#footer").stickyFooter();
		}
		
		/* :: boxshadow for ie8 and below ::*/
		if (typeof $.fn.boxShadow == "function" && $.browser.version.substr(0,1) > 6) {			
			$(".media").boxShadow({ 'xOffset':'0', 'yOffset':'0', 'blurRadius':'2', 'shadowColor':'#cccccc'});
		}

		/* :: carousel :: */
		$.easing.custom = function (x, t, b, c, d) {
			var s = 1.70158; 
			if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
			return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
		}		
		if (typeof $.fn.scrollable == "function") {					
			$("#flowpanes").scrollable({size: 1, clickable: false, easing: 'custom', speed:800}).circular();
			$(".carousel-nav").click(function(e){ e.preventDefault(); });
		}

		/* :: accortdion list for archive ::*/
		if (typeof $.fn.accordionList == "function") {							
			$(".accordionlist").accordionList();
		}
		
		/* :: newsticker iin annotation ::*/		
		if (typeof $.fn.innerfade == "function") {									
			$(".newsticker").innerfade();		
		}

		/* :: globalsearch :: */
		if(!($.browser.version.substr(0,1) == 6)){
			var $queryBar  =  $("#nav .search input.query");
			var $searchBar =  $queryBar.parents(".search-bar");
			var $searchAnimation = { speed:200, padding:20 };
			var $orgWidth = { queryBar: $queryBar.width(), searchBar: $searchBar.width() };					   
			$queryBar.focusin(function(){
				$queryBar.animate({width: $orgWidth.queryBar + $searchAnimation.padding}, $searchAnimation.speed);
				$searchBar.animate({width: $orgWidth.searchBar + $searchAnimation.padding}, $searchAnimation.speed);												
			}).focusout(function(){
				$queryBar.animate({width: $orgWidth.queryBar}, $searchAnimation.speed);
				$searchBar.animate({width: $orgWidth.searchBar}, $searchAnimation.speed);												
			});
		}
		
		var $queryBars = $(".search input.query, .blog-comment .fu .text");
		var $queryBarColor = {active:"#000", restore:$queryBars.css("color")}
		
		if($($queryBars).val() != $($queryBars).attr("title")){ $($queryBars).css("color",$queryBarColor.active); }
		else { $($queryBars).css("color",$queryBarColor.restore); }

		$queryBars.focusin(function(){ 
			if($(this).val() == $(this).attr("title"))
				$(this).val("").css("color",$queryBarColor.active);
		}).focusout(function(){
			if($(this).val() == "" || $(this).val() == " ")
				$(this).val($(this).attr("title")).css("color",$queryBarColor.restore);
		});

		/* :: bottom banners :: */
		$(".HBanner img.normal").hover(
		function() { $(this).stop().animate({"opacity": "0"}, "normal"); },
		function() { $(this).stop().animate({"opacity": "1"}, "normal"); });

		/* :: navigation level3 dropdown :: */
		//$("ul.level3").parent().end().click(function(e){e.stopPropagation();});

		var $menuOpen = false;
		$("ul#level2 li.dropdownmenu span.arrow").toggle(function(event) {
			$(this).parent().addClass("dropdownmenu-open");
			$(this).parent().find("ul.level3").slideDown('fast');			

			if(!$menuOpen){
				$("body").bind("click.hideMenu",function(e){
						$('.dropdownmenu-open .arrow').click();
						$menuOpen=false;
						$(this).unbind("click.hideMenu");
					});
			}
			$menuOpen=true;
		},function(){
				$(this).parent().removeClass("dropdownmenu-open");						
				$(this).parent().find("ul.level3").slideUp();

				$("body").unbind("click.hideMenu");
				$menuOpen=false;
		});
		
		/* :: conactlist expand/ collapse :: */
		$(".contactlist").each(function(e){
			var contactList
			if($(this).parents(".search-result-contacts").length > 0){
				contactList = $(".search-result-contacts .contactlist .person:gt(3)");
			}else {
				contactList = $(".contacts .contactlist .person:gt(1)");	
			}
		
			contactList.hide();
			$(".search-result-contacts .btn.expand, .contacts .btn.expand").toggle(function(e){
				$(this).removeClass("expand").addClass("collapse");
				$(this).children(":nth-child(1)").hide().next().show();
				$(this).attr("title", $(this).children(":nth-child(2)").text());
				contactList.show();										
				e.preventDefault();
			},function(){
				$(this).removeClass("collapse").addClass("expand");
				$(this).children(":nth-child(2)").hide().prev().show()
				$(this).attr("title", $(this).children(":nth-child(1)").text());			
				contactList.hide();
				e.preventDefault();
			});
		});		

		/* :: tablesorter :: */
		if (typeof $.fn.tablesorter == "function") {		
			$(".tablesorter.contacts-table, .tablesorter.product-table").collapsible("td.collapsible", { collapse: true, classChildRow:'row-expand' });
			$(".tablesorter.members-table").tablesorter({ headers: {4: {sorter: false} }});
			// $(".tablesorter.contacts-table").tablesorter({ headers: {4: {sorter: false},3: {sorter: false}} }); // NO SORTING HERE /ALC
			$(".tablesorter.product-table").tablesorter({ headers: {0: {sorter: false},1: {sorter: false},4: {sorter: false},5: {sorter: false}} });			
			$("td.collapsible a").toggle(
				function(){ $(this).parents("tr").addClass("current-expand");},
				function(){ $(this).parents("tr").removeClass("current-expand");
			});						
		}
		$(".table table tbody tr").hover(
		   function(){ $(this).addClass("highlight"); },
		   function(){ $(this).removeClass("highlight"); }
		);
		
		/* :: find el-net iframe :: */
		$(".VBanner .find-elnet").click(function(e){
			$(".popup-box.popup-find-elnet > .popup-box-content").html(showIframe($(this).attr("href")));
			$(".popup-box.popup-find-elnet").modal({overlayClose:true, overlayCss: {backgroundColor:"#000"}, closeClass: "popup-close", onClose: function (dialog){
				$.modal.close();
				$(".popup-box.popup-find-elnet > .popup-box-content").html("");
				return false;
			} });						   												
			e.preventDefault();
		});
		
		/* :: tip a friend :: */
		$(".toollist .tip").click(function(e){
			$(".popup-box .popup-box-content").html(showIframe($(this).attr("href")));
			$(".popup-box").modal({overlayClose:true, overlayCss: {backgroundColor:"#000"}, closeClass: "popup-close", onClose: function (dialog){
				$.modal.close();
				$(".popup-box > .popup-box-content").html("");
				return false;
			} });						   												
			e.preventDefault();
		});
		
		/* :: google map for location list :: */
		$(".locationlist .map-zoom").click(function(e){
			$(".popup-box .popup-box-content").addClass("map");
			$(".popup-box.popup-map").modal({overlayClose:true, overlayCss: {backgroundColor:"#000"}, closeClass: "popup-close" });						   												
			
			$geoInfo 	= 	$(this).parents(".location").find(".info");
			$geoHtml 	= 	"<strong>" + $geoInfo.find(".name").text() + "</strong>" + "<br/><br/>" + $geoInfo.find(".adr").text();
			$lat 		= 	$geoInfo.find(".latitude").text();
			$lon 		= 	$geoInfo.find(".longitude").text();	
			
			gMapInfo($geoHtml, $lat, $lon);

			e.preventDefault();
		});

		/* :: password field for filelists :: */
		$(".filebox.password-req .password-field").each(function(){
			var $passfield = $(this);
			$passfield.hide();
			$(this).parent().find("a").toggle(function(){
				$passfield.slideDown();
			},function(){
			 	$passfield.slideUp();
			}); 
		});

		// Auto-adjust height of the .mod element in teasers. 
		// Add "autoheight" on row.
		// TODO: write a function instead
		var whatHeight = (typeof document.body.style.maxHeight === "undefined") ? 'height' : 'min-height';
		$(".autoheight").each(function(){
			var highest = 0; 
			var $cols = $(this).find(".mod");
			$cols.each(function(){
				var $col = $(this);
				var $paddingFix = parseInt($col.css("padding-top").replace("px", "")) + parseInt($col.css("padding-bottom").replace("px", ""));
				var h = $col.outerHeight();
				if (h >= highest) {highest=h;}
				$col.css(whatHeight, highest - $paddingFix);				
			});
			$cols.each(function(){
				var $col = $(this);
				var $paddingFix = parseInt($col.css("padding-top").replace("px", "")) + parseInt($col.css("padding-bottom").replace("px", ""));
				$col.css(whatHeight, highest - $paddingFix);
			});
		});
		
	});
})(jQuery);


/* =========================================================
// jquery.innerfade.js
// Datum: 2008-02-14
// Firma: Medienfreunde Hofmann & Baldes GbR
// Author: Torsten Baldes
// Mail: t.baldes@medienfreunde.com
// Web: http://medienfreunde.com
// ========================================================= */
(function($) {

    $.fn.innerfade = function(options) {
        return this.each(function() {   
            $.innerfade(this, options);
        });
    };

    $.innerfade = function(container, options) {
        var settings = {
        	'animationtype':    'fade',
            'speed':            'slow',
            'type':             'sequence',
            'timeout':          5000,
            'containerheight':  'auto',
            'runningclass':     'innerfade',
            'children':         null
        };
        if (options)
            $.extend(settings, options);
        if (settings.children === null)
            var elements = $(container).children();
        else
            var elements = $(container).children(settings.children);
        if (elements.length > 1) {
            $(container).css('position', 'relative').css('height', settings.containerheight).addClass(settings.runningclass);
            for (var i = 0; i < elements.length; i++) {
                $(elements[i]).css('z-index', String(elements.length-i)).css('position', 'absolute').hide();
            };
            if (settings.type == "sequence") {
                setTimeout(function() {
                    $.innerfade.next(elements, settings, 1, 0);
                }, settings.timeout);
                $(elements[0]).show();
            } else if (settings.type == "random") {
            		var last = Math.floor ( Math.random () * ( elements.length ) );
                setTimeout(function() {
                    do { 
							current = Math.floor ( Math.random ( ) * ( elements.length ) );
						} while (last == current );             
							$.innerfade.next(elements, settings, current, last);
                }, settings.timeout);
                $(elements[last]).show();
						} else if ( settings.type == 'random_start' ) {
								settings.type = 'sequence';
								var current = Math.floor ( Math.random () * ( elements.length ) );
								setTimeout(function(){
									$.innerfade.next(elements, settings, (current + 1) %  elements.length, current);
								}, settings.timeout);
								$(elements[current]).show();
						}	else {
							alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
						}
				}
    };
    $.innerfade.next = function(elements, settings, current, last) {
        if (settings.animationtype == 'slide') {
            $(elements[last]).slideUp(settings.speed);
            $(elements[current]).slideDown(settings.speed);
        } else if (settings.animationtype == 'fade') {
            $(elements[last]).fadeOut(settings.speed);
            $(elements[current]).fadeIn(settings.speed, function() {
							removeFilter($(this)[0]);
						});
        } else
            alert('Innerfade-animationtype must either be \'slide\' or \'fade\'');
        if (settings.type == "sequence") {
            if ((current + 1) < elements.length) {
                current = current + 1;
                last = current - 1;
            } else {
                current = 0;
                last = elements.length - 1;
            }
        } else if (settings.type == "random") {
            last = current;
            while (current == last)
                current = Math.floor(Math.random() * elements.length);
        } else
            alert('Innerfade-Type must either be \'sequence\', \'random\' or \'random_start\'');
        setTimeout((function() {
            $.innerfade.next(elements, settings, current, last);
        }), settings.timeout);
    };

})(jQuery);

// **** remove Opacity-Filter in ie ****
function removeFilter(element) {
	if(element.style.removeAttribute){
		element.style.removeAttribute('filter');
	}
}
function showIframe($source, $settings){
        var $opt = {
        	'scrolling'		:    'no',
			'frameborder'	:	 '0',
			'errorTxt'		:	 '<p>Your browser does not support iframes.</p>'
        };
        if ($settings)
            $.extend($opt, $settings);
	return "<iframe src ="+ $source +" frameborder="+$opt.frameborder+" scrolling="+$opt.scrolling+">"+$opt.errorTxt+"</iframe>";
}

/*
 * Extending gMap for location list
 * Created by Mith
 * Requires:
 *   jQuery 1.3+, gMap plugin
 */
function gMapInfo($geoHtml, $lat, $lon){
	if(typeof $.fn.gMap == "function"){
			$(".popup-map .map").gMap({ 
						   markers: [{ 
										latitude: $lat,
										longitude: $lon,
										html:  $geoHtml,
										popup: true 
									}], 
						   controls: ["GLargeMapControl3D"], 
						   zoom:16, 
						   icon: { 
									image: "/de2010/css/img/ico_map_pin.png", 
									iconsize:           [30, 35],
									iconanchor:         [0, 25],
									infowindowanchor:   [15, 5]
								}
						}); //GMAP											
	}else {
		$(".popup-map .map").text("## gMap initialization error ##");
	}
}

/*
 * Created by Mith
 * MIT (http://www.opensource.org/licenses/mit-license.php) licensed.
 *
 * Version: 0.1
 *
 * Requires:
 *   jQuery 1.3+
 */
(function($){
	var footer;
	$.fn.extend({
	  stickyFooter: function(options) {
		footer = this;
		
		positionFooter();
		$(window).resize(positionFooter);
	
		function positionFooter() {
		  var docHeight = $(document.body).height() - $("#sticky-footer-push").height();
		  if(docHeight < $(window).height()){
			var diff = $(window).height() - docHeight;
			if (!$("#sticky-footer-push").length > 0) {
			  $(footer).before('<div id="sticky-footer-push"></div>');
			}
			$("#sticky-footer-push").height(diff);
		  }
		}
	  }
	});
})(jQuery);

/*
 * Created by Mith
 * MIT (http://www.opensource.org/licenses/mit-license.php) licensed.
 *
 * Version: 0.1
 *
 * Requires:
 *   jQuery 1.3+
 */
(function($){
	var list;
	$.fn.extend({
	  accordionList: function(options) {
		list = this;
		list.each(function(){
			list.find("ul").hide()
			.end().find("ul.open").show().prev(".head").addClass("selected");
	
			list.find("li a").click(function(e) {
				var checkElement = $(this).next();
				if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
					e.preventDefault();
				}
				if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
					$(list).find('ul:visible').slideUp('normal').prev(".head").removeClass("selected");
					checkElement.slideDown('normal').prev("a.head").addClass("selected");
					e.preventDefault();
				}
			});
		});
	  }
	});
})(jQuery);

/*
 * UNDER CONSTRUCTION
 * MIT (http://www.opensource.org/licenses/mit-license.php) licensed.
 *
 * Version: 0.1
 *
 * Requires:
 *   jQuery 1.3+
 */
(function($) {
	$.fn.boxShadow = function(options) {
        var settings = {
        	'xOffset'		:    '0',
            'yOffset'		:    '0',
            'blurRadius'	:    '5',
            'shadowColor'	:    '#000'
        };
        if (options)
            $.extend(settings, options);

		if (!($.browser.msie) && $.browser.version.substr(0,1) <= 8 && typeof document.body.style.boxShadow == "undefined") return;
		return this.each(function(){
			$(this).css({ position:	"relative", zoom: 1, zIndex: "2" });
			$(this).parent().css({ position: "relative" });
			
			var div=document.createElement("div");
			$(this).parent().append(div);

			var _top, _left, _width, _height;
			if (settings.blurRadius != 0) {
				$(div).css("filter", "progid:DXImageTransform.Microsoft.Blur(pixelRadius="+(settings.blurRadius)+", enabled='true')");
				_top = 		settings.yOffset-settings.blurRadius-1;
				_left =		settings.xOffset-settings.blurRadius-1;
				_width =	$(this).outerWidth()+1;
				_height =	$(this).outerHeight()+1;
			} else {
				_top = 		settings.yOffset;
				_left =		settings.xOffset;
				_width = 	$(this).outerWidth();
				_height = 	$(this).outerHeight();
			}
			$(div).css({
				top: 		_top,
				left:		_left,
				width:		_width,
				height:		_height,
				background:	settings.shadowColor,
				position:	"absolute",
				zIndex:		1
			});
			
	  });
	};
})(jQuery);

(function($){
    $.fn.jExpand = function(){
        var element = this;
        $(element)
		.find("tr:odd").addClass("odd")
		.end().find("tr:not(.odd)").hide()
		.end().find("tr:first-child").show()
		.end().find("tr.odd").click(function() {
            element.next("tr").toggle();
        });        
    }    
})(jQuery); 