var isIE6 = (navigator.userAgent.toLowerCase().substr(25,6)=="msie 6") ? true : false;
var isIE7 = (navigator.userAgent.toLowerCase().substr(25,6)=="msie 7") ? true : false;

function openup(url) {
	window.open(url, "newWindow", "width=600,height=400,status=yes,scrollbars=yes,resizable=yes");
}

function openup_grossansicht(url) {
  newWin = window.open(url, "_blank", "width=850,height=850,left=100,top=200,scrollbars=yes");
  return false;
}


function opendownload(url) {
	location.href = url;
}

function clearSearch() {    
    if ('Suche' == document.getElementById('searchField').value) {
        document.getElementById('searchField').value = '';
    }
}
function setSearch() {
    var suche = rTrim(lTrim(document.getElementById('searchField').value));
    if ('' == suche) {
        document.getElementById('searchField').value = 'Suche';
    }
}

/*---- TRIM ----*/
function rTrim(text) {
    while (text.charAt(0) == " ") {
        text = text.substr(1);
    }
    return text;
}
function lTrim(text) {
    while (text.charAt(text.length - 1)  == " ") {
        text = text.substr(0, text.length - 1);
    }
    return text;
}


function startupHideZeitstrahl() {

	$('#zeitstrahl_wrapper').css("visibility", "");

	if(!isIE6 && !isIE7) {
		$('#zeitstrahl_wrapper').css("left", "-90%");
	} else {
		$('#zeitstrahl_wrapper').css("left", "-1000px");
	}

	$('#zeitstrahl_navi').removeClass('close');
	$('.scrollingHotSpotRight').addClass('hide');
	$("#makeMeScrollable").smoothDivScroll("stopAutoScroll");
	zeitstrahl = false;

	return;
}

function toggleZeitstrahl () {

	if (!zeitstrahl) {
		// einblenden
		$('#zeitstrahl_wrapper').animate({
			'left' : '-46px'
		});
		zeitstrahl = true;
		$('#zeitstrahl_navi').addClass('close');
		$('.scrollingHotSpotRight').removeClass('hide');
		$("#makeMeScrollable").smoothDivScroll("startAutoScroll");
	} else {
		// ausblenden
		$("#makeMeScrollable").smoothDivScroll("stopAutoScroll");
		if(!isIE6 && !isIE7) {
			$('#zeitstrahl_wrapper').animate({
				'left' : '-90%'
			});
		} else {
			$('#zeitstrahl_wrapper').animate({
				'left' : '-1000px'
			});
		}
		$('#zeitstrahl_navi').removeClass('close');
		$('.scrollingHotSpotRight').addClass('hide');
		zeitstrahl = false;
	}
}

function showInfotext (nb) {
	$("#makeMeScrollable").smoothDivScroll("stopAutoScroll");
	$('#infotext'+nb).show();
	
}

function hideInfotext (nb) {
	$('#infotext'+nb).hide();
	$("#makeMeScrollable").smoothDivScroll("startAutoScroll");
}




function toggleStrassenzugPopUp (sz) {

	szDiv = '#'+sz;
		
	if (!strassenzug) {
		// einblenden
		$('#overlay').css('display', 'block');
		$('#strassenzugPopUp_wrapper').css('display', 'block');
		
		
		$(szDiv).css('display', 'block');
		$(szDiv+'_hl').css('display', 'block');
		strassenzug = true;
		
		//alert($("div#makeMeScrollableSZ").find(".scrollingHotSpotLeftSZ").width());

		$(function() {
			$("div#makeMeScrollableSZ").smoothDivScroll({
				visibleHotSpots: "always",
				scrollableArea : "div.scrollableAreaSZ",
				scrollWrapper: "div.scrollWrapperSZ"
			});
		});
	
		$('#strassenzug_navi').addClass('close');
		
	} else {
		// ausblenden
		$('#overlay').css('display', 'none');
		
		$('#hl_wrapper').children('div').css('display', 'none');
		$('#bgelements_strassenzuege').children('div').css('display', 'none');
		
		$('#strassenzugPopUp_wrapper').css('display', 'none');
		strassenzug = false;
	}
}

function showInfotextSZ (nb) {
	$('#infotextSZ'+nb).show();
}

function hideInfotextSZ (nb) {
	$('#infotextSZ'+nb).hide();
}
	
function showFlag(obj) {
	obj.next().show();
}

function hideFlag(obj){
	obj.next().hide();
}

function showPreis(linkid, idtoshow){
	var str = idtoshow.substr(0, idtoshow.lastIndexOf('_'));

	$('#'+idtoshow).parents('.wrap').children('span').each(function(){
		$(this).hide();
		$(this).children('img').hide();
	});
	
	$(linkid).parents('table').find('.'+str).removeClass('selected');
	$(linkid).addClass('selected');
	$('#'+idtoshow).parent().css('display','inline-block');
	$('#'+idtoshow).show();
}

function showGallery(imgId) {
	// Gallerie und Overlay anzeigen
	$('#overlay').css('display', 'block');
	$('#galleryPopup_wrapper').css('display', 'block');
	// Aktuelles Bild einblenden
	$('#image_'+imgId).css('display', 'block');
}

function changeGalleryImage(hideImgId,displayImgId) {
	$('#image_'+hideImgId).css('display', 'none');
	$('#image_'+displayImgId).css('display', 'block');
}

function closeGallery() {
	$('#overlay').css('display', 'none');
	$('#galleryPopup_wrapper').css('display', 'none');
	$(".entry").each(function(index) {
		$(this).css('display','none');
	});
}

function showPasswordRecovery() {
	$('#okt_login_error_message').hide();
	$('#loginformular_headline').hide();
	$('#recoveryformular_headline').show();
	$('#loginformular_wrapper').hide();
	$('#recoveryformular_wrapper').show();
}

function showLogin() {
	$('#passwort_vergessen_error_message').hide();
	$('#loginformular_headline').show();
	$('#recoveryformular_headline').hide();
	$('#loginformular_wrapper').show();
	$('#recoveryformular_wrapper').hide();
}

$(document).ready(function() {
	if(document.getElementById('main_body').offsetHeight >= document.getElementById('siteBody').offsetHeight) {
		var tmp_height = document.getElementById('main_body').offsetHeight;
	} else {
		var tmp_height = document.getElementById('siteBody').offsetHeight;
	}
	var overlayheight = tmp_height +225;
	var overlaywidth =  window.innerWidth || self.innerWidth || (document.documentElement&&document.documentElement.clientWidth) || document.body.clientWidth;
	$('#overlay').css('height', overlayheight);
	
	//nur im IE6 width setzen
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		$('#overlay').css('width', overlaywidth);
	}

})
