$(function() // pageload
    {
	  legenda_closed = false;
		
	  $("#legenda_content INPUT[type='checkbox']").click(function()
	  {
		remove_overlay();
		poi_return = false;
		this_id = $(this).attr("id").substr(14); 
		this_checked = $(this).attr("checked");	
	
		for (i=0;i<marker_accenten[this_id].length;i++)
		{
		    id = marker_accenten[this_id][i]; 
						
		    if (this_checked==true) 
		    { 
			  addMarker(id);
			  if (legenda_closed==id) {
				poiClick(id);
			  }
		    } 
		    else 
		    { 
			  removeMarker(id);
			  if (openMarker==id) {
				poiClose(id);
				legenda_closed=id;
			  } 
		    }
		}			
	  });
	 
	  $("#zoeken_op_kaart_form").submit(function()
	  {
		submit_zoeken_kaart();
		return false;
	  });
		
	  $("#zoeken_op_kaart").click(function()
	  {										 
		submit_zoeken_kaart();	
	  });
	
	  $(".noselect").each(function()
	  { 	
		$(this).unselectable="on";
		$(this).css('MozUserSelect',"none");
	  });
	
	  $(".sluitpopup").click(function() {
		sluitpopup();
	  });
	

    });


function sluitpopup()
{
    $(".popOver").hide();	
	setPageTitle();
    //timeout om te voorkomen dat nieuw geopende popup ook wordt gesloten bij onclick
    setTimeout('returntonieuws()',20); 
}

function submit_zoeken_kaart()
{
    $("#zoeken_op_kaart_load").fadeIn("fast");
    gemeente = $("#zoeken_op_kaart_gemeente").val();
    naam = $("#zoeken_op_kaart_naam").val();		
    $.ajax({
	  type: "POST", 
	  url: "/ajax/zoeken.php",
	  data:{
		gemeente:gemeente,
		naam:naam
	  },
	  success:function(data)
	  {
		
		for (i=0;i<marker_list.length;i++) {
		    removeMarker(marker_list[i]);
		}	
		if (data!='') 
		{ 
		    ids=data.split(","); 
		    aantal = ids.length; 
		    if (aantal==1) {
			  text = '1 locatie';
		    } else {
			  text = aantal+' locaties';
		    }
		    $("#zoeken_op_kaart_zoekresultaat").html(text+' gevonden.');
		    for (i=0;i<ids.length;i++) {
			  if (!marker_used[ids[i]]) {
				marker_list.push(ids[i]);
			  }
			  addMarker(ids[i]);
		    } 
		    $("#zoeken_op_kaart_load").fadeOut("fast");			
		}
		else
		{
		    $("#zoeken_op_kaart_zoekresultaat").html('0 locaties gevonden.');
		    $("#zoeken_op_kaart_load").fadeOut("fast"); 
		}
		if (openMarker) {
		    if (!marker_visible[openMarker]) {
			  poiClose(openMarker);
		    }
		}
	  if ((gemeente=='')&&(naam=='')) 
	  { 
		$("#zoeken_op_kaart_zoekresultaat").html('Vul eerst een zoekopdracht in.'); 
		$("#zoeken_op_kaart_load").fadeOut("fast"); 
		map.clearOverlays();
		marker_visible=[];
		for (i=0;i<marker_list_active.length;i++) {
		    id = marker_list_active[i];
		    addMarker(id);
		}
	  }
	
	
    }
    });
}


function print_div(target)
{
    $("#print").html($("#"+target).html());
    window.print();	
}


