

function CreateTabber($container, $header)
{
  var $_headers = $container.find('.tab');
  var $_contents = $container.find('.tab-content');
  var _activeHeader = $header.find('.active')[0];
  var _activeContent = $container.find('.tab-content.active')[0];
  $(_activeContent).show();

  $_headers.each(function(i, elem)
  {
    $(elem).click(function()
    {
      var header = $_headers[i];
      var content = $_contents[i];
      showTab(header, content, _activeHeader, _activeContent);
      _activeHeader = header;
      _activeContent = content;
    });
  });
}

function showTab(header, content, oldHeader, oldContent)
{
  if (oldHeader)
    $(oldHeader).removeClass('active');
  if (oldContent)
    $(oldContent).hide().removeClass('active');
  
  $(content).show().addClass('active');
  $(header).addClass('active');
  return false;
}

// not tested if there are multiple tabbers on same page
function showRequiredTab() {
  var hash = document.location.hash.replace('#', '').trim();
  var tabName = null;
  if(document.location.hash.length >= 1) {
    $('.tab').each(function(key, elem) {
      tabName = $(elem).find('span').attr('tab_href').trim().toLowerCase(); // do we still need attribute tab_href in span?
      if (tabName == hash) {
        showTab(key, elem);
      }
    });
  }
}



function redirectHash() {
  var href = document.location.href;
  var hash = document.location.hash.replace('#', '');
  var query = href.replace(/^[^?]*\??/, '');
  query = query.replace('#'+hash, '');
  if(query)
    query = '?' + query;
var temp = '';
  if(document.location.hash.length >= 1) {
    // Begin check if it is events.php page
    if(href.indexOf('events') != -1 || href.indexOf('evenimente') != -1) {
      if(href.indexOf('cautare') != -1) {
        href = href.replace(/evenimente\/([^\/]*\/)?cautare\?/, 'evenimente/'+hash + '/cautare?');
      }
      else if(href.indexOf('search') != -1) {
        href = href.replace(/events\/([^\/]*\/)?search\?/, 'events/'+hash + '/search?');
      }
      else {
        if(href.indexOf('events') != -1) {
          href = href.replace(/events.*$/, 'events/'+hash + query);
        }
        else if(href.indexOf('evenimente') != -1) {
          href = href.replace(/evenimente.*$/, 'evenimente/'+hash + query);
        }
      }
    }
    // Beging check if it is place(s).php page

    else if(href.indexOf('places') != -1) {
      temp = href.match(/places\/([^\/]*\/)([\w|-]*)/)[0];
      href = href.replace(/places\/([^\/]*\/)([\w|-]*).*$/, temp + '/' + hash);
    }
    else if(href.indexOf('locuri') != -1) {
      temp = href.match(/locuri\/([^\/]*\/)([\w|-]*)/)[0];
      href = href.replace(/locuri\/([^\/]*\/)([\w|-]*).*$/, temp + '/' + hash);
    }

    
    // if there is a match, change href
    if(href != document.location.href) {
      href = href.replace('#'+hash, '');
      document.location.href = href;
    }

  }
}

//redirectHash();