 $(document).ready(function() {
   $("#companytab").hover(
     function(){$("#company_snav").show();$("#company_snav_de").show();},
     function(){$("#company_snav").hide();$("#company_snav_de").hide();}
   );    
   $("#company_snav,#company_snav_de").hover(
     function(){$(this).show();$("#companytab a").addClass('sub_hover');},
     function(){$(this).hide();$("#companytab a").removeClass('sub_hover');}
   );    
   $("#productstab").hover(
     function(){$("#product_snav").show();$("#product_snav_de").show();},
     function(){$("#product_snav").hide();$("#product_snav_de").hide();}
   );      
  $("#product_snav,#product_snav_de").hover(
     function(){$(this).show();$("#productstab a").addClass('sub_hover');$("#productstab a span").addClass('sub_span_hover');},
     function(){$(this).hide();$("#productstab a").removeClass('sub_hover');$("#productstab a span").removeClass('sub_span_hover');}
   );    
  $("#techtab").hover(
     function(){$("#technology_snav").show();$("#technology_snav_de").show();},
     function(){$("#technology_snav").hide();$("#technology_snav_de").hide();}
   );      
  $("#technology_snav,#technology_snav_de").hover(
     function(){$(this).show();$("#techtab a").addClass('sub_hover');$("#techtab a span").addClass('sub_span_hover');},
     function(){$(this).hide();$("#techtab a").removeClass('sub_hover');$("#techtab a span").removeClass('sub_span_hover');}
   );             
  $("#secondnav ul li").hover(
     function(){$(this).addClass('highlighted_nav');},
     function(){$(this).removeClass('highlighted_nav');}
   );   
   
   /* remove border from bottom lineitems in the subnav  */
   $("#secondnav ul").find("li:last").css('border-bottom','none'); 
   
   /* Add a simple toggle control for the details on the view page */
   if ($("#install_toggle_details")) {
     $("#install_toggle_details").toggle(
       function() {
       	if (lang == "de") {
       		$(this).text("- Ausblenden");
	     	} else {
	     		$(this).text("- Hide details");
	     	}
         $("#installdetails").show("fast");
       },
       function() {
       	if (lang == "de") {
       		$(this).text("+ Einblenden")
	     	} else {
	     		$(this).text("+ View more details")
	     	}
         $("#installdetails").hide("fast");
       }
     );}
     
     
     if ($("#categoryselect").length) {
     	$("#categoryselect").bind("change",
     		function () {
     			if (!isNaN($(this).attr("value"))) {
     				// append the section filter to the request and reload the page
     				var qs = "";
     				if (document.location.search.match("site=[0-9]+")) {
     					qs = "?section=" + $(this).attr("value") + "&site=" + document.location.search.match("site=([0-9]+)")[1];
   					} else {
   						qs = "?section=" + $(this).attr("value");
   					}
     				document.location = document.location.pathname + qs;
   				} else {
   					// Reset the page to the baseline filter
   					var qs2 = "";
   					if (document.location.search.match("site=[0-9]+")) {
   						qs2 = "?site=" + document.location.search.match("site=([0-9]+)")[1];
   					}
   					document.location = document.location.pathname + qs2;
   				}
     		}
   		);
   		$("#siteselect").bind("change",
     		function () {
     			if (!isNaN($(this).attr("value"))) {
     				// append the section filter to the request and reload the page
     				var qs = "";
     				if (document.location.search.match("section=[0-9]")) {
     					qs = "?site=" + $(this).attr("value") + "&section=" + document.location.search.match("section=([0-9])")[1];
   					} else {
   						qs = "?site=" + $(this).attr("value");
   					}
     				document.location = document.location.pathname + qs;
   				} else {
   					// Reset the page to the baseline filter
   					var qs2 = "";
   					if (document.location.search.match("section=[0-9]")) {
   						qs2 = "?section=" + document.location.search.match("section=([0-9])")[1];
   					}
   					document.location = document.location.pathname + qs2;
   				}
     		}
 			);
     }
          
     if ($("#image_browser").length) {
     var x = 0;
     var thumbs = $("#image_browser").children();
     $("#photocredit").text($("#photocreditdata").text());
     if (pages > 0) {
      	$("#ib_left").bind("click", function () {
      		if ( x != 0) {
        		$("#image_browser").animate({"left": "+=672px"});
        		x = x - 1;
        		if (x < pages) {
        		  $("#ib_right").attr("src", "/images/installations/ib_right.png");
        		}
        		if (x == 0) {
        		  $(this).attr("src", "/images/installations/ib_left_off.png");
        		}
      		} else {
      		  $(this).attr("src", "/images/installations/ib_left_off.png");
      		}
    		});
       	$("#ib_right").bind("click", function () {
       		if (x < pages) {
       			$("#image_browser").animate({"left": "-=672px"});
       			x = x + 1;
       			$("#ib_left").attr("src", "/images/installations/ib_left.png");
       			if (x == pages) {
       			  $(this).attr("src", "/images/installations/ib_right_off.png");
       			}
     			}
     		});
   		} else {
   		  $("#ib_right").attr("src", "/images/installations/ib_right_off.png");
   		}
     thumbs.bind("click", function() {$("#ib_preview").hide(); $(this).siblings().css({"border": "1px solid #fff"}); $(this).css({"border": "1px solid #000"}); var t = $(this); var p = $("#currentphoto"); var d = $("#installtitle");var i = imageInfo[t.attr("id")]; p.fadeOut("normal", function() {
     	p.attr("src", t.attr("src"));
     	d.text(t.attr("title"));
     	if ($("#installer").length) {
	     	$("#installer").text(i.installer);
	     	$("#install_size").text(i.size);
	     	$("#install_location").text(i.location);
	     	$("#install_date").text(i.date);
	     	$("#installdetails").html(i.content);
	     	$("#photocredit").text($("#photocreditdata").text());
   		}
   		if ($("#constdetails").length) {
   			$("#constdetails").html(i.content);
   			$("#constdate").text(i.date);
   		}
     	p.fadeIn();
     	});});
     	thumbs.bind("mouseenter", function () {$("#ib_preview").css({"left": $("#image_browser").attr("offsetLeft") + $(this).attr("offsetLeft") - 20}).children().attr("src", $(this).attr("src")); $("#ib_preview").fadeIn("fast") });
     	thumbs.bind("mouseleave", function () { $("#ib_preview").hide(); });
     }         
 });
