$(document).ready(function(){
	$(".font-smaller").click(function(e){
		e.preventDefault();
		if(parseInt($("body").css("font-size")) < 12) return;
		$("body").css("font-size",(parseInt($("body").css("font-size"))-2)+"px");
	});
	$(".font-bigger").click(function(e){
		e.preventDefault();
		if(parseInt($("body").css("font-size")) > 16) return;
		$("body").css("font-size",(parseInt($("body").css("font-size"))+2)+"px");
	});
	
	$(".full").find("tr").not("*[class*=head]").each(function(){
		
	});
	
	$(".full").each(function(){
		var i = 0;
		$(this).find("tr").not("*[class*=head]").each(function(){
			if(i%2==0) $(this).find("td").css("background","#fff");
			else $(this).find("td").css("background","#eee");
			i++;
		});
	});
	
	
	
	initScrollbars();
	
	$(".script-hover").mouseover(function(){
		if($(this).is(".active")) return;
		$(this).find("img").not(".hover-pic").hide();
		$(this).find(".hover-pic").show();
	});
	
	$(".script-hover").mouseout(function(){
		if($(this).is(".active")) return;
		$(this).find("img").not(".hover-pic").show();
		$(this).find(".hover-pic").hide();
	});
	
	$(".script-hover").click(function(e){
		$(".script-hover").removeClass("active");
		$(this).addClass("active");
		$(".script-hover").mouseout();
	});
	

	$(".script-filter-offices:first").click(function(e){
		e.preventDefault();
		$(this).parents("#objekt-liste").find(".small-objekt").filter(".art-1").show();
		$(this).parents("#objekt-liste").find(".small-objekt").filter(".art-2").hide();
		$('#bild_offices').show();
		$('#bild_gewerbe').hide();
		initScrollbars();
	});
	
	$(".script-filter-offices:last").click(function(e){
		e.preventDefault();
		$(this).parents("#objekt-liste").find(".small-objekt").filter(".art-2").show();
		$(this).parents("#objekt-liste").find(".small-objekt").filter(".art-1").hide();
		$('#bild_offices').hide();
		$('#bild_gewerbe').show();
		initScrollbars();
	});
	
	$(".script-filter-offices:first").mouseover();
	$(".script-filter-offices:first").click();
	
	$(".galerie").each(function(){
		$(this).attr("rel","0");
	
		$(this).append('<div class="pfeil-rechts"></div>');
		$(this).append('<div class="pfeil-links"></div>');
		
		$(this).find(".bild").css("cursor","pointer").not(":first").hide();
		$(this).find(".pfeil-rechts").click(function(){
			$(this).parents(".galerie").find(".bild:visible").fadeOut("slow",function() {
				var next = $(this).next(".bild"); 
				//alert(next.length);
				if(next.length==0) next = $(this).parents(".galerie").find(".bild:first");
				next.fadeIn("slow");
			});
		});
		$(this).find(".pfeil-links").click(function(){
			$(this).parents(".galerie").find(".bild:visible").fadeOut("slow",function() {
				var next = $(this).prev(".bild"); 
				//alert(next.length);
				if(next.length==0) next = $(this).parents(".galerie").find(".bild:last");
				next.fadeIn("slow");
			});
		});
	});
	
	$(".script-diashow").toggle(function(){
		$(this).html("&raquo; Diashow beenden");
		interval = window.setInterval('diaShow(".galerie")',4000);
	},
	function(){
		$(this).html("&raquo; Diashow starten");
		clearInterval(interval);
	});
	
	$("body.lightbox").each(function(){
		//if($("#flag-plan").text()=="") $("#navigation").find("a:last").hide();
	});
	
	$(".open-lightbox").click(function(e){
		e.preventDefault();
		var link = $(this).attr("href");
		$("body").darker(800);
		$("body").preloader("fileadmin/tmpl/preloader.gif",0);
		$("body").append('<div id="lightbox"></div>');
		$("#lightbox")
			.css("position","fixed")
			.css("display","none")
			.css("left","50%")
			.css("top","50%")
			.css("width","800px")
			.css("height","550px")
			.css("margin-left","-400px")
			.css("margin-top","-275px")
			.css("z-index","10000")
			.css("background","#fff");
		$("#lightbox").each(function(){
			$(this).append('<iframe width="100%" height="100%" src="'+link+'" scrolling="no" frameborder="0" border="0"></iframe>');
			$(this).find("iframe").load(function(){
				$("body").closePreloader(1000,function(){
					$("#lightbox").show();
				});
				$("#lightbox iframe").contents().find(".schliessen").click(function(e){
					e.preventDefault();
					$("#lightbox").remove();
					$("body").closeDarker(1000);
				});
			});
		});
	});
	
	$(".lightbox").find(".schliessen").click(function(e){
		e.preventDefault();
		top.location.href = top.location.href;
	});
	
	$("a[href*=.pdf]").click(function(e){
		e.preventDefault();
		window.open("http://www.kgal.at/"+$(this).attr("href").split("http://www.kgal.at").join(""),"_blank","scrolling=no,width=900,height=500");
	});
	
	// ######### SCRIPT FÜR DROPDOWN MENÜ //
	
	navigation_index = 0;
	navigation_mouseout = 1;
	$("#navigation").find("a").each(function(){
		if($("#dropdowns").length!=1) return;
		$(this).attr("rel",navigation_index);
		$("#dropdowns").find(".dropdown:eq("+navigation_index+")").attr("rel",navigation_index);
		$(this).mouseover(function(){
			links_html = $("#dropdowns").find(".dropdown[rel="+$(this).attr("rel")+"]").html();
			$("#dropdown").remove();
			$("body").append('<div id="dropdown"></div>');
			$("#dropdown").html(links_html+'<div class="top"></div>');
			$("#dropdown").css({
				"opacity"	:	0.9,
				"top"		:	($(this).offset().top + $(this).find("img").height()+1)+"px",
				"left" 		:	($(this).offset().left-10)+"px"
			});
			$("#dropdown").find(".top").css({
				"position"	:	"absolute",
				"top"		:	"-7px",
				"left"		:	"10px",
				"width"		:	"40px",
				"height"	:	"7px",
				"background":	"#900"
			});
			$("#dropdown a, #navigation a").mouseover(function(){
				navigation_mouseout = 0;
			});
			$("#dropdown, #navigation a").mouseout(function(){
				navigation_mouseout = 1;
			});
		});
		navigation_index++;
		//alert(navigation_index);
	});
	
	window.setInterval('if(navigation_mouseout) $("#dropdown").remove()',2000);
	
	$('#mailform').live('submit', function(e){

	  if($(this).find("input[type=text]").val().length==0){

		return false;
	   }

	});
	
});

