/* Mar 15 2011

------------------------------------------------
              1. Global Variables & Functions
                 1.2 Amenities Carousel
                 1.3 The Estates Photo Gallery
                 1.4 Floorplans
                 1.5 The Artchitect Overlay
                    1.5.2 The Interior Designer Overlay
                 1.6 Video Gallery
                    1.6.2 Your Custom Video Popup
                 1.7 Multimedia Gallery
                 1.8 Legal
                 1.9 Staff Gallery
              2. Footer Pop up
              3. Contact Form
              4. Choose Your Home
              5. Amenities Menu
              6. Navigations
                 6.1 Staff
                 6.2 Your Custom Video Thumbnail Animation
                 6.3 Staff still
              7. Custom Video Links
              8. Footer Fix for iPad and iPhone
              9. Email a Friend
              10. Center Overlay
              11. Staff details
              12. Email Overlay
              13. Intro Video Controls
              14. Splash and Intro
              15. Video Mash Up
              16. Swipe event for iPod/iPhone/iPad
              17. Open house popup
------------------------------------------------
*/


/*----------------------------------------------
------------------------------------------------
1. GLOBAL VARIABLES & FUNCTIONS START
------------------------------------------------
------------------------------------------------*/

  //Amenities Prev and Next
  var next;
  var prev;

  $(document).ready(function() {
    
    $(".fs-arrow-left").live('click',function() {
       navigation();
       prev.click();  

    });
    
    $(".fs-arrow-right").live('click',function() {
       navigation();
       next.click();
     
    });  
});

  //Amenities page wrappers
  function createwrapperandcarousel() {
    //Add a wrapper to each row  
    var items = $(".fs-amenities-item");

    //Add a wrapper every 5 items but ignore the first one
    for(var i = 0; i < items.length; i+=5) {
    items.slice(i, i+5)
       .wrapAll("<div class='wrapper'></div>");
    }    

/*-----------------------------------------------
 1.2 AMENITIES CAROUSEL
 ------------------------------------------------*/    

    $(".fs-amenities-carousel a").each(function() {
      var url = $(this).children(".url").text();
      url = url.replace(/ /gi,"%20");

      $(this).css("background-image","url("+url+")").animate({opacity:'0.2'}, 0);
    });
    
    $(".fs-amenities-carousel a").live('mouseenter',function() {
      $(this).stop().animate({opacity:'1'}, 250);
    });
    $(".fs-amenities-carousel a").live('mouseleave',function() {
      $(this).stop().animate({opacity:'0.2'}, 250);
    });
    
    
  // Amenities Overlay
  if($('#carousel-popup').length) {
    
    $('#carousel-popup').insertAfter('body > #container');
    
    $('.fs-amenities-carousel a').live('click',function(e){
      e.preventDefault();
      
      $("#popup-nav").append('<div class="fs-arrow-left"></div><div class="fs-arrow-right"></div>');
    
      var img = new Image();
      var bigimg = $(this).find(".url").attr("rel");
      next = $(this).next();
      prev = $(this).prev();
      navigation();
      $('#carousel-popup .overlay,#carousel-popup').fadeIn();
      $(preloader).appendTo('#carousel-popup');
      
      $(img).hide().load(function() {
          $("#carousel-popup #main-photo img").animate({opacity:'1'});
          $("#carousel-popup #main-photo").empty().append(this);
          $(this).fadeIn();
          $(".fs-preloader").remove();
               
          $('#carousel-popup,#carousel-container,#carousel-container .fs-carousel-popup').fadeIn();
          $('#carousel-popup .popup-container:visible').center();
      }).attr({"src":bigimg,"id":"slideshow-image"});
      
    });
    
    $(window).bind('resize', function() {
      $('#carousel-popup .popup-container:visible').center();
    });
  }

}
  //Navigation (prev/next)
  function navigation() {
    
     //Preloader effect
     $("#carousel-popup #main-photo img").animate({opacity:'0.2'});
     $("#carousel-popup #main-photo").append(preloader);
       if(next.length==0) {
         $(".fs-arrow-right").hide();
       } else {
         $(".fs-arrow-right").show();
       }
       if(prev.length==0) {
         $(".fs-arrow-left").hide();
        } else {
         $(".fs-arrow-left").show();
       }
    }

/*------------------------------------------------
  1.3 THE ESTATES PHOTO GALLERY
  ------------------------------------------------*/    

   function buildgallery() {
   
    if($('.the-estates-gallery').length > 0) {
      
      if($('#carousel-popup').length) {
         $('#carousel-popup').insertAfter('body > #container');
         $('.the-estates-gallery .item').live('click',function(e){
           e.preventDefault();
           xprLog("click");
            $("#popup-nav").append('<div class="fs-arrow-left"></div><div class="fs-arrow-right"></div>');
    
            var img = new Image();
            var bigimg = $(this).find(".large").attr("src");
            next = $(this).next();
            prev = $(this).prev();
            navigation();
            $('#carousel-popup .overlay,#carousel-popup').fadeIn();
            $(preloader).appendTo('#carousel-popup');
      
         $(img).hide().load(function() {
            $("#carousel-popup #main-photo img").animate({opacity:'1'});
            $("#carousel-popup #main-photo").empty().append(this);
            $(this).fadeIn();
            $(".fs-preloader").remove();
               
            $('#carousel-popup,#carousel-container,#carousel-container .fs-carousel-popup').fadeIn();
            $('#carousel-popup .popup-container:visible').center();
         }).attr("src",bigimg);
    });
    
    $(window).bind('resize', function() {
      $('#carousel-popup .popup-container:visible').center();
    });
  }
    //Create carousel thumbnails
    $('.the-estates-gallery .item').each(function(i){   
      $(this).css("cssText","background:url("+$(this).find('.small').attr('src')+") no-repeat 50% 50%");
    });  
      
   //Carousel
   var $_total = $('.the-estates-gallery .item').length;
   var $_total2 = Math.ceil($_total / 4);
   var $slideshow_width = $('.the-estates-gallery .screen').width();
   var $_total_width = $_total2 * $slideshow_width;
   var $_first = $('.the-estates-gallery .item:first');
   var $npos = 0;

   if($_total_width < $('.the-estates-gallery .navigation').width()){
      $_total_width = $('.the-estates-gallery .navigation').width();
   }
      
   $(".the-estates-gallery .screen").css("width","20000em");        
        
   $('.the-estates-gallery .prev').live('click',function(e){
    e.preventDefault();
    $npos--;
    if($npos < 0) $npos = 0;
    $('.the-estates-gallery .screen').animate({left:$npos * -($slideshow_width+5)}, 500);
   });
        
   $('.the-estates-gallery .next').live('click',function(e){

    e.preventDefault();
    $npos++;
    if($npos >= $_total2) $npos = 0;

    $('.the-estates-gallery .screen').animate({left:$npos * -($slideshow_width+5)}, 500);
   });
    }}
   //Add swipe event
     $(document).ready(function() {
        if (! $.browser.msie ) {
         $('.the-estates-gallery .navigation').swipe({
             swipeLeft: function() { $('.the-estates-gallery .next').click(); },
           swipeRight: function() { $('.the-estates-gallery .prev').click(); }
         }); 
         }      
     });
 
   //Hightlight text function
   function highlightall(textbox) {
     textbox.focus();
     textbox.select();
   }

/*------------------------------------------------
  1.4 FLOORPLANS
  ------------------------------------------------*/    

   function loadfloorplans() {  
     $(".fs-floorplans .left a:first").addClass("active");
     var firstsrc = $(".left a.active .img").html();
     firstsrc = firstsrc.replace(/ /gi,"%20");
     var views = $(".left a.active .views").html();
     var pdf = $(".left a.active:last .pdf").text();
     var id = $(".left a.active .views").find(".main-img").attr("rel");
     var firstimg = new Image();

     //Store first data
     $('body').data('activeview',views);
     $('body').data('activeid',id);
     
     //Load first image and links
     $("#pdf").attr("href",pdf);
     $(".right .current-image").append(preloader);
     
     $(firstimg).hide().load(function() {
       $(".right .current-image").empty().append(this);
       $(this).fadeIn();
       $(".fs-preloader").remove();
     }).attr("src",firstsrc);
     
     //Event Handlers
     $(".fs-floorplans .left a").live('mouseenter',function(event) {
        $(this).stop().animate({opacity:'1'}, 200);    
     });
  
     $(".fs-floorplans .left a").live('mouseleave',function(event) {      
        $(this).stop().animate({opacity:'0.5'}, 70);    
     });
     
     $(".fs-floorplans .left a").live('click',function(event) {
        event.preventDefault();
       
        var img = $(this).find(".img").text();
        img = img.replace(/ /gi,"%20");
        var views = $(this).find(".views").html();
        var pdf = $(this).find(".pdf").text();
        var newimg = new Image();
        var id = $(this).find(".main-img").attr("rel");

        //Store data
        $('body').data('activeview',views);
        $('body').data('activeid',id);       
       
        $(".fs-floorplans .left a.active").removeClass("active");
        $(this).addClass("active");
       
        //Load image
        $(".right .current-image").empty().append(preloader);
        
        $(newimg).hide().load(function() {
          $(".right .current-image").empty().append(this);
          $(this).fadeIn();
          $(".fs-preloader").remove();
        }).attr("src",img);
       
        //Add views image and pdf
        $("#pdf").attr("href",pdf);
     });
     
         //View overlay
        $("#views").click(function(e) {
          
           e.preventDefault();
           var img = new Image();   
           var href = $(this).attr("href");

           $('#carousel-popup').insertAfter('body > #container');

           $(preloader).appendTo('#carousel-popup');
      
           $(img).hide().load(function() {
              $(this).fadeIn();
              $(".fs-preloader").remove();  
              $('#carousel-popup,#carousel-container,#carousel-container .fs-carousel-popup,#carousel-popup .overlay').fadeIn();             
              $('#carousel-popup .popup-container:visible').center();                
           }).attr("src",href);
    
        //Views gallery
        $('.views-gallery').each(function() {    
        //Load first image
        $(".views-gallery .main-img").append(preloader);
        var img = new Image();
        var first = $('.large:first').attr('src');
        first = first.replace(/ /gi,"%20");  
        var activeview = $('body').data('activeview');
        var activeid = $('body').data('activeid');
           
        $("#carousel-popup #main-photo").html(activeview);
          
        $('.views-gallery .item').each(function(i){
           var url = $(this).find('.small').attr('src');
           url = url.replace(/ /gi,"%20");
          
           $(this).css("cssText","background:url("+url+") no-repeat 50% 50%");
          
           $('.views-gallery .item').click(function(e){
              e.preventDefault();  
              var img = new Image();
              var large = $(this).find('.large').attr('src');
              large = large.replace(/ /gi,"%20");             
              //$(".main-img[rel='"+activeid+"']").empty().append(preloader);
            
           $(img).load(function() {
               // $(".fs-preloader").remove();
                $(".main-img[rel='"+activeid+"']").empty().append(this);
     
               // $(".main-img[rel='"+activeid+"'] img").fadeIn();
            }).attr('src',large);
         });
       });  

    });    
    
        $(".fs-preloader").remove();
        $('#carousel-popup,#carousel-container,#carousel-container .fs-carousel-popup,#carousel-popup .overlay').fadeIn();             
        $('#carousel-popup .popup-container:visible').center();     

   });
 
        $(window).bind('resize', function() {
           $('#carousel-popup .popup-container:visible').center();
        });
     
        $(".fs-views-left").live('mouseover',function() {
              $(".fs-views-left").unbind('mouseover');
              $(".main-img img").stop().animate({marginLeft:0}, 1000);       
        });
     
        $(".fs-views-right").live('mouseover',function() {
              $(".fs-views-right").unbind('mouseover');
              $(".main-img img").stop().animate({marginLeft:-513}, 1000);       
        });
             
        $(".fs-views-left,.fs-views-right").live('mouseout',function() {
              $(".fs-views-left,.fs-views-right").unbind('mouseout');
              $(".main-img img").stop().animate({marginLeft:-255}, 500);
        });
   }

