// set the page to the middle of the browser
$(document).ready(function()
{
	// no more...resizeHomeImage();$


    if ($("img#bgImageHome").length > 0)
    {
        $("div#container").height($("img#bgImageHome").height());
        //$("div#quickLinksContent").css("display", "none");
        $("img#newsContentArrow").css("display", "none");
		$("img#quickLinksContentArrow").css("display", "none");
        //setHomeOpacity();
    }

    positionFooter();

    $(window).resize(function()  { positionFooter(); });
    $(window).scroll(function()  { checkScroll(); });


	/*
	centerPage();

	$(window).resize(function()  { centerPage(); });

	// fader fÃ¼r hometeils
	$("li.home").hover(
		function () { $(this).find("img.home2").fadeIn(50); },
		function () { $(this).find("img.home2").fadeOut(50); }
	);

   // mail fÃ¼r footer
   $('#contactmail').attr('href', 'mailto:info@naturgartenleben.ch');

   // impressum anzeigen oder nicht
   $('div#impressum').click(function()
   {
	   if($('div#impressumBig').css("display") == "none") { $('div#impressumBig').fadeIn(100); }
	   else { $('div#impressumBig').fadeOut(100); }
	});
	*/
});

/*
function setHomeOpacity()
{
    //console.log($("#news .quickLinks").innerHeight());
    $("#news .rightBoxBG").height($("#news .quickLinks").innerHeight()).css({opacity:0.7});
    $("#quickLinksHome .rightBoxBG").height($("#quickLinksHome .quickLinks").innerHeight()).css({opacity:0.7});
}
*/


// center the page
 function centerPage()
{
	var cheight  = $("div#pagecontent").innerHeight();
	var wheight  = $(window).height() - ($("div#footer").height()+20); //  hÃ¶he vom footer abgezogen inklusive abstand zu footer inklusive margin top=20

	// hÃ¶he des seiten inhalts ohne footer "page"
	if(cheight< (wheight)) { $("div#page").css("height", wheight+"px"); }
	else {$("div#page").css("height", cheight+"px"); }

	// margin-top von "pagecontent";
	var cmargin = Math.round(($("div#page").height()-cheight)/2) +10;
	$("div#pagecontent").css("top", cmargin+"px");
}

function getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	arrayPageSize = [w,h];
	return arrayPageSize;
}

function resizeHomeImage()
{
	var size = getPageSize();
	$("img#bgImageHome").css("width", (size[0])+"px");
	$("img#bgImageHome").css("height", (size[1]-42)+"px");
}

function positionFooter()
{
    var size = getPageSize();
    var contentHeight = $("div#container").height();
    //alert("juu"+size[1]+"  "+ allHeight+" "+$.browser.msie);

    if (size[1] - 42 < contentHeight)
    {
    // FIXED!
        if ($.browser.msie && parseInt($.browser.version) <= 6)
        {
			//alert(parseInt($.browser.version));
            // do ie style fixed hack
            // alert("opop");
            /*
            $("div#footer").css("position", "absolute");
            $("div#footer").css("top", "expression( ( - 0 - footer.offsetHeight + ( document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + 'px');");
            */
            $("div#footer").attr("class", "footerFixed");
        }
        else
        {
            $("div#footer").css("position", "fixed");
            $("div#footer").css("bottom", "0px");
        }
    }
    else
    {
    // RELATIVE
        if ($.browser.msie)
        {
            // do ie style fixed hack
            $("div#footer").attr("class", "");
        }
        else
        {
            $("div#footer").css("position", "relative");
            $("div#footer").css("bottom", "0px");
        }
    }
}


function checkScroll()
{
    if ($.browser.msie)
    {
        var size = getPageSize();
        var contentHeight = $("div#container").height();
        var scroll = $("body").scrollTop();

        //alert(scroll + " " + size[1] + " "+contentHeight);
        if (scroll + size[1] > contentHeight)
        {
            $("body").scrollTop(contentHeight - size[1]);
        }
    }
}


function addBookmark() {
    var title = document.title;
    var url = location.href;
    if (window.sidebar) { // firefox
          window.sidebar.addPanel(title, url,"");
    } else if( document.all ) { //MSIE
            window.external.AddFavorite( url, title);
    } else {
           alert("Sorry, your browser doesn't support this");
    }
}

function homeSlide(which)
{
    if (which == "newsContent")
    {
        showId = "newsContent";
        hideId = "quickLinksContent";
    }
    else
    {
        showId = "quickLinksContent";
        hideId = "newsContent";
    }

    $("#"+showId).slideDown(300);
    $("#"+hideId).slideUp(300);

    $("#"+hideId+"Arrow").fadeIn(0);
    $("#"+showId+"Arrow").fadeOut(0);

}

function checkSearchBox(who, text)
{
	if(who.value == "suchen" || who.value == "search" || who.value == "rechercher" || !who.value.length > 0)
		who.value = text;
}


function onThemaChange(select) {

	document.getElementById('powermail_thema').value = select.options[select.selectedIndex].title;
	//document.forms.formular.submit();
	document.location.href = select.options[select.selectedIndex].id;
	//document.location.href = this.options[this.selectedIndex].title;
}

function onSchulungChange(select) {

	document.getElementById('powermail_seminar').value = select.options[select.selectedIndex].title;
	//document.location.href = this.options[this.selectedIndex].title;
}



