
/*****  Show travel popups   *******/
function showHide(obj) {
  obj = document.getElementById(obj);
  obj.style.display = (obj.style.display == 'block') ? 'none' : 'block';
}

//function to display or hide a given element
function showPlusMinus(myItem, myButton) {

//this is the ID of the hidden item
var myItem = document.getElementById(myItem);

//this is the ID of the plus/minus button image
var myButton = document.getElementById(myButton);

    if (myItem.style.display != "none") {
        //items are currently displayed, so hide them
        myItem.style.display = "none";
        swapImage(myButton,"plus");
    }
    else {
        //items are currently hidden, so display them
        myItem.style.display = "block";
        swapImage(myButton,"minus");
    }
}

//function to swap an image based on its current state
function swapImage(myImage, state) {

    if (state == "minus") {
        myImage.src = "http://family.go.com/images/travel/bg_minus.png";
    }
  
    else {
        myImage.src = "http://family.go.com/images/travel/bg_plus.png";
  }
}

//functions to toggle the 'remove selection' button in the poi filters
function showRemoveButton(buttonId, listingId) {
document.getElementById(buttonId).style.display='block';
document.getElementById(listingId).className='rollover';
}

function hideRemoveButton(buttonId, listingId) {
document.getElementById(buttonId).style.display='none';
document.getElementById(listingId).className='rollout';
}


var __omAutoHideTime  = 500;
var __omTimers      = new Array();

function __om(id) {
  var elem = document.getElementById(id);
  if (!elem) {
    throw "Invalid overlay menu id";
  }
  if (!elem.onmouseout) {
    elem.onmouseout = function() {
      queueHideOverlayMenu(id);
    }
    elem.onmousein = function() {
      unQueueHideOverlayMenu(id);
    }
    elem.onmousemove = function() {
      unQueueHideOverlayMenu(id);
    }
  }
  return elem;
}

function toggleOverlayMenu(id) {
  if (__om(id).style.display=="block") {
    unQueueHideOverlayMenu(id);
    hideOverlayMenu(id);
  } else {
    queueHideOverlayMenu(id);
    showOverlayMenu(id);
    var iframe = document.createElement('iframe');
    iframe.src = 'javascript:void(0);';
    iframe.style.position = 'absolute';
    iframe.style.top = '30px';
    iframe.style.left = '10px';
    //iframe.style.visibility = 'hidden';
    iframe.style.zIndex = '-1';
    iframe.style.width = '100%';
    iframe.style.height = '90%';
    iframe.style.border = 'none';
    iframe.style.background = 'none';
    //document.getElementById(id).appendChild(iframe);
  }
}

function toggleOverlayMenuItin(id) {
  if (__om(id).style.display=="block") {
    unQueueHideOverlayMenu(id);
    hideOverlayMenu(id);
  } else {
    queueHideOverlayMenu(id);
    showOverlayMenu(id);
    var iframe = document.createElement('iframe');
    iframe.src = 'javascript:void(0);';
    iframe.style.position = 'absolute';
    iframe.style.top = '30px';
    iframe.style.left = '10px';
    //iframe.style.visibility = 'hidden';
    iframe.style.zIndex = '-1';
    iframe.style.width = '100%';
    iframe.style.height = '90%';
    iframe.style.border = 'none';
    iframe.style.background = 'none';
    //document.getElementById(id).appendChild(iframe);
  }
}

function hideOverlayMenu(id) {
  unQueueHideOverlayMenu(id);
  __om(id).style.display = "none";
}

function showOverlayMenu(id) {
  unQueueHideOverlayMenu(id);
  //__om(id).style.height = "500px";
  //__om(id).style.width = "340px";
  __om(id).style.display = "block";

}

function queueHideOverlayMenu(id) {
  unQueueHideOverlayMenu(id);
  __omTimers[id] = setInterval(function() { hideOverlayMenu(id); }, __omAutoHideTime);
}

