﻿var blnStarted = false;
var blnOnce = false;
var landingFade;
var ttTimeout;

$(document).ready(function () {
  if (!blnStarted) {
    blnStarted = true;
    radStartUp();
  }
});

function pageLoad(sender, args) {
  if (!blnStarted) {
    blnStarted = true;
    radStartUp();
  }
}

function radStartUp() {
	var blnLanding = false;

	$("a.logindd").click(function () {
		$(this).fadeOut(150);
		$("div.smallButton").animate({
			height: 170
		}, 200);
	});

	var fadeDelay = 0;
	var aHover = false;
	$("a.tt").hover(function () {
		var thisTip = $("div." + $(this).attr("rel"));
		if (!(thisTip).is(":visible")) {
			$("div.tooltip").fadeOut(200);
			$(thisTip).fadeIn(200);
		}
		clearTimeout(ttTimeout);
	},
	function () {
		aHover = false;
		hideTooltip();
	});

	$("div.tooltip").hover(function () {
		clearTimeout(ttTimeout);
	},
	function () {
		aHover = false;
		//if ($(this).attr("class") == "loginPopup tooltip") {
		//	fadeDelay = 3000;
		//	alert('out');
		//} else {
			fadeDelay = 1000;
		//}
		hideTooltip();
	});
	
	function hideTooltip() {

		ttTimeout = setTimeout(function () {
			//alert(aHover);
			if (!aHover) {
				$(".tooltip").fadeOut(150);
			}
		}, fadeDelay);
	}
  
  $("fieldset.collapsible a.expand").click(function(){
    if($(this).parent().attr("class") == 'collapsible closed') {
      $(this).parent().attr("class","collapsible open");
    } else {
      $(this).parent().attr("class","collapsible closed");
    }
  });

  attachFB();

  var browser = navigator.userAgent;
    
    /*================== FAQ EXPANDER ==================*/
  
    $("ul.faqs>li>a").css("display","block");
    $("ul.faqs li").each(function () {
    	$(this).height(25);
    });
    $("ul.faqs>li>a").click(function() {
      if($(this).parent().height() > $(this).height()) {
        $(this).parent().animate({
          height:     $(this).height()
        },200);
      } else {
        var newHeight = 0;
        $($(this).parent().children("p")).each(function(){
          newHeight += ($(this).height() + 20)
          $(this).parent().animate({
            height:     newHeight
          },200);
        });
        $($(this).parent().children("ul")).each(function(){
          newHeight += ($(this).height() + 20)
          $(this).parent().animate({
            height:     newHeight
          },200);
        });
        $(this).parent().animate({
          height:     newHeight += 10
        },10);
      }
    });
    
    /* =================== CONTACT CODE =================== */
    $("ul.contact li input").click(function(){
      var newValues = '';
      $("ul.contact li input").each(function() {
        if($(this).attr("checked")) {
          newValues = newValues + $(this).parent().text() + ',';
        }
        $("input.txtContactAbout").val(newValues);
      });
    });
    
    /* =================== START SLIDESHOW CODE =================== */

    try {
      if ($('div.rotater').children("div").length > 1) {
        $('div.rotater').jshowoff({ speed: 6000, links: false, controls: false });
      }
      $('div.pSlideShow').jshowoff({ speed: 6000, links: false, controls: true, cssClass: 'product' });
    } catch (err) { }

    if ($('div.largeRotater').length != 0) {
      $("div.content").css("padding-top", "12px");
      $("body").addClass("home");
      $("div.containerLarge").removeClass("subpage");
      if ($('div.largeRotater div ul').children("li").length > 1) {
        $('div.largeRotater div ul').jshowoff({ speed: 6000, links: false, controls: false });
      }
    }
    /* =================== START SLIDER CODE =================== */

    var $slide = $("div.slider ul");
    var $slidePos = $slide.position();
    var totalWidth = 0;
    var scrollWidth = 0;
    var clicks = 0;
    var items = $("div.slider ul").children("li").length;
    $("div.slider ul li").each(function () {
      totalWidth += $(this).width() + 50;
    });
    $slide.width(totalWidth);
    scrollWidth = totalWidth / items;
    $("div.slider a.arrow.right").click(function () {
      if (clicks < (items - 4)) {
        $slidePos.left -= scrollWidth;
        $slide.css("left", $slidePos.left + "px");
        clicks += 1;
      } else {
        $slide.css("right", "0px");
      }
      return false;
    });
    $("div.slider a.arrow.left").click(function () {
      if ($slidePos.left + scrollWidth > 0) {
          $slide.css("left", "0px");
        } else {
          $slidePos.left += scrollWidth;
          $slide.css("left", $slidePos.left + "px");
        }
      return false;
    });

    /* =================== START DROPDOWN NAVIGATION CODE =================== */
    
    var FadeNav;
    var FadeTO;
    var liCount = 0;

    $("ul.subNav.products li").slice(11, $("ul.subNav.products li").length).appendTo("ul.subNav.col2");

    $("ul.siteNav>li").hover(function () {
      if ($(this).attr("id") != "contact" && $(this).attr("id") != "blog") {
        if ($(this).attr("id") == "equipment") {
          $("div.subNav").addClass("wide");
        } else {
          $("div.subNav").removeClass("wide");
         }
         changePanels($(this).children("a").attr("rel"));

        clearTimeout(FadeNav);
        $("ul.siteNav li").removeClass("current");
        $(this).addClass("current");
        showMainNav();

        $("div.navPane").hide();
        $("div#subNav" + $(this).children("a").attr("rel")).show();
      }
    }, function() {
      FadeNav = setTimeout(hideMainNav, 100);
    });
    
    $("div.subNav").hover(function() {
      clearTimeout(landingFade);
      clearTimeout(FadeNav);
    }, function(){
        FadeNav = setTimeout(hideMainNav, 100);
    });
    
    $("div.infoPane div.pane0").css("display","block");
    $("ul.subNav>li").hover(function () {
      //$(this).children("a").css("background","solid 2px pink");
      changePanels($(this).children("a").attr("rel"));
      clearTimeout(FadeTO);
      $("ul.subNav>li").removeClass("selected");
      if ($(this).attr("class").indexOf("liHeader") < 0) {
        $(this).addClass("selected");
      }
      var navPos = $(this).position();

      if ($(this).children("ul").length) {
        $(this).children("ul").css("top", "0px");
        $(this).children("ul").css("left", $(this).width() + 1 + "px");
        $(this).children("ul").fadeIn(100);
      } else {
        $("ul.subNav>li ul").fadeOut(500);
      }
    },
    function () {
      $("div.pane").hide();
      $("div.pane0").show();
      FadeTO = setTimeout(hideSubNav, 500);
    });
    
    function showMainNav() {
      var navPos = $("li.current").position();
      //alert(navPos.left + " " + $("li.current").width());
      
      switch ($("li.current").attr("id")) {
        case "home":
          $("div.subNav").css("left", "80px");
          $("div.arrowDiv div.arrow").css("margin-right", "360px");  
          break;
        case "pools":
          $("div.subNav").css("left", "195px");
          $("div.arrowDiv div.arrow").css("margin-right", "360px");
          break;
        case "equipment":
         	$("div.subNav").css("left", "100px");
         	$("div.arrowDiv div.arrow").css("margin-right", "395px");
         	break;
        default:
          $("div.subNav").css("left", (navPos.left - ($("div.subNav").width() / 2) - 40 + "px"));
          $("div.arrowDiv div.arrow").css("margin-right", (217 - ($("li.current").width() / 2)) + "px");
          break;
      }
      
      $("div.subNav").animate({
        paddingTop:     '20px',
        paddingBottom:  '10px',
        height:         '286px'
      }, 250);
    }
    
    function hideMainNav() {
    if(!blnLanding) {
      $("div.subNav").animate({
          paddingTop:     '0px',
          paddingBottom:  '0px',
          height:         '0px'
        }, 250);
        $("ul.siteNav li").removeClass("current");
      }
      setCurrentNav();
    }
    
    function hideSubNav() {
      $("ul.subNav li").children("ul").hide();
      $("ul.subNav>li").removeClass("selected");
    }
    
    function setCurrentNav() {
      var sPath = window.location.pathname;
      var sPage = sPath.substring(sPath.lastIndexOf('/') + 1).toLowerCase();
      var navName = "";
      switch(sPage) {
        case "about-natare":
          showNav("home");
          break;
        case "natare-pools":
          showNav("pools");
          break;
        case "equipment-systems":
          showNav("equipment");
          break;
        case "services":
          showNav("services");
          break;
        case "resources":
          showNav("knowledge");
          break;
        case "contactus.aspx":
          showNav("contact");
          break;
      }
    }
    
    function showNav(cNav) {
      if(!blnOnce) {
        $("ul.siteNav li#" + cNav).mouseenter();
        //landingFade = setTimeout(hideMainNav, 3000);
        blnOnce = true;
      }
    }
		
    function changePanels(panelID) {
    	blnImage = true;
			if(panelID == '' || panelID == 'undefined') { panelID = 0 }
      //$("div.infoPane").html(panelID);
			switch (panelID) {
      	//ABOUT NATARE
				case "aboutnatare":
				case "1":
					$("div.infoPane div").html("We not only build and design indoor, outdoor and elevated swimming pools; we provide systems for zero-depth entry and beach pools, wet playgrounds, and water features including fountains and spray heads. Our engineered pool systems meet the needs of today's most innovative aquatic facilities.");
					break;
				case "dealers-distributors":
					$("div.infoPane div").html("Natare pools, stainless steel perimeter gutter systems and PVC lining systems are distributed and installed by certified pool contractors in select markets throughout the world.");
					break;
				case "careers":
					$("div.infoPane div").html("If you are an experienced aquatics, pool or construction professional, we may have a position for you.");
					break;
				case "news":
					$("div.infoPane div").html("The latest products, events and news from Natare Corporation. ");
					break;
				case "our-history":
					$("div.infoPane div").html("Setting the standard for swimming pool and aquatic facility construction since 1969.");
					break;
				case "our-projects":
					$("div.infoPane div").html("Natare projects run the gamut from international competition venues to the world’s most luxurious pools and spas, and everything in between.");
					break;
				case "press":
					$("div.infoPane div").html("Find our press kit, quick facts and the latest Natare headlines.");
					break;

				//NATARE POOLS 
				case "natarepools":
				case "2":
					$("div.infoPane div").html("A Natare pool gives you something you won’t find anywhere else—options. Whether you’re renovating an aging concrete pool and simply need a colorful lining system to make it watertight, or a brand new aquatic facility built from scratch, we will tailor a pool for you.");
					break;
				case "aquatic-recreation-public-pools":
					$("div.infoPane div").html("Natare pools for aquatic recreation, public, municipal and community pools.");
					break;
				case "competition-and-training-pools":
					$("div.infoPane div").html("Natare pools provide the perfect environment for serious training and competition.");
					break;
				case "fitness-therapy-pools":
					$("div.infoPane div").html("Natare whirlpools, spas and hydrotherapy for athletic training, leisure, rehabilitation and more.");
					break;
				case "hotel-resort-pools":
					$("div.infoPane div").html("Natare has designed, built and installed some of the most impressive and awe-inspiring resort pools in the world.");
					break;

				//EQUIPMENT & SYSTEMS
				case "products":
				case "3":
					$("div.infoPane div").html("Natare supplies a wide variety of components and specialty equipment for construction and renovation, including water-saving pool filters, moving bulkheads, indestructible grating , high-capacity perimeter gutters and water-saving filtration and mechanical systems.");
					break;
				case "accessories":
					$("div.infoPane div").html("High-quality swimming pool and spa equipment for safety, maintenance and mechanical use.");
      		break;
      	case "bulkheads":
      		$("div.infoPane div").html("Natare bulkheads mean fast times and allow a facility to host multiple activities in a single pool.");
      		break;
      	case "filtration":
      		$("div.infoPane div").html("Natare <strong><i>high-E</strong></i> pool filtration systems save water, save money and save time, while being totally <strong><i>Green</strong></i>.");
      		break;
      	case "grating":
      		$("div.infoPane div").html("Safe, durable, cost-effective grating systems for pool renovation or new construction.");
      		break;
      	case "natadek-pool-floor-deck-surfacing":
      		$("div.infoPane div").html("Waterproof flooring and decking for pool surfaces, pool decks and other wet environments.");
      		break;
      	case "natatec-pool-linings":
      		$("div.infoPane div").html("Colorful, durable and 100% watertight PVC membrane lining systems for renovation and new construction.");
      		break;
      	case "natatec-containment-lining":
      		$("div.infoPane div").html("PVC and hybrid systems for water containment, waterproofing and general containment requirements.");
      		break;
      	case "perimeter-pool-gutters":
      		$("div.infoPane div").html("Natare stainless steel pool gutters provide water supply and return within a single, self-contained perimeter gutter profile.");
      		break;
      	case "sparger-(bubbler)-systems":
      		$("div.infoPane div").html("Air safety cushion sparger systems provide mounds of highly aerated water in the diver’s entry area to prevent injury and aid training.");
      		break;
      	case "underwater-windows":
      		$("div.infoPane div").html("Sturdy, shatter-resistant underwater windows are an invaluable tool for aquatic training and education.");
      		break;
      	case "vgb-(virgina-graeme-baker)-compliance":
      		$("div.infoPane div").html("Certified VGB-compliant drain covers, grates and sump covers.");
      		break;
      	case "water-features":
      		$("div.infoPane div").html("Water features and systems for decorative, environmental, industrial and agricultural applications.");
      		break;
      	case "water-features-wave-pools-and-wet-playgrounds":
      		$("div.infoPane div").html("Complete design solutions for a variety of recreational water features include wave pools, water parks and wet playgrounds.");
      		break;
      	case "whirlpools-spas":
      		$("div.infoPane div").html("Durable, hygienic and low-maintenance whirlpools, spas and hydrotherapy systems.");
      		break;

      	//SERVICES 
      	case "services":
      	case "4":
      		$("div.infoPane div").html("Natare offers a wide range of consulting services with comprehensive assistance for construction, renovation and facility operation. Our years of involvement allow us to offer a unique perspective on equipment design, installation and performance.");
      		break;
				case "construction":
					$("div.infoPane div").html("Complete on-site pool construction services from sketches to start-up.");
      		break;
      	case "consulting-technical-services":
      		$("div.infoPane div").html("Whether it’s help with a complex operational problem, assistance with construction issues or sound advice, Natare has the answers.");
      		break;
      	case "design":
      		$("div.infoPane div").html("Architectural, structural and civil design services for pools and water features.");
      		break;
      	case "engineering":
      		$("div.infoPane div").html("Put Natare’s world-class engineering support team to work for you.");
      		break;
      	case "planning":
      		$("div.infoPane div").html("Natare’s planning services include project development, consulting and feasibility studies to ensure your operation’s success.");
      		break;
      	case "renovation":
      		$("div.infoPane div").html("Natare breathes new life into old pools, at a fraction of the cost for new construction.");
      		break;

      	//RESOURCES 
      	case "resources":
      	case "5":
      		$("div.infoPane div").html("Find brochures, articles, references and warranties, as well as technical information like typical drawings and specifications to help you gather information and learn more about our products and services.");
      		break;
				case "faqs":
					$("div.infoPane div").html("Frequently Asked Questions.");
      		break;
      	case "terminology":
      		$("div.infoPane div").html("Reference guides to help you interpret, understand and learn our jargon and technical language.");
      		break;
      	case "literature":
      		$("div.infoPane div").html("Quickly locate and download literature and technical data for all your project needs.");
      		break;
      	case "ftc":
      		$("div.infoPane div").html("This is the area of our Knowledge Center that allows you to send and receive files.");
      		break;
      	case "kc":
      		$("div.infoPane div").html("Home to all of your research and technical needs; browse literature, download files and register as a member to access exclusive content. ");
      		break;
      	case "website-help":
      		$("div.infoPane div").html("Tips and resources for enhancing your Natare website experience.");
      		break;
			}
      if (blnImage) {
      	$("div.infoPane img").show();
				$("div.infoPane img").attr("src", "/imagedir/subnav/" + panelID + ".jpg");
      } else {
				$("div.infoPane img").hide();
      }
    }
    $("a.lnkClose").click(function(){hideMainNav()});
		
    setCurrentNav();
    //alert($("div.radFiles").length);
    if ($(".ftc").length != 0) {
      $("div.homeRibbon").hide();
    }
    if ($("div.radFiles").length != 0 && $("li#litTab").length == 0) {
      $("ul.tabs").append('<li><a href="/UserControls/fileContainer.aspx?FileID=' + $('div.radFiles input').val() + '">Literature &amp; Technical Information</a></li>');
      //alert("appended");
    };
    if ($("ul.tabs").children("li").length == 0) {
      $("ul.tabs").css("display", "none");
    }
}

function attachFB() {
    try {
    	$(".imageList a, div#slidePH ul li a").fancybox();

        $(".iconPreview.lb").fancybox();

        $("a.videoContainer").fancybox({
            'width': 650,
            'height': 400,
            'scrolling': 'no',
            'titleShow': false,
            'autoDimensions': false
        });

        $("a.iframe").fancybox({
            'width': 800,
            'height': 372,
            'scrolling': 'no',
            'titleShow': false
           });

           $("a.large").fancybox({
           	'width': 800,
           	'height': 530,
           	'scrolling': 'no',
           	'titleShow': false
           });

        $("a.small").fancybox({
            'width': 350,
            'height': 470,
            'scrolling': 'no',
            'titleShow': false
        });

        $("a.smaller").fancybox({
            'width': 310,
            'height': 355,
            'scrolling': 'no',
            'titleShow': false
        });

        $("a#lnkDownload").fancybox({
            'width': 550,
            'height': 480,
            'titleShow': false
        });
    }
    catch (err) { }
}

function isChecked(container) {
  var blnChecked = false;
  $(container + " input").each(function(){
    if($(this).is(":checked")){
      blnChecked = true;
    }
  });
  return blnChecked;
}

