var windowHeight = $(window).height();
var setHeight = "";
$(window).load(function(){
  windowHeight = $(window).height();
  setHeight = (windowHeight / 1.9);
  if (windowHeight < 600){
    $("#slider, .slider_spacer").height("435px");
  }else{
    $("#slider, .slider_spacer").height(setHeight);
  }
});

$(document).ready(function() {
  $("#back, #mid, #top").hide();
  $(".cover").click(function (){
    $(this).parents().children(".cover").toggleClass("cover_open");
    var set_id = $(this).attr("id");
    var photoload_url = "http://www.campemerson.com/site/gallery_photos/"+ set_id;
    $(this).parent().siblings(".active_photos").find(".active_photo_list").load(photoload_url,function (){
      $(".modal_photo").fancybox();
    });
    $(this).parent().siblings(".active_photos").toggle("drop", {direction: "up"},600);
  });
  
  $("a.close_photobook").click(function(){
    $(this).parent().hide("drop", {direction: "down"},600);
    $(this).parents(".grid_12").find(".cover").removeClass("cover_open");
  });
  //Vimeo video modal window
  $("#campmov").fancybox({
    type: "iframe",
    width: 700,
    height:450
  });

  //Photo Slider for top of banner and photo
  function showBanner(){
    $("#back").show("blind", {direction: "right"}, 1000);
    $("#mid").show("blind", {direction: "left"}, 900);
    $("#top").delay(1000).show("blind", {direction: "right"}, 500);
  }

  function hideBanner(){
    $("#back, #mid, #top").hide("fade", 100);
  }
    
  $("#top").cycle({
    timeout:6000,
    delay:1000
  });

  $("#photos").cycle({
    timeout: 6000,
    before: hideBanner,
    after: showBanner
  });

  function thankYou(){
    alert("Thank you!");
  }

  //Camp Countdown
  var sixCamp = $('.campcount:first').text().split(" ");
  var twoCamp = $('.campcount:last').text().split(" ");
  $('.countdown_row:first').countdown({until: new Date(sixCamp[0], sixCamp[1]-1, sixCamp[2], 8), format: 'DHM', 
                       layout: '<div class="days"><span class="digit">{d100}</span> <span class="digit">{d10}</span><span class="digit">{d1}</span></div> <div class="hours"><span class="digit">{h10}</span><span class="digit">{h1}</span></div> <div class="minutes"><span class="digit">{m10}</span><span class="digit">{m1}</span></div>', 
                       description: ''});
  $('.countdown_row:last').countdown({until: new Date(twoCamp[0], twoCamp[1]-1, twoCamp[2], 8), format: 'DHM', 
                       layout: '<div class="days"><span class="digit">{d100}</span> <span class="digit">{d10}</span><span class="digit">{d1}</span></div> <div class="hours"><span class="digit">{h10}</span><span class="digit">{h1}</span></div> <div class="minutes"><span class="digit">{m10}</span><span class="digit">{m1}</span></div>', 
                       description: ''});
  $(".active_photos").hide();

  $("#freeform input, #freeform textarea").each(function(){
    var clickedOn = 0;
    $(this).focus(function(){
      if (clickedOn == 0){
        $(this).css("color", "#000").removeAttr("value", "");
        clickedOn = 1;
      }else{
          $(this).css("color", "#000");
        }
    });
  });

  $("#freeform").validate();

  //Homepage Slider Resize
  $(window).resize(function(){
    windowHeight = $(window).height();
    setHeight = (windowHeight / 1.9);
    if (windowHeight < 800){
      $("#slider, .slider_spacer").height("435px");
    }else{
      $("#slider, .slider_spacer").height(setHeight);
    }
  });


//Analytics Codez
$(function(){
    //$('a').click(function(){
    //    _gaq.push(['_trackEvent', 'Category', 'Action', 'Label']);
    //});
    $('.brochure-cta').click(function(){
        _gaq.push(['_trackEvent', 'PDFs', 'Download', 'Download Brochure from CTA']);
    });
    $('.enroll-home').click(function(){
        _gaq.push(['_trackEvent', 'Enroll', 'Enroll', 'Enrolled from Homepage']);
    });
    $('.plan-now').click(function(){
        _gaq.push(['_trackEvent', 'Internal', 'Read', 'Clicked C2A to Plan Now']);
    });
    $('.inquiry-cta').click(function(){
        _gaq.push(['_trackEvent', 'External', 'Leave', 'Visited Inquiry Page']);
    });
    $('.submit-form').click(function(){
        _gaq.push(['_trackEvent', 'Form', 'Submit', 'Filled out and Submitted Form Global']);
    });
    $('.campminder-global').click(function(){
        _gaq.push(['_trackEvent', 'External', 'Leave', 'Visit Campminder from Header']);
    });
    $('.enroll_int').click(function(){
        _gaq.push(['_trackEvent', 'Enroll', 'Enroll', 'Enroll Through International Families']);
    });
    $('.email-directors').click(function(){
        _gaq.push(['_trackEvent', 'Email', 'Email', 'Email Directors']);
    });
    $('.email-directors-phil').click(function(){
        _gaq.push(['_trackEvent', 'Email', 'Email', 'Email Directors from Philosophy']);
    });
    $('.campminder-link').click(function(){
        _gaq.push(['_trackEvent', 'External', 'Leave', 'Visit Campminder']);
    });
    $('.handbook').click(function(){
        _gaq.push(['_trackEvent', 'PDFs', 'Download', 'Download Handbook']);
    });
    $('.medpack').click(function(){
        _gaq.push(['_trackEvent', 'External', 'Leave', 'Visit KidsMedPacks']);
    });
    $('.telephone').click(function(){
        _gaq.push(['_trackEvent', 'PDFs', 'Download', 'Download Phone Schedule']);
    });
    $('.clothing').click(function(){
        _gaq.push(['_trackEvent', 'PDFs', 'Download', 'Download Clothing List']);
    });
    $('.bunkline').click(function(){
        _gaq.push(['_trackEvent', 'External', 'Leave', 'Visit Bunkline']);
    });
    $('.berkshires').click(function(){
        _gaq.push(['_trackEvent', 'External', 'Leave', 'Visit Berkshires']);
    });
    $('.rookies').click(function(){
        _gaq.push(['_trackEvent', 'PDFs', 'Download', 'Download Rookie Schedule']);
    });
    $('.rookie-app').click(function(){
        _gaq.push(['_trackEvent', 'PDFs', 'Download', 'Download Rookie Day App']);
    });
    $('.brochure-download').click(function(){
        _gaq.push(['_trackEvent', 'PDFs', 'Download', 'Download Brochure']);
    });
    $('.online-app').click(function(){
        _gaq.push(['_trackEvent', 'Application Link', 'Sidebar', 'Textlink']);
    });
    $('.campminder-sc').click(function(){
        _gaq.push(['_trackEvent', 'External', 'Exit', 'Visit Campminder from Staff Connection']);
    });
    $('.getting').click(function(){
        _gaq.push(['_trackEvent', 'PDFs', 'Download', 'Download Getting to Camp']);
    });
    $('.staffcontact').click(function(){
        _gaq.push(['_trackEvent', 'PDFs', 'Download', 'Download Staff Contact Info']);
    });
    $('.nottobring').click(function(){
        _gaq.push(['_trackEvent', 'PDFs', 'Download', 'Download What Not to Bring']);
    });
    $('.aboutce').click(function(){
        _gaq.push(['_trackEvent', 'PDFs', 'Download', 'Download About CE']);
    });
    $('.immunizations').click(function(){
        _gaq.push(['_trackEvent', 'PDFs', 'Download', 'Download Immunization Info']);
    });
    $('.finalcheck').click(function(){
        _gaq.push(['_trackEvent', 'PDFs', 'Download', 'Download Final Checklist']);
    });
    $('.emailstaff').click(function(){
        _gaq.push(['_trackEvent', 'Email', 'Email', 'Email Staff from Staff Connection']);
    });
 });
});