function gotohome() 
{
    var durationSave = 850;
    var widthSave = "18px";
	setPageTitle();
    $("#cultuurnota_index,#cultuurnota_tekst,#subsidiemogelijkheden_content,#links_content,#banners_content").css("overflow","hidden");
    current_cat = false;
    var checkId = "ContOntEnBeleven";
    var element = document.getElementById(checkId);
    if(element.style.width != widthSave){
	  
	  $("#"+ checkId +"").animate( {
		width:widthSave
	  },{
		queue:false, 
		duration:durationSave
	  } )
    }
	
	
    var checkId = "ContLerenEnOntd";
    var element = document.getElementById(checkId);
    if(element.style.width != widthSave){
	  
	  $("#"+ checkId +"").animate( {
		width:widthSave
	  }, {
		queue:false, 
		duration:durationSave
	  } )
	  $("#"+checkId+"Blokken").animate( {
		marginLeft:"-712px"
	  }, {
		queue:false, 
		duration:durationSave
	  } )
    }
	
	
    var checkId = "ContDoenEnOntplooi";
    var element = document.getElementById(checkId);
    if(element.style.width != widthSave){
	
	  $("#"+ checkId +"").animate( {
		width:widthSave
	  }, {
		queue:false, 
		duration:durationSave
	  } )
    }
		
    var checkId = "ContVerbindenEnProm";
    var element = document.getElementById(checkId);
    if(element.style.width != widthSave){
	 
	  $("#"+ checkId +"").animate( {
		width:widthSave
	  }, {
		queue:false, 
		duration:durationSave
	  } )
    }

	
    var checkId = "ContBewarEnBeheren";
    var element = document.getElementById(checkId);
    if(element.style.width != widthSave){
	 
	  $("#"+ checkId +"").animate( {
		width:widthSave
	  }, {
		queue:false, 
		duration:durationSave
	  } )
	  $("#"+checkId+"Blokken").animate( {
		marginLeft:"-712px"
	  }, {
		queue:false, 
		duration:durationSave
	  } )
    }
	
    var checkId = "ContVertelEnOntsluiten";
    var element = document.getElementById(checkId);
    if(element.style.width != widthSave){
	  
	  $("#"+ checkId +"").animate( {
		width:widthSave
	  }, {
		queue:false, 
		duration:durationSave
	  } )
    } 

    /* sliders right */
    var checkId = "ContBanners";
    var element = document.getElementById(checkId);
    if(element.style.width != widthSave){
	  
	  $("#"+ checkId +"").animate( {
		width:widthSave
	  }, {
		queue:false, 
		duration:durationSave
	  } )
    }
		
    var checkId = "ContLinks";
    var element = document.getElementById(checkId);
    if(element.style.width != widthSave){
	  
	  $("#"+ checkId +"").animate( {
		width:widthSave
	  }, {
		queue:false, 
		duration:durationSave
	  } )
    }

	
    var checkId = "ContCultuurNota";
    $('#cultuurnota_zoeken_zoekresultaten,#cultuurnota_index,#cultuurnota_tekst').removeHighlight(); //verwijder eventuele highlight
    var element = document.getElementById(checkId);
    if(element.style.width != widthSave){
	 
	  $("#"+ checkId +"").animate( {
		width:widthSave
	  }, {
		queue:false, 
		duration:durationSave
	  } )
    }

	
    var checkId = "ContSubsidieMoge";
    var element = document.getElementById(checkId);
    if(element.style.width != widthSave){
	  $("#"+ checkId +"").animate( {
		width:widthSave
	  }, {
		queue:false, 
		duration:durationSave
	  } )
    }

}

function openSlider(objname, direction, specialSize) {
    //alert("open");
    var element = document.getElementById("sliderRight");
    element.style.width = "795px";
    element.style.left = "194px";
}
function closeSlider(objname, direction, specialSize) {
    var element = document.getElementById("sliderRight");
    element.style.width = "90px";
    element.style.left = "950px";
}

