
$(document).ready(function() {
  replaceText();
  load_google_map();

  $('ul#galerij_links').innerfade({
    speed: 2000,
    timeout: 5000,
    type: 'sequence',
    containerheight: '368px'
  });

  $('ul#galerij_rechts').innerfade({
    speed: 2000,
    timeout: 5000,
    type: 'sequence',
    containerheight: '368px'
  });

  $('ul#galerij_projectaanpak').innerfade({
    speed: 1500,
    timeout: 2500,
    type: 'sequence',
    containerheight: '368px'
  });
});

$(document).unload(function() {
  GUnload();
});

function replaceText()
{
  //rolloverscript
  var teller = 0;
  overs = new Array();
  outs = new Array();

  $('ul#hoofdnav li a').each(function() {
     var text = escape($(this).text());
     var last = '';

     if($(this).attr('class') == "navItemActive")
     {
       $(this).html('<img src="images/gd/image.php?type=hoofdbuttonactief&text='+urlencode(text)+'" id="hoofdbutton' + teller + '" />');
     }
     else if($(this).attr('class') == "navItemOver")
     {
       $(this).html('<img src="images/gd/image.php?type=hoofdbuttonover&text='+urlencode(text)+'" id="hoofdbutton' + teller + '" />');
     }
     else
     {
       if($(this).attr('class') == "last")
       {
       // last = '&last=1';
       }
       overs[teller] = new Image();
       overs[teller].src= 'images/gd/image.php?type=hoofdbuttonover' + last + '&text=' + urlencode(text);

       outs[teller] = new Image();
       outs[teller].src= 'images/gd/image.php?type=hoofdbutton' + last + '&text=' + urlencode(text);

       $(this).html('<img src="images/gd/image.php?type=hoofdbutton' + last + '&text='+urlencode(text)+'" id="hoofdbutton' + teller + '" />');

       $(this).hover(function() {
           var id = $(this).find('img').attr('id').replace('hoofdbutton','');
           document.getElementById($(this).find('img').attr('id')).src = overs[id].src;
         },
         function() {
           var id = $(this).find('img').attr('id').replace('hoofdbutton','');
           document.getElementById($(this).find('img').attr('id')).src = outs[id].src;
         });

     }

     teller++;

   });

   //referentiebuttons
  $('ul#refnav li a').each(function() {
     var text = escape($(this).text());
     var last = '';

     if($(this).attr('class') == "navItemActive")
     {
       $(this).html('<img src="images/gd/image.php?type=refbuttonactief&text='+urlencode(text)+'" id="refbutton' + teller + '" />');
     }
     else if($(this).attr('class') == "navItemOver")
     {
       $(this).html('<img src="images/gd/image.php?type=refbuttonover&text='+urlencode(text)+'" id="refbutton' + teller + '" />');
     }
     else
     {
       if($(this).attr('class') == "last")
       {
       // last = '&last=1';
       }
       overs[teller] = new Image();
       overs[teller].src= 'images/gd/image.php?type=refbuttonover' + last + '&text=' + urlencode(text);

       outs[teller] = new Image();
       outs[teller].src= 'images/gd/image.php?type=refbutton' + last + '&text=' + urlencode(text);

       $(this).html('<img src="images/gd/image.php?type=refbutton' + last + '&text='+urlencode(text)+'" id="refbutton' + teller + '" />');

       $(this).hover(function() {
           var id = $(this).find('img').attr('id').replace('refbutton','');
           document.getElementById($(this).find('img').attr('id')).src = overs[id].src;
         },
         function() {
           var id = $(this).find('img').attr('id').replace('refbutton','');
           document.getElementById($(this).find('img').attr('id')).src = outs[id].src;
         });

     }

     teller++;

   });

  //replace page title
  $('#content h1').each(function() {
    var text = escape($(this).text());
    $(this).html('<img src="images/gd/image.php?type=paginatitel&text='+urlencode(text)+'" />');
  });

  //replace nieuws title
  $('#nieuwsitemcontent h1').each(function() {
    var text = escape($(this).text());
    $(this).html('<img src="images/gd/image.php?type=paginatitel&text='+urlencode(text)+'" />');
  });

  //replace nieuws title
  $('span.nieuws_titel').each(function() {
    var text = escape($(this).text());
    $(this).html('<img src="images/gd/image.php?type=paginatitel&text='+urlencode(text)+'" />');
  });

  //replace page title
  $('#route_container h1').each(function() {
    var text = escape($(this).text());
    $(this).html('<img src="images/gd/image.php?type=paginatitel&text='+urlencode(text)+'" />');
  });

  //replace nieuws home title
  $('.nieuwstekst h2').each(function() {
    var text = escape($(this).text());
    $(this).html('<img src="images/gd/image.php?type=nieuwstitelhome&text='+urlencode(text)+'" />');
  });

  //replace nieuws home title
  $('.detail_tekst h2').each(function() {
    var text = escape($(this).text());
    $(this).html('<img src="images/gd/image.php?type=nieuwstitelhome&text='+urlencode(text)+'" />');
  });

  //replace gloed titel
  $('.gloed h2').each(function() {
    var text = escape($(this).text());
    $(this).html('<img src="images/gd/image.php?type=gloedtitel_wit&text='+urlencode(text)+'" />');
  });
  $('.gloed h3').each(function() {
    var text = escape($(this).text());
    $(this).html('<img src="images/gd/image.php?type=gloedtitel_grijs&text='+urlencode(text)+'" />');
  });

  //replace ref naam
  $('ul#refnav_namen li.refnaam').each(function() {
    var text = escape($(this).text());
    $(this).html('<img src="images/gd/image.php?type=refnaam&text='+urlencode(text)+'" />');
  });

  //replace referentie hover titel
  $('.categorie_over h2').each(function() {
    var text = escape($(this).text());
    $(this).html('<img src="images/gd/image.php?type=referentiehovertitel&text='+urlencode(text)+'" />');
  });

}

