/**
* Funktion ermittelt die Position des Scrollbalkens auf der Seite
* Mehr Infos hier: http://www.quirksmode.org/viewport/compatibility.html
*
*/
function get_scrolling_offset() {
    var x,y;
    if (self.pageYOffset) {
        x = self.pageXOffset;
        y = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        x = document.documentElement.scrollLeft;
        y = document.documentElement.scrollTop;
    } else if (document.body) {
        x = document.body.scrollLeft;
        y = document.body.scrollTop;
    }
    return y;
}

$(document).ready(maininit);
function maininit() {
    /* Funktion zeigt beim absenden eines Formulares das DIV loader an, vergrößert dessen Größe mit attr */
    $('input[@type^="submit"]').click(function(){
        var scroll_position = get_scrolling_offset();
    	var total_height = $('#wrapper').height();
		$('#loader').attr({ style: "height: " + total_height + "px;"});
		$('#loaderimg').attr({ style: "position: absolute; width: 100%; top: " + (scroll_position - 0) + "px;"});
        $('#loader').toggle();
    });

	
	
	
	

    /*$('h1').click(function(){
        $('h1').attr({ style:"border: 1px solid red;"});
        alert('Ich habe auf die H1 geklickt.');
    })*/
    
    
    $('a.external').click(function(){
		window.open(this.href);
		return false;
		});

    /********************************************
    ********************************************/

    /* Schiebt das in rel angegebene Element zusammen oder auÃŸeinander */
    $('a.slideToogle').click(function(index){
        $(this).hide();
        var target = '#' + $(this).attr('rel');
        $(target).slideToggle('slow');
    });

    /********************************************
    ********************************************/

    /* Show-Hide-Funktionen */
    $('a.showhide').click(function() {
        var myid = '#' + $(this).attr('rel');
        $(myid).toggle();
        return false;
    });

    /********************************************
    ********************************************/



    /* Datumspicker initieren */
    $.datePicker.setLanguageStrings(
    	['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
    	['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
    	{p:'zurück', n:'vorwärts', c:'schließen', b:'Datum wählen'}
    );
    $.datePicker.setDateFormat('dmy','.');

    var datumzeit = new Date();
    var today     = datumzeit.getDate() + '.' + (datumzeit.getMonth() + 1) + '.' + datumzeit.getFullYear();
    $('input.date-picker').datePicker({
        startDate: '01.01.2000',
        endDate: undefined,
        firstDayOfWeek: 1
    });
    $('input.date-picker-till-now').datePicker({
        startDate: '01.01.2000',
        endDate: undefined,
        firstDayOfWeek: 1
    });

    $('#inputString').keyup(function() {
        var input = (this).value;
            lookup(input);
    });

	/*function()
	{
		$.ImageBox.init(
			{
				loaderSRC: 'images/imagebox/loading.gif',
				closeHTML: '<img src="images/imagebox/close.png" />'
			}
		);
	}*/

};
	function lookup(inputString) {
		var formdata = $("input").serialize();
        console.log(formdata);
		if(inputString.length == 0) {
			// Hide the suggestion box.
			$('#suggestions').hide();
		} else {
			/*alert('Bereich: '+area+"  ips: "+inputstring);*/
			/*var area = $('#area']).getProperty('value');*/

			$.post("inc/rpc.php",formdata, function(data){
				if(data.length >0) {
					$('#suggestions').show();
					$('#autoSuggestionsList').html(data);
				}
			});
		}
	} // lookup


	function fill(thisValue) {
		$('#inputString').val(thisValue);
		setTimeout("$('#suggestions').hide();", 200);
	}
	function setid(thisValue) {
		$('#id').val(thisValue);
		/*setTimeout("$('#suggestions').hide();", 200);*/
	}


