/**
* 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();
    });


	/*$('.weissnich *').tooltip({
		showURL: false,
	});*/

	/*$('.cycle').cycle({
			    fx : 'scrollLeft',
			    timeout: 2000,
			    speed: 600,Fdatepick

				 });*/


	$('#s5').cycle({
        fx     : 'scrollLeft',
        timeout: 7000,
        pause  : 1,
        delay  : -1500
    });

	/*$('.car_fade').cycle({
		fx : 'scrollLeft',
		timeout: 4500,
		pause : 1,
		delay : -1500
	});*/


    /*$('h1').click(function(){
        $('h1').attr({ style:"border: 1px solid red;"});
        alert('Ich habe auf die H1 geklickt.');
    })*/

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

    /* 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);
        //alert("inputstring : "+inputString.length);
		if(inputString.length == 0) {
			// Hide the suggestion box.
			$('#suggestions').hide();
		} else {
		    //alert("hi");
			//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);*/
	}

	$(function(){
		$("[title]").mbTooltip({ // also $([domElement])..mbTooltip  >>  in this case only children element are involved
			opacity : .85,       //opacity
			wait:300,           //before show
			cssClass:"default",  // default = default
			timePerWord:70,      //time to show in milliseconds per word
			hasArrow:false,			// if you whant a little arrow on the corner
			imgPath:"images/tooltip/",
			ancor:"mouse", //"parent"  you can ancor the tooltip to the mouse position or at the bottom of the element
			shadowColor:"white" //the color of the shadow
		});
	})

