  /*
  *
  * @Author	Ren̩ v. Sweeden
  * @Date	31/03/2010
  * @Mod. by	Ren̩ v. Sweeden
  * @Mod. date	01/04/2010
  *
  */
  
  var init = {
          resize: null,
          map: null,
          set: false,
          geocoder: null,
          load: function() {
                  // Select container
                  var cont = $( '#container' );
                  if( cont.length ) {
                          var wdh = $( window ).height();
                          if( cont.height() < wdh )
                                  init.resize = cont.height( wdh );
                  }
                  
                  // Fix navigation
                  var navi = $( 'ul.bottom' );
                  if( navi.length ) {
                          // Get last element
                          var li = $( 'li:last-child', navi );
                          if( li.length ) {
                                  li.addClass( 'last-child' );
                                  
                                  // Little background fix
                                  $( 'a', li ).css( 'background-position', '-' + ( 222/*background image width*/ - li.width() ) + 'px 0px' );
                          }
                          
                          // Get first element
                          var li = $( 'li:first-child', navi );
                          if( li.length ) {
                                  li.addClass( 'first-child' );
                          }
                  }
                  
                  // Find lang. menu
                  var l_m = $( 'a.arrow.down.lang' );
                  if( l_m.length ) {
                          l_m.bind( 'click', function(){
                                  $(this).next().toggleClass( 'show' );
                          });
                          
                          // Get lang. children
                          /*$.each( $( 'li', l_m.next() ), function(){
                                 var li = $(this);
                                 
                                 // Bind click event
                                 li.find( 'a' ).bind( 'click', function(){
                                         // Get current location
                                         var currentLoc = window.location.href;
                                         
                                         // Get current lang
                                         var currentLang = $( '#lang' ).attr( 'content' );
                                         
                                         // Replace
                                         window.location = currentLoc.replace( '\/' + currentLang + '\/', '/' + $(this).attr( 'lang' ) + '/' );
                                 });
                          });*/
                  }
                  
                  // Find search button
                  var s_b = $( 'input.search' );
                  if( s_b.length ) {
                          s_b.bind( 'focus', function(){
                                  if( $(this).val() == 'Search' ) {
                                          $(this).val( '' );
                                  }
                          }).bind( 'blur', function(){
                                  if( $(this).val() == '' ) {
                                          $(this).val( 'Search' );
                                  }
                          }).bind( 'keyup', function(event){
                                  var e = ( !event ? window.event : event );
                                  if( e.keyCode == 13 )
                                          $(this).next().trigger( 'click' );
                          });
                          
                          // Get arrow
                          s_b.next().bind( 'click', function(){
                                  var inp = $(this).prev().val();
                                  if( inp != '' )
                                          window.location = url + '/' + current_lang + '/search/' + encodeURI( inp );
                          });
                  }
                  
                  // Find map canvas
                  var map = $( 'div#map_canvas' );
                  if( map.length ) {
                          // Init gmaps
                          if ( GBrowserIsCompatible() ) {
                                  init.map = new GMap2( map.get(0) );
                                  init.map.setUIToDefault();
                                  init.geocoder = new GClientGeocoder();
                                  init.set = false;
                                  
                                  // Set lines
                                  map.css( 'border', '1px solid #443D31' );
                                  
                                  // Get address
                                  var addr = map.prev();
                                  
                                  $( addr ).each(function(){
                                          var dv = $(this);
                                          
                                          // Get addr lines
                                          var lns = dv.html();
                                          
                                          // Lines
                                          var totall_addr = dv.attr( 'title' );
                                          
                                          // Diff addr?
                                          /*
                                          if( lns[5].substr(0,2) != 'T:' ){
                                                  totall_addr += ', ' + lns[5];
                                                  
                                                  if( lns[6].substr(0,2) != 'T:' )
                                                          totall_addr += ', ' + lns[6];
                                          }*/
                                          
                                          init.geocoder.getLatLng(totall_addr, (function(v){
                                                  return function(point){
                                                          if(point) {
                                                                  if( !init.set ){ init.map.setCenter( point, 5 ); init.set=true; }
                                                                  var marker = new GMarker(point, {
                                                                  });
                                                                  
                                                                  GEvent.addListener( marker, "click", (function(mv){
                                                                          return function() {
                                                                                  marker.openInfoWindowHtml( mv );
                                                                          };
                                                                  })(v));
                                                                  
                                                                  init.map.addOverlay(marker);
                                                          }
                                                  };
                                          })(lns));
                                  });
                          }
                  }
          }
  };
  
  $( window ).bind( 'load', init.load ).bind( 'resize', function(){
          if( init.resize ) { 
                  var wdh = $( window ).height();
                  if( init.resize.css( 'height', 'auto' ).height() < wdh )
                          init.resize.height( $( window ).height() );
          }
  });


  /*
  *
  * Etopia BV
  * Init JavaScript
  *
  */
  
  var init = {
          load: function(){
            
                  init.contentFix();
                   
                  // Create a fade effect on the header,
                  // but only if there are more images then one
                  var imageCollection = $( '.interested' );
                  if( imageCollection.children().length >= 2 ) {
                          $( '.interested' ).cycle({
                                  fx: 'fade',
                                  slideExpr: 'a',
                                  timeout: 4000
                                  //pager: '#header .image_pager'
                          });
                  }
          
          },
          
          contentFix: function() {
                  // Get first content holder, compare
                  // with the other one's to make it equal
                  var f = $( '#content > .left' ), s = $( '#content > .right' );
                  if( f.length && s.length ) {
                          var fHeight = f.height(), sHeight = s.height();
                          if( fHeight > sHeight ) {
                                  s.css( 'height', fHeight + 'px' );
                          }
                          else { 
                                  f.css( 'height', sHeight + 'px' );
                          }
                  }
          }
  };
  
  // Load
  $(function(){
          init.load();
  });
