
  /*
  *
  * 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 = $( '#header > .image_collection' );
                  if( imageCollection.children().length >= 2 ) {
                          $( '#header' ).cycle({
                                  fx: 'fade',
                                  slideExpr: '.image_collection > img',
                                  timeout: 8000,
                                  pager: '#header .image_pager'
                          });
                  }
                  
                  setTimeout(function(){
                          // Get image height
                          var firstImageFound = $( '#header .image_collection > img' );
                          
                          if( firstImageFound.height() > 200 ) {
                                 // Set imageHeight to header
                                 $( '#header' ).css( 'height', firstImageFound.height() + 'px' );
                          }
                  }, 1500 );
                  
                  // Get last list
                  var list = $( '.logo > ul' );
                  if( list.length ) {
                          $( 'li:last-child', list ).addClass( 'last-child' );
                  }
                  
                  // Load search option
                  var s_opt = $( 'input.autofill' );
                  if( s_opt.length ) {
                          s_opt.attr( 'default_val', s_opt.val() ).bind( 'focus', function(){
                                  var m = $(this);
                                  if( m.val() == m.attr( 'default_val' ) ) {
                                          m.val('');
                                  }
                          }).bind( 'blur', function(){
                                  var m = $(this);
                                  if( m.val() == '' || m.val() == ' ' ) {
                                          m.val( m.attr( 'default_val' ) );
                                  }
                          }).bind( 'keyup', function( event ){
                                  var e = (!event?window.event:event);
                                  if( e.keyCode == 13 ) {
                                          $( this ).trigger( 'send' );
                                  }
                          }).bind( 'send', function(){
                                  window.location = url + '/' + current_lang + '/search/' + encodeURI( $(this).val() );
                          });
                  }
                  
                  // Get images
                  var content = $( '#content' );
                  if( content.length ) {
                          // Got some images?
                          var images = content.find( 'img' );
                          if( images.length ) {
                                  images.each(function(){
                                         if( $(this).parent()[0].tagName != 'A' ) {
                                                $(this).wrap( $( '<a />' ).attr( 'href', $(this).attr( 'src' ) ).addClass( 'shadowbox' ) );
                                         }
                                  });
                          }
                          
                          Shadowbox.setup( 'a.shadowbox', {} );

                  }
          
          },
          
          contentFix: function() {
                  // Get first content holder, compare
                  // with the other one's to make it equal
                  var f = $( '#content > .first' ), s = $( '#content > .second' ), t = $( '#content > .third' );
                  if( f.length && s.length && !t.length ) {
                          var fHeight = f.height(), sHeight = s.height();
                          if( fHeight > sHeight ) {
                                  s.css( 'height', fHeight + 'px' );
                          }
                          else { 
                                  f.css( 'height', sHeight + 'px' );
                          }
                  }
                  else if( f.length && s.length && t.length ) {
                          if( f.height() > s.height() ) {
                                  if( f.height() > t.height() ) {
                                          s.css( 'height', f.height() + 'px' );
                                          t.css( 'height', f.height() + 'px' );
                                  }
                                  else {
                                          s.css( 'height', t.height() + 'px' );
                                          f.css( 'height', t.height() + 'px' );
                                  }
                          }
                          else if( s.height() > t.height() ) {
                                  if( s.height() > f.height() ) {
                                          f.css( 'height', s.height() + 'px' );
                                          t.css( 'height', s.height() + 'px' );
                                  }
                                  else {
                                          t.css( 'height', f.height() + 'px' );
                                          s.css( 'height', f.height() + 'px' );
                                  }
                          }
                  }
          },
          
          headerExpand: function(Op) {
                  var logo = $( '#header > .logo' );
                  if( Op ) {
                          logo.toggleClass( 'opacity' );
                  }
                  
                  logo.toggleClass( 'expand' );
          }
  };
  
  // Load
  $(function(){
          init.load();
  });