/* menu.js instructions */
/*
Copyright 8007-8010 by Marco van Hylckama Vlieg

web: http://www.i-marco.nl/weblog/
email: marco@i-marco.nl

Free to use any way you like.
*/
	jQuery.fn.initMenu = function() {
		return this.each(function() {
			var theMenu = $(this).get(0);
			$('.acitem', this).hide();
			$('li.expand > .acitem', this).show();
			$('li.expand > .acitem', this).prev().addClass('active');
			$('li a', this).click(
			function(e) {
				e.stopImmediatePropagation();
				var theElement = $(this).next();
				var parent = this.parentNode.parentNode;
				if ($(parent).hasClass('noaccordion')) {
					if (theElement[0] === undefined) {
						window.location.href = this.href;
					}
					$(theElement).slideToggle(0, function() {
						if ($(this).is(':visible')) {
							$(this).prev().addClass('active');
						}
						else {
							$(this).prev().removeClass('active');
						}
					});
					return false;
				}
				else {
					if (theElement.hasClass('acitem') && theElement.is(':visible')) {
						if ($(parent).hasClass('collapsible')) {
							$('.acitem:visible', parent).first().slideUp(0, function() {
								$(this).prev().removeClass('active');
							});
							return false;
						}
						return false;
					}
					if (theElement.hasClass('acitem') && !theElement.is(':visible')) {
						$('.acitem:visible', parent).first().slideUp(0, function() {
							$(this).prev().removeClass('active');
						});
						theElement.slideDown(0, function() {
							$(this).prev().addClass('active');
						});
						return false;
					}
				}
			});
		});
		};


/* jQuery DETECT */

(function() {

    var BrowserDetect = {
        init: function () {
            this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
            this.version = this.searchVersion(navigator.userAgent)
                || this.searchVersion(navigator.appVersion)
                || "an unknown version";
            this.OS = this.searchString(this.dataOS) || "an unknown OS";
        },
        searchString: function (data) {
            for (var i=0;i<data.length;i++) {
                var dataString = data[i].string;
                var dataProp = data[i].prop;
                this.versionSearchString = data[i].versionSearch || data[i].identity;
                if (dataString) {
                    if (dataString.indexOf(data[i].subString) != -1)
                        return data[i].identity;
                }
                else if (dataProp)
                    return data[i].identity;
            }
        },
        searchVersion: function (dataString) {
            var index = dataString.indexOf(this.versionSearchString);
            if (index == -1) return;
            return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
        },
        dataBrowser: [
            {
                string: navigator.userAgent,
                subString: "Chrome",
                identity: "Chrome"
            },
            {   string: navigator.userAgent,
                subString: "OmniWeb",
                versionSearch: "OmniWeb/",
                identity: "OmniWeb"
            },
            {
                string: navigator.vendor,
                subString: "Apple",
                identity: "Safari",
                versionSearch: "Version"
            },
            {
                prop: window.opera,
                identity: "Opera"
            },
            {
                string: navigator.vendor,
                subString: "iCab",
                identity: "iCab"
            },
            {
                string: navigator.vendor,
                subString: "KDE",
                identity: "Konqueror"
            },
            {
                string: navigator.userAgent,
                subString: "Firefox",
                identity: "Firefox"
            },
            {
                string: navigator.vendor,
                subString: "Camino",
                identity: "Camino"
            },
            {       // for newer Netscapes (6+)
                string: navigator.userAgent,
                subString: "Netscape",
                identity: "Netscape"
            },
            {
                string: navigator.userAgent,
                subString: "MSIE",
                identity: "Explorer",
                versionSearch: "MSIE"
            },
            {
                string: navigator.userAgent,
                subString: "Gecko",
                identity: "Mozilla",
                versionSearch: "rv"
            },
            {       // for older Netscapes (4-)
                string: navigator.userAgent,
                subString: "Mozilla",
                identity: "Netscape",
                versionSearch: "Mozilla"
            }
        ],
        dataOS : [
            {
                string: navigator.platform,
                subString: "Win",
                identity: "Windows"
            },
            {
                string: navigator.platform,
                subString: "Mac",
                identity: "Mac"
            },
            {
                string: navigator.userAgent,
                subString: "iPhone",
                identity: "iPhone/iPod"
            },
            {
                string: navigator.platform,
                subString: "Linux",
                identity: "Linux"
            }
        ]

    };

    BrowserDetect.init();

    window.$.client = { os : BrowserDetect.OS, browser : BrowserDetect.browser };

})();