current_cat = 0;
function openScreen(objname, direction, specialSize) 
{
  
    if (jongerenkaart) {
	  switch_jongerenkaart();
    }
	
    o2n = [];
    o2n["ContBanners"]=10;
    o2n["ContLinks"]=9;
    o2n["ContSubsidieMoge"]=8;
    o2n["ContCultuurNota"]=7;
    o2n["ContOntEnBeleven"]=6; 
    o2n["ContLerenEnOntd"]=3;
    o2n["ContDoenEnOntplooi"]=4;
    o2n["ContVerbindenEnProm"]=5;
    o2n["ContBewarEnBeheren"]=1;
    o2n["ContVertelEnOntsluiten"]=2;
	
    n2o = [];
    n2o[10]="ContBanners";
    n2o[9]="ContLinks";
    n2o[8]="ContSubsidieMoge";
    n2o[7]="ContCultuurNota";
    n2o[6]="ContOntEnBeleven"; 
    n2o[3]="ContLerenEnOntd";
    n2o[4]="ContDoenEnOntplooi";
    n2o[5]="ContVerbindenEnProm";
    n2o[1]="ContBewarEnBeheren";
    n2o[2]="ContVertelEnOntsluiten";
	
    $("#cultuurnota_index,#cultuurnota_tekst,#subsidiemogelijkheden_content,#links_content,#banners_content").css("overflow","hidden");
    current_cat = o2n[objname];	
	
    var durationSave = 850;
    var widthSave = "18px";

    var checkId = "ContOntEnBeleven";
    if(checkId != objname) {
	  
	  var element = document.getElementById(checkId);
	  if(element.style.width != widthSave){
		$("#"+ checkId +"").animate( {
		    width:widthSave
		},{
		    queue:false, 
		    duration:durationSave
		} )
	  }
    }
    else
	  {setPageTitle('Ontwikkelen en Beleven');}
	
    var checkId = "ContLerenEnOntd";
    if(checkId != objname) {
	  
	  var element = document.getElementById(checkId);
	  if(element.style.width != widthSave){
		$("#"+ checkId +"").animate( {
		    width:widthSave
		}, {
		    queue:false, 
		    duration:durationSave
		} )
		$("#"+checkId+"Blokken").animate( {
		    marginLeft:"-712px"
		}, {
		    queue:false, 
		    duration:durationSave
		} )
	  }
    }
    else
	  {setPageTitle('Leren en Ontdekken');}
	
    var checkId = "ContDoenEnOntplooi";
    if(checkId != objname) {
	 
	  var element = document.getElementById(checkId);
	  if(element.style.width != widthSave){
		$("#"+ checkId +"").animate( {
		    width:widthSave
		}, {
		    queue:false, 
		    duration:durationSave
		} )
	  }
    }
    else
	  { setPageTitle('Doen en Ontplooien');}
	
    var checkId = "ContVerbindenEnProm";
    if(checkId != objname) {
	 
	  var element = document.getElementById(checkId);
	  if(element.style.width != widthSave){
		$("#"+ checkId +"").animate( {
		    width:widthSave
		}, {
		    queue:false, 
		    duration:durationSave
		} )
	  }
    }	else {  setPageTitle('Verbinden en Promoten');}
	
    var checkId = "ContBewarEnBeheren";
    if(checkId != objname) {
	  
	  var element = document.getElementById(checkId);
	  if(element.style.width != widthSave){
		$("#"+ checkId +"").animate( {
		    width:widthSave
		}, {
		    queue:false, 
		    duration:durationSave
		} )
		$("#"+checkId+"Blokken").animate( {
		    marginLeft:"-712px"
		}, {
		    queue:false, 
		    duration:durationSave
		} )
	  }
    }else { setPageTitle('Bewaren en Beheren');}
	
    var checkId = "ContVertelEnOntsluiten";
    if(checkId != objname) {
	  
	  var element = document.getElementById(checkId);
	  if(element.style.width != widthSave){
		$("#"+ checkId +"").animate( {
		    width:widthSave
		}, {
		    queue:false, 
		    duration:durationSave
		} )
	  }
    }
    else
	  {
		setPageTitle('Vertellen en Ontsluiten');}

    /* sliders right */
    var checkId = "ContLinks";
    if(checkId != objname) {
	   
	  var element = document.getElementById(checkId);
	  if(element.style.width != widthSave){
		$("#"+ checkId +"").animate( {
		    width:widthSave
		}, {
		    queue:false, 
		    duration:durationSave
		} )
	  }
    }
    else
    {
	  setPageTitle('Links');
	  setTimeout('$("#links_content").css("overflow-y","auto")',800);	 		
    }
    var checkId = "ContBanners";
    if(checkId != objname) {
		
	  var element = document.getElementById(checkId);
	  if(element.style.width != widthSave){
		$("#"+ checkId +"").animate( {
		    width:widthSave
		}, {
		    queue:false, 
		    duration:durationSave
		} )
	  }
    }
    else
    {setPageTitle('Banners');
	  setTimeout('$("#banners_content").css("overflow","auto")',800);	 		
    }
	
    var checkId = "ContCultuurNota";
    if(checkId != objname) {
	  
	  $('#cultuurnota_zoeken_zoekresultaten,#cultuurnota_index,#cultuurnota_tekst').removeHighlight(); //verwijder eventuele highlight
	  var element = document.getElementById(checkId);
	  if(element.style.width != widthSave){
		$("#"+ checkId +"").animate( {
		    width:widthSave
		}, {
		    queue:false, 
		    duration:durationSave
		} )
	  }
    }
    else
    {
	   setPageTitle('Cultuurnota Achtergrond');
	  setTimeout('$("#cultuurnota_index,#cultuurnota_tekst").css("overflow","auto")',800);			
    }
	
    var checkId = "ContSubsidieMoge";
    if(checkId != objname) {
	 
	  var element = document.getElementById(checkId);
	  if(element.style.width != widthSave){
		$("#"+ checkId +"").animate( {
		    width:widthSave
		}, {
		    queue:false, 
		    duration:durationSave
		} )
	  }
    }	
    else
    {
	   setPageTitle('Subsidiemogelijkheden');
	  setTimeout('$("#subsidiemogelijkheden_content").css("overflow","auto")',800);			
    }

    if(objname != "closeAll") {
	 
	  if(document.getElementById(objname).style.width == widthSave){
		// div is hidden, so let's slide down
		if(specialSize != undefined) {
		    $("#"+objname+"").animate( {
			  width:specialSize+"px"
		    }, {
			  queue:false, 
			  duration:600
		    } )
		} else { 
		    $("#"+objname+"").animate( {
			  width:"721px"
		    }, {
			  queue:false, 
			  duration:durationSave
		    } )
		}
		$("#"+objname+"Blokken").animate( {
		    marginLeft:"-10px"
		}, {
		    queue:false, 
		    duration:durationSave
		} )
	  } else{
		// div is not hidden, so slide up
		$("#"+objname+"").animate( {
		    width:widthSave
		}, {
		    queue:false, 
		    duration:durationSave
		} )
		if(direction == "right") {
		    $("#"+objname+"Blokken").animate( {
			  marginRight:"-712px"
		    }, {
			  queue:false, 
			  duration:durationSave
		    } )
		} else {
		    $("#"+objname+"Blokken").animate( {
			  marginLeft:"-712px"
		    }, {
			  queue:false, 
			  duration:durationSave
		    } )
		}
	  }
    }
    else
	  {setPageTitle();}
	

}

