
  /*
  *  JS
  * Etopia BV
  */
  
  var map, gdir, geocoder;
  $(function(){
          $( 'ul#items:not(.mini) li' ).each(function(){
                  $(this).click(function(){
                          if( $(this).find( 'a.more-info' ).length ) {
                                  var ur = sub + '/' + $(this).find( 'a.more-info' ).attr( 'href' );
                                  ur = ur.replace( /\.\.\/\.\.\//g, '' );
                                  window.location = ur;
                          }
                  });
          });
          
          var clickVid = $( '#click-vid' );
          if( clickVid.length ) {
                  /*clickVid.click(function(){
                          $( '<div />' ).addClass( 'vid-player' ).html( '<object type="application/x-shockwave-flash" data="' + url + '/javascript/shadowbox/player.swf" width="300" height="250" id="sb-player" style="visibility: visible; "><param name="bgcolor" value="#000000"><param name="allowfullscreen" value="true"><param name="flashvars" value="file=' + url + '/upload/videos/valk-FIN.flv&amp;height=290&amp;width=300&amp;autostart=true&amp;controlbar=bottom&amp;backcolor=0x000000&amp;frontcolor=0xCCCCCC&amp;lightcolor=0x557722"></object>' ).appendTo( $(this).parent() );
                          $( 'div#container > div#image' ).css( 'background-image', 'url(' + skin + 'images/home_bg_vid.png)' );
                          $(this).remove();
                  }).attr( 'href', 'javascript:void(0)' );*/
          }
          
          $( 'ul#items.mini li' ).each(function(i){
                  var sUrl = '';
                  switch( i ) {
                          case 0:
                                  sUrl = '/groeten_uit';
                          break;
                          case 1:
                                  sUrl = '/meld_u_aan';
                          break;
                          case 2:
                                  sUrl = '/bestel_nu';
                          break;
                  }
                  
                  $(this).find( 'a.more-info' ).attr( 'href', url + '/' + current_lang + sUrl );
                  $(this).click(function(){
                          if( $(this).find( 'a.more-info' ).length ) {
                                  window.location = $(this).find( 'a.more-info' ).attr( 'href' );
                          }
                  });
          });
          
          var a = $( 'div.return_home a' );
          if( a.length ) {
                  a.attr( 'href', url );
          }
          
          var a_learn = $( 'a.self_help_book, a.learn_and_relax' );
          if( a_learn.length ) {
                  a_learn.attr( 'href', url + '/nl/bestel_nu' );
                  
                  // Load up parent
                  a_learn.parent().find( 'h3' ).attr( 'data-href', url + '/nl/bestel_nu' ).click(function(){
                          window.location = $(this).attr( 'data-href' );
                  });
          }
          
          var a_learn = $( 'a.the_dvd_box' );
          if( a_learn.length ) {
                  a_learn.attr( 'href', url + '/nl/bestel_nu#dvdbox' );
          }
          
          var a_learn = $( 'a.app' );
          if( a_learn.length ) {
                  a_learn.attr( 'href', url + '/nl/bestel_nu#app' );
          }
          
          var i_twitter = $( 'img[src="' + url + '' + skin.substr( sub.length ) + 'images/twitter.png"], img[src="..' + skin.substr( sub.length ) + 'images/twitter.png"]' );
          if( i_twitter.length ) {
                  i_twitter.parent().attr( 'href', 'http://twitter.com/#!/stichtingvalk' ).attr( 'target', '_blank' );
          }
          
          var i_facebook = $( 'img[src="' + url + '' + skin.substr( sub.length ) + 'images/facebook.png"], img[src="..' + skin.substr( sub.length ) + 'images/facebook.png"]' );
          if( i_facebook.length ) {
                  i_facebook.parent().attr( 'href', 'http://www.facebook.com/pages/Stichting-VALK/306358249393577' ).attr( 'target', '_blank' );
          }
  
          var gmap = $( 'div#gmaps' );
          if( gmap.length ) {
                  if( GBrowserIsCompatible() ) {
                          map = new GMap2(document.getElementById("gmaps"));
                          map.setUIToDefault();
                          
                          // Add directions set to the end of the map
                          var dr = $( '<div />' ).css( 'display', 'none' ).attr( 'id', 'dirs' );
                          gmap.after(dr);
                          $( '<h3 />' ).text( 'Routebeschrijving' ).css({
                                'position': 'relative'
                          }).append(
                                $( '<a />' ).css({
                                      'position': 'absolute',
                                      'top': '2px',
                                      'right': '2px'
                                }).attr( 'href', 'javascript:window.print()' ).append(
                                     $( '<img />' ).css( 'border', '0 none' ).attr( 'src', skin +'/images/print.png' ).attr( 'alt', 'print' )
                                )
                          ).appendTo(dr);
                          $( '<div />' ).attr( 'id', 'directions' ).appendTo(dr);
                          
                          gdir = new GDirections(map, document.getElementById("directions"));
                          GEvent.addListener(gdir, "load", function(){
                                 $( '#dirs' ).show();
                          });
                          GEvent.addListener(gdir, "error", function(er){  });
                          
                          geocoder = new GClientGeocoder();
                          if ( geocoder ) {
                                  // Get addresses
                                  var addr1 = 'Sandifortdreef 1a, 2300 AC Leiden';
                                  geocoder.getLatLng(
                                          addr1,
                                          function(point) {
                                                  if (!point) {
                                                          alert(address);
                                                  } else {
                                                          map.setCenter(point, 17);
                                                          var marker = new GMarker(point, {});
                                                          GEvent.addListener(marker, "click", function(){
                                                                  marker.openInfoWindowHtml('Sandifortdreef 1a,<br />2300 AC Leiden<br />');
                                                          });
                                                          map.addOverlay(marker);
                                                  }
                                  });
                          }
                  }
          }

          
  });
