﻿var highlights={settings:{interval:5000,speed:1500},items:null,interval:null,current:null,init:function(){highlights.items=$(".home ul.select li");if(highlights.items.length==0)return;highlights.current=highlights.items.first();highlights.items.mouseenter(function(){highlights.openItem(this)});$("div.home").hover(function(){clearInterval(highlights.interval)},function(){highlights.interval=highlights.startAutoPlay()});highlights.interval=highlights.startAutoPlay()},openItem:function(item){item=$(item);var index=item.index();highlights.current=item;$(".home ul.select li").css("background-image","url(/themes/gab/images/gb"+(index+1)+".jpg)");var stageItems=$(".home ul.stage li");if(index==1){stageItems.eq(1).animate({left:0}).siblings().animate({left:-715})}else{stageItems.eq(1).animate({left:715}).siblings().animate({left:0})}},startAutoPlay:function(){clearInterval(highlights.interval);return setInterval(function(){highlights.tick()},highlights.settings.interval)},tick:function(){var $next=highlights.current.next();if($next.length==0)$next=highlights.items.first();highlights.openItem($next)}};var projects=(function(){var projects;var map;var windows=[];var landkreise;var sortedProjects=[];var animation=null;var GB1=false;var GB2=false;var LoadLayer;var LoadLayerRef;var FilterRef;var redIcon="http://chart.apis.google.com/chart?chst=d_map_pin_letter_withshadow&chld=|FF0000|000000";var greenIcon="http://chart.apis.google.com/chart?chst=d_map_pin_letter_withshadow&chld=|24972B|000000";var yellowIcon="http://chart.apis.google.com/chart?chst=d_map_pin_letter_withshadow&chld=|f07e2e|000000";var showLoadLayer=function(){LoadLayerRef=setTimeout(function(){$("#loadlayer").show()},10)};var hideLoadLayer=function(){clearTimeout(LoadLayerRef);setTimeout(function(){$("#loadlayer").hide()},10)};var runFilterInt=function(){showLoadLayer();var filter={status:$("#ddStatus").multiselect("getChecked").map(function(){return $(this).val()}).get(),bezirk:$("#ddRegbez").multiselect("getChecked").map(function(){return $(this).val()}).get(),landkreis:$("#ddLandkreis").multiselect("getChecked").map(function(){return $(this).val()}).get()};if(GB1){filter.branche=$("#ddBranche").multiselect("getChecked").map(function(){return $(this).val()}).get()}if(GB2){filter.massnahme=$("#ddMassnahme").multiselect("getChecked").map(function(){return $(this).val()}).get()}sortedProjects=[];projects.each(function(){this.match=true;if(filter.status.length>0){var result=jQuery.inArray(this.status,filter.status);this.match=this.match&&(result!=-1)}if(filter.bezirk.length>0){var result=jQuery.inArray(this.bezirk,filter.bezirk);this.match=this.match&&(result!=-1)}if(filter.landkreis.length>0){var result=jQuery.inArray(this.landkreis,filter.landkreis);this.match=this.match&&(result!=-1)}if(GB1){if(filter.branche.length>0){var result=jQuery.inArray(this.branche.id,filter.branche);this.match=this.match&&(result!=-1)}}if(GB2){if(filter.massnahme.length>0){if(this.massnahmen.length>0){var result=false;$(this.massnahmen).each(function(){if(jQuery.inArray(this.toString(),filter.massnahme)!=-1){result=true;return false}});this.match=this.match&&result}else{this.match=false}}}$(this.ref).toggleClass("match",this.match);if(this.match){var point=this.lat+"|"+this.lng;if(!(point in sortedProjects)){sortedProjects[point]=[]}sortedProjects[point][sortedProjects[point].length]=this}});addProjects(sortedProjects);$("div.projects table tbody tr.match").fadeIn();$("div.projects table tbody tr:not(.match)").fadeOut();$(windows).each(function(){this.close()});hideLoadLayer()};var runFilter=function(){FilterRef=clearTimeout(FilterRef);FilterRef=setTimeout(function(){runFilterInt()},10)};var setupMap=function(){var latlng=new google.maps.LatLng(48.949444,11.395);var myOptions={zoom:7,minZoom:5,maxZoom:10,center:latlng,mapTypeId:google.maps.MapTypeId.TERRAIN,streetViewControl:false};map=new google.maps.Map(document.getElementById("ProjectsMap"),myOptions);var everythingElse=[new google.maps.LatLng(-85,-20),new google.maps.LatLng(85,-20),new google.maps.LatLng(85,50),new google.maps.LatLng(-85,50)];var returnGeom='10.05495,50.51632|10.01212,50.45990|9.94639,50.42222|9.89916,50.40777|9.74445,50.29902|9.62584,50.22652|9.55771,50.22562|9.50521,50.23458|9.49819,50.18069|9.51542,50.11354|9.42319,50.08791|9.37014,50.12625|9.32722,50.14027|9.23708,50.14472|9.10666,50.12527|9.01583,50.10208|8.97424,50.04833|9.04722,49.85666|9.11833,49.76194|9.10416,49.68833|9.08334,49.62056|9.11045,49.57509|9.26153,49.57819|9.41861,49.64403|9.40292,49.71819|9.31375,49.76444|9.42584,49.78554|9.49750,49.78416|9.63250,49.77694|9.70736,49.72153|9.82555,49.69888|9.92958,49.55500|9.94111,49.47944|10.00000,49.47893|10.05111,49.50555|10.09354,49.54083|10.12958,49.50958|10.13323,49.38176|10.11597,49.34027|10.12805,49.25916|10.18055,49.18583|10.21889,49.15416|10.27806,49.04666|10.35687,49.03235|10.44139,48.95833|10.46986,48.91638|10.47222,48.72583|10.43195,48.67222|10.33722,48.61695|10.31472,48.53361|10.13569,48.47962|10.05764,48.46733|9.98916,48.36777|10.06639,48.28634|10.13583,48.10861|10.13666,48.05042|10.10222,47.86888|10.12805,47.81389|10.12666,47.69888|10.08334,47.66972|9.91986,47.65777|9.86285,47.67479|9.65750,47.60666|9.60916,47.58611|9.57792,47.53742|9.69253,47.52952|9.74625,47.56583|9.81097,47.59416|9.95500,47.53972|10.04306,47.49528|10.23174,47.37374|10.21166,47.32249|10.17334,47.27472|10.22889,47.27604|10.27445,47.28889|10.33666,47.31270|10.47374,47.43764|10.46618,47.48291|10.43639,47.52916|10.43368,47.58048|10.48180,47.58652|10.56945,47.54027|10.69084,47.55389|10.90945,47.51806|11.00834,47.39583|11.10403,47.39653|11.29639,47.42889|11.45750,47.51222|11.50528,47.50916|11.57986,47.52409|11.68305,47.58472|12.00639,47.62445|12.14139,47.61111|12.20155,47.61299|12.20111,47.65749|12.45500,47.66777|12.51444,47.63326|12.57639,47.64416|12.66584,47.68500|12.73695,47.68271|12.82785,47.62124|12.78819,47.58354|12.95787,47.47702|13.01250,47.46979|13.05334,47.49756|13.10014,47.64292|13.07750,47.68736|13.02306,47.72416|12.91395,47.72500|12.94416,47.78875|13.00889,47.85416|12.96666,47.90695|12.91889,47.95777|12.86535,47.99460|12.83750,48.03000|12.79916,48.05458|12.75972,48.12173|12.87125,48.20291|13.01777,48.25944|13.15445,48.29222|13.25805,48.29888|13.31305,48.31583|13.39500,48.36610|13.43792,48.42944|13.45750,48.51555|13.44323,48.56024|13.51861,48.58458|13.60277,48.56806|13.67695,48.53229|13.72600,48.51559|13.80374,48.58264|13.82542,48.63111|13.83361,48.77361|13.74563,48.87076|13.69945,48.87930|13.65195,48.90444|13.62611,48.94764|13.56483,48.97366|13.50972,48.97250|13.40255,49.00619|13.39611,49.04916|13.31847,49.10083|13.17305,49.16722|13.03111,49.28777|12.95903,49.33493|12.88720,49.34038|12.79722,49.33985|12.67445,49.42500|12.59777,49.52750|12.55472,49.61666|12.51548,49.67722|12.45556,49.69554|12.46847,49.78347|12.54597,49.90958|12.49139,49.97583|12.42944,49.99389|12.26555,50.06611|12.20615,50.10621|12.20916,50.16361|12.09370,50.32254|12.03833,50.32923|11.98292,50.34972|11.90528,50.41499|11.82472,50.38972|11.52639,50.37680|11.41798,50.44874|11.42000,50.51714|11.35195,50.52194|11.24903,50.47485|11.27639,50.37186|11.26806,50.30305|11.18278,50.27777|11.13767,50.29475|11.07750,50.35277|10.94334,50.38722|10.85889,50.38888|10.80944,50.38166|10.71576,50.35722|10.76861,50.29222|10.72666,50.21472|10.61403,50.22596|10.49333,50.35472|10.31500,50.49000|10.19736,50.55138|10.12861,50.55806|10.05495,50.51632';var geomAry=new Array();geomAry=returnGeom.split('|');var XY=new Array();var points=[];for(var i=0;i<geomAry.length;i++){XY=geomAry[i].split(',');points.push(new google.maps.LatLng(parseFloat(XY[1]),parseFloat(XY[0])))}var bayern=new google.maps.Polygon({paths:[everythingElse,points],strokeColor:"#000000",strokeOpacity:0.8,strokeWeight:0.5,fillColor:"#E9EAEB",fillOpacity:0.8});bayern.setMap(map)};var addProjects=function(resortedProjects){$(projects).each(function(){if(this.marker!=undefined){this.marker.setMap(null)}});windows.length=0;for(var i in resortedProjects){var value=resortedProjects[i];if(value.length==1){addProject(value[0])}else{var marker=new google.maps.Marker({map:map,animation:animation,position:new google.maps.LatLng(value[0].lat,value[0].lng),title:value.length+" Projekte",icon:"http://chart.apis.google.com/chart?chst=d_map_pin_letter_withshadow&chld="+value.length+"|cccccc|000000"});var contentString='<div id="content" style="width: 300px; height: 200px; overflow: auto; font-size: 1em;">';var intprojects=[];for(var ii in value){var project=value[ii];intprojects[intprojects.length]=project;contentString+='<div style="border-bottom: 1px dashed #cccccc; padding-bottom: 0.5em; margin-bottom: 1em; overflow: hidden">'+createWindowContent(project)+'</div>';project.marker=marker}contentString+='<div>';var theinfowindow=new google.maps.InfoWindow({content:contentString,maxWidth:350});marker.projects=intprojects;$(intprojects).each(function(){this.infowindow=theinfowindow});windows[windows.length]=theinfowindow;google.maps.event.addListener(marker,'click',function(){setActive(this.projects)})}}};var createWindowContent=function(project){var contentString="";if(project.img!=""){contentString+='<img style="float: right; margin-left: 1em; margin-bottom: 1em; width: 100px;" src="'+project.img+'" />'}contentString+='<p><strong>'+project.name+'</strong><br />'+project.owner+'<br />'+'<br />'+'<strong>Projektstatus:</strong> '+project.status+'<br />';if(GB1){contentString+='<strong>Branche:</strong> '+project.branche.title+'<br />'}contentString+='</p><ul><li><a href="'+location.href+'/show/'+project.number+'">Details anzeigen</a></li></ul>';return contentString};var addProject=function(project){var micon;switch(project.status){case"Läuft":micon=yellowIcon;break;case"Abgeschlossen":micon=greenIcon;break;default:micon=redIcon;break}var marker=new google.maps.Marker({map:map,animation:animation,position:new google.maps.LatLng(project.lat,project.lng),title:project.name,icon:micon});var contentString='<div id="content" style="width: 300px; height: 200px; font-size: 1em;">'+createWindowContent(project)+'</div>';var infowindow=new google.maps.InfoWindow({content:contentString});project.marker=marker;project.infowindow=infowindow;windows[windows.length]=infowindow;google.maps.event.addListener(marker,'click',function(){setActive([project])})};var setActive=function(projects){var items=$("div.projects table tbody tr");items.removeClass("active");$(projects).each(function(){$(this.ref).addClass("active")});$(windows).each(function(){this.close()});projects[0].infowindow.open(map,projects[0].marker)};return{init:function(){var items=$("div.projects table tbody tr");if(items.length==0)return;showLoadLayer();GB1=$("body").is(".GB1ProjektsPage");GB2=$("body").is(".GB2ProjektsPage");projects=items.map(function(){var data=$(this).removeClass("active").data("project");data.ref=this;return data});items.hover(function(){$(this).addClass("hover")},function(){$(this).removeClass("hover")}).click(function(){var project;var id=$(this).data("project").id;projects.each(function(){if(id==this.id){project=this;return false}});if(project)setActive([project])});$.ech.multiselect.prototype.options.checkAllText="alle";$.ech.multiselect.prototype.options.uncheckAllText="aufheben";$("#ddRegbez").multiselect({noneSelectedText:'Regierungsbezirk',selectedText:'Regierungsbezirk: # ausgewählt',selectedList:2,click:runFilter,uncheckAll:runFilter,checkAll:runFilter}).change(runFilter).change(function(){$("#ddLandkreis").html("");var bezirke=$("#ddRegbez").multiselect("getChecked").map(function(){return $(this).val()}).get();if(bezirke.length>0){$("#ddLandkreis").append(landkreise.filter(function(){var result=jQuery.inArray($(this).data("bezirk").toString(),bezirke);return(result!=-1)}).clone())}else{$("#ddLandkreis").append(landkreise.clone())}$("#ddLandkreis").multiselect("refresh")});var $ddLandkreis=$("#ddLandkreis");landkreise=$ddLandkreis.find("option").clone();$ddLandkreis.multiselect({noneSelectedText:'Landkreis',selectedText:'Landkreis: # ausgewählt',selectedList:2,click:runFilter,uncheckAll:runFilter,checkAll:runFilter}).multiselectfilter();$("#ddStatus").multiselect({noneSelectedText:'Projektstatus',selectedText:'Projektstatus: # ausgewählt',selectedList:2,click:runFilter,uncheckAll:runFilter,checkAll:runFilter}).change(runFilter);if(GB1){$("#ddBranche").multiselect({noneSelectedText:'Branche',selectedText:'Branche: # ausgewählt',selectedList:2,click:runFilter,uncheckAll:runFilter,checkAll:runFilter}).multiselectfilter()}if(GB2){$("#ddMassnahme").multiselect({noneSelectedText:'Maßnahme',selectedText:'Maßnahme: # ausgewählt',selectedList:2,click:runFilter,uncheckAll:runFilter,checkAll:runFilter}).multiselectfilter()}setupMap();projects.each(function(){var point=this.lat+"|"+this.lng;if(!(point in sortedProjects)){sortedProjects[point]=[]}sortedProjects[point][sortedProjects[point].length]=this});animation=null;addProjects(sortedProjects);setTimeout(function(){hideLoadLayer()},2000)}}})();$(function(){$("ul.nav > li").hover(function(){var $this=$(this);$this.siblings().find("ul").stop(true,true).fadeOut("fast");$this.find("ul").stop(true,true).fadeIn("fast")},function(){});$("ul.nav").mouseleave(function(){var $section=$("ul.nav > li.section");$section.siblings().find("ul").stop(true,true).fadeOut("fast");$section.find("ul").stop(true,true).fadeIn("fast")});highlights.init();projects.init()});