startChange = 1;
function changePic(action) {
    if(action == "back") {
	  if(startChange == 1) {
		startChange = 3;
	  } else {
		startChange = startChange - 1;
	  }
    }
    if(action == "next") {
	  if(startChange == 3) {
		startChange = 1;
	  } else {
		startChange = startChange + 1;
	  }
    }
    var element = document.getElementById("BB3");
    if(startChange == 1) {
	  element.style.backgroundImage = "url(/gfx/content/BBblok3.png)";
    }
    if(startChange == 2) {
	  element.style.backgroundImage = "url(/gfx/content/BBblok3_2.png)";
    }
    if(startChange == 3) {
	  element.style.backgroundImage = "url(/gfx/content/BBblok3_3.png)";
    }
}

startChange = 1;
function changePic2(action) {
    if(action == "back") {
	  if(startChange == 1) {
		startChange = 2;
	  } else {
		startChange = startChange - 1;
	  }
    }
    if(action == "next") {
	  if(startChange == 2) {
		startChange = 1;
	  } else {
		startChange = startChange + 1;
	  }
    }
    var element = document.getElementById("BB2");
    var elementLink = document.getElementById("BB2opKaart");
    if(startChange == 1) {
	  element.style.backgroundImage = "url(/gfx/content/BBblok2.png)";
	  elementLink.onclick = function(){
		if(openMarker!=2){
		    poiClick('2');
		}
		openScreen('ContBewarEnBeheren');
	  };
    }
    if(startChange == 2) {
	  element.style.backgroundImage = "url(/gfx/content/BBblok2_2.png)";
	  elementLink.onclick = function(){
		if(openMarker!=1){
		    poiClick('1');
		}
		openScreen('ContBewarEnBeheren');
	  };
    }
}

startChange = 1;
function changePic3(action) {
    if(action == "back") {
	  if(startChange == 1) {
		startChange = 2;
	  } else {
		startChange = startChange - 1;
	  }
    }
    if(action == "next") {
	  if(startChange == 2) {
		startChange = 1;
	  } else {
		startChange = startChange + 1;
	  }
    }
    var element = document.getElementById("LO2");
    var elementLink = document.getElementById("LO2opKaart");
    if(startChange == 1) {
	  element.style.backgroundImage = "url(/gfx/content/LOblok2.png)";
	  elementLink.onclick = function(){
		if(openMarker!=13){
		    poiClick('13');
		}
		openScreen('ContLerenEnOntd');
	  };
    }
    if(startChange == 2) {
	  element.style.backgroundImage = "url(/gfx/content/LOblok2_2.png)";
	  elementLink.onclick = function(){
		if(openMarker!=14){
		    poiClick('14');
		}
		openScreen('ContLerenEnOntd');
	  };
    }
}