/* INSTRUCTIONS */


$(document).ready(function() { 

		$('.menu').initMenu(); /*initialize menu.js*/
		var $advSearchButton = $('a#advSearch,img#closeWindow');
		var $advSearchForm = $('#advSearchForm');
		var $keyVisualImg = $('img#keyVisualImg');
		var $tooltip = $('span.tooltip');
		var $tooltipArrow = $('<div class="triangle"></div>');
		var $commentButton = $('section#comments h1.switch');
		var $comments = $('section#comments article , section#comments form');
		var $placeHeldTargets = $('form#search input.searchField, form#login input, form#default input, #advSearchForm input');
		var $toggleOverview = $('a#toggleOverview');
		var $toggleOverviewClose = $('a#toggleOverviewClose');
		var $overviewP = $('#overview.urteil p');
		var $overview = $('#overview.urteil');
		var $overviewMore = $('#overview #overviewMore');

		patchAutocomplete();
		
		if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/Android/i)) || (navigator.userAgent.match(/IEMobile/i))) {
			$('html').addClass('touchOS');
				} else {
			$('html').addClass('no-touchOS');
		}
		
		$tooltip.append($tooltipArrow);
		$placeHeldTargets.placeHeld();
		
		$advSearchButton.click(function() {
			if ($advSearchForm.is(':visible')) {
				$advSearchForm.slideUp(180);
				$advSearchButton.html('<img src="/img/plus.png" alt="plus" width="11" height="11" />Hier klicken f&uuml;r erweiterte Suche').css({
					'opacity': ''
				});
			} else {
				$advSearchForm.slideDown(180);
				$advSearchButton.html('<img src="/img/minus.png" alt="minus" width="11" height="11" />Erweiterte Suche schlie&szlig;en').css({
					opacity: 0.75
				});
			}
			return false;
		});
		$commentButton.click(function() {
			if ($comments.is(':visible')) {
				$comments.fadeOut();
				$commentButton.html('<img src="/img/plus.png" alt="plus" width="11" height="11" id="plusMinus" />Kommentare ('+contentComments+') einblenden<span class="tooltip"><div class="triangle"></div>'+contentComments+' Kommentare vorhanden<span>zum Aufklappen klicken</span></span>');
				$commentButton.blur();
			} else {
				$comments.fadeIn();
				$commentButton.html('<img src="/img/minus.png" alt="minus" width="11" height="11" id="plusMinus" />Kommentare ausblenden');
			}
			return false;
		});
		$('a#tcc').hover(

		function() {
			$('img', this).attr('src', '/img/tccHover.gif');
		}, function() {
			$('img', this).attr('src', '/img/tcc.gif');
		});
		$('a#manitu').hover(

		function() {
			$('img', this).attr('src', '/img/manituHover.gif');
		}, function() {
			$('img', this).attr('src', '/img/manitu.gif');
		});
		$toggleOverview.click(function() {
			$overviewP.toggle('fast', function() {
				$toggleOverview.hide();
				$toggleOverviewClose.show();
				$overviewMore.hide();
			});
		});
		$toggleOverviewClose.click(function() {
			$overviewP.toggle('fast', function() {
				$toggleOverview.show();
				$toggleOverviewClose.hide();
				$overviewMore.show();
			});
		});
		
		if($.client.os == 'Mac') {
			$('html').addClass('mac');}
		else if($.client.os == 'Windows'){
			$('html').addClass('windows');}
		else if($.client.os == 'Linux'){
			$('html').addClass('linux');}
	});

