var t = null;

function initialFade() {
	if (strSubnavi == "none") {
		fadeToIndustry(true);
	}
}

function fadeToIndustry(loopit) {
	$("#agroBox").fadeOut(1000);
	
	if ($("#agroTab img")[0].src.indexOf("_ak") != -1) $("#agroTab img")[0].src = $("#agroTab img")[0].src.replace("_ak", "");
	if ($("#industriTab img")[0].src.indexOf("_ak") == -1) $("#industriTab img")[0].src = $("#industriTab img")[0].src.replace("_nav","_nav_ak");

	if (loopit && strSubnavi == "none") t = setTimeout("fadeToAgro(true)", 5000);
}

function fadeToAgro(loopit) {
	$("#agroBox").fadeIn(1000);

	if ($("#industriTab img")[0].src.indexOf("_ak") != -1) $("#industriTab img")[0].src = $("#industriTab img")[0].src.replace("_ak", "");
	if ($("#agroTab img")[0].src.indexOf("_ak") == -1) $("#agroTab img")[0].src = $("#agroTab img")[0].src.replace("_nav","_nav_ak");
	
	if (loopit && strSubnavi == "none") t = setTimeout("fadeToIndustry(true)", 5000);
}

$(document).ready(function() {

	$("#noscript").hide();

	if (window.location.hash) {
		var h = window.location.hash;

		if (h == "#industri") {
		    $("#agroBox.container").hide();
		    fadeToIndustry(false);
		} else if (h == "#agro") {
		    //$("#industryBox.container").hide();
            fadeToAgro(false);
        }
	} else {
        if ($("#agroBox, #industryBox").length > 0) {		
		    //$("#industryBox.container").hide();
//    		setTimeout("fadeToIndustry(true)", 3000);
    		setTimeout("initialFade()", 3000);
	    }
	}


	$("#agroTab a").click(function () { clearTimeout(t); fadeToAgro(false) } );	
	$("#industriTab a").click(function () { clearTimeout(t); fadeToIndustry(false) } );
	
});

strSubnavi = "none";
function togglenavi(strTab) {
	//alert(strTab);
	if (strSubnavi == "none") {
		strSubnavi = strTab;
	} else {
		strSubnavi = "none";
	}
	if (strSubnavi == "agro") {
		document.getElementById("agrosubnavi").style.display = "block";
		clearTimeout(t);
		fadeToAgro(false);
	}
	if (strSubnavi == "industri") {
		document.getElementById("industrisubnavi").style.display = "block";
		clearTimeout(t);
		fadeToIndustry(false);
	}
	if (strSubnavi == "none") {
		document.getElementById("agrosubnavi").style.display = "none";
		document.getElementById("industrisubnavi").style.display = "none";
	}
}

