//Build a PHP like $_GET Array
var $_GET = {};

document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
    function decode(s) {
        return decodeURIComponent(s.split("+").join(" "));
    }

    $_GET[decode(arguments[1])] = decode(arguments[2]);
});


function prealert(input_array) {
	var x = "";
	for (key in input_array) {
		x += key+" = "+input_array[key]+"\n";
	}
	alert(x);
}

$(function(){
	$("a").click(function(){
		$(this).blur();
	});
	$("a").focus(function(){
		$(this).blur();
	});
	
	
	/** Korrekturen für MSIE 6 **/
	if ($.browser.msie==true && $.browser.version=="6.0") {
		/** PNG FIX **/
		 
		/** TOPMENU FIX **/
			$('#topnav .level1').mouseover(function(){
				$("ul.submenu", this).show();
			}).mouseout(function(){
				$("ul.submenu", this).hide();
			});
			
			//$('#page').css("margin-top", "120px");
			$('#header').css("position", "absolute").css("z-index", "9999999").css("top", "0px").css("left", "0px");
			
		/** Startseite Overlay Fix**/
			$('#dot_map .dot').mouseover(function(){
				$("a", this).show();
			}).mouseout(function(){
				$("a", this).hide();
			});
			
			/* IE6 Hinweis */
			$('#header').after("<div id='ie6Msg'>Unsere Seiten sind für aktuelle Browser programmiert. Um den vollen Umfang nutzen zu können, führen Sie bitte ein<br /> Browserupdate aus. Dies wird auch zu Ihrer eigenen Internet-Sicherheit dringend empfohlen.</div>");
			
	}

        //TOOLTIPPS FÜR STANDORTKARTE UND STELLENLISTE
        coda_tooltip();
	
});


function coda_tooltip(){



    $('.bubbleInfo').each(function () {

        // options
        var distance = 10;
        var time = 250;
        var hideDelay = 250;

        var hideDelayTimer = null;

        // tracker
        var beingShown = false;
        var shown = false;

        var trigger = $('.trigger', this);
        var popup = $('.popup', this).css('opacity', 0);

        // set the mouseover and mouseout on both element
        $([trigger.get(0), popup.get(0)]).mouseover(function (e) {
          // stops the hide event if we move from the trigger to the popup element
          if (hideDelayTimer) clearTimeout(hideDelayTimer);

          // don't trigger the animation again if we're being shown, or already visible
          if (beingShown || shown) {
            return;
          } else {
            beingShown = true;

            // reset position of popup box
            
            popup.css({
              top: e.pageY - $('#page').css("padding-top").replace("px", ""),
              left: (e.pageX + 120) - $('#page').offsetLeft,
              display: 'block' // brings the popup back in to view
            })

            // (we're using chaining on the popup) now animate it's opacity and position
            .animate({
              top: '-=' + distance + 'px',
              opacity: 1
            }, time, 'swing', function() {
              // once the animation is complete, set the tracker variables
              beingShown = false;
              shown = true;
            });
          }
        }).mouseout(function () {
          // reset the timer if we get fired again - avoids double animations
          if (hideDelayTimer) clearTimeout(hideDelayTimer);

          // store the timer so that it can be cleared in the mouseover if required
          hideDelayTimer = setTimeout(function () {
            hideDelayTimer = null;
            popup.animate({
              top: '-=' + distance + 'px',
              opacity: 0
            }, time, 'swing', function () {
              // once the animate is complete, set the tracker variables
              shown = false;
              // hide the popup entirely after the effect (opacity alone doesn't do the job)
              popup.css('display', 'none');
            });
          }, hideDelay);
        });
      });
}

var ENV = "production";
var baseUrl = SERVER_HTTP_HOST() + "/ci_admin/";
var baseUrlFileadmin = baseUrl.replace(/ci_admin\//i, "");


function SERVER_HTTP_HOST(){
	var url = window.location.href;
	url = url.replace("http://", "");

	var urlExplode = url.split("/");
	var serverName = urlExplode[0];

	serverName = 'http://'+serverName;
	return serverName;
}




/** 
 * Zeigt ein Web2.0 LoadingOverlay mit LoadingIndicator an.
 * Skaliert ausserdem automatisch auf die Dimensionen von "object" oder des gesamten Fensters!!
 **/
function showOverlay(object, loadingDiv_ID){
	if (loadingDiv_ID=="" || typeof(loadingDiv_ID)=="undefined" || typeof(loadingDiv_ID)==undefined) {
		loadingDiv_ID = "#divLoading";
	}
	
	try {
		var offset = $(object).offset();
		var newHeight = $(object).outerHeight();
		var newWidth = $(object).outerWidth();
		var pos_x = offset.left;
		var pos_y = offset.top;
	}
	catch (e) {
		var newHeight = $(document).outerHeight();
		var newWidth = "100%";
		var pos_x = 0;
		var pos_y = 0;		
	}
	/*
	var av_height = screen.availHeight;
	var center = (av_height/2) + scrolltop;
	var offset_from_center = center - (tab_height*2);
	*/
	$(loadingDiv_ID).height(newHeight);
	$(loadingDiv_ID).css("width", newWidth);
	$(loadingDiv_ID).css("top", pos_y);
	$(loadingDiv_ID).css("left", pos_x);
	if (newWidth==0 || newHeight==0) {
		return;
	}
	else {
		$(loadingDiv_ID).show();
	}
	// alert("newWidth "+newWidth+"  newHeight"+newHeight);
}


// Versteckt das Overlay wieder
function hideOverlay(){
	$(loadingDiv_ID).hide();
}


//MERKLISTE
function merklisteAddItem(id, type){
    $.ajax({
        type: "POST",
        url: baseUrl + "merkliste/merklisteAddItem/",
        cache: false,
        data: "&id=" + id + "&type=" + type,
        async: true,
        success: function(data) {
            alert("Zur Merkliste hinzugefügt");
        }
    });
    return false;
}

function merklisteRemoveItem(id, type, idObjHide){
    $.ajax({
        type: "POST",
        url: baseUrl + "merkliste/merklisteRemoveItem/",
        cache: false,
        data: "&id=" + id + "&type=" + type,
        async: true,
        success: function(data) {
            if(idObjHide != ""){
                 $('#' + idObjHide).addClass('toBeFadedOut');
                $('#' + idObjHide).fadeOut('slow');
            }
        }
    });
    return false;
}

 /** Größe des Anzeigebereichs "#page" automatisch einstellen **/
function resize_page_height() {
    var current_height = $('#page').height();
    var new_height = current_height;
    var offet = $('#page').offset();
    var availHeight = $(document).height();
    var minusHeight = $('#footer').height();

    if ( (current_height+offet.top-minusHeight) < availHeight) new_height = current_height+offet.top-minusHeight;
    $('#page').height(new_height);
}

/**
 * Länge eines assoziativen Arrays
 * Beispiel:
 * var mapAjaxProcesses = new Array();
 * mapAjaxProcesses["testKey"] = "true";
 * alert(getAssocArrayLength(mapAjaxProcesses)); //Gibt 1 zurück
 */
function getAssocArrayLength(tempArray) {
   var countResults = 0;
   for ( tempValue in tempArray ) {
       if(tempArray.hasOwnProperty(tempValue)){
        countResults++;
       }
   }
   return countResults;
}
