function updateTitle() {
  if (document.getElementById('pageTitle').innerHTML) {
    document.title = document.getElementById('pageTitle').innerHTML;
  }
}

function updateKw() {
  tags = document.getElementsByTagName("meta");
  if (document.getElementById('kw').innerHTML) {
    tags[5].setAttribute('content', "bulged, website, digital, print, cards, catalog, дигитален, печат, визитка, визитки, каталог, брошура, "+document.getElementById('kw').innerHTML);
  } else {
    tags[5].setAttribute('content', "bulged, website, digital, print, cards, catalog, дигитален, печат, визитка, визитки, каталог, брошура");  
  }
}

function sifr_init(sIFR)
{
  if (document.getElementById('pageTitle').innerHTML) {
    document.title = document.getElementById('pageTitle').innerHTML;
  }

 if(typeof sIFR == 'function'){ 
    sIFR.replaceElement('h3.grotesk', '/fonts/grotesk_light_30.swf', '#ff7e00', null, '#FFFFFF', null, 0, 0, 0, 0);
    sIFR.replaceElement('h4.grotesk', '/fonts/grotesk_19.swf', '#ff7e00', null, '#FFFFFF', null, 0, 0, 0, 0);
  };

  tags = document.getElementsByTagName("meta");
  if (document.getElementById('kw').innerHTML) {
    tags[5].setAttribute('content', "bulged, website, digital, print, cards, catalog, дигитален, печат, визитка, визитки, каталог, брошура, "+document.getElementById('kw').innerHTML);
  } else {
    tags[5].setAttribute('content', "bulged, website, digital, print, cards, catalog, дигитален, печат, визитка, визитки, каталог, брошура");  
  }

  // track page on each sifr initialization (~= ajax page load)
  if (pageTracker) {
    pageTracker._trackPageview(window.location.href.replace(/#/, ""));
  }
}

function switch_language(language)
{
  if(window.location.hash.substr(-1).match('#') || (!window.location.hash.substr(-1))) { 
      window.location.href = language+'#actual';
  } else {
      window.location.href = language+window.location.hash; 
  }
}

function switch_to(menu) {
  var lang = menu.substr(3, 2);
  var module = menu.substr(6);
  var hash = '';
  var href = '';

  Element.removeClassName("template", "active");
  Element.removeClassName("maillist", "active");

  switch(module) {
    case 'products':
      hash='products/all';
      href='products/all';
      break
    case 'services':
      hash='services/all';
      href='services/all';
      break
    case 'enquiry':
      hash='enquiry/index';
      href='enquiry/index';
      break
    case 'about':
      hash='about';
      href='about';
      break
    case 'promos':
      window.location.href = 'http://login.bulged.net/';
      return;
      break
    default:
      hash='promos/all';
      href='promos/all';
  };

  new Ajax.Updater('cAjax', lang+'/'+hash, {asynchronous:true, evalScripts:false, method:'get', onComplete:function(request, json){sifr_init(sIFR)}});
  window.location.hash = '#'+href;
}

function updateContent(location, culture)
{

  if(location.hash) {
      hash = location.hash.substr(1);
      var module = location.hash.substr(1, location.hash.indexOf("/")-1) || location.hash.substr(1);

      switch (module) {
        case 'products':
          flashProxy.call("doSelect", 1, 0);
          break;
        case 'promos':
          flashProxy.call("doSelect", 5, 0);
          break;
        case 'services':
          flashProxy.call("doSelect", 3, 0);
          break;
        case 'enquiry':
          flashProxy.call("doSelect", 6, 0);
          break;
        case 'about':
          flashProxy.call("doSelect", 4, 0);
          break;
        case 'templates':
          Element.addClassName("template", "active");
          flashProxy.call("doSelect", 0, 0);
          break;
        case 'mailing_list':
          Element.addClassName("maillist", "active");
          flashProxy.call("doSelect", 0, 0);
          break;
        case 'equipment':
          break;
        default:
         flashProxy.call("doSelect", 0, 0);
      }

      var lang = location.pathname.substr(0, location.pathname.indexOf('#')) || culture;

      new Ajax.Updater('cAjax', lang+'/'+hash, {asynchronous:true, evalScripts:false, method:'get', onComplete:function(request, json){$('cAjax').show();sifr_init(sIFR)}});
      return true;
    }
    
    $('cAjax').show();
}
  
function change_style(from, to, flash_to_zero) {

  if (from.match('index')) {
    Element.removeClassName("template", "active");
    Element.removeClassName("maillist", "active");
    from = window.location.hash.substr(1, window.location.hash.indexOf('/')-1) || window.location.hash.substr(1);
  } else {
    sifr_init(sIFR);
  }
  
  if (flash_to_zero == 1 || from.match('products') || from.match('services') || from.match('promos') || from.match('about') || from.match('enquiry')) {
    flashProxy.call("doSelect", 0, 0);
  }
  
 
  switch (from) {
    case 'templates':
      Element.removeClassName("template", "active");
      break; 
    case 'maillist':
      Element.removeClassName("maillist", "active");
      break; 
  }

  switch (to) {
    case 'products':
      flashProxy.call("doSelect", 1, 0);
      break;
    case 'promos':
      flashProxy.call("doSelect", 2, 0);
      break;
    case 'services':
      flashProxy.call("doSelect", 3, 0);
      break;
    case 'enquiry':
      flashProxy.call("doSelect", 6, 0);
      break;
    case 'about':
      flashProxy.call("doSelect", 4, 0);
      break;
    case 'templates':
      Element.addClassName("template", "active");
      break;
    case 'maillist':
      Element.addClassName("maillist", "active");
      break;
  }
}