function unQueueHideOverlayMenu(id) {
  if (__omTimers[id]) {
    clearInterval(__omTimers[id]);
    __omTimers[id] = null;
  }
}
var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the FSCommand messages in a Flash movie.
function POI_DoFSCommand(command, args) {
   var POIObj = isInternetExplorer ? document.all.POI : document.POI;
   //
   // Place your code here.
   //
}
// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 &&
navigator.userAgent.indexOf("Windows") != -1 &&
navigator.userAgent.indexOf("Windows 3.1") == -1) {
   document.write('<script language=\"VBScript\"\>\n');
   document.write('On Error Resume Next\n');
   document.write('Sub POI_FSCommand(ByVal command, ByVal args)\n');
   document.write('    Call POI_DoFSCommand(command, args)\n');
   document.write('End Sub\n');
   document.write('</script\>\n');
}
function vid_getSpeed()
{
 // speed value: higher numbers make for slower more accurate tweens. lower numbers make for
 // faster less accurate tweens. 
 return 20;
}

function decideCarouselHeight()
{
  var carouselArray = vid_getData();
  if (carouselArray.length < 2){
    var addHeight = 0;
    /*
    var carouselWrapper = document.getElementById('poi_video_wrapper');
    var rating = YAHOO.util.Dom.getElementsByClassName('good_for_kids_t1', 'div', 'poi_video_wrapper')[0];
    var thisYPos = YAHOO.util.Dom.getY(carouselWrapper);
    var ratingYPos = YAHOO.util.Dom.getY(rating);
    //alert(ratingYPos);
    //alert(thisYPos);
    var yPosDifference = ratingYPos - thisYPos;
    if (yPosDifference <= 130){
      //alert('right column is small' + yPosDifference);
      //right col is so small we can collapse the container directly to the carousel
      var addHeight = 0;
    } else if (yPosDifference <= 223) {
      //alert('right column sticks out' + yPosDifference);
      //right col is large enough that we can't collapse all the way
      var addHeight = yPosDifference - 130;
    } else {
      //alert('right column is larger than the full carousel' + yPosDifference);
      //right col is so big, we don't want to do anything
      return;
    }
    */
    var carouselContainer = document.getElementById('poi_video');
    //var whiteBackground = document.getElementById('whiteFlashBg');
    var outsideHeight = 257 - 0 + addHeight;
    //var insideHeight = 220 - 0 + addHeight;
    carouselContainer.style.height = outsideHeight + 'px';
    //carouselWrapper.style.height = outsideHeight + 'px';
    //whiteBackground.style.height = insideHeight + 'px';
    //alert(YAHOO.util.Dom.getStyle(carouselWrapper, 'height'));
  }
}

