

/* don't indiscriminately change heights here or in the css,
   the sidebar and inner component heights are precisely specified to work together. */

var MODE1_TPK_HEIGHT_REGULAR = '441px';
var MODE1_TPK_HEIGHT_MAX = '586px';


$(document).ready(function() {

    
  trusted_hide_all();

  filter_hide_all();

  icontent_hide_all(); 

  $('#INITIAL-SHOW').css('display', 'block');




  $('#explore-expand').click(function() {
    

    if (explore_is_shown()) {

      resetter();
      icontent_hide_all();
      explore_hide();
      explore_set_tpk_size_max();
      explore_expand_tpk();
      explore_set_expand_image_plus();

    } else {

      resetter();
      icontent_hide_all();
      explore_show();
      explore_set_tpk_size_reg();
      explore_expand_tpk();
      explore_set_expand_image_minus();

    }

    return false;
  });



  // THIS LOOKS LIKE DEAD CODE NOW!!!!  see:   attach_trusted_clicks()
  $('.exp-trusted-show').click(function() {
    
    if (trusted_is_shown($(this))) {
      hide_trusted_and_set_not_active($(this));
    } else {
      show_trusted_and_set_active($(this));
    }

    return false;
  });




  $('.exp-filter-show').click(function() {
    
    filter_disable_command_show($(this));
    filter_enable_command_hide($(this));

    filter_show($(this));

    return false;
  });

  $('.exp-filter-hide').click(function() {
    
    filter_disable_command_hide($(this));
    filter_enable_command_show($(this));

    filter_hide($(this));

    return false;
  });





  $('.color-log').click(function() {
    
    bar_clicked(this);

    //return false;
  });



  $('.single-special-view-all-link').click(function() {
    
    var x = $(this).parents('.exp-content').prev('.color-log');

    bar_clicked(x);

    return false;
  });






  // what mode to run in, from the query string
  //
/*
  if (location.search === '?map_with_tpk') {
    // do nothing, this is the default view
  }

  if (location.search === '?map_with_empty_tpk') {
    mode__map_with_empty_tpk();
  }

  if (location.search === '?map_page_non_tpk') {
    mode__map_page_non_tpk();
  }

  if (location.search === '?guide_page') {
    mode__guide_page();
  }
*/



});












function explore_is_shown() {
  return $('#explore-contents').css('display') === 'block';
}

function explore_hide() {
  $('#explore-contents').css('display', 'none');
}

function explore_show() {
  $('#explore-contents').css('display', 'block');
}

function explore_unexpand_tpk() {
  $('#tpk-items').next('.exp-content').css('display', 'none');
}

function explore_expand_tpk() {
  $('#tpk-items').next('.exp-content').css('display', 'block');
}

function explore_set_tpk_size_max() {
  $('#tpk-items').next('.exp-content').css('height', MODE1_TPK_HEIGHT_MAX);
}

function explore_set_tpk_size_reg() {
  $('#tpk-items').next('.exp-content').css('height', MODE1_TPK_HEIGHT_REGULAR);
}

function explore_set_expand_image_plus() {
  $('#explore-expand').removeClass('expand-minus');
  $('#explore-expand').addClass('expand-plus');
}

function explore_set_expand_image_minus() {
  $('#explore-expand').removeClass('expand-plus');
  $('#explore-expand').addClass('expand-minus');
}








function trusted_hide_all() {
  $('.exp-trusted-the-content').css('display', 'none');
}

function trusted_is_shown(x) {
  return(
    x.parent('.exp-element-trusted')
      .hasClass('trusted-is-active')
  );
}

function show_trusted_and_set_active(x) {
  x.parent('.exp-element-trusted')
    .addClass('trusted-is-active');

  x.parent('.exp-element-trusted').children('.exp-trusted-handle').removeClass('exp-trusted-handle-plus');
  x.parent('.exp-element-trusted').children('.exp-trusted-handle').addClass('exp-trusted-handle-minus');

  x.parent('.exp-element-trusted')
    .nextAll('.exp-trusted-the-content')
    .css('display', 'block');
}

function hide_trusted_and_set_not_active(x) {
  x.parent('.exp-element-trusted')
    .removeClass('trusted-is-active');

  x.parent('.exp-element-trusted').children('.exp-trusted-handle').removeClass('exp-trusted-handle-minus');
  x.parent('.exp-element-trusted').children('.exp-trusted-handle').addClass('exp-trusted-handle-plus');

  x.parent('.exp-element-trusted')
    .nextAll('.exp-trusted-the-content')
    .css('display', 'none');
}










function filter_hide_all() {
  $('.exp-filter-content').css('display', 'none');
}

function filter_get_element(x) {
  return(
    x.parent('.exp-filter')
    .nextAll('.exp-filter-content-wrap')
    .find('.exp-filter-content')
  );
}

function filter_show(x) {
  filter_get_element(x).css('display', 'block');
}
function filter_hide(x) {
  filter_get_element(x).css('display', 'none');
}


function filter_enable_command_show(x) {
  x.parent().children('.exp-filter-show').css('display', 'block');
}
function filter_disable_command_show(x) {
  x.parent().children('.exp-filter-show').css('display', 'none');
}
function filter_enable_command_hide(x) {
  x.parent().children('.exp-filter-hide').css('display', 'block');
}
function filter_disable_command_hide(x) {
  x.parent().children('.exp-filter-hide').css('display', 'none');
}






