$(document).ready(function() {

	var $subnav_background = $('<div id="subnav-bg"></div>');					   

	$("#main-navigation > li").mouseover(function() {
		
		//add subnav background div is submenu exists, otherwise remove it.
		if($(this).find('ul').length > 0 ) { 		 						   	
			$subnav_background.prependTo($('body'));	
		} else {
			$('#subnav-bg').remove();
		}
		
		//hide all other subnavs
		if($(this).hasClass('active-tab') == false ) {
			$('li.active-tab > ul').hide();
		}
		
	}).mouseout(function(){
		
		//remove subnav background  and show active submenu
		$('#subnav-bg').remove();
		$('li.active-tab > ul').show();
		
		//if active tab exists restore subnav background
		if($('li.active-tab').length > 0 ) {
			$subnav_background.prependTo($('body'));	
		}
		
	});
	
	//if active-tabs exist, show subnav
	if($("li.active-tab").length > 0 ) { 
		 $('li.active-tab').find('ul').show();
		 $subnav_background.prependTo($('body'));	
	}
	
	
	// Foto gallery lightbox
	$('div.gallery a.item').lightBox({
      imageLoading:			'/app_themes/beestengoed/img/lightbox-ico-loading.gif', 
			imageBtnPrev:			'/app_themes/beestengoed/img/lightbox-btn-prev.gif', 
			imageBtnNext:			'/app_themes/beestengoed/img/lightbox-btn-next.gif', 
			imageBtnClose:		'/app_themes/beestengoed/img/lightbox-btn-close.gif', 
			imageBlank:				'/app_themes/beestengoed/img/lightbox-blank.gif'	
  
  });
  
  
  
  // Highlight menu item on home page 
  
  if ($("div.main-home-layout").length > 0) 
  {
      $("a#back-home").addClass("active-home");
  }
  
  
  
  
  //Webshop-bestel
  
  // select producten by query string id
  if ($("div.webshop-bestel").length > 0) {
    var queryId = $.jqURL.get('id');
    if (queryId.length > 0) 
    {      
      $('select.producten-selector option').each(function() {
          if ($(this).val() == queryId) {
            $(this).attr('selected', 'yes');
          }
      });
    }
  }
  
  // clear factuur-adres input fields when selected 'Nee'
  if ($("div.factuur-adres").length > 0)
  {
      $("table.equal-adreses input").change(function() 
      { 
        var state = $(this).parent().find("label").text();
        
        if (state == "Nee") {
          $("div.factuur-adres td.form-input input").val("");        
        }   
        
        if (state == "Ja") 
        {          
          $("div.factuur-adres input.inp_voornaam").val($("div.aflever-adres input.inp_voornaam").val());
          
          $("div.factuur-adres input.inp_achternaam").val($("div.aflever-adres input.inp_achternaam").val());
          
          $("div.factuur-adres input.inp_adres").val($("div.aflever-adres input.inp_adres").val());
          
          $("div.factuur-adres input.inp_postcode").val($("div.aflever-adres input.inp_postcode").val());
          
          $("div.factuur-adres input.inp_plaats").val($("div.aflever-adres input.inp_plaats").val());
		  
          $("div.factuur-adres input.inp_tel").val($("div.aflever-adres input.inp_tel").val());
		  
          $("div.factuur-adres input.inp_email").val($("div.aflever-adres input.inp_email").val());
        }           
      });
  }
  
  
  
  // Search & Login
  
  if ($("input.searchfield").length > 0 && $("input.searchfield").val().length == 0) {
    $("input.searchfield").val("Zoeken");
  }
  $("input.searchfield").focus(function() {
    if($(this).val().indexOf("Zoeken") != -1) {
        $(this).val("");
    } 
  });  

  // Search results paging changes
  if($(".PagerResults").length > 0)
  {
 	 var s = $(".PagerResults").html();
	  s = s.replace("Displaying results", "Resultaten");
	  s = s.replace("(of", "(van");
	  $(".PagerResults").html(s);
  }
  if($(".ResultPath").length > 0)
  {
	$('.ResultPath').each(function() {
 	 	 var s = $(this).html();
		 s = s.replace("Path:", "Locatie:");
		 $(this).html(s);

        });
  }
  
  
  
  if ($("input.user-gebruikersnaam").length > 0 && $("input.user-gebruikersnaam").val().length == 0) {
    $("input.user-gebruikersnaam").val("Gebruikersnaam");
  }
  $("input.user-gebruikersnaam").focus(function() {
    if($(this).val().indexOf("Gebruikersnaam") != -1) {
        $(this).val("");
    } 
  });  
  
  
  if ($("input.user-wachtwoord").length > 0 && $("input.user-wachtwoord").val().length == 0) {
    $("input.user-wachtwoord").val("Wachtwoord");
  }
  $("input.user-wachtwoord").focus(function() {
    if($(this).val().indexOf("Wachtwoord") != -1) {
        $(this).val("");
    } 
  });
  
  
  // newsbrief
  $("div.nieuwsbrief input.uw-email").focus(function() {    
    if($(this).val().indexOf("Uw email adres") != -1) {
        $(this).val("");
    } 
  });
  
  
  // Restore password
  $("div.wachtwoord-vergeten input.form-voornaam").focus(function() {    
    if($(this).val().indexOf("Uw emailadres") != -1) {
        $(this).val("");
    } 
  });
  
  
  
  // Teaser replace
  if ($("div#teaser_image img").length > 0) {
    
    var imgPath = $("div#teaser_image img").attr("src");
    $("div#container").css("background-image", "url(\"" + imgPath + "\")");
  }
  
  
  
  
  
  
  
  
		
});