function displayOn(target) {
    var element = document.getElementById(target);
//element.style.display = "block";
}
function displayOff(target) {
    var element = document.getElementById(target);
//element.style.display = "none";
}

function moveOn(target) {
    var element = document.getElementById(target);
//element.style.top = "-123px";
}
function moveOff(target) {
    var element = document.getElementById(target);
//element.style.top = "30px";
}

//ie indexOf fix
if(!Array.indexOf){
    Array.prototype.indexOf = function(obj){
	  for(var i=0; i<this.length; i++){
		if(this[i]==obj){
		    return i;
		}
	  }
	  return -1;
    }
}
	
function validate_email(email)
{
    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (filter.test(email)) {
	  return true;
    } else {
	  return false;
    } 	
}
current_hash = '';
ignore_hash = false; 
 var hash = new String(document.location).split("#")[1];

function ajax_load_page(hash) {
    if (!hash) return false; 
    if (ignore_hash) return false;

    t = hash.split('/');
    q1 = t[1];
    q2 = t[2];
    q3 = t[3];
		
    //slides
    if (q1=='bewaren-en-beheren') $("#pos1 a").trigger("click");
    if (q1=='vertellen-en-ontsluiten') $("#pos2 a").trigger("click");
    if (q1=='leren-en-ontdekken') $("#pos3 a").trigger("click");
    if (q1=='doen-en-ontplooien') $("#pos4 a").trigger("click");
    if (q1=='verbinden-en-promoten') $("#pos5 a").trigger("click");
    if (q1=='ontwikkelen-en-beleven') $("#pos6 a").trigger("click");
    if (q1=='cultuurnota-achtergrond') $("#pos7 a").trigger("click");
    if (q1=='subsidiemogelijkheden') $("#pos8 a").trigger("click");
    if (q1=='banners') $("#pos9 a").trigger("click");
    if (q1=='links') $("#pos10 a").trigger("click");
		
    //themas
    if (q1=='thema-levend-verleden') $("#thema_1_link").trigger("click");
    if (q1=='thema-genieten-en-meedoen') $("#thema_2_link").trigger("click");
    if (q1=='thema-mooi-noord-holland') $("#thema_3_link").trigger("click");
    if (q1=='accent') { if (q2>1) { accent_bekijk(q2) } } 
		
    //main menu
    if (q1=='') $("#home_link").trigger("click");
    if (q1=='tijdlijn') { $("#tijdlijn_link").trigger("click"); setPageTitle('Tijdlijn'); }
    if (q1=='nieuws') { setPageTitle('Nieuws'); $("#nieuws_link").trigger("click");  }
    if (q1=='contact') { $("#contact_link").trigger("click"); setPageTitle('Contact'); }
    if (q1=='over-de-cultuurnota') { setPageTitle('Over de cultuurnota'); $("#overcultuurnota_link").trigger("click");  }
    if (q1=='statistiek') { if (q2>1) { statistiek_overige_bekijk(q2) } } 

    //kaart
    if (q1=='statistische-kaart') { if (q2>1) { statistische_kaart_bekijk(q2);}   }
    if (q1=='uitgelicht-op-de-kaart') { if (q2>1) poiClick(q2); if (q3=='leesverder') { poi_lees_verder(q2); }   }
    if (q1=='uitgelicht') { if (q2>1) {} uitgelicht_leesverder(q2); }       
    if (q1=='jongerenkaart') { if (q3=='leesverder') { } else { if (q2>1) poiClickJongerenkaart(q2);} }



}
	  

function check_hash() {
  
   var hash = new String(document.location).split("#")[1];
    if (hash!=current_hash) {
	  current_hash = hash;
	  pageview();
	  ajax_load_page(hash);
    }
    setTimeout(check_hash,500);
}
	  

	  
function ajax_set_url(hash) {
    ignore_hash = true;
    
    document.location='#/'+hash;
    setTimeout(function(){
	  ignore_hash = false;
    },500);
}



function setPageTitle(title)
{
    if (title == undefined) title = '';
    if (title=='') title = 'Cultuurnota Noord-Holland';
    if (title.length>100) title = title.substr(0,100)+'..';
    document.title = 'Cultuur op de Kaart - '+title;
}
