var flashdata = {};


/**
 * Coverflow function
 */
function triggerApplicationReady(name) {
  $('#' + name)[0].setData(flashdata[name + '_data']);
}


/**
 * Split textpic to coverflow content
 */
function splitTextpicDataToCoverflowData(_images, _titles){
  var images = images.split(',');
  var titles = titles.split('\n');
  var data = [];
  for (var i = 0; i < images.length; i++) {
    data.push({
      'image': images[i],
      'text' : (titles[i] ? titles[i] : '')
    });
  }
  return data;
}


/**
 * Set select value to span in forms
 */
function vFillSelectSpan (poSelect) {
  var sName  = 'show-text-' + poSelect.id;
  var iIndex = poSelect.selectedIndex;
  var sValue = poSelect.options[iIndex].text;
  document.getElementById(sName).innerHTML = sValue;
}


/**
 * Share a page on facebook
 */
function fbShare() {
  var url = window.location.href;
  win = window.open(
    'http://www.facebook.com/sharer.php?u=' + encodeURIComponent(window.location.href) + '',
    'fbsharer',
    'width=1000,height=650,resizable=yes,scrollbars=yes'
  );
  win.focus();
}

/*
 * Safe default values of search field to ensure they're not submitted later
 */
var searchFieldDefaultValue;
var toFieldDefaultValue;
$(document).ready(function() {
  searchFieldDefaultValue = $('#searchinput').val();
  toFieldDefaultValue = $('#tripfinder .search-form-to .search-input').val();
});

/**
 * Check if there is input in the searchbox; if there's any pass it to extended search
 */
function goToExtendedSearch(oLink, oSearchBox) {
  if(oLink != null && oSearchBox != null) {
    var sUrl = oLink.href;
    var sSearchInput = oSearchBox.val();
    if(sSearchInput != '' && sSearchInput != searchFieldDefaultValue && sSearchInput != toFieldDefaultValue) {
      sUrl += '?to=' + sSearchInput;
    }
    window.location.href = sUrl;
    return false;
  }
  return true;
}


/**
 * Add new css class to the list element next to the active tab
 */
jQuery(document).ready(function ($) {
  $('ul.list-tabs li.current').next().addClass('no-background');
});

