/* 
The Orchard Leeds JavaScript 
Author: Gjokica George Zafirovski
Author URL: http://gz.sunsblog.net
*/

$(document).ready(function() {

  // mute all pages with sub-pages - turn them in to navigation links
  $("#orchard-navigation a").each(function(i) {
	if($(this).parent().children("ul").size() == 1) {
       $(this).attr('href', 'javascript:void(0)');
     }
  });
  
  // set on mouse click to show sub-nav and hide siblings if opened
  $("#orchard-navigation a").click(function() {
  	   if($(this).parent().children("ul").size() == 1) {
  	   		$(this).parent().siblings().children("ul").each(function(i){
  	   			if($(this).css('display') == 'block') {
  	   				$(this).slideToggle('slow');
  	   			}
  	   		});
			$(this).parent().children("ul").slideToggle("slow");
       }
  });
  
  // show selected page
  
  if ($(".current_page_item").is("li")){
  	$(".current_page_item").parent().show();
  	$(".current_page_parent").parent().show();
                      if($(".current_page_parent").attr('class')=="page_item page-item-228 current_page_parent" || $(".current_page_parent").attr('class')=="page_item page-item-236 current_page_parent") {
                      $(".current_page_parent").parent().parent().parent().show();
                      }
  } else {
  	$(".page-item-168").parent().show();
  	$(".page-item-168").parent().parent().show();
  	$(".page-item-168").css('backgroundColor', '#7BB372');
  }
  
  // create breadcrumbs
  /*
  $(".current_page_item a").clone().prependTo("#breadcrumbs");
  $(".current_page_parent a").eq(0).clone().prependTo("#breadcrumbs");
  $(".current_page_parent").parent().parent().clone().prependTo("#breadcrumbs");
  */
  
  // set content-container hight to fit window if body haight not bigger then window height
  if($.browser.msie) { 
  	if($("body").height() < document.documentElement.offsetHeight){
  		var newHeight = document.documentElement.offsetHeight - ($("#header").height() + $("#footer").height()) - 15 + 'px';
  		$("#content-container").height(newHeight);
  	}
  } else {
    if($("body").height() < window.innerHeight){
    	var newHeight = window.innerHeight - ($("#header").height() + $("#footer").height()) - 10 + 'px';
        $("#content").height(newHeight);
  	}
  }
});