function showItinMap(sourceElementId, size, printable) {
  if (sourceElementId == null) sourceElementId = 'mapPoiList1';
  if (size == null) size = 'large';
  if (printable == null) printable = false;
  /*
  alert(sourceElementId);
  alert(size);
  alert(printable);
  */
  //don't do any of this until we have some data to put on the map
  YAHOO.util.Event.onContentReady(sourceElementId, function(){
    setTimeout(function(){
      //on rare occassion, the 'best of' list is empty, so we hop to Day 1
      var numberOfPois = document.getElementById(sourceElementId).getElementsByTagName('li').length;
      if (numberOfPois < 1){
        //mapPoiList2 is the Day 1 list
        document.getElementById(sourceElementId + 'Trigger').style.display = 'none';
        sourceElementId = 'mapPoiList2';
      }
      
      function setLightboxBackground() {
        darkness.style.width = YAHOO.util.Dom.getDocumentWidth() + 'px';
        darkness.style.height = YAHOO.util.Dom.getDocumentHeight() + 'px';
      }
      
      if(!printable){
        var currentScroll = YAHOO.util.Dom.getDocumentScrollTop();
        var colAScroll = YAHOO.util.Dom.getY('col_a');
        var scrollBy = colAScroll - currentScroll;
        mapCloseUnScroll = 0 - scrollBy;
        window.scrollBy(0, colAScroll - currentScroll);
        darkness = document.createElement('img');
        darkness.src = "http://family.go.com/images/lightbox_bg.png";
        darkness.className = 'transparency';
        darkness.id = 'lightboxDarkBg';
        darkness.style.position = 'absolute';
        darkness.style.zIndex = 3;
        darkness.style.top = '0px';
        darkness.style.left = '0px';
        darkness.style.width = YAHOO.util.Dom.getDocumentWidth() + 'px';
        darkness.style.height = YAHOO.util.Dom.getDocumentHeight() + 'px';
        YAHOO.util.Event.addListener(window, 'resize', function() {
          setLightboxBackground();
          positionMap();
          }, this, true);
        document.body.appendChild(darkness);
      }

      background = document.getElementById('mapFrame');
      
      switch(size){
        case 'small':
          YAHOO.util.Dom.addClass(background, 'mapSmall');
          var backgroundHeight = 490;
          var backgroundWidth = 860;
          break;
        case 'large':
          YAHOO.util.Dom.addClass(background, 'mapLarge');
          var backgroundHeight = 700;
          var backgroundWidth = 1021;
          break;
      }
      
      function positionMap() {
        var viewportHeight = YAHOO.util.Dom.getViewportHeight();
        var viewportWidth = YAHOO.util.Dom.getViewportWidth();
        var scrollTop = YAHOO.util.Dom.getDocumentScrollTop();
        var topCorrection = scrollTop;
        var leftCorrection = ((viewportWidth - backgroundWidth) / 2);
        topCorrecetion = (topCorrection < 0) ? 0 : topCorrection;
        leftCorrecetion = (leftCorrection < 0) ? 0 : leftCorrection;
        background.style.position = 'absolute';
        background.style.zIndex = 4;
        background.style.top = topCorrection + 'px';
        background.style.left = leftCorrection + 'px';
      }
      
      if(!printable){
        positionMap();
      }
      background.style.display = 'block';
      document.body.appendChild(background);

      var map = document.getElementById('gmapOverlayContainer');
      map.style.position = 'absolute';
      map.style.zIndex = 3;
      if(printable){
        map.style.top = '278px';
        map.style.left = '371px';
      } else {
        map.style.top = '98px';
        map.style.left = '341px';
      }
      map.style.display = 'block';
      background.appendChild(map);
      makePoiListTabActive(sourceElementId + 'Trigger');
      showPoiList(sourceElementId.replace(/.*(\d)/, "$1"));
      //alert(sourceElementId.replace(/.*(\d)/, "$1"));
      if(printable){
        loadMap(sourceElementId, 'map', 1, size, true, true);
      } else {
        loadMap(sourceElementId, 'map', 1, size, true, false);
      }
    }, 1000);
  });
}


//scroll select menu down on travel deals 
function scrollListDown(upArrow, downArrow,listId,interval,lessHeight) {
  getList = document.getElementById(listId);
  var yPos = parseFloat(getList.style.top);
  var theHeight = getList.offsetHeight;
  var stopScroll = -(theHeight - lessHeight); 
  if (yPos <= stopScroll){
    document.getElementById(downArrow).className = 'select_scroll_down_off';
    clearInterval(getList.movement);
  } else if (yPos >= stopScroll){
    document.getElementById(upArrow).className = 'select_scroll_up_on';
    yPos = yPos - 4;  
  }
  getList.style.top = yPos + "px";
  var repeat = "scrollListDown('"+upArrow+"','"+downArrow+"','"+listId+"',"+interval+","+lessHeight+")";
  getList.movement = setTimeout(repeat,interval);
}