/*------------------------------------------------
  1.5 THE ARCHITECT OVERLAY
  ------------------------------------------------*/   

   $("#the-arc").live('click',function(e) {
           e.preventDefault();
              
           $('#carousel-popup').insertAfter('body > #container');

           $(preloader).appendTo('#carousel-popup');

           $.get('/relay.php?ejaxKey=PublicAjaxElementRunner.run&elementInstanceId=1050&format=html',{}, function(response) {
             $('#carousel-popup #main-photo').html(response);
            
               //Load first video
               var firstsourceone = $(".source:first").children("span").eq(0).text();
               var firstsourcetwo = $(".source:first").children("span").eq(1).text();
               var firstsourcethree = $(".source:first").children("span").eq(2).text();
               var firstembed =  $(".embed:first").text();
               var firstposter = $(".poster:first").text();
               
               //Adding controls              
               $(".the-architect-gallery .main-img").empty().html('<div class="video-container" id="vid-container"></div><div class="jp-video jp-video-360p"><div class="jp-type-single"><div id="jplayer-1" class="jp-jplayer"></div><div  id="jp_interface_1" class="jp-interface"><ul  class="jp-controls"><li><a href="#" class="jp-play"  tabindex="1">play</a></li><li><a href="#" class="jp-pause"  tabindex="1">pause</a></li><li><a href="#" class="jp-mute" tabindex="1">mute</a></li><li><a href="#" class="jp-unmute" tabindex="1">unmute</a></li></ul><div class="jp-progress"><div class="jp-seek-bar"><div class="jp-play-bar"></div></div></div><div  class="jp-volume-bar"><div class="jp-volume-bar-value"></div></div><div  class="jp-current-time"></div><div class="jp-duration"></div></div></div></div>');
              
              $("#jplayer-1").jPlayer({
                ready: function () {
                   $(this).jPlayer("setMedia", {ogg: firstsourceone,m4v: firstsourcetwo,poster: firstposter}).jPlayer("play");
                },
                size: {width: "797px",height: "447px"},
                swfPath: "/includes/libs/js/jplayer/",wmode: "transparent",preload:"auto",supplied: "m4v, ogg",cssSelectorAncestor: "#jp_interface_1", cssSelector: {"play" : ".jp-play","pause" : ".jp-pause","stop" : ".jp-stop","videoPlay" : ".jp-video-play","seekBar" : ".jp-seek-bar","playBar" : ".jp-play-bar","mute" : ".jp-mute","unmute" : ".jp-unmute","volumeBar" : ".jp-volume-bar","volumeBarValue" : ".jp-volume-bar-value","currentTime" : ".jp-current-time","duration" : ".jp-duration"}});
             
              $(".the-architect-gallery .item").each(function() {
             
               //Add video button to thumbnail      
               var isvideo = $(this).find(".source").children("span").eq(1).text();        
               if(isvideo != '') {
                  $(this).find(".small").append('<div class="fs-thumb-vid-bg"></div>');
               }
                
               //Load video on click
               $(this).click(function() {
                 
               var sourceone = $(this).find(".source").children("span").eq(0).text();
               var sourcetwo = $(this).find(".source").children("span").eq(1).text();
               var sourcethree = $(this).find(".source").children("span").eq(2).text();
               var embed = $(this).find(".embed").text();
               var poster = $(this).find(".poster").text();
               
               //Clear previous jPlayer
               $("#jplayer-1").jPlayer("destroy");  
                 
               //Adding controls              
               $(".the-architect-gallery .main-img").empty().html('<div  class="video-container" id="vid-container"></div><div  class="jp-video jp-video-360p"><div  class="jp-type-single"><div id="jplayer-1"  class="jp-jplayer"></div><div  id="jp_interface_1"  class="jp-interface"><ul  class="jp-controls"><li><a  href="#"  class="jp-play"  tabindex="1">play</a></li><li><a  href="#"  class="jp-pause"  tabindex="1">pause</a></li><li><a  href="#" class="jp-mute"  tabindex="1">mute</a></li><li><a href="#"  class="jp-unmute"  tabindex="1">unmute</a></li></ul><div  class="jp-progress"><div class="jp-seek-bar"><div  class="jp-play-bar"></div></div></div><div  class="jp-volume-bar"><div   class="jp-volume-bar-value"></div></div><div  class="jp-current-time"></div><div   class="jp-duration"></div></div></div></div>');
               
               $("#jplayer-1").jPlayer({
                 ready: function () {
                    $(this).jPlayer("setMedia", {ogg: sourceone,m4v: sourcetwo,poster: poster}).jPlayer("play");
                 },
                 size: {width: "797px",height: "447px"},
                 swfPath: "/includes/libs/js/jplayer/",wmode: "transparent",preload:"auto",supplied: "m4v, ogg",cssSelectorAncestor: "#jp_interface_1", cssSelector: {"play" : ".jp-play","pause" : ".jp-pause","stop" : ".jp-stop","videoPlay" : ".jp-video-play","seekBar" : ".jp-seek-bar","playBar" : ".jp-play-bar","mute" : ".jp-mute","unmute" : ".jp-unmute","volumeBar" : ".jp-volume-bar","volumeBarValue" : ".jp-volume-bar-value","currentTime" : ".jp-current-time","duration" : ".jp-duration"}});
             
               
               $(".fs-preloader").remove();
               });         
             });

               $(".fs-preloader").remove();
               $('#carousel-popup,#carousel-container,#carousel-container .fs-carousel-popup,#carousel-popup .overlay').fadeIn();
               $('#carousel-popup .popup-container:visible').center();
               
           });    
   });
    
   $(window).bind('resize', function() {
      $('#carousel-popup .popup-container:visible').center();
   });

/*------------------------------------------------
  1.5.2 THE INTERIOR OVERLAY
  ------------------------------------------------*/   

   $("#the-int").live('click',function(e) {
           e.preventDefault();
              
           $('#carousel-popup').insertAfter('body > #container');
           $(preloader).appendTo('#carousel-popup');

           $.get('/relay.php?ejaxKey=PublicAjaxElementRunner.run&elementInstanceId=1068&format=html',{}, function(response) {
             $('#carousel-popup #main-photo').html(response);

               //Load first video
               var firstsourceone = $(".source:first").children("span").eq(0).text();
               var firstsourcetwo = $(".source:first").children("span").eq(1).text();
               var firstsourcethree = $(".source:first").children("span").eq(2).text();
               var firstembed =  $(".embed:first").text();
               var firstposter = $(".poster:first").text();
               
               //Adding controls              
               $(".the-interior-gallery .main-img").empty().html('<div  class="video-container" id="vid-container"></div><div  class="jp-video jp-video-360p"><div  class="jp-type-single"><div id="jplayer-1"  class="jp-jplayer"></div><div  id="jp_interface_1"  class="jp-interface"><ul  class="jp-controls"><li><a  href="#"  class="jp-play"  tabindex="1">play</a></li><li><a  href="#"  class="jp-pause"  tabindex="1">pause</a></li><li><a  href="#" class="jp-mute"  tabindex="1">mute</a></li><li><a href="#"  class="jp-unmute"  tabindex="1">unmute</a></li></ul><div  class="jp-progress"><div class="jp-seek-bar"><div  class="jp-play-bar"></div></div></div><div  class="jp-volume-bar"><div   class="jp-volume-bar-value"></div></div><div  class="jp-current-time"></div><div   class="jp-duration"></div></div></div></div>');
               
               $("#jplayer-1").jPlayer({
                 ready: function () {
                    $(this).jPlayer("setMedia", {ogg: firstsourceone,m4v: firstsourcetwo,poster: firstposter}).jPlayer("play");
                 },
                 size: {width: "797px",height: "447px"},
                 swfPath: "/includes/libs/js/jplayer/",wmode: "transparent",preload:"auto",supplied: "m4v, ogg",cssSelectorAncestor: "#jp_interface_1", cssSelector: {"play" : ".jp-play","pause" : ".jp-pause","stop" : ".jp-stop","videoPlay" : ".jp-video-play","seekBar" : ".jp-seek-bar","playBar" : ".jp-play-bar","mute" : ".jp-mute","unmute" : ".jp-unmute","volumeBar" : ".jp-volume-bar","volumeBarValue" : ".jp-volume-bar-value","currentTime" : ".jp-current-time","duration" : ".jp-duration"}});
             
                          
            $(".the-interior-gallery .item").each(function() {
              
               //Add video button to thumbnail      
               var isvideo = $(this).find(".source").children("span").eq(1).text();        
               if(isvideo != '') {
                  $(this).find(".small").append('<div class="fs-thumb-vid-bg"></div>');
               }
              
               //Load video on click
               $(this).click(function() {
                             
               var sourceone = $(this).find(".source").children("span").eq(0).text();
               var sourcetwo = $(this).find(".source").children("span").eq(1).text();
               var sourcethree = $(this).find(".source").children("span").eq(2).text();
               var embed = $(this).find(".embed").text();
               var poster = $(this).find(".poster").text();
     
                 
               //Clear previous jPlayer
               $("#jplayer-1").jPlayer("destroy");    
                 
                //Adding controls              
                $(".the-interior-gallery .main-img").empty().html('<div  class="video-container" id="vid-container"></div><div  class="jp-video jp-video-360p"><div  class="jp-type-single"><div id="jplayer-1"  class="jp-jplayer"></div><div  id="jp_interface_1"  class="jp-interface"><ul  class="jp-controls"><li><a  href="#"  class="jp-play"  tabindex="1">play</a></li><li><a  href="#"  class="jp-pause"  tabindex="1">pause</a></li><li><a  href="#" class="jp-mute"  tabindex="1">mute</a></li><li><a href="#"  class="jp-unmute"  tabindex="1">unmute</a></li></ul><div  class="jp-progress"><div class="jp-seek-bar"><div  class="jp-play-bar"></div></div></div><div  class="jp-volume-bar"><div   class="jp-volume-bar-value"></div></div><div  class="jp-current-time"></div><div   class="jp-duration"></div></div></div></div>');
               
               $("#jplayer-1").jPlayer({
                 ready: function () {
                    $(this).jPlayer("setMedia", {ogg: sourceone,m4v: sourcetwo,poster: poster}).jPlayer("play");
                 },
                 size: {width: "797px",height: "447px"},
                 swfPath: "/includes/libs/js/jplayer/",wmode: "transparent",preload:"auto",supplied: "m4v, ogg",cssSelectorAncestor: "#jp_interface_1", cssSelector: {"play" : ".jp-play","pause" : ".jp-pause","stop" : ".jp-stop","videoPlay" : ".jp-video-play","seekBar" : ".jp-seek-bar","playBar" : ".jp-play-bar","mute" : ".jp-mute","unmute" : ".jp-unmute","volumeBar" : ".jp-volume-bar","volumeBarValue" : ".jp-volume-bar-value","currentTime" : ".jp-current-time","duration" : ".jp-duration"}});
                 
               $(".fs-preloader").remove();
            });         
             });

               $(".fs-preloader").remove();
               $('#carousel-popup,#carousel-container,#carousel-container .fs-carousel-popup,#carousel-popup .overlay').fadeIn();
               $('#carousel-popup .popup-container:visible').center();
           });    
   });
    
   $(window).bind('resize', function() {
      $('#carousel-popup .popup-container:visible').center();
   });

/*------------------------------------------------
  1.6 VIDEO GALLERY
  ------------------------------------------------*/    

   function videogallery() {

        //Load first video
        var firstsourceone = $(".video-gallery .source:first").children("span").eq(0).text();
        var firstsourcetwo = $(".video-gallery .source:first").children("span").eq(1).text();
        var firstsourcethree = $(".video-gallery .source:first").children("span").eq(2).text();
        var firstembed =  $(".video-gallery .embed:first").text();
        var firstposter = $(".video-gallery .poster:first").text();

        //Adding controls              
        $(".video-gallery .main-img").empty().html('<div  class="video-container" id="vid-container"></div><div  class="jp-video jp-video-360p"><div  class="jp-type-single"><div id="jplayer-1"  class="jp-jplayer"></div><div  id="jp_interface_1"  class="jp-interface"><ul  class="jp-controls"><li><a  href="#"  class="jp-play"  tabindex="1">play</a></li><li><a  href="#"  class="jp-pause"  tabindex="1">pause</a></li><li><a  href="#" class="jp-mute"  tabindex="1">mute</a></li><li><a href="#"  class="jp-unmute"  tabindex="1">unmute</a></li></ul><div  class="jp-progress"><div class="jp-seek-bar"><div  class="jp-play-bar"></div></div></div><div  class="jp-volume-bar"><div   class="jp-volume-bar-value"></div></div><div  class="jp-current-time"></div><div   class="jp-duration"></div></div></div></div>');
               
               $("#jplayer-1").jPlayer({
                 ready: function () {
                    $(this).jPlayer("setMedia", {ogg: firstsourceone,m4v: firstsourcetwo,poster: firstposter}).jPlayer("play");
                 },
                 size: {width: "895px",height: "500px"},
                 swfPath: "/includes/libs/js/jplayer/",wmode: "transparent",preload:"auto",supplied: "m4v, ogg",cssSelectorAncestor: "#jp_interface_1", cssSelector: {"play" : ".jp-play","pause" : ".jp-pause","stop" : ".jp-stop","videoPlay" : ".jp-video-play","seekBar" : ".jp-seek-bar","playBar" : ".jp-play-bar","mute" : ".jp-mute","unmute" : ".jp-unmute","volumeBar" : ".jp-volume-bar","volumeBarValue" : ".jp-volume-bar-value","currentTime" : ".jp-current-time","duration" : ".jp-duration"}});
             
           $(".video-gallery .item").each(function() {
          
        //Add video button to thumbnail      
        var isvideo = $(this).find(".source").children("span").eq(1).text();        
        if(isvideo != '') {
          $(this).find(".small").append('<div class="fs-thumb-vid-bg"></div>');
        }
          
        //Load video on click
        $(this).click(function() {
                      
        var sourceone = $(this).find(".source").children("span").eq(0).text();
        var sourcetwo = $(this).find(".source").children("span").eq(1).text();
        var sourcethree = $(this).find(".source").children("span").eq(2).text();
        var embed = $(this).find(".embed").text();
        var poster = $(this).find(".poster").text();

        //Clear previous jPlayer
        $("#jplayer-1").jPlayer("destroy");    
          
        //Adding controls              
         $(".video-gallery .main-img").empty().html('<div  class="video-container"  id="vid-container"></div><div  class="jp-video  jp-video-360p"><div  class="jp-type-single"><div  id="jplayer-1"  class="jp-jplayer"></div><div  id="jp_interface_1"  class="jp-interface"><ul  class="jp-controls"><li><a  href="#"  class="jp-play"  tabindex="1">play</a></li><li><a  href="#"  class="jp-pause"  tabindex="1">pause</a></li><li><a  href="#"   class="jp-mute"  tabindex="1">mute</a></li><li><a   href="#"  class="jp-unmute"  tabindex="1">unmute</a></li></ul><div  class="jp-progress"><div   class="jp-seek-bar"><div  class="jp-play-bar"></div></div></div><div  class="jp-volume-bar"><div     class="jp-volume-bar-value"></div></div><div  class="jp-current-time"></div><div     class="jp-duration"></div></div></div></div>');
                
         $("#jplayer-1").jPlayer({
           ready: function () {
            $(this).jPlayer("setMedia", {ogg: sourceone,m4v: sourcetwo,poster: poster}).jPlayer("play");
                  },
           size: {width: "895px",height: "500px"},
           swfPath: "/includes/libs/js/jplayer/",wmode: "transparent",preload:"auto",supplied: "m4v, ogg",cssSelectorAncestor: "#jp_interface_1", cssSelector: {"play" : ".jp-play","pause" : ".jp-pause","stop" : ".jp-stop","videoPlay" : ".jp-video-play","seekBar" : ".jp-seek-bar","playBar" : ".jp-play-bar","mute" : ".jp-mute","unmute" : ".jp-unmute","volumeBar" : ".jp-volume-bar","volumeBarValue" : ".jp-volume-bar-value","currentTime" : ".jp-current-time","duration" : ".jp-duration"}});

         $(".fs-preloader").remove();
            });         
      });
     
   }
 
