/* GUID-4C404F2A848D4011BB3240526B466DA7 */

$(document).ready(function() {
	if ($('#chart').length) $('#chart').flexchart( { data: chartdata, flashUrl: "/pensioenfondsstork/flash/Flexchart.swf" } )
})

/*Button functions*/
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

/* Fix Minimal Page Height */
function fixMinHeight( correction ) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

  document.write("<img src='/images/blank.gif' width='1' height='" + (myHeight - correction) + "' border='0'>")
  
}


/* Fix Minimal Page Width */
function fixMinWidth( correction ) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  if( myWidth < 800)
  document.write(" ")
  else if(myWidth >800)
  document.write("<img src='/images/spacer.gif' height='189' width='" + (myWidth - correction) + "' border='0'>")
}


/*
mailto replaces the mailto:
anchor link and prevents
spambots harvesting the 
address.
*/

function mailto(name, domain){
 location.href = "mailto:" + name + "@" + domain;
}

window.onload = function()
{
  var ticker = document.getElementById('ticker');
  if(ticker)
    window.Ticker = new Ticker(ticker, 'LI', 2);  
}

$(document).ready(function(){
  
  /*var size = $.cookie('font_size'); 
  if(size)
    $('body').attr('class',"body " + size);*/

  $('div#fontsize div').click(function() {
    $.cookie('font_size', this.className,{expires: '7'}); 
    $('body').attr('class',"body " + this.className);
  });
  $("a.popup, a[href$='.pdf'], a[href$=Informatie-aanvragen.html], .legal-menu a, .tickerarea a").each(function()
  {
      $(this).addClass('iframe');
      //$(this).fancybox({frameWidth: Math.min($(window).width() - 75, 900), frameHeight: Math.min($(window).height() - 75, 500)});
  });
  
  $('.checkbox-check').each(function() {
     $('#C4_Form').submit(function() {
      var checked = false;
      $('#C4_Form input:checked').each(function() {
        checked = true;
      });
      
      if (!checked)
      {
        alert('U dient minimaal 1 brochure aanvinken');
        return false;
      }
      
      return true;
     });
  });
  
  $('#page.frame').each(function() {
    $('body').addClass('frame');
  });
	if($("#accordion").length) $("#accordion").accordion({ autoHeight: false,collapsible: true,header: 'h3' });
	
	$('#accordion .head').click(function() {
		$(this).next().toggle('slow');
		return false;
	}).next().hide();

});


// google maps
var toPoint;
// Call this function when the page has been loaded 

function setDirections() {
  geocoder = new google.maps.ClientGeocoder();
  if (geocoder) {
    geocoder.getLocations(toPoint, function(oResults) {
      var map = new google.maps.Map2(document.getElementById("map"));
      map.enableScrollWheelZoom();
      map.setMapType(G_HYBRID_MAP);
      
      $$('directions').innerHTML = "";
      gdir = new google.maps.Directions(map, $$('directions'));
      google.maps.Event.addListener(gdir, "error", handleErrors);
      if (oResults.Status.code = 200)
      {
        gdir.load("from: " + $$('fromAddress').value + " to: " + oResults.Placemark[0].address,{locale: "nl"});
      }
      else
      {
        alert('Helaas kan de bestemming niet nauwkeurig vastgesteld worden.');
      } 
    });
  }
}

function handleErrors(){
	   if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("Adres kon niet gevonden worden. Gelieve postcodes zonder spatie invoeren.\nError code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("Onbekende fout.\n Error code: " + gdir.getStatus().code);
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("Geen adres ingevoerd.\n Error code: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert("Neem contact op met uw webmaster. \n Error code: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("Uw route kon niet berekend worden.\n Error code: " + gdir.getStatus().code);
	    
	   else alert("Er is een onbekende fout opgetreden.");
	   
     initialize();
	}

function Ticker(ticker, tagName, speed)
{
  var self = this;
  
  self.Ticker = ticker;
  self.InitialSpeed = speed;
  self.TagName = tagName;

  self.Timer = 0;
  
  self.Scroll = function()
  {
    if(self.Speed != 0)
    {
      var l = self.Ticker.style.left == '' ? 0 : parseInt(self.Ticker.style.left);
      l -= self.Speed;
      if(l > 0)
        l = self.MostLeft;
      else if(l <= self.MostLeft)
        l = 0;
      self.Ticker.style.left = l + 'px';
      if(self.Timer)
        clearTimeout(self.Timer);
      self.Timer = setTimeout(self.Scroll, 75);
    }
  }

  self.Stop = function()
  {
    self.Speed = 0;
    if(self.Timer)
      clearTimeout(self.Timer);
  }
  
  self.Start = function()
  {
    self.Speed = self.InitialSpeed;
    self.Scroll();
  }
  
  self.Init = function()
  {
    self.List = self.Ticker.getElementsByTagName(self.TagName);
    self.Count = self.List.length + 10;
    self.MostLeft = 0;
  
    if(true)
      self.MostLeft = self.Ticker.clientWidth;
    else
    {
      for(var i=0; i < self.Count; i++)
        self.MostLeft = self.MostLeft + self.List[i].clientWidth;
    }

    self.Ticker.style.width = '1955px';
    self.MostLeft = self.MostLeft * -1;
  
    for(var i=0; i < self.Count; i++)
    {
      var x = self.List[0].parentNode.appendChild(self.List[i].cloneNode(true));
      self.List[i].onmouseover = x.onmouseover = self.Stop;
      self.List[i].onmouseout = x.onmouseout = self.Start;
    }
    
    self.Start();
  }
  self.Init();
}
