
    function sub_pop() {
      v = document.forms['subscribe'].email.value;
      if (v == 'email address') { v = ''; }
      url = 'http://simon.statemachine.net/clients/boreal/subscribe.html?list_resortnews=yes&email=' + v
      window.open(url,'testing','width=600,height=480,resizeable=1,scrollbars=1');
      return false;
    }

    function popLiveCam(thisURL) {
      window.open(thisURL, 'LiveCam', "scrollbars=yes,toolbar=no,location=no,status=no,menubar=no,resizeable=yes,width=720,height=615");
      return false;
    }

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

jQuery(document).ready(function($) {

  // menus
  $('ul#nav').superfish(
    { 
      delay:       1000,                           
      animation:   {opacity:'show'}, 
      speed:       'fast',                         
      autoArrows:  false,                          
      dropShadows: true                           
    }
  );

  // homepage cycle http://malsup.com/jquery/cycle/options.html
  $("div#hp-hero-container div.contrast-block-inner").cycle({
    fx: 'fade',
    timeout: 5000,
    next: "strong.hero_next-button",
    prev: "strong.hero_prev-button"
  });
  // handle play/pause control
  $("p.hp-hero-controls strong.hero_play_pause-button span").click(function() {
    if ( $(this).hasClass('pause-button') ) {
      $("p.hp-hero-controls strong.hero_play_pause-button span").attr('class', 'play-button').html('<em>play</em>');
      $("div#hp-hero-container div.contrast-block-inner").cycle('pause');
    } else {
      $("p.hp-hero-controls strong.hero_play_pause-button span").attr('class', 'pause-button').html('<em>pause</em>');
      $("div#hp-hero-container div.contrast-block-inner").cycle('resume');
    }
  });


  // button open close for aside contrast-bar widgets
  function set_button_state(button, button_state) {
    if (button_state) {
      button.addClass("button_close-state").removeClass("button_open-state");
    } else {
      button.addClass("button_open-state").removeClass("button_close-state");
    }
  }
  function just_doit(button, button_state, animate) {
    if (button_state) {
      button.parents("div.contrast-bar").next("div.contrast-bar-join").slideUp(animate, function() {
        set_button_state(button, button_state);
      });
    } else {
      button.parents("div.contrast-bar").next("div.contrast-bar-join").slideDown(animate, function() {
        set_button_state(button, button_state);
      });
    }
  }
  $("div#aside div.contrast-bar h2 strong.button").each(function() {
    var button = $(this);
    var widget_id = button.parents("div.widget-block").attr("id");
    if (widget_id != undefined) {
      button.click(function(e) {
        var is_open = button.hasClass("button_open-state");
        just_doit(button, is_open, "slow");
        var button_state = is_open ? "closed" : "open" ;
        createCookie(widget_id, button_state, 10);
      });
      c = readCookie(widget_id); // c is for cookie, and that's good enough for me
      if (c == null) {
      } else {
        var button_state = c == "open" ? true : false ;
        just_doit(button, !button_state, 0);
      }
    }
  });

});


$(document).ready(function() {
// set the value from the title
  $(".embedded_input_title").each(function () {
    $(this).attr("value", $(this).attr("title"));
  });

// empty the field on click if it has default value
  $(".embedded_input_title").click(function () {
    if ($(this).attr("value") == $(this).attr("title")) {
      $(this).attr("value", '');
    }
  });

// reset the field to default value on blur if it is empty
  $(".embedded_input_title").blur(function () {
    if (!$(this).attr("value")) {
      $(this).attr("value", $(this).attr("title"));
    }
  });

// validate the fields
  $(".embedded_titles").submit(function() {

    // check email
    var email = $(this).find("input[name='email']").attr("value");
    var filter=/^.+@.+\..{2,3}$/;
    if (email) {
      if (!filter.test(email)) {
        alert("Please input a valid email address!");
        return false;
      }
    }

    // empty the field if the same value as title before submitting
    $(this).find(".embedded_input_title").each(function() {
      if ($(this).attr("value") == $(this).attr("title")) {
        $(this).attr("value", '');
      }
    });
    return true;
  });

});

