var grSBIntegrator = new function(){
  this.fbWasInitialized = false;
  this.getLocalizedTexts = function(){
    var lsTexts;
    if(gsLang == 'cs'){
      lsTexts = {cancel:     'Storno',
                 loading:    'nahrávám',
                 close:      'Zavřít',
                 next:       'Další',
                 prev:       'Předchozí',
                 errors:{
                   single: 'Pro prohlížení tohoto obsahu si musíte do vašeho prohlížeče nainstalovat rozšíření <a href="{0}">{1}</a>.',
                   shared: 'Pro prohlížení tohoto obsahu si musíte do vašeho prohlížeče nainstalovat <a href="{0}">{1}</a> a <a href="{2}">{3}</a>.',
                   either: 'Pro prohlížení tohoto obsahu si musíte do vašeho prohlížeče nainstalovat <a href="{0}">{1}</a> nebo <a href="{2}">{3}</a>.'
                 }
               };
    }else if(gsLang == 'ru'){
      lsTexts = {cancel:     'Отменить',
                 loading:    'загрузка',
                 close:      'Закрыть',
                 next:       'Следующий',
                 prev:       'Предыдущий',
                 errors:{
                   single: 'Вы должны установить <a href="{0}">{1}</a> плагин браузера для просмотра этого содержания.',
                   shared: 'Вы должны установить <a href="{0}">{1}</a> и <a href="{2}">{3}</a> плагины браузера для просмотра этого содержания.',
                   either: 'Вы должны установить,  либо <a href="{0}">{1}</a>,  либо <a href="{2}">{3}</a> плагин браузера для просмотра этого содержания.'
                 }
               };
    }else{
      lsTexts = {
        cancel:     'Cancel',
        loading:    'loading',
        close:      'Close',
        next:       'Next',
        prev:       'Previous',
        errors: {
            single: 'You must install the <a href="{0}">{1}</a> browser plugin to view this content.',
            shared: 'You must install both the <a href="{0}">{1}</a> and <a href="{2}">{3}</a> browser plugins to view this content.',
            either: 'You must install either the <a href="{0}">{1}</a> or the <a href="{2}">{3}</a> browser plugin to view this content.'
        }
      }
    }
    return lsTexts;
  }
  this.init = function(){

    if (!CrossBrowser.IsUndefined(grOnClickEventManager)) {
      grOnClickEventManager.addListener(this, null, 'a', null, 600);
      grOnClickEventManager.addListener(this, 'shadowbox_content', 'img', null, 601);
    }


    Shadowbox.init({ handleLgImages: "none",
                     loadingImage: "/img/imgloading.gif",
                     animate: true,
                     animSequence: "sync",
                     //overlayColor: "#0065B7",
                     overlayOpacity: 0.4,
                     viewportPadding: 0,
                     initialWidth: 0,
                     initialHeight: 0,
                     text: this.getLocalizedTexts()
                   });

  }
  this.CapturedClick = function(irElement, inPriority) {
    if(inPriority == 600)
      lbResult = this.DisplayImage(irElement);
    else if (inPriority == 601)
      lbResult = this.CloseBox(irElement);
    return lbResult;
  }
  this.CloseBox = function(irElement){
    Shadowbox.close();
    return false;
  }
  this.DisplayImage = function(irElement){
    var lrImages = irElement.getElementsByTagName('img');
    var lrHandledAnchors = [];
    var lbResult = true;
    if((lrImages.length == 1) && (lrImages[0].className == 'zoomimage')){
      if(!this.fbWasInitialized){
        this.fbWasInitialized = true;
      }
      Shadowbox.open({title: lrImages[0].title,
                      type: 'img',
                      content: irElement.href
                     },
                     { handleLgImages: "none",
                       loadingImage: "/img/imgloading.gif",
                       animate: true,
                       animSequence: "sync",
                       //overlayColor: "#808080",
                       overlayOpacity: 0.4,
                       viewportPadding: 0,
                       initialWidth: 0,
                       initialHeight: 0
                     });
      lbResult = false;
    }
    return(lbResult);
  }
}

CrossBrowser.addEventListener(window, 'load', function(){grSBIntegrator.init()}, false);