/*------------------------------------------------
  1.6.2 YOUR CUSTOM VIDEO
  ------------------------------------------------*/  

 function customvideopopup() {

    var hashCode = getQuerystring('customVideo');
    if (!hashCode) {
        hashCode = getQuerystring('hashcode');
    }
    if (!hashCode) {
        hashCode = $.cookie('customVideo');
    }
    if (!hashCode) {
        window.location.href='/';
    }
  
    var container = $('<div class="share-container"><h1>Your Ideal Day At Four Seasons Private Residences Denver</h1></div>');     
    var player = $("<div></div>").attr('id', 'share-player');
    var fadeTop = $("<div></div>").addClass('fade-top');
    var fadeBottom = $("<div></div>").addClass('fade-bottom');
    var share = $("<a href='#'>SHARE</a>").attr('id','share2').addClass("right");    
    
    //Show overlay
    $('#carousel-popup').insertAfter('body > #container');
  
    $('#carousel-popup .overlay,#carousel-popup').fadeIn();
    
    if (Modernizr.touch) {
        var video = $('<video></video>');
        video.css('height', '100%');
        video.css('width', '100%');
        video.attr('preload', 'auto');
        video.attr('controls', 'true');
        video.attr('autobuffer', 'true');

        video.bind('canplay', function(e) { this[0].play(); });
        video.bind('ended', function(e) {
            cleanup();

            $("div.intro").animate({opacity: '0'}, 1500, function() {
                $('div.intro').remove();
            });
        });
        var source = $('<source></source>');
        source.attr('src', '/media/default-mashup-01c.reencoded.mp4');
        source.attr('type', 'video/mp4');
        
        video.append(source);
        player.append(video);
    } else {
        player.xprMediaPlayer({height: '100%', width: '100%'});
        player.xprMediaPlayer('addAudioTrack', {mp3: '/media/pov48.mp3', ogg: '/media/pov48.ogg'});
        player.xprMediaPlayer('loadPlaylist', '/relay.php?ejaxKey=FS_QuestionFormAjax.decodePlaylist&format=json&hashcode=' + hashCode);
        player.bind('playlistLoaded', function() {
            player.xprMediaPlayer('startBuffering');
            setTimeout(function() { player.xprMediaPlayer('startPlayer'); }, 3000);
        });
      
        player.bind('playlistEnded', function() {
          cleanup();

          $("div.intro").animate({opacity: '0'}, 1500, function() {
                $('div.intro').remove();
          });

        });
    }            
        //Add content to overlay
        $("#carousel-popup #main-photo").html(container);
        container.append(player);
        fadeTop.insertBefore(player);
        fadeBottom.insertAfter(player);
        share.insertAfter(fadeBottom);  
    
        $(".fs-preloader").remove();
        $('#carousel-popup,#carousel-container,#carousel-container .fs-carousel-popup').fadeIn();             
        $('#carousel-popup .popup-container:visible').center();      
  
        $(window).bind('resize', function() {
           $('#carousel-popup .popup-container:visible').center();
        });
  
    //Custom Video Share popup
    $("#share2").live('click',function(e) {
            
      if(Modernizr.touch) {
         //Clean up overlay before popups share links on iPad
         $("#popup-nav").empty();
         $('.popup-container,.overlay').stop().fadeOut();

         $("#carousel-popup .fs-carousel-popup").stop().fadeOut(500,function(){
       
            //Move share tools out of overlay
            $("#footer").prepend($("#fs-share"));
            $("#fs-share").show();  
            $("#carousel-popup #main-photo").empty();
         });

         $(".fs-preloader").remove();
   
         //Reset width for iPad
         if(Modernizr.touch) {
           $("#footer-content,#container #main").css("cssText","width:1230px;opacity:1;filter:alpha(opacity=100);-ms-filter:'progid:DXImageTransform.Microsoft.Alpha(Opacity=100)';");
         }
  
         //Destroy jPlayer
         $("#jplayer-1").jPlayer("destroy");       
        
      }  else {
         $("#fs-share").show();
      }
        
     var vidshareurl = "http%3A%2F%2Fwww.nowthisisyourtime.com%2F%23%2Fyour-video%3Fhashcode="+hashCode+"%21";
      
     //Prepare video social share
     $(".fs-share-social .video").each(function() {
      var Social = $(this).attr("title");
      
      switch(Social) {
      case "Facebook":
      $(this).attr("href","http://www.facebook.com/sharer.php?u="+vidshareurl);
      break;
      case "Twitter":
      $(this).attr("href","http://twitter.com/share?url="+vidshareurl+"&amp;source=sharethiscom");          
      break;
      case "Stumpleupon":
      $(this).attr("href","http://www.stumbleupon.com/submit?url="+vidshareurl+"&amp;title=Now%20This%20Is%20Your%20Time");          
      break;
      case "Delicious":
      $(this).attr("href","http://www.delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url="+vidshareurl+"&amp;title=Now%20This%20Is%20Your%20Timea");          
      break;
      case "MySpace":
      $(this).attr("href","javascript:void(window.open('http://www.myspace.com/Modules/PostTo/Pages/?u='+encodeURIComponent('"+vidshareurl+"'),'ptm','height=450,width=550').focus())");          
      break;
      case "Digg":
      $(this).attr("href","http://digg.com/submit?url="+vidshareurl);          
      break;
      case "Tumblr":
      $(this).attr("href","http://www.tumblr.com/share/link?url="+vidshareurl+"&name=Now%20This%20Is%20Your%20Time");          
      break;
      case "Google":
      $(this).attr("href","https://www.google.com/bookmarks/mark?op=add&amp;bkmk="+vidshareurl+"&amp;title=Now%20This%20Is%20Your%20Time");          
      break;
      }
       
     });
      
     $(".fs-share-social .video").show();
     $(".fs-share-social .site").hide();
      
     //Highlight all strings
     //highlightall($("#urlstring"));
      $("#urlstring").attr("value","http://www.nowthisisyourtime.com/#/your-video?hashcode="+hashCode+"!");

     e.preventDefault();
     $("#fs-share").animate({
       bottom: '20',opacity:'1'
     }, 200);
   });
}

