var aProfileInfoBlocks = [
    'detail_page_profile_firm_block',
    'detail_page_profile_special_block',
    'detail_page_profile_awards_block',
    'detail_page_profile_reference_block',
    'detail_page_profile_contacts_block',
    'detail_page_profile_artists_block'
];


var sEnlargedFileBlockId = 'enlarged_file_block_content';
var sCarouselBlockId = "showroom_detail_page_carousel";

function ShowroomProfiler(oLabelDiv, sAppearDiv) {
  sStateFlag = $(sAppearDiv).style.display;
  if (sStateFlag == "none") {
    aProfileInfoBlocks.each(
      function (item) {
        if ($(item) != null) {
          if ($(item).style.display != "none") {
            Effect.SlideUp(item);
          }
        }
      }
    );
    Effect.SlideDown(sAppearDiv);
  } else {
    Effect.SlideUp(sAppearDiv);
  }
}

function sUpdateEnlargedBlock(sSiteName, sPageParam) {
 var sModeParam = '&mode=enlarged_block';
 var sUrlParams = sPageParam + sModeParam;
 if (sSiteName) {
   vUpdateContent(sSiteName, sUrlParams, sEnlargedFileBlockId, sAjaxBusyIcon); 
 }	
}

function vCarouselJSPager(sSiteName, sParamsStr) {
  var sModeParam = '&mode=carousel_list';
  sUrlParams = sParamsStr + sModeParam;
  if (sSiteName) {
    vUpdateContent(sSiteName, sUrlParams, sCarouselBlockId, sAjaxBusyIcon); 
  }
}


function sSetVideoPlayerBlockContent(sXmlFile) {
  if (sPlayerPath.length == 0 ) alert("player path is not correct");  
  if (!sXmlFile) alert("bad xml");
  
  var sVideoPlayerWidth = "470";
  var sVideoPlayerHeight = "353"; //320
  var sVideoBlockContentElId = "enlarged_block_video_player";
  var flashvars = {
    config: sVideoPlayerConfig,
    file: sXmlFile
  };
  var params = {
    allowscriptaccess: "always",
    allowfullscreen: "true",
    wmode: "transparent"
  };
  var attributes = {};
  swfobject.embedSWF(sPlayerPath, sVideoBlockContentElId, sVideoPlayerWidth, sVideoPlayerHeight, "9.0.124.0",
                   false, flashvars, params, attributes,alertStatus);
}


var sSetVideoPlayerBlockContentTest = function(text) {
  alert(text);
}

function sSetAudioPlayerBlockContent(sXmlFile) {
  if (sPlayerPath.length == 0 ) alert("player path is not correct");  
  if (!sXmlFile) alert("bad xml");
  
  var sAudioPlayerWidth = "707";
  var sAudioPlayerHeight = "124"; //84
  var sAudioBlockContentElId = "audio_player_block_content";
  
  var flashvars = {
    config: sAudioPlayerConfig,
    file: sXmlFile
  };
  var params = {
    allowscriptaccess: "always",
    allowfullscreen: "false"
  };
  var attributes = {};
  swfobject.embedSWF(sPlayerPath, sAudioBlockContentElId, sAudioPlayerWidth, sAudioPlayerHeight, "9.0.124.0",
                   false, flashvars, params, attributes,alertStatus);  
}

function alertStatus(e) {
  //      alert("e.success = " + e.success +"\ne.id = "+ e.id +"\ne.ref = "+ e.ref);
}

var DownloadButton = Class.create();

DownloadButton.prototype.aData = {};
DownloadButton.prototype.sButtonContainer = "showroom_download_button";
DownloadButton.prototype.sFileContainer = "enlarged_file_block_content";
DownloadButton.prototype.sIconPath  = "";
DownloadButton.prototype.iCurrentFileId  = 0;

DownloadButton.prototype.sIconFile  = "download.png";
DownloadButton.prototype.initialize= function () {
  try {
    this.aData = window.oFilesDownloadData;
    this.sIconPath = window.sImageDir + this.sIconFile;
  } catch (err) {
    alert(err.toString());
  }
}


DownloadButton.prototype.showButton = function() {
  try {
    if (null != $(this.sButtonContainer)) {
      $(this.sButtonContainer).remove();
    }
    //alert(this.aData[this.iCurrentFileId]);
    if (this.aData[this.iCurrentFileId] >0) {
      sUrl = window.sShowroomFileDownloadUrl;
      sUrl += '&mode=get_download_link' + '&file_uid=' + this.iCurrentFileId;
      mContent = [Builder.node(
          'a', 
          {
            href:sUrl, 
            target:'_blank', 
            onclick:"return confirm(window.oLocalLang.sGetLang('download_confirm'));",
            title:window.oLocalLang.sGetLang('download_button_tooltip')
          },
          Builder.node('img',
            {
              src:this.sIconPath, 
              id:'showroom_download_button_img',
              alt:window.oLocalLang.sGetLang('download_button_tooltip')
          })
        )];
      sElement = Builder.node('div',{'id':this.sButtonContainer}, mContent);
      $(this.sFileContainer).appendChild(sElement);
      //alert('all ok');
    }
  } catch (err) {
    alert(err.toString());
  }
}



document.observe("page:detailpage_file_download", function() {
  //alert ("aaaa");
  oDownloadButton = new DownloadButton();
  //oDownloadButton.sFileIdFieldId = 'tx_showroom_enlarged_file_id';
  //oDownloadButton.iCurrentFileId = $(oDownloadButton.sFileIdFieldId).value;
  oDownloadButton.iCurrentFileId = window.oEnlargedFileParams.file_uid;
  oDownloadButton.showButton();
  //alert(oDownloadButton.iCurrentFileId);
  //oDow
  //oDownloadButton.iCurrentFileId = '159';
//  alert(oDownloadButton.iCurrentFileId);
  //oDownloadButton.showButton();
  //alert(oDownloadButton.aData['287']);
});

document.observe("detail_page:update_button", function(event){
  if (undefined == window.oDownloadButton) {
    return;
  }
  oDownloadButton.iCurrentFileId = event.memo.file_uid;
  oDownloadButton.showButton();
  
});