function diaShow(expr)
{
	$(expr).find(".pfeil-rechts").click();
}

function initScrollbars () {
	$(".scroll").jScrollPane({
		scrollbarWidth : 10
	});
	
	$(".jScrollPaneDrag").css({
		width : "6px",
		border : "2px solid #ccc",
		background : "#fff"
	});
	
	$(".jScrollPaneTrack").css({
		background : "#ccc"
	});
}

$.fn.initMap = function (lat, lon) {

	
	var ll = new google.maps.LatLng(lat, lon);

	var myOptions = {
				zoom: 14,
				center: ll,
				backgroundColor: "#ffffff",
				mapTypeId: google.maps.MapTypeId.ROADMAP,
				navigationControlOptions: {
				  style: google.maps.NavigationControlStyle.SMALL
				},
				mapTypeControl: false,
				scaleControl: false
			};
	
			map = new google.maps.Map(document.getElementById("map-rechts"), myOptions);
	
		  //Instantiate startPosMarker
			var startPosMarker = new google.maps.Marker({map: map, position: ll, icon: "fileadmin/tmpl/standort.png"});      



	return;
	
	var initialAddress = adresse;
	var geocoderCountry = "austria";
	geocoder = new google.maps.Geocoder();
  
	if (geocoder) {
	
		geocoder.geocode( { 'address': initialAddress, 'country': geocoderCountry}, function(results, status) {
	  
			if (status == google.maps.GeocoderStatus.OK) {
				result_temp =  results[0].geometry.location;
				var myOptions = {
					zoom: 17,
					center: result_temp,
					backgroundColor: "#ffffff",
					mapTypeId: google.maps.MapTypeId.ROADMAP,
					navigationControlOptions: {
					  style: google.maps.NavigationControlStyle.SMALL
					},
					mapTypeControl: false,
					scaleControl: false
				};
		
				map = new google.maps.Map(document.getElementById("map-rechts"), myOptions);
		
			  //Instantiate startPosMarker
				var startPosMarker = new google.maps.Marker({map: map, position: result_temp, icon: "fileadmin/tmpl/standort.png"});      
			}
		});
	}
}