//scroll select menu up
function scrollListUp(upArrow, downArrow, listId, interval) {
  getList = document.getElementById(listId);
  var yPos = parseFloat(getList.style.top);
  var theHeight = getList.offsetHeight;
  var stopScroll = 0;
  if (yPos >= stopScroll){
    document.getElementById(upArrow).className = 'select_scroll_up_off';
    clearTimeout(getList.movement);
  } else if (yPos <= stopScroll){
    yPos = yPos + 4;
    document.getElementById(downArrow).className = 'select_scroll_down_on';   
  }
  getList.style.top = yPos + "px";
  var repeat = "scrollListUp('"+upArrow+"','"+downArrow+"','"+listId+"',"+interval+")";
  getList.movement = setTimeout(repeat,interval);
}

//stop scrolling
function stopScroll() { 
  clearTimeout(getList.movement);
}



//keeps selected item highlighted
function keepListItemSelected() {
  var scrollItem = document.getElementsByTagName("li");
  for (var i=0; i<scrollItem.length; i++) {
    var liClass = scrollItem[i].getAttribute("class");
    if ((scrollItem[i].parentNode.id == "select_dd_menu_content_scroll_1") || (scrollItem[i].parentNode.id == "select_dd_menu_content_scroll_2") || (scrollItem[i].parentNode.parentNode.id == "locationDropdown")) {
      scrollItem[i].firstChild.onclick = function() {
      var selectedItem = this.parentNode.parentNode.getElementsByTagName("a");
      for (var i=0; i<selectedItem.length; i++) {
        YAHOO.util.Dom.removeClass(selectedItem[i], "selected_location");
        }
      YAHOO.util.Dom.addClass(this, "selected_location");
      }
    }
  }
}

//makes "other" field appear and disapppear
function showHideOtherField() {
  var listItems = document.getElementById('locationDropdown').getElementsByTagName('a');
  for (var i=0; i<listItems.length; i++) {
    var stayClassy = listItems[i].getAttribute("id");
    if (stayClassy == "other") {
      listItems[i].onclick = function() {
      document.getElementById("otherLocation").style.display = "block";
      }
    } else {listItems[i].onclick = function() {
      document.getElementById("otherLocation").style.display = "none";
      }
    }
  }
}


//BEGIN functions for submitting votes
    function alertFamily(header, message, top, left){
      var sorryMsg = document.getElementById("sorryMsgVote");
      var sorryMsgHeader = document.getElementById("sorryMsgVoteHeader");
      var sorryMsgText = document.getElementById("sorryMsgVoteText");
      sorryMsg.style.top = top + "px";
      sorryMsg.style.left = left + "px";
      sorryMsg.style.display = "block";
      sorryMsgHeader.innerHTML = header;
      sorryMsgText.innerHTML = message;
    }
    
  function evaluateJSON(passBack){
    return eval('(' + passBack.responseText.replace(/^\s*/, "").replace(/\s*$/, "") + ')');
  }

  function vote(element){
    //captures the position of the clicked button
    var xy = YAHOO.util.Dom.getXY(element);
    xLoc = xy[0] - 10;
    yLoc = xy[1] - 40;
    //var ajVote = new Ajax.Request('/contest/vote.do',{method:'get', parameters:'contestEntryId=${entry.contestEntryId}&date='+encodeURIComponent((new Date()).getTime()), onComplete: refreshVote});
  }
  
  function refreshVote(passBack){
    var r = evaluateJSON(passBack);
    if( r.voteCount != null ){
    alertFamily( "Thank You", "Your vote has been submitted.", yLoc, xLoc );
    }
    else if( r.error != null ){
      alertFamily( "We're Sorry", r.error, yLoc, xLoc );
    }
  }

//END functions for submitting votes


function checkForEmptyTravelSponsorLogo() {
  if( digAdData[ 'SponsorLogo' ] != undefined && digAdData[ 'SponsorLogo' ][ 'creative' ][ 'text' ] != "<!-- Blank -->" )
  { 
    document.getElementById( 'page_main_title' ).style.width = '617px'; 
    document.getElementById( 'sponsor_logo_container' ).style.display = 'block';
  }
}