function resetter() {

  if (siva_is_at_smallsize()) {
    //alert('resetting siva');
    siva_set_size_normal();
    icontent_hide_all();
  }

  if (mpxn_is_at_smallsize()) {
    //alert('resetting mpxn');
    mpxn_set_size_large();
    icontent_hide_all();
  }

}


function bar_clicked(x) {
  
  resetter();
    
  if (icontent_is_already_showing($(x))) return;
  
  icontent_hide_all();
   
  icontent_show_single($(x));
  

}








function icontent_hide_all() {
  $('.exp-content').css('display', 'none');
}

function icontent_show_single(x) {
  x.next('.exp-content').css('display', 'block');
}

function icontent_is_already_showing(x) {
  return (x.next('.exp-content').css('display') === 'block');
}











var MPXN_SMALLSIZE_HEIGHT_REGULAR = '95px';
var MPXN_SMALLSIZE_HEIGHT_PHOTO = '120px';
var MPXN_LARGESIZE_HEIGHT = '506px';


function mode__guide_page() {

  mode__map_page_non_tpk();
   //mpxn_set_a_click_on_photos();
  mpxn_hide_checkboxes();

}

/**
 * Special mode for the external tpk widget (side of blog, or webpage, etc).
 */
function mode__tpkwidget_page() {

//  mode__map_page_non_tpk();
   //mpxn_set_a_click_on_photos();
  mpxn_hide_checkboxes();
  mpxn_hide_trusted();

}


function mode__map_page_non_tpk() {

  mpxn_hide_top();
  
  mpxn_set_size_smallsize();

  deidei_swap_innards_to_special();

  mpxn_show_all_recs_content();
  
  mpxn_hide_trusted();

}

function mode__map_page_non_tpk_no_special_and_start_on_photos() {
  mode__map_page_non_tpk();
  mpxn_set_a_click_on_photos();
  //check the box
  $('#exp-photos .exp-check').attr('checked','true');
}

function mpxn_set_a_click_on_photos() {
  bar_clicked($('#exp-photos'));
}

function mpxn_hide_top() {
  $('#tpk-items').css('display', 'none');
  $('#explore-recs-wrap').css('display', 'none');
}

function mpxn_show_all_recs_content() {
  // show all content
  $('.exp-content').css('display', 'block');
  // except for tpk content (shouldn't even be generated in the html in this mode)
  explore_unexpand_tpk();
}

function mpxn_hide_trusted() {
  $('.exp-element-trusted').css('display', 'none');
}

function mpxn_is_at_smallsize() {
  return ($('#exp-photos').next('.exp-content').css('height') === MPXN_SMALLSIZE_HEIGHT_PHOTO);
}

function mpxn_set_size_smallsize() {
  $('.exp-content').css('height', MPXN_SMALLSIZE_HEIGHT_REGULAR);
  $('#exp-photos').next('.exp-content').css('height', MPXN_SMALLSIZE_HEIGHT_PHOTO);
}

function mpxn_set_size_large() {
  $('.exp-content').css('height', MPXN_LARGESIZE_HEIGHT);
  deidei_swap_innards_to_all();
}

function mpxn_hide_checkboxes() {
   
  $('.exp-check').css('display', 'none');
}







function deidei_swap_innards_to_special() {
  $('.all-innards').css('display', 'none');
  $('.single-special-innard').css('display', 'block');
}

function deidei_swap_innards_to_all() {
  $('.all-innards').css('display', 'block');
  $('.single-special-innard').css('display', 'none');
}









var SIVA_SMALLSIZE_HEIGHT_TPK = '128px';
var SIVA_SMALLSIZE_HEIGHT_PHOTO = '120px';
var SIVA_SMALLSIZE_HEIGHT_ATT_ACC = '95px';


function mode__map_with_empty_tpk() {

  deidei_swap_innards_to_special();

  siva_set_size_smallsize();

}



function siva_is_at_smallsize() {
  return ($('#tpk-items').next('.exp-content').css('height') === SIVA_SMALLSIZE_HEIGHT_TPK);
}

function siva_set_size_smallsize() {

  $('.exp-content').css('display', 'none');

  $('#tpk-items').next('.exp-content').css('height', SIVA_SMALLSIZE_HEIGHT_TPK);
  $('#tpk-items').next('.exp-content').css('display', 'block');

  $('#exp-photos').next('.exp-content').css('height', SIVA_SMALLSIZE_HEIGHT_PHOTO);
  $('#exp-photos').next('.exp-content').css('display', 'block');
 
  $('#exp-attractions').next('.exp-content').css('height', SIVA_SMALLSIZE_HEIGHT_ATT_ACC);
  $('#exp-attractions').next('.exp-content').css('display', 'block');

  $('#exp-accomodations').next('.exp-content').css('height', SIVA_SMALLSIZE_HEIGHT_ATT_ACC);
  $('#exp-accomodations').next('.exp-content').css('display', 'block');

}

function siva_set_size_normal() {
  $('.exp-content').css('height', MODE1_TPK_HEIGHT_REGULAR);
  deidei_swap_innards_to_all();
}


function attach_trusted_clicks(){

  trusted_hide_all();

  $('.exp-trusted-show').click(function() {
    trusted_clicked(this);
    return false;
  });

  $('.exp-trusted-handle').click(function() {
    trusted_clicked(this);
    return false;
  });

}


function trusted_clicked(x) {

  if (trusted_is_shown($(x))) {
    hide_trusted_and_set_not_active($(x));
  } else {
    show_trusted_and_set_active($(x));
  }

  return;
}