function load_google_map() {

  var markerHTML;

  markerHTML = "<div id=\"google_address\"><b>Reklaspits</b> <br><br>Industrieweg 59<br />1521 NE Wormerveer <br /><a style='color:#e32219;' href =\"mailto:info@reklaspits.nl\">info@reklaspits.nl</a> <br />tel: +31 (0)75 6353551  <br /><br> Routebeschrijving? <a style='color:#e32219;' href='http://maps.google.com/maps?f=q&source=s_q&hl=nl&geocode=&q=Industrieweg+59,+1521+wormerveer&sll=52.516156,4.781349&sspn=0.009637,0.019205&ie=UTF8&hq=&hnear=Industrieweg+59,+1521+Westknollendam,+Zaanstad,+Noord-Holland,+Nederland&ll=52.516325,4.781349&spn=0.009637,0.019205&z=16&iwloc=r0&iwstate1=dir' target='_blank'>Klik hier</a></div>";

  var google_div = document.getElementById('google_map');

  if(google_div != null)
  {
    if (GBrowserIsCompatible())
    {
      var map = new GMap2(document.getElementById("google_map"));
      map.addControl(new GSmallMapControl());
      map.setCenter(new GLatLng(latitude, longitude), 12);
      var point = new GPoint(longitude, latitude);
      map.addOverlay(new GMarker(point));
        var marker = new GMarker(point);
      map.addOverlay(marker);
      marker.openInfoWindowHtml(markerHTML);
    }
  }
}

function urlencode( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Brett Zamir
    // %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'

    var histogram = {}, tmp_arr = [];
    var ret = str.toString();

    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };

    // The histogram is identical to the one in urldecode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';
    histogram['%20'] = '+';

    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);

    for (search in histogram) {
        replace = histogram[search];
        ret = replacer(search, replace, ret) // Custom replace. No regexing
    }

    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });

    return ret;
}