function getQuerystring(key, default_) {
    if (default_==null) default_="";
    key = key.replace(/[[]/,"[").replace(/[]]/,"]");
    var regex = new RegExp("[?&]"+key+"=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if(qs == null)
      return default_;
    else
      return qs[1];
}

/*------------------------------------------------
  1.7 MULTIMEDIA GALLERY
  ------------------------------------------------*/    

   function multigallery() {

    if($('.the-director-gallery').length) {
      
      //Load first item
 
      var firstsourceone = $(".source:first").children("span").eq(0).text();
      var firstsourcetwo = $(".source:first").children("span").eq(1).text();
      var firstsourcethree = $(".source:first").children("span").eq(2).text();
      var firstposter = $(".poster:first").text();
   
      if(firstsourcetwo == '') {
         //Photo
         $(".the-director-gallery .main-img").empty().html('<div class="fs-preloader"></div><img src="" alt=""/>');
         $(".the-director-gallery .main-img img").hide().load(function() {
            $(".fs-preloader").remove();
            $(this).fadeIn();
         }).attr('src',firstposter);            
      } else {
         //Video
                     
         //Adding controls              
         $(".the-director-gallery .main-img").empty().html('<div  class="video-container" id="vid-container"></div><div  class="jp-video jp-video-360p"><div  class="jp-type-single"><div  id="jplayer-1"  class="jp-jplayer"></div><div  id="jp_interface_1"  class="jp-interface"><ul  class="jp-controls"><li><a  href="#"  class="jp-play"  tabindex="1">play</a></li><li><a   href="#"  class="jp-pause"  tabindex="1">pause</a></li><li><a  href="#"  class="jp-mute"  tabindex="1">mute</a></li><li><a  href="#"  class="jp-unmute"  tabindex="1">unmute</a></li></ul><div  class="jp-progress"><div   class="jp-seek-bar"><div  class="jp-play-bar"></div></div></div><div  class="jp-volume-bar"><div  class="jp-volume-bar-value"></div></div><div  class="jp-current-time"></div><div  class="jp-duration"></div></div></div></div>');
              
         $("#jplayer-1").jPlayer({
           size: {width: '510px',height: '365px'},
           ready: function () {
             $(this).jPlayer("setMedia", {m4v: firstsourcetwo,ogg: firstsourceone,poster: firstposter}).jPlayer("play");
           },
           swfPath: "/includes/libs/js/jplayer/",preload: "auto",wmode: "transparent",supplied: "m4v, ogg",cssSelectorAncestor: "#jp_interface_1", cssSelector: {"play" : ".jp-play","pause" : ".jp-pause","stop" : ".jp-stop","videoPlay" : ".jp-video-play","seekBar" : ".jp-seek-bar","playBar" : ".jp-play-bar","mute" : ".jp-mute","unmute" : ".jp-unmute","volumeBar" : ".jp-volume-bar","volumeBarValue" : ".jp-volume-bar-value","currentTime" : ".jp-current-time","duration" : ".jp-duration"}});
        
      }
      
      $('.the-director-gallery .item').each(function(i){
        
          //Add Player to thumbnail
          var isvideo = $(this).find(".source").children("span").eq(1).text();        
          if(isvideo != '') {
             $(this).find(".small").append('<div class="fs-thumb-vid-bg"></div>');
          }
          //Show photo/video on click
          $(".the-director-gallery .item").live('click',function(){
            
              var sourceone = $(this).find(".source").children("span").eq(0).text();
              var sourcetwo = $(this).find(".source").children("span").eq(1).text();
              var sourcethree = $(this).find(".source").children("span").eq(2).text();
              var poster = $(this).find(".poster").text();
               
              //Clear previous jPlayer
              $("#jplayer-1").jPlayer("destroy");                        
            
            if(sourcetwo == '') {
               //Photo
               $(".the-director-gallery .main-img").empty().html('<div class="fs-preloader"></div><img src="" alt=""/>');
               $(".the-director-gallery .main-img img").hide().load(function() {
                   $(".fs-preloader").remove();
                   $(this).fadeIn();
               }).attr('src',poster);            
            } else {
               //Video
              
               //Adding controls              
               $(".the-director-gallery .main-img").empty().html('<div class="video-container" id="vid-container"></div><div class="jp-video jp-video-360p"><div class="jp-type-single"><div id="jplayer-1" class="jp-jplayer"></div><div  id="jp_interface_1" class="jp-interface"><ul  class="jp-controls"><li><a href="#" class="jp-play"  tabindex="1">play</a></li><li><a href="#" class="jp-pause"  tabindex="1">pause</a></li><li><a href="#" class="jp-mute" tabindex="1">mute</a></li><li><a href="#" class="jp-unmute" tabindex="1">unmute</a></li></ul><div class="jp-progress"><div class="jp-seek-bar"><div class="jp-play-bar"></div></div></div><div  class="jp-volume-bar"><div  class="jp-volume-bar-value"></div></div><div  class="jp-current-time"></div><div class="jp-duration"></div></div></div></div>');
              
              $("#jplayer-1").jPlayer({
                ready: function () {
                   $(this).jPlayer("setMedia", {ogg: sourceone,m4v: sourcetwo,poster: poster}).jPlayer("play");
                },
                size: {width: "510px",height: "365px"},
                swfPath: "/includes/libs/js/jplayer/",wmode: "transparent",preload:"auto",supplied: "m4v, ogg",cssSelectorAncestor: "#jp_interface_1", cssSelector: {"play" : ".jp-play","pause" : ".jp-pause","stop" : ".jp-stop","videoPlay" : ".jp-video-play","seekBar" : ".jp-seek-bar","playBar" : ".jp-play-bar","mute" : ".jp-mute","unmute" : ".jp-unmute","volumeBar" : ".jp-volume-bar","volumeBarValue" : ".jp-volume-bar-value","currentTime" : ".jp-current-time","duration" : ".jp-duration"}});
   
            }
              
          });
      });
    }

   //Building Carousel
   var $_total = $('.the-director-gallery .item').length;
   var $_total2 = Math.ceil($_total / 7);
   var $slideshow_width = $('.the-director-gallery .screen').width();
   var $_total_width = $_total2 * $slideshow_width;
   var $_first = $('.the-director-gallery .item:first');
   var $npos = 0;
xprLog($_total);
   if($_total_width < $('.the-director-gallery .navigation').width()){
      $_total_width = $('.the-director-gallery .navigation').width();
   }
      
   $(".the-director-gallery .screen").css("width","20000em");        
        
   $('.the-director-gallery .prev').live('click',function(e){
    e.preventDefault();
    $npos--;
    if($npos < 0) $npos = 0;
    $('.the-director-gallery .screen').animate({left:$npos * -($slideshow_width+7)}, 500);
   });
        
   $('.the-director-gallery .next').live('click',function(e){
    e.preventDefault();
    $npos++;

    if($npos >= $_total2) $npos = 0;

    $('.the-director-gallery .screen').animate({left:$npos * -($slideshow_width+7)}, 500);
   });

   }

/*-----------------------------------------------
  1.8 LEGAL
  ------------------------------------------------*/     
  
  var legaltext = 0;

  function hideLegal() {   
    legaltext = 0;
    if(legaltext == 0) {
     $(".fs-legal").hide();
    } else {   
     $(".fs-legal").show();
    }
  }

  function legal() {
    legaltext = 1;
    $(".fs-legal").show();
  }

/*-----------------------------------------------
  1.9 STAFF GALLERY
  ------------------------------------------------*/

   function staffgallery() {

    if($('.the-staff-gallery').length) {
      
      $('.the-staff-gallery .item').each(function(i){
          //Add video button to thumbnail      
          var isvideo = $(this).find(".source").children("span").eq(1).text();        
          if(isvideo != '') {
             $(this).find(".small").append('<div class="fs-thumb-vid-bg"></div>');
          }
        
          //Show photo/video on click
          $(".the-staff-gallery .item").live('click',function(){
                        
              if($('#video').length && Modernizr.video) {
                //Stop streaming previous video
                var vid = document.getElementById("video");
                vid.pause();vid.src = "";vid.load();  
              }
            
              var sourceone = $(this).find(".source").children("span").eq(0).text();
              var sourcetwo = $(this).find(".source").children("span").eq(1).text();
              var sourcethree = $(this).find(".source").children("span").eq(2).text();
              var poster = $(this).find(".poster").html();
              
              if(sourcetwo == '') {
               //Photo
               $(".the-staff-gallery .main-img").html('<div class="fs-preloader"></div><img src="" alt=""/>');
               $('#carousel-popup .popup-container:visible').center();
               $(".the-staff-gallery .main-img img").hide().load(function() {
                   $(".fs-preloader").remove();
                   $(this).fadeIn();

                   $('#carousel-popup .popup-container:visible').center();

               }).attr('src',poster);            
              } else {        
               //Video
                               
               //Clear previous jPlayer
               $("#jplayer-1").jPlayer("destroy");  
                
               //Adding controls              
         $(".the-staff-gallery .main-img").empty().html('<div  class="video-container"  id="vid-container"></div><div  class="jp-video  jp-video-360p"><div  class="jp-type-single"><div  id="jplayer-1"  class="jp-jplayer"></div><div  id="jp_interface_1"  class="jp-interface"><ul  class="jp-controls"><li><a  href="#"  class="jp-play"  tabindex="1">play</a></li><li><a  href="#"  class="jp-pause"  tabindex="1">pause</a></li><li><a  href="#"   class="jp-mute"  tabindex="1">mute</a></li><li><a   href="#"  class="jp-unmute"  tabindex="1">unmute</a></li></ul><div  class="jp-progress"><div   class="jp-seek-bar"><div  class="jp-play-bar"></div></div></div><div  class="jp-volume-bar"><div     class="jp-volume-bar-value"></div></div><div  class="jp-current-time"></div><div     class="jp-duration"></div></div></div></div>');
                
                $("#jplayer-1").jPlayer({
                  ready: function () {
                     $(this).jPlayer("setMedia", {ogg: sourceone,m4v: sourcetwo,poster: poster}).jPlayer("play");
                  },
                  //Close overlay when video is ended
                  ended: function() {
                  cleanup();  
                  },
                  size: {width: "797px",height: "447px"},
                  swfPath: "/includes/libs/js/jplayer/",wmode: "transparent",preload:"auto",supplied: "m4v, ogg",cssSelectorAncestor: "#jp_interface_1", cssSelector: {"play" : ".jp-play","pause" : ".jp-pause","stop" : ".jp-stop","videoPlay" : ".jp-video-play","seekBar" : ".jp-seek-bar","playBar" : ".jp-play-bar","mute" : ".jp-mute","unmute" : ".jp-unmute","volumeBar" : ".jp-volume-bar","volumeBarValue" : ".jp-volume-bar-value","currentTime" : ".jp-current-time","duration" : ".jp-duration"}});
                
               $('#carousel-popup .popup-container:visible').center();

              }
          });
      });
    }
   }

  //Hide buttons when link is incorrect
    var prevurl = $(".staff-profile > #prevurl").attr("rel");   
    var nexturl = $(".staff-profile > #nexturl").attr("rel");

  function showhidecontrols() {
    //Staff controls
    if(prevurl == ''){
       $("#prev").fadeOut();

    } else {
       $("#prev").fadeIn();
    }
     
     if(nexturl == '/the-story/default'){
        $("#next").fadeOut();
     } else {
        $("#next").fadeIn();
     }
  }

/*-----------------------------------------------
 ------------------------------------------------
 1. GLOBAL VARIABLES & FUNCTIONS END
 ------------------------------------------------
 ------------------------------------------------*/

/*-----------------------------------------------
 ------------------------------------------------
 2. FOOTER POPUP
 ------------------------------------------------
 ------------------------------------------------*/

$(document).ready(function() {
  
  //Hightlight all strings
    $('#urlstring').click(function() { highlightall(jQuery(this)) });  
  //Close button
  $(".close-small").click(function(e) {
    
    //Reset social links
    $(".fs-share-social .video,.fs-share-social .site").hide();

    e.preventDefault();
    $("#fs-share").animate({
      bottom: '0', opacity: '0'
    }, 200, function() {
    $("#fs-share").hide();
    });
  });
    
  //Open share popup
  $("#share").click(function(e) {
    //Show Site social share
    $(".fs-share-social .video").hide();
    $(".fs-share-social .site").show();
    //Highlight all strings
    //highlightall($("#urlstring"));
    $("#urlstring").attr("value","http://www.nowthisisyourtime.com");
//    $("#fs-share").insertBefore("#footer-content").show();
    $("#fs-share").show();
    e.preventDefault();
    $("#fs-share").animate({
      bottom: '30',opacity:'1'
    }, 200);
  });

/*------------------------------------------------
  ------------------------------------------------
  3. CONTACT FORM
  ------------------------------------------------
  ------------------------------------------------*/
  
  //Handle input focus
    $(".fs-contact-form").find("input[type=text]").live('focus',function() {
    $(this).css({"background-position":"right 0px","color":"#464646"});
    $(this).prev().css({"background-position":"right 0px"});
  });  
    $(".fs-contact-form").find("input[type=text]").live('blur',function() {
    $(this).css({"background-position":"right -27px","color":"#FFF"});
    $(this).prev().css({"background-position":"right -27px"});
  });  
  //Mark up radio buttons
  $(".set1").live('click',function() {
      var id = $(this).attr("id");
      $(".set1.active").removeClass("active");
      $(this).addClass("active");
      $(".option1:visible").hide();
      $("#option"+id).fadeIn();  
  });
  
  $(".set2").live('click',function() {
      var id = $(this).attr("id");
      $(".set2.active").removeClass("active");
      $(this).addClass("active");
      $(".option2:visible").hide();
      $("#option"+id).fadeIn();  
  });
  
  $(".both1").live('click',function() {
      $(".option1").fadeIn();  
  });
  
  $(".both2").live('click',function() {
      $(".option2").fadeIn();  
  });
  
/*------------------------------------------------
  ------------------------------------------------
  4. CHOOSE YOUR HOME
  ------------------------------------------------
  ------------------------------------------------*/
  
  $("a.gold,a.silver").live('mouseenter',function(event) {
       if ( $.browser.msie ) {
         $("#est-icon").css("filter","0");
       } else {
         $(this).children("img").stop().animate({opacity:'1'}, 500); 
       }  
    $(this).next("p").stop().animate({opacity:'1'}, 500);

  });
  
  $("a.gold,a.silver").live('mouseleave',function(event) {  
       if ( $.browser.msie ) {
         $("#res-icon").css("filter","0");
       } else {
         $(this).children("img").stop().animate({opacity:'0.5'}, 200);
       } 
       $(this).next("p").stop().animate({opacity:'0'}, 500);  
        
  });
 
/*------------------------------------------------
  ------------------------------------------------
  5. AMENITIES MENU
  ------------------------------------------------
  ------------------------------------------------*/
    
  $(".fs-amenities-item").live('mouseenter',function() {
       $(this).find("img.thumb").stop().animate({opacity:'0.2'}, 250);
       $(this).children(".title-container").show();
  });
  
  $(".fs-amenities-item").live('mouseleave',function() {
       $(this).find("img.thumb").stop().animate({opacity:'1'}, 250);
       $(this).children(".title-container").hide();
  });
  
  $(".fs-amenities-item").live('click',function() {
         var id = $(this).attr('id').replace('amenity','');
         
         if(!$(this).hasClass('active')){
                 $(".fs-amenities-item").removeClass('active');
            $(this).addClass('active');
            
            $(".fs-amenities-item").attr("rel","disabled");
           
            //Dealing with content
            var html = $(this).find(".html").html();
            var wrapper = $(this).parent(".wrapper,.wrapper-first");
            
            $('.fs-valet-services-content-container').animate({height:0, opacity:0},400,function(){
                $("<div class='fs-valet-services-content-container' id='adetail"+id+"'>"+html+"</div>").animate({height:'hide',opacity:0}).insertAfter(wrapper).animate({height:'show',opacity:1},400,function() {
                   $(".fs-amenities-item").attr("rel","");
                });
                $(this).remove();
            });    
         }
         else
         {
             // slide back and remove
             $(".fs-amenities-item").removeClass('active');
             $('.fs-valet-services-content-container').animate({height:0, opacity:0},400,function(e){
               $(this).remove();  
               $('.<div style="display: none; clear: both;" class="fs-valet-services-content-container"></div>').insertAfter('.fs-amenities .wrapper:last');
             });
             
         }                                                        
  });
  
/*------------------------------------------------
  ------------------------------------------------
   6. NAVIGATIONS
  ------------------------------------------------
  ------------------------------------------------*/
  
  //Back button

  
  //Disabled link
  $('a[rel="disabled"]').live('click',function(e) {
       e.preventDefault();
  });

/*-------------------------------------------------
   6.1 STAFF
  -------------------------------------------------*/   
  
  //PREV   
  $("span[rel='prev']").live('click',function(e) {
     //e.preventDefault();
     prevurl = $(".staff-profile > #prevurl").attr("rel");   
     $("#next,#prev").attr("rel","disabled");
     $("#staff-popup").remove();
    
     $('<div class="fs-left-content staff"></div>').insertAfter("#content-container").load(prevurl +" .staff-profile",{}, function(response){            
               
                $(this).animate({
                     left: '143'}, 700, function() {
                     $(".fs-left-content").removeClass("fs-left-content").addClass("left").attr("id","content-container");         
                    });
                $('#content-container .staff-profile').animate({
                   left: '1500'}, 700, function() {
                      $(this).remove();
                      $("#content-container").removeAttr("id");
                      $("#next").attr("rel","next");
                      $("#prev").attr("rel","prev");
                      //$.history.load(prevurl);
                      staffdetail();
                   });       
                
            });
      //return false;
  });
  
  //NEXT
  $("span[rel='next']").live('click',function(e) {
     //e.preventDefault();
     nexturl = $(".staff-profile #nexturl").attr("rel");  
     $("#next,#prev").attr("rel","disabled");
     $("#staff-popup").remove();


     $('<div class="fs-right-content staff"></div>').insertAfter("#content-container").load(nexturl +" .staff-profile",{}, function(response){
         
                $(this).animate({
                    left: '143'}, 700, function() {
                    $(".fs-right-content").removeClass("fs-right-content").addClass("left").attr("id","content-container");        
                    });
                $('#content-container .staff-profile').animate({
                    left: '-1500'}, 700, function() {
                       $(this).remove();
                       $("#content-container").removeAttr("id");
                       $("#next").attr("rel","next");
                       $("#prev").attr("rel","prev");
                       //$.history.load(nexturl);
                       staffdetail();
                    });           
            
            });
          //return false;
  });
 
/*-------------------------------------------------
   6.2 Your Custom Video Thumbnail Animation
  -------------------------------------------------*/   
    
  //Hover thumbnail
   $(".fs-your-custom-video").live('mouseenter',function(e) {
      $("#yourvid").stop().animate({
      bottom: '27',opacity:'1'
      }, 200);
      $(this).find("a").css("cssText","color:#FFF4F1;text-shadow:0px 0px 20px #FFF4F1;");
   });
  
   $(".fs-your-custom-video").live('mouseleave',function(e) {
     $("#yourvid").stop().animate({
      bottom: '0',opacity:'0'
      }, 200);
     $(this).find("a").css("cssText","color:#BBB;text-shadow:0px;");
   });
  
//end .ready()
});  

/*-------------------------------------------------
   6.3 STAFF STILL
  -------------------------------------------------*/   

function staff_still()
{
    $('.staff-obj').hover(function(e)
    {
        $(this).find('.normal').fadeOut(300);
        $(this).find('.hover, .title').fadeIn(300);
    }
    ,function(e)
    {
        $(this).find('.normal').fadeIn(300);
        $(this).find('.hover, .title').fadeOut(300);
    });
    
    $('.html-staff').fadeIn(500);
}

/*------------------------------------------------
  ------------------------------------------------
   7. CUSTOM VIDEO LINKS
  ------------------------------------------------
  ------------------------------------------------*/

$(document).ready(function() {
  
  //Modify Your video link to show pop up
  $("#nav a[title='Your Personal Video']").attr("rel","");
  
  //Show your video pop up
  $("#yourvid,#yourvidtext,#nav a[title='Your Personal Video']").live('click',function(e) {
    e.preventDefault();
    customvideopopup();
    
    //Move share popup to the overlay
    $("#fs-share").insertBefore($("#share2")).css("cssText","right:0px;").show();

    return false;
  });
  
  //make video link
  $("#makevid").click(function() {
    //Hide scrollers  
    $('body').css("cssText","position:relative;width:100%;height:100%;overflow:hidden;");   
    $("#container").css("cssText","position:static;").append('<div class="skip-btn">skip</div>');

    skip_no = 1;
  });

});

/*------------------------------------------------
  ------------------------------------------------
   8. FOOTER FIX FOR iPAD AND IPHONE
  ------------------------------------------------
  ------------------------------------------------*/

$(function(){
    if (Modernizr.touch){
      $("#footer").css({"position":"relative","width":"1230px"});
      $("#fs-share").css({"position":"relative","left":"800px","bottom":"30px"});
    }
});


/*------------------------------------------------
  ------------------------------------------------
   9. EMAIL A FRIEND
  ------------------------------------------------
  ------------------------------------------------*/

function submitEmailFriend() {
  var formData = $('#emailFriend').serialize();
  var postTo = "http://www.nowthisisyourtime.com/relay.php?ejaxKey=FourSeasonsAjaxEmailHandler.run&email_element_id=1078&format=html&success_url=/contact/email-a-friend&fail_url=/the-story/";

  $('.fs-popup').html('<div class="error-container">' + preloader + '</div>');

  $.post(postTo, formData, function(data) {
    var article;
    if (data == "success")
      article = 'email-a-friend';    
    else
      article = 'email-a-friend---error';
    $.get('http://www.nowthisisyourtime.com/relay.php?ejaxKey=FourSeasonsAjaxPageRunner.run&url=/contact/' + article, function(insert) {
      $('.fs-popup').empty().animate({opacity:'0'}, 0);
      $('.fs-popup').html('<a class="fs-popup-close" href=""></a>'+insert).animate({opacity:'1'},500);
    });
  });
}

/*------------------------------------------------
  ------------------------------------------------
   10. CENTER OVERLAY
  ------------------------------------------------
  ------------------------------------------------*/

(function($){
     $.fn.extend({
          center: function (options) {
               var options =  $.extend({ // Default values
                    inside:window, // element, center into window
                    transition: 0, // millisecond, transition time
                    minX:0, // pixel, minimum left element value
                    minY:50, // pixel, minimum top element value
                    vertical:true, // booleen, center vertical
                    withScrolling:true, // booleen, take care of element inside scrollTop when minX < 0 and window is small or when window is big
                    horizontal:true // booleen, center horizontal
               }, options);
               return this.each(function() {
                    var props = {position:'absolute'};
                    if (options.vertical) {
                         
                         //Resizing image based on viewport's height 
                         if($(this).find('#slideshow-image').length) {
                            $(this).find('#slideshow-image').width("auto").height( $(window).height()*90/100 );
                         }
                      
                         var top = ($(options.inside).height() - $(this).outerHeight()) / 2;
                         if (options.withScrolling) top += $(options.inside).scrollTop() || 0;
                         top = (top > options.minY ? top : options.minY);
                         $.extend(props, {top: top+'px'});
                      

                    }
                    if (options.horizontal) {
                      
                          //Resizing image based on viewport's height
                          if($(this).find('#slideshow-image').length) {                      
                             $(this).find('#slideshow-image').width("auto").height( $(window).height()*90/100 );
                          }
                      
                          var left = ($(options.inside).width() - $(this).outerWidth()) / 2;
                          if (options.withScrolling) left += $(options.inside).scrollLeft() || 0;
                          left = (left > options.minX ? left : options.minX);
                          $.extend(props, {left: left+'px'});
                    }
                    if (options.transition > 0) $(this).animate(props, options.transition);
                    else $(this).css(props);
         //Go full screen for iPad        
         if(Modernizr.touch) {             
            $("#container #main,#footer-content").css("cssText","width:auto;");
         }
                    return $(this);
               });
          }
     });
})(jQuery);

//Clean up contents
function cleanup() {
   $("#popup-nav").empty();
     $('.popup-container,.overlay').stop().fadeOut();

     $("#carousel-popup .fs-carousel-popup").stop().fadeOut(500,function(){
       //Check for Staff contents before clean up
       if($(".staff-video-flash").length) {
          $(".staff-video-flash").hide().insertAfter(".video-preview");
       }
       
       //Move share tools out of overlay
       $("#footer").prepend($("#fs-share"));
       $("#fs-share").hide();
       
       $("#carousel-popup #main-photo").empty();
     });

     $(".fs-preloader").remove();
    
     //Stop streaming previous video
     if($("#video").length && Modernizr.video) {                
       var vid = document.getElementById("video");
       vid.pause();vid.src = "";vid.load();  
     }  
     //Reset width for iPad
     if(Modernizr.touch) {
        $("#footer-content,#container #main").css("cssText","width:1230px;opacity:1;filter:alpha(opacity=100);-ms-filter:'progid:DXImageTransform.Microsoft.Alpha(Opacity=100)';");
     }
  
     //Destroy jPlayer
     $("#jplayer-1").jPlayer("destroy");
  
}

//Close button

$(document).ready(function() {

  $('.overlay,.fs-popup-close,.fs-popup-close-text').live('click',function(event) {
     event.preventDefault();
     cleanup();
  });
});

/*------------------------------------------------
  ------------------------------------------------
   11. STAFF DETAILS
  ------------------------------------------------
  ------------------------------------------------*/

function staffCallback(url)
{
    $.history.load(url);
}

function log(msg) {
    if (window.console) console.log(msg);
}

function video_action(event,cp1,cp2,cp3,cp4){

    if(event.currentTime > cp1 && event.className != "active"){
        event.currentTime = 0;
        event.pause();
    }
    
    if(event.currentTime > cp4 && event.className == "active"){
        event.currentTime = cp3;
    }

}

// staff details
  
function staffdetail() {  
//Build gallery  
staffgallery();
showhidecontrols();
hideLegal();
 
//Activate scroller
  $('#section-scroll').jScrollPane({showArrows:true,animateTo:true});
  
   //Add swipe event
   $(document).ready(function() {
    if (! $.browser.msie ) {
     $('#section-scroll').swipe({
       swipeUp: function() {
         $('#section-scroll')[0].scrollBy(parseInt('+100'));
       },
       swipeDown: function() {
         $('#section-scroll')[0].scrollBy(parseInt('-100'));
       }
     });    
   } 
   });  

  $(document).ready(function() {
    //Add fadeout graphic
    $('<div class="fs-staff-fadeout"></div>').insertBefore('#section-scroll');
    
    //Move gallery out of body tag
    $(".video-preview").appendTo("#staff-gallery-html");
    $(".video-preview").eq(1).remove();

  });  
  
    //Add Player to thumbnail
    $('.video-preview .item').each(function(e){
       var video = $(this).find(".source").children("span").eq(1).text();        
      if(video != '') {
          $(this).find(".small").append('<div class="fs-thumb-vid-bg"></div>');
      }
    });
  
    //staff detail overlay
    $('.video-preview .item').live('click',function(e){
      
      e.preventDefault();
      
      var content = $(".staff-video-flash");

      if($('#video').length && Modernizr.video) {
         //Stop streaming previous video
         var vid = document.getElementById("video");
         vid.pause();vid.src = "";vid.load();  
      }
            
              var sourceone = $(this).find(".source").children("span").eq(0).text();
              var sourcetwo = $(this).find(".source").children("span").eq(1).text();
              var sourcethree = $(this).find(".source").children("span").eq(2).text();
              var poster = $(this).find(".poster").html();
                  
              if(sourcetwo == '') {
               //Photo

               $(".the-staff-gallery .main-img").html('<div class="fs-preloader"></div><img src="" alt=""/>');
               $(".the-staff-gallery .main-img img").hide().load(function() {
                   $(".fs-preloader").remove();
                   $(this).fadeIn();

                   $('#carousel-popup .popup-container:visible').center();

               }).attr('src',poster);            
              } else {        
               //Video
              
               //Adding controls              
               $(".the-staff-gallery .main-img").empty().html('<div class="video-container" id="vid-container"></div><div class="jp-video jp-video-360p"><div class="jp-type-single"><div id="jplayer-1" class="jp-jplayer"></div><div id="jp_interface_1" class="jp-interface"><ul class="jp-controls"><li><a href="#" class="jp-play"  tabindex="1">play</a></li><li><a href="#" class="jp-pause"  tabindex="1">pause</a></li><li><a href="#" class="jp-mute" tabindex="1">mute</a></li><li><a href="#" class="jp-unmute" tabindex="1">unmute</a></li></ul><div class="jp-progress"><div class="jp-seek-bar"><div class="jp-play-bar"></div></div></div><div  class="jp-volume-bar"><div  class="jp-volume-bar-value"></div></div><div  class="jp-current-time"></div><div class="jp-duration"></div></div></div></div>');
              
              $("#jplayer-1").jPlayer({
                ready: function () {
                   $(this).jPlayer("setMedia", {ogg: sourceone,m4v: sourcetwo,poster: poster}).jPlayer("play");
                },
                ended: function() {
                  //Close overlay when video is ended
                  cleanup();
                },
                size: {width: "797px",height: "447px"},
                swfPath: "/includes/libs/js/jplayer/",wmode: "transparent",preload:"auto",supplied: "m4v, ogg",cssSelectorAncestor: "#jp_interface_1", cssSelector: {"play" : ".jp-play","pause" : ".jp-pause","stop" : ".jp-stop","videoPlay" : ".jp-video-play","seekBar" : ".jp-seek-bar","playBar" : ".jp-play-bar","mute" : ".jp-mute","unmute" : ".jp-unmute","volumeBar" : ".jp-volume-bar","volumeBarValue" : ".jp-volume-bar-value","currentTime" : ".jp-current-time","duration" : ".jp-duration"}});
                
               $('#carousel-popup .popup-container:visible').center();
                
              }

      $('#carousel-popup #main-photo').append(content);

      $('#carousel-popup').insertAfter('body > #container');

      $('#carousel-popup,#carousel-container,#carousel-container .fs-carousel-popup,#carousel-popup .overlay,.staff-video-flash').fadeIn();
      $('#carousel-popup .popup-container:visible').center();
    });
    
    $(window).bind('resize', function() {
      $('#carousel-popup .popup-container:visible').center();
    });
  
   //Bio Transition
    var img = new Image();
    var bio = $("#content-container #bio").html();

    $("#content-container .left-img").append(preloader);
    $(img).hide().empty().load(function() {
       $("#content-container .left-img").empty().append(this).append("<div class='staff-fadeout'></div>");
       $("#content-container .left-img img").fadeIn();
       showhidecontrols();
    }).attr("src",bio);
  
}

$(function() {  

// staff hmtl 5
if($('.staff-html5').length)
{
    $('.staff').each(function(i){
        var cuepoints = $(this).attr('class').replace('staff cue','').split(',');
        var video_id = $(this).find('video').attr('id');
        
        // on time update
        $(this).find('video').attr('ontimeupdate','video_action(this,'+cuepoints[0]+','+cuepoints[1]+','+cuepoints[2]+','+cuepoints[3]+')');
        
        $(this).mouseover(function(e){
            $(this).find('video').addClass('active');
            document.getElementById(video_id).play();
        });
        
        $(this).mouseout(function(e){
            $(this).find('video').removeClass('active');
        });
    });
}
 
  /*------------------------------------------------
  ------------------------------------------------
   12. EMAIL OVERLAY
  ------------------------------------------------
  ------------------------------------------------*/

if($('#email-popup').length)
{
      $('#email-popup').insertAfter('body > #container');
      $('#email-popup .popup-container').center();
    $('#sendemail,#sendemail2').click(function(e){
      e.preventDefault();

      $('#email-popup .popup-container:visible').center();
      $('#email-popup .overlay, #email-popup .popup-container').fadeIn();
    });
    
    $(window).bind('resize', function() {
      $('#email-popup .popup-container:visible').center();
    });
      return false;
}

});

//stick the footer at the bottom of the page if we're on an iPad/iPhone due to viewport/page bugs in mobile webkit
if (Modernizr.touch)
{
     $("#footer").css({"position":"relative"});
}

  /*------------------------------------------------
  ------------------------------------------------
   13. INTRO VIDEO CONTROLS
  ------------------------------------------------
  ------------------------------------------------*/

$('#jplayer-play').live('click',function(e){
    e.preventDefault();
    $(this).hide();
    $('#jplayer-pause').show();
});

$('#jplayer-play').live('click',function(e){
    e.preventDefault();
    $(this).hide();
    $('#jplayer-play').show();
});

$('#jplayer-mute').live('click',function(e){
    e.preventDefault();
    $(this).hide();
    $('#jplayer-unmute').show();
});

$('#jplayer-unmute').live('click',function(e){
    e.preventDefault();
    $(this).hide();
    $('#jplayer-mute').show();
});

  /*------------------------------------------------
  ------------------------------------------------
   14. SPLASH AND INTRO
  ------------------------------------------------
  ------------------------------------------------*/

var introHidden = false;
 var skip_no = 0;
 //preloader graphic
 var preloader = "<div class='fs-preloader'></div>";
 var opacityFlag = 0;
 var _startintro = 0;
 var interval = "";

/*-----------------------------------------------
 1.1 INTRO VIDEO
 ------------------------------------------------*/        

 function autoplay() {
   if($("#video").length) {
    var vid = document.getElementById("video");  
    if (Modernizr.video && Modernizr.video.ogg && !$.browser.webkit || Modernizr.touch){
        //Firefox & iPad
        vid.play();         
    } else if(Modernizr.video && Modernizr.video.h264){
        //Chrome & Safari
        vid.addEventListener('canplay', function() { this.play(); } );
    }
   }
 }

//Hide window scrollers, go full width and height  
function fullscreen() {
  
  var skip = $("<div>skip</div>").addClass("skip-btn");
$("body").prepend(skip);
    $('body').css("cssText","position:relative;width:100%;height:100%;overflow:hidden;");   
    $("#container").css("cssText","position:static;background:none;");
    $("#container #main").css("cssText","width:auto;");
    $("#footer").hide();
}
/*
function introText()
{
    var watch = 0;
    
    $(".skip-btn").remove();

    $('.splash .text01').delay(3000).fadeIn(1000,function(e){
        $('.splash .text02').delay(2000).fadeIn(1000,function(e){
            $('.splash .text03').delay(2000).fadeIn(1000,function(e){
                $('.splash .text01, .splash .text02, .splash .text03').delay(1000).fadeOut(1000,function(e){
                    $('.splash .watch-btn').delay(2000).fadeIn(1000);
                });
            });
        });
    });
    
    $('.splash .watch-btn').live('click',function(e){
        $('.splash .watch-btn').fadeOut(500,function(e)
        {
            $('.splash').remove();
        });
    });
}
*/
function deleteintro() {
//Clear previous jPlayer
$("#introVideo").jPlayer("destroy");
  
$(".splash").remove();  
  
}
   
 //Detect if user has generated their custom video
 function customvideodisplay() {
  $(document).ready(function() {
   if($.cookie('customVideo')) {
     $("#has-cookie").show();
     $("#no-cookie").hide();   
     $("#nav a[title='Make Your Personal Video Now']").text("Your Personal Video").attr({href:"",id:"",title:"Your Personal Video",rel:""});    

   } else {
     $("#no-cookie").show();
     $("#has-cookie").hide();
     $("#nav a[title='Your Personal Video']").text("Make Your Personal Video Now").attr({href:"/time-lapse",id:"makevidnav",title:"Make Your Personal Video Now",rel:"ajax"});

   }
  });
 }

 function showstage() {
    //Fade in stage
   if (opacityFlag == 0) { $("#header,#footer").css("opacity","0");$("#footer").hide(); }
   
       $("#container,#container #main").css("cssText","position:relative;opacity:1!important;filter:alpha(opacity=100)!important;-ms-filter:'progid:DXImageTransform.Microsoft.Alpha(Opacity=100)'!important;").animate({opacity: '1'}, 1500, function() {
       if ( $.browser.msie ) {
       $("#header,#footer").hide().delay(500).css("cssText","opacity:1!important;filter:alpha(opacity=100)!important;-ms-filter:'progid:DXImageTransform.Microsoft.Alpha(Opacity=100)'!important;").fadeIn();
       } else {
        $("#header,#footer").show().delay(500).animate({opacity:'1'},1000);
       }      
    });    
    //Reset body styles
   $('body').css({overflow:'visible'});
   $("#container").css("cssText","");
   $("#container #main,#footer-content").css("cssText","width:1230px;");
   
   //Fix black border png in IEs
   if ( $.browser.msie ) {
      $("#content").css({"filter":"alpha(opacity=100)","zoom":"1"});
   }
   opacityFlag = 1;
   
   //Hide open house popup when visiting Contact page
   (location.hash == '#/contact/') ? $(".openhouse-popup1,.openhouse-popup2").hide():$(".openhouse-popup2").show(); 
   
 }
    

function hideIntro() {
    xprLog('hiding intro');
    showstage();
    $('.flash-container,.time-lapse,.flash-bg,.time-lapse-bg').remove();

    introHidden = true;
}

function pageTitle(pagetitle) {
  $(document).ready(function() {
    this.title = pagetitle;
  });
}

/*-----------------------------------------------
 1.2 SKIP BUTTON
 ------------------------------------------------*/  
$(document).ready(function() {
  
  $('.skip-btn').live('click',function(e){
    if(skip_no == 1) {
        //Skip time lapse
        $("#header").css("opacity","1");
        $('.time-lapse').animate({opacity:'0'});
          //Detecting mobile devices
          if(Modernizr.touch){
            $.history.load('/staff-mobile');
            } else {
            $.history.load('/the-story/');
          }

          $('.time-lapse,.time-lapse-bg').remove();
          $('#introhtml').empty();
          $(".skip-btn,#introhtml").remove();
          showstage();
          $(".mashup-video,video").remove();
    } else {
      //Skip Intro
      deleteintro();
        $('#intro-container').fadeOut(1000,function(e){
          $(this).remove();
          $(".fs-intro").remove();
        });
        if($("#video").length && Modernizr.video) {
          var vid = document.getElementById("video");
          vid.pause();vid.src = "";vid.load();  
        }
        $(".fs-intro,#intro-container,#video").remove();  
      
        $('.time-lapse').fadeIn(1000);     
        skip_no=1;
        if(Modernizr.touch){
          $.history.load('/time-lapse-mobile');
        } else {
          $.history.load('/time-lapse');
        }
    }
  });    
});

 /*------------------------------------------------
 ------------------------------------------------
   15. VIDEO MASH UP
 ------------------------------------------------
 ------------------------------------------------*/

var player;
function playVideo(){
  xprLog('playing mashup video');
    
    $(".time-lapse").hide();
    $('.mashup-video').append('<div id="video-player-nav"><div class="video-player-nav-con"><a class="btn-play active" href="#"></a><a class="btn-mute" href="#"></a><div class="clear"></div></div></div></div>');
    
    xprLog('time-lapse faded out');
    if (Modernizr.touch) {
        $('.mashup-video video')[0].play();

    } else {
        player.xprMediaPlayer('startPlayer');
    }
    
    setVideoNav();

}

function timelapseComplete(msg){
  xprLog('loading mashup video');
  // alert('loading mashup video');

  xprLog(msg);
  //$(".time-lapse").fadeOut(500,function(e){
    $.cookie('customVideo', msg, {expires: 120});
    player = $("<div></div>").attr('id', 'videoPlayer');
    $("<div class='mashup-video'></div>").insertAfter('.time-lapse');
    $(".mashup-video").append(player);
    if (Modernizr.touch) {
        xprLog('loading ipad video');
        var video = $('<video></video>');
        video.css('height', '90%');
        video.css('width', '100%');        
        video.attr('preload', 'auto');
        video.attr('controls', 'true');
        video.attr('autobuffer', 'true');
        video.attr('src', '/mashup/'+msg+'.m3u8');

        video.bind('canplay', function(e) { this[0].play(); });
        video.bind('ended', function(e) {
            xprLog('mashup over, closing overlay');
            $(".skip-btn, #introhtml").remove();
            $.history.load('/the-story/');
            showstage();
          
          
            $('.flash-container,.time-lapse-bg, .mashup-video').remove();
          
          
        });
        player.append(video);
    } else {
        player.xprMediaPlayer({height: '100%', width: '100%'});
        player.xprMediaPlayer('addAudioTrack', {mp3: '/media/pov48.mp3', ogg: '/media/pov48.ogg'});
        player.xprMediaPlayer('loadPlaylist', '/relay.php?ejaxKey=FS_QuestionFormAjax.decodePlaylist&format=json&hashcode=' + msg);
        player.bind('playlistLoaded', function() {
            xprLog('loading staff page');
          // alert('about to start loading staff page');
            player.xprMediaPlayer('startBuffering');
        });
        
        player.bind('playlistEnded', function() {
           xprLog('mashup over, closing overlay');
          $(".skip-btn,#introhtml").remove();
          $.history.load('/the-story/');
          xprLog('about to show the stage');
          showstage();
        
        $('.flash-container,.time-lapse,.time-lapse-bg, .mashup-video').remove();
        
        });
    }
    //});
              customvideodisplay();
}


function setVideoNav()
{
    $('.btn-play').click(function(e){
        e.preventDefault();
        if($(this).hasClass('active'))
        {
            $(this).removeClass('active');
            player.xprMediaPlayer('pause');
        }
        else
        {
            $(this).addClass('active');
            player.xprMediaPlayer('play');
        }
    });
    
    $('.btn-mute').click(function(e){
        e.preventDefault();
        if($(this).hasClass('active'))
        {
            $(this).removeClass('active');
            player.xprMediaPlayer('unmute');
        }
        else
        {
            $(this).addClass('active');
            player.xprMediaPlayer('mute');
        }
    });
}

/*----------------------------------------------
------------------------------------------------
16. SWIPE EVENT
------------------------------------------------
------------------------------------------------*/

(function($) {
  $.fn.swipe = function(options) {
    
    // Default settings & swipe functions
    var defaults = {
      setting: {
        x: 150,
        y: 60
      },
      swipeLeft: function() {},
      swipeRight: function() {},
      swipeUp: function() {},
      swipeDown: function() {}
    };
    
    // Options to modify functions
    var options = $.extend(defaults, options);
    
    if (!this) return false;
    
    return this.each(function() {
      
      var originalCoord = { x: 0, y: 0 }
      var finalCoord = { x: 0, y: 0 }
      
      // Screen touched, store the original coordinate
      function touchStart(event) {
        originalCoord.x = event.targetTouches[0].pageX
        originalCoord.y = event.targetTouches[0].pageY
      }
      
      // Store coordinates as finger is swiping
      function touchMove(event) {
        event.preventDefault();
        finalCoord.x = event.targetTouches[0].pageX // Updated X,Y coordinates
        finalCoord.y = event.targetTouches[0].pageY
      }
      
      // Calculate the swipe
      function touchEnd(event) {

        var changeY = originalCoord.y - finalCoord.y

          changeX = originalCoord.x - finalCoord.x
          
          if(changeX > defaults.setting.x) {
            defaults.swipeLeft()
          }
          if(changeX < (defaults.setting.x*-1)) {
            defaults.swipeRight()
          }
          if(changeY > defaults.setting.y) {
            defaults.swipeUp()
          }
          if(changeY < (defaults.setting.y*-1)) {
            defaults.swipeDown()
          }
      }
      
      // Swipe was started
      function touchStart(event) {
        originalCoord.x = event.targetTouches[0].pageX
        originalCoord.y = event.targetTouches[0].pageY

        finalCoord.x = originalCoord.x
        finalCoord.y = originalCoord.y
      }
      
      // Swipe was canceled
      function touchCancel(event) {
      }
      
      // Add gestures to all swipable areas
      this.addEventListener("touchstart", touchStart, false);
      this.addEventListener("touchmove", touchMove, false);
      this.addEventListener("touchend", touchEnd, false);
      this.addEventListener("touchcancel", touchCancel, false);
        
    });
    
  };
})(jQuery);

/*----------------------------------------------
------------------------------------------------
17. OPEN HOUSE POPUP
------------------------------------------------
------------------------------------------------*/
  var firsttime = 0;
  function openhouseinfo() {
    if(firsttime == 0) {
    $("a[title='Contact']").addClass("active relative").delay(2000).fadeOut(200).fadeIn(200).fadeOut(200).fadeIn(200).fadeOut(200).fadeIn(200).fadeOut(200).fadeIn(200).append('<img class="openhouse-popup1" src="http://www.nowthisisyourtime.com/media/templates/openhouse-popup1-noglow.png"/><img class="openhouse-popup2" src="http://www.nowthisisyourtime.com/media/templates/openhouse-popup2.png"/>');

     $(".openhouse-popup1").delay(3800).fadeIn().delay(4000).fadeOut();
     $(".openhouse-popup2").delay(8200).fadeIn(2000);
    firsttime = 1;
    }


  }


/* -----------------------------------------------------------
    AddThis
  -------------------------------------------------------------- */
  
var addthis_share = { templates: { twitter: '{{title}} {{url}} via @backbonetech' } };
var addthis_config = {"data_track_clickback":true};

$(function()
{
  /* -----------------------------------------------------------
    Website JS Framework
  -------------------------------------------------------------- */
  
  // background image replacement
  $('.bgimg, .bgimg0').each(function()
  {
    // replace
    var img = $('img',this).attr('src');
    if(img.search(/png|jpg|gif/) != -1)
    {
      if($(this).hasClass('bgimg')) $(this).css({background:'url("'+img+'") 50% 50% no-repeat'});
      if($(this).hasClass('bgimg0')) $(this).css({background:'url("'+img+'") 50% 0% no-repeat'});
    }
  });
  
  
  // animate-to
  $('a.animate-to').click(function(e)
  {
    e.preventDefault();
    
    var id = $(this).attr('href');
    var top = $(id).offset().top;
    
    if(!$('html:animated, body:animated').length)
      if($(window).scrollTop() > 10)
        $('html,body').animate({scrollTop: top},700,'easeInOutCirc');
  });
  
  
  // pretty date
  $('.pretty-date').prettyDate();
  
  
  // placeholder
  $(":input[placeholder]").placeholder();
  
  
  // custom style
  $('.custom-select select').customStyle();
  
  
  // bold title with {}
  bold_title('.bold-title:contains({)');
  function bold_title(target)
  {
    if($(target).length){
      $(target).each(function(){
        var text = $(this).html().replace(/{/g,'<strong>').replace(/}/g,'</strong>');
        $(this).html(text);
      });
    }
  }
  
  $('p:empty').remove();
  $('p').each(function()
  {
    if($(this).html() == "&nbsp;"){
      $(this).remove();
    }
  });
});


/*

  Supersized - Fullscreen Slideshow jQuery Plugin
  Version : 3.2.6
  Site  : www.buildinternet.com/project/supersized
  
  Author  : Sam Dunn
  Company : One Mighty Roar (www.onemightyroar.com)
  License : MIT License / GPL License
  
*/

(function(a){a(document).ready(function(){a("body .home").parents('body').append('<div id="supersized-loader"></div><ul id="supersized"></ul>')});a.supersized=function(b){var c="#supersized",d=this;d.$el=a(c);d.el=c;vars=a.supersized.vars;d.$el.data("supersized",d);api=d.$el.data("supersized");d.init=function(){a.supersized.vars=a.extend(a.supersized.vars,a.supersized.themeVars);a.supersized.vars.options=a.extend({},a.supersized.defaultOptions,a.supersized.themeOptions,b);d.options=a.supersized.vars.options;d._build()};d._build=function(){var g=0,e="",j="",h,f="",i;while(g<=d.options.slides.length-1){switch(d.options.slide_links){case"num":h=g;break;case"name":h=d.options.slides[g].title;break;case"blank":h="";break}e=e+'<li class="slide-'+g+'"></li>';if(g==d.options.start_slide-1){if(d.options.slide_links){j=j+'<li class="slide-link-'+g+' current-slide"><a>'+h+"</a></li>"}if(d.options.thumb_links){d.options.slides[g].thumb?i=d.options.slides[g].thumb:i=d.options.slides[g].image;f=f+'<li class="thumb'+g+' current-thumb"><img src="'+i+'"/></li>'}}else{if(d.options.slide_links){j=j+'<li class="slide-link-'+g+'" ><a>'+h+"</a></li>"}if(d.options.thumb_links){d.options.slides[g].thumb?i=d.options.slides[g].thumb:i=d.options.slides[g].image;f=f+'<li class="thumb'+g+'"><img src="'+i+'"/></li>'}}g++}if(d.options.slide_links){a(vars.slide_list).html(j)}if(d.options.thumb_links&&vars.thumb_tray.length){a(vars.thumb_tray).append('<ul id="'+vars.thumb_list.replace("#","")+'">'+f+"</ul>")}a(d.el).append(e);if(d.options.thumbnail_navigation){vars.current_slide-1<0?prevThumb=d.options.slides.length-1:prevThumb=vars.current_slide-1;a(vars.prev_thumb).show().html(a("<img/>").attr("src",d.options.slides[prevThumb].image));vars.current_slide==d.options.slides.length-1?nextThumb=0:nextThumb=vars.current_slide+1;a(vars.next_thumb).show().html(a("<img/>").attr("src",d.options.slides[nextThumb].image))}d._start()};d._start=function(){if(d.options.start_slide){vars.current_slide=d.options.start_slide-1}else{vars.current_slide=Math.floor(Math.random()*d.options.slides.length)}var o=d.options.new_window?' target="_blank"':"";if(d.options.performance==3){d.$el.addClass("speed")}else{if((d.options.performance==1)||(d.options.performance==2)){d.$el.addClass("quality")}}if(d.options.random){arr=d.options.slides;for(var h,m,k=arr.length;k;h=parseInt(Math.random()*k),m=arr[--k],arr[k]=arr[h],arr[h]=m){}d.options.slides=arr}if(d.options.slides.length>1){if(d.options.slides.length>2){vars.current_slide-1<0?loadPrev=d.options.slides.length-1:loadPrev=vars.current_slide-1;var g=(d.options.slides[loadPrev].url)?"href='"+d.options.slides[loadPrev].url+"'":"";var q=a('<img src="'+d.options.slides[loadPrev].image+'"/>');var n=d.el+" li:eq("+loadPrev+")";q.appendTo(n).wrap("<a "+g+o+"></a>").parent().parent().addClass("image-loading prevslide");q.load(function(){a(this).data("origWidth",a(this).width()).data("origHeight",a(this).height());d.resizeNow()})}}else{d.options.slideshow=0}g=(api.getField("url"))?"href='"+api.getField("url")+"'":"";var l=a('<img src="'+api.getField("image")+'"/>');var f=d.el+" li:eq("+vars.current_slide+")";l.appendTo(f).wrap("<a "+g+o+"></a>").parent().parent().addClass("image-loading activeslide");l.load(function(){d._origDim(a(this));d.resizeNow();d.launch();if(typeof theme!="undefined"&&typeof theme._init=="function"){theme._init()}});if(d.options.slides.length>1){vars.current_slide==d.options.slides.length-1?loadNext=0:loadNext=vars.current_slide+1;g=(d.options.slides[loadNext].url)?"href='"+d.options.slides[loadNext].url+"'":"";var e=a('<img src="'+d.options.slides[loadNext].image+'"/>');var p=d.el+" li:eq("+loadNext+")";e.appendTo(p).wrap("<a "+g+o+"></a>").parent().parent().addClass("image-loading");e.load(function(){a(this).data("origWidth",a(this).width()).data("origHeight",a(this).height());d.resizeNow()})}d.$el.css("visibility","hidden");a(".load-item").hide()};d.launch=function(){d.$el.css("visibility","visible");a("#supersized-loader").remove();if(typeof theme!="undefined"&&typeof theme.beforeAnimation=="function"){theme.beforeAnimation("next")}a(".load-item").show();if(d.options.keyboard_nav){a(document.documentElement).keyup(function(e){if(vars.in_animation){return false}if((e.keyCode==37)||(e.keyCode==40)){clearInterval(vars.slideshow_interval);d.prevSlide()}else{if((e.keyCode==39)||(e.keyCode==38)){clearInterval(vars.slideshow_interval);d.nextSlide()}else{if(e.keyCode==32&&!vars.hover_pause){clearInterval(vars.slideshow_interval);d.playToggle()}}}})}if(d.options.slideshow&&d.options.pause_hover){a(d.el).hover(function(){if(vars.in_animation){return false}vars.hover_pause=true;if(!vars.is_paused){vars.hover_pause="resume";d.playToggle()}},function(){if(vars.hover_pause=="resume"){d.playToggle();vars.hover_pause=false}})}if(d.options.slide_links){a(vars.slide_list+"> li").click(function(){index=a(vars.slide_list+"> li").index(this);targetSlide=index+1;d.goTo(targetSlide);return false})}if(d.options.thumb_links){a(vars.thumb_list+"> li").click(function(){index=a(vars.thumb_list+"> li").index(this);targetSlide=index+1;api.goTo(targetSlide);return false})}if(d.options.slideshow&&d.options.slides.length>1){if(d.options.autoplay&&d.options.slides.length>1){vars.slideshow_interval=setInterval(d.nextSlide,d.options.slide_interval)}else{vars.is_paused=true}a(".load-item img").bind("contextmenu mousedown",function(){return false})}a(window).resize(function(){d.resizeNow()})};d.resizeNow=function(){return d.$el.each(function(){a("img",d.el).each(function(){thisSlide=a(this);var f=(thisSlide.data("origHeight")/thisSlide.data("origWidth")).toFixed(2);var e=d.$el.width(),h=d.$el.height(),i;if(d.options.fit_always){if((h/e)>f){g()}else{j()}}else{if((h<=d.options.min_height)&&(e<=d.options.min_width)){if((h/e)>f){d.options.fit_landscape&&f<1?g(true):j(true)}else{d.options.fit_portrait&&f>=1?j(true):g(true)}}else{if(e<=d.options.min_width){if((h/e)>f){d.options.fit_landscape&&f<1?g(true):j()}else{d.options.fit_portrait&&f>=1?j():g(true)}}else{if(h<=d.options.min_height){if((h/e)>f){d.options.fit_landscape&&f<1?g():j(true)}else{d.options.fit_portrait&&f>=1?j(true):g()}}else{if((h/e)>f){d.options.fit_landscape&&f<1?g():j()}else{d.options.fit_portrait&&f>=1?j():g()}}}}}function g(k){if(k){if(thisSlide.width()<e||thisSlide.width()<d.options.min_width){if(thisSlide.width()*f>=d.options.min_height){thisSlide.width(d.options.min_width);thisSlide.height(thisSlide.width()*f)}else{j()}}}else{if(d.options.min_height>=h&&!d.options.fit_landscape){if(e*f>=d.options.min_height||(e*f>=d.options.min_height&&f<=1)){thisSlide.width(e);thisSlide.height(e*f)}else{if(f>1){thisSlide.height(d.options.min_height);thisSlide.width(thisSlide.height()/f)}else{if(thisSlide.width()<e){thisSlide.width(e);thisSlide.height(thisSlide.width()*f)}}}}else{thisSlide.width(e);thisSlide.height(e*f)}}}function j(k){if(k){if(thisSlide.height()<h){if(thisSlide.height()/f>=d.options.min_width){thisSlide.height(d.options.min_height);thisSlide.width(thisSlide.height()/f)}else{g(true)}}}else{if(d.options.min_width>=e){if(h/f>=d.options.min_width||f>1){thisSlide.height(h);thisSlide.width(h/f)}else{if(f<=1){thisSlide.width(d.options.min_width);thisSlide.height(thisSlide.width()*f)}}}else{thisSlide.height(h);thisSlide.width(h/f)}}}if(thisSlide.parents("li").hasClass("image-loading")){a(".image-loading").removeClass("image-loading")}if(d.options.horizontal_center){a(this).css("left",(e-a(this).width())/2)}if(d.options.vertical_center){a(this).css("top",(h-a(this).height())/2)}});if(d.options.image_protect){a("img",d.el).bind("contextmenu mousedown",function(){return false})}return false})};d.nextSlide=function(){if(vars.in_animation||!api.options.slideshow){return false}else{vars.in_animation=true}clearInterval(vars.slideshow_interval);var h=d.options.slides,e=d.$el.find(".activeslide");a(".prevslide").removeClass("prevslide");e.removeClass("activeslide").addClass("prevslide");vars.current_slide+1==d.options.slides.length?vars.current_slide=0:vars.current_slide++;var g=a(d.el+" li:eq("+vars.current_slide+")"),i=d.$el.find(".prevslide");if(d.options.performance==1){d.$el.removeClass("quality").addClass("speed")}loadSlide=false;vars.current_slide==d.options.slides.length-1?loadSlide=0:loadSlide=vars.current_slide+1;var k=d.el+" li:eq("+loadSlide+")";if(!a(k).html()){var j=d.options.new_window?' target="_blank"':"";imageLink=(d.options.slides[loadSlide].url)?"href='"+d.options.slides[loadSlide].url+"'":"";var f=a('<img src="'+d.options.slides[loadSlide].image+'"/>');f.appendTo(k).wrap("<a "+imageLink+j+"></a>").parent().parent().addClass("image-loading").css("visibility","hidden");f.load(function(){d._origDim(a(this));d.resizeNow()})}if(d.options.thumbnail_navigation==1){vars.current_slide-1<0?prevThumb=d.options.slides.length-1:prevThumb=vars.current_slide-1;a(vars.prev_thumb).html(a("<img/>").attr("src",d.options.slides[prevThumb].image));nextThumb=loadSlide;a(vars.next_thumb).html(a("<img/>").attr("src",d.options.slides[nextThumb].image))}if(typeof theme!="undefined"&&typeof theme.beforeAnimation=="function"){theme.beforeAnimation("next")}if(d.options.slide_links){a(".current-slide").removeClass("current-slide");a(vars.slide_list+"> li").eq(vars.current_slide).addClass("current-slide")}g.css("visibility","hidden").addClass("activeslide");switch(d.options.transition){case 0:case"none":g.css("visibility","visible");vars.in_animation=false;break;case 1:case"fade":g.animate({opacity:0},0).css("visibility","visible").animate({opacity:1,avoidTransforms:false},d.options.transition_speed,function(){d.afterAnimation()});break;case 2:case"slideTop":g.animate({top:-d.$el.height()},0).css("visibility","visible").animate({top:0,avoidTransforms:false},d.options.transition_speed,function(){d.afterAnimation()});break;case 3:case"slideRight":g.animate({left:d.$el.width()},0).css("visibility","visible").animate({left:0,avoidTransforms:false},d.options.transition_speed,function(){d.afterAnimation()});break;case 4:case"slideBottom":g.animate({top:d.$el.height()},0).css("visibility","visible").animate({top:0,avoidTransforms:false},d.options.transition_speed,function(){d.afterAnimation()});break;case 5:case"slideLeft":g.animate({left:-d.$el.width()},0).css("visibility","visible").animate({left:0,avoidTransforms:false},d.options.transition_speed,function(){d.afterAnimation()});break;case 6:case"carouselRight":g.animate({left:d.$el.width()},0).css("visibility","visible").animate({left:0,avoidTransforms:false},d.options.transition_speed,function(){d.afterAnimation()});e.animate({left:-d.$el.width(),avoidTransforms:false},d.options.transition_speed);break;case 7:case"carouselLeft":g.animate({left:-d.$el.width()},0).css("visibility","visible").animate({left:0,avoidTransforms:false},d.options.transition_speed,function(){d.afterAnimation()});e.animate({left:d.$el.width(),avoidTransforms:false},d.options.transition_speed);break}return false};d.prevSlide=function(){if(vars.in_animation||!api.options.slideshow){return false}else{vars.in_animation=true}clearInterval(vars.slideshow_interval);var h=d.options.slides,e=d.$el.find(".activeslide");a(".prevslide").removeClass("prevslide");e.removeClass("activeslide").addClass("prevslide");vars.current_slide==0?vars.current_slide=d.options.slides.length-1:vars.current_slide--;var g=a(d.el+" li:eq("+vars.current_slide+")"),i=d.$el.find(".prevslide");if(d.options.performance==1){d.$el.removeClass("quality").addClass("speed")}loadSlide=vars.current_slide;var k=d.el+" li:eq("+loadSlide+")";if(!a(k).html()){var j=d.options.new_window?' target="_blank"':"";imageLink=(d.options.slides[loadSlide].url)?"href='"+d.options.slides[loadSlide].url+"'":"";var f=a('<img src="'+d.options.slides[loadSlide].image+'"/>');f.appendTo(k).wrap("<a "+imageLink+j+"></a>").parent().parent().addClass("image-loading").css("visibility","hidden");f.load(function(){d._origDim(a(this));d.resizeNow()})}if(d.options.thumbnail_navigation==1){prevThumb=loadSlide;a(vars.prev_thumb).html(a("<img/>").attr("src",d.options.slides[prevThumb].image));vars.current_slide==d.options.slides.length-1?nextThumb=0:nextThumb=vars.current_slide+1;a(vars.next_thumb).html(a("<img/>").attr("src",d.options.slides[nextThumb].image))}if(typeof theme!="undefined"&&typeof theme.beforeAnimation=="function"){theme.beforeAnimation("prev")}if(d.options.slide_links){a(".current-slide").removeClass("current-slide");a(vars.slide_list+"> li").eq(vars.current_slide).addClass("current-slide")}g.css("visibility","hidden").addClass("activeslide");switch(d.options.transition){case 0:case"none":g.css("visibility","visible");vars.in_animation=false;d.afterAnimation();break;case 1:case"fade":g.animate({opacity:0},0).css("visibility","visible").animate({opacity:1,avoidTransforms:false},d.options.transition_speed,function(){d.afterAnimation()});break;case 2:case"slideTop":g.animate({top:d.$el.height()},0).css("visibility","visible").animate({top:0,avoidTransforms:false},d.options.transition_speed,function(){d.afterAnimation()});break;case 3:case"slideRight":g.animate({left:-d.$el.width()},0).css("visibility","visible").animate({left:0,avoidTransforms:false},d.options.transition_speed,function(){d.afterAnimation()});break;case 4:case"slideBottom":g.animate({top:-d.$el.height()},0).css("visibility","visible").animate({top:0,avoidTransforms:false},d.options.transition_speed,function(){d.afterAnimation()});break;case 5:case"slideLeft":g.animate({left:d.$el.width()},0).css("visibility","visible").animate({left:0,avoidTransforms:false},d.options.transition_speed,function(){d.afterAnimation()});break;case 6:case"carouselRight":g.animate({left:-d.$el.width()},0).css("visibility","visible").animate({left:0,avoidTransforms:false},d.options.transition_speed,function(){d.afterAnimation()});e.animate({left:0},0).animate({left:d.$el.width(),avoidTransforms:false},d.options.transition_speed);break;case 7:case"carouselLeft":g.animate({left:d.$el.width()},0).css("visibility","visible").animate({left:0,avoidTransforms:false},d.options.transition_speed,function(){d.afterAnimation()});e.animate({left:0},0).animate({left:-d.$el.width(),avoidTransforms:false},d.options.transition_speed);break}return false};d.playToggle=function(){if(vars.in_animation||!api.options.slideshow){return false}if(vars.is_paused){vars.is_paused=false;if(typeof theme!="undefined"&&typeof theme.playToggle=="function"){theme.playToggle("play")}vars.slideshow_interval=setInterval(d.nextSlide,d.options.slide_interval)}else{vars.is_paused=true;if(typeof theme!="undefined"&&typeof theme.playToggle=="function"){theme.playToggle("pause")}clearInterval(vars.slideshow_interval)}return false};d.goTo=function(f){if(vars.in_animation||!api.options.slideshow){return false}var e=d.options.slides.length;if(f<0){f=e}else{if(f>e){f=1}}f=e-f+1;clearInterval(vars.slideshow_interval);if(typeof theme!="undefined"&&typeof theme.goTo=="function"){theme.goTo()}if(vars.current_slide==e-f){if(!(vars.is_paused)){vars.slideshow_interval=setInterval(d.nextSlide,d.options.slide_interval)}return false}if(e-f>vars.current_slide){vars.current_slide=e-f-1;vars.update_images="next";d._placeSlide(vars.update_images)}else{if(e-f<vars.current_slide){vars.current_slide=e-f+1;vars.update_images="prev";d._placeSlide(vars.update_images)}}if(d.options.slide_links){a(vars.slide_list+"> .current-slide").removeClass("current-slide");a(vars.slide_list+"> li").eq((e-f)).addClass("current-slide")}if(d.options.thumb_links){a(vars.thumb_list+"> .current-thumb").removeClass("current-thumb");a(vars.thumb_list+"> li").eq((e-f)).addClass("current-thumb")}};d._placeSlide=function(e){var h=d.options.new_window?' target="_blank"':"";loadSlide=false;if(e=="next"){vars.current_slide==d.options.slides.length-1?loadSlide=0:loadSlide=vars.current_slide+1;var g=d.el+" li:eq("+loadSlide+")";if(!a(g).html()){var h=d.options.new_window?' target="_blank"':"";imageLink=(d.options.slides[loadSlide].url)?"href='"+d.options.slides[loadSlide].url+"'":"";var f=a('<img src="'+d.options.slides[loadSlide].image+'"/>');f.appendTo(g).wrap("<a "+imageLink+h+"></a>").parent().parent().addClass("image-loading").css("visibility","hidden");f.load(function(){d._origDim(a(this));d.resizeNow()})}d.nextSlide()}else{if(e=="prev"){vars.current_slide-1<0?loadSlide=d.options.slides.length-1:loadSlide=vars.current_slide-1;var g=d.el+" li:eq("+loadSlide+")";if(!a(g).html()){var h=d.options.new_window?' target="_blank"':"";imageLink=(d.options.slides[loadSlide].url)?"href='"+d.options.slides[loadSlide].url+"'":"";var f=a('<img src="'+d.options.slides[loadSlide].image+'"/>');f.appendTo(g).wrap("<a "+imageLink+h+"></a>").parent().parent().addClass("image-loading").css("visibility","hidden");f.load(function(){d._origDim(a(this));d.resizeNow()})}d.prevSlide()}}};d._origDim=function(e){e.data("origWidth",e.width()).data("origHeight",e.height())};d.afterAnimation=function(){if(d.options.performance==1){d.$el.removeClass("speed").addClass("quality")}if(vars.update_images){vars.current_slide-1<0?setPrev=d.options.slides.length-1:setPrev=vars.current_slide-1;vars.update_images=false;a(".prevslide").removeClass("prevslide");a(d.el+" li:eq("+setPrev+")").addClass("prevslide")}vars.in_animation=false;if(!vars.is_paused&&d.options.slideshow){vars.slideshow_interval=setInterval(d.nextSlide,d.options.slide_interval);if(d.options.stop_loop&&vars.current_slide==d.options.slides.length-1){d.playToggle()}}if(typeof theme!="undefined"&&typeof theme.afterAnimation=="function"){theme.afterAnimation()}return false};d.getField=function(e){return d.options.slides[vars.current_slide][e]};d.init()};a.supersized.vars={thumb_tray:"#thumb-tray",thumb_list:"#thumb-list",slide_list:"#slide-list",current_slide:0,in_animation:false,is_paused:false,hover_pause:false,slideshow_interval:false,update_images:false,options:{}};a.supersized.defaultOptions={slideshow:1,autoplay:1,start_slide:1,stop_loop:0,random:0,slide_interval:5000,transition:1,transition_speed:750,new_window:1,pause_hover:0,keyboard_nav:1,performance:1,image_protect:1,fit_always:0,fit_landscape:0,fit_portrait:1,min_width:0,min_height:0,horizontal_center:1,vertical_center:1,slide_links:1,thumb_links:1,thumbnail_navigation:0};a.fn.supersized=function(b){return this.each(function(){(new a.supersized(b))})}})(jQuery);


var openPopup = window.open;

function show_msg(msg) { alert(msg); }

function validateForm() {
	missing_required = 0;

	for (i = 0; i < arguments.length; i++) {
		if(arguments[i] == '') {
			missing_required = 1;
		}
	}

	if(missing_required) {
		alert("A required form field is missing.");
		return false;
	} else {
		return true;
	}
}

function expCustomLink(myURL) {
	location.href = myURL;
}

function setUrl(path) {
	document.location.href = path;
}

function expArticleLink(sectionId, articleId) {
	location.href = '/index.php?section_id=' + sectionId + '&section_copy_id=' + articleId;
}

function expPopupWindow(url, widthVal, heightVal, resizableVal, scrollbarsVal, toolbarVal, locationVal, directoriesVal, statusVal, menubarVal, copyHistoryVal) {

	var attributes = "width="  	 	 + widthVal       +
				 	 ",height=" 	 + heightVal      +
				 	 ",resizable="  + resizableVal  +
				 	 ",scrollbars="  + scrollbarsVal  +
				 	 ",toolbar=" 	 + toolbarVal 	  +
				 	 ",location=" 	 + locationVal 	  +
				 	 ",directories=" + directoriesVal +
				 	 ",status=" 	 + statusVal 	  +
				 	 ",menubar=" 	 + menubarVal 	  +
				 	 ",copyhistory=" + copyHistoryVal;

	window.open(url, 'WindowName', attributes);
}

function xprLog(msg) {
    if (window.console) console.log(msg);
}

if (document.addEventListener) {  
    document.addEventListener("DOMContentLoaded", function () { if (typeof onXprPageLoad == 'function') onXprPageLoad(); }, false);
} else if (document.attachEvent) {  
    document.attachEvent('DOMContentLoaded', function () { if (typeof onXprPageLoad == 'function') onXprPageLoad(); });
}  

