/*______________________________________

  Miz_ImageClip #071004
  
  Copyright (C) 1999-2007 Mizuyari All rights reserved.
  Script written by Mahiro Komura.
  http://mizuyari.jp/
______________________________________*/


var loading;
var imageClip;

// mizuyari.addOnLoadEvent(progressBarInit);
mizuyari.addOnLoadEvent(imageClipInit);

function Miz_ImageClip(name) { // Miz_ImageClip #071004

 Miz_ImageClip.prototype.self			= name;
 Miz_ImageClip.prototype.fadeInOutTimer		= null;
 Miz_ImageClip.prototype.fadeInOutOpacity	= 0;
 Miz_ImageClip.prototype.fadeInOutBaseFrms	= 10;
 Miz_ImageClip.prototype.autoPlay		= false;
 Miz_ImageClip.prototype.autoPlayWeit		= 4000;
 Miz_ImageClip.prototype.autoPlayTimer		= null;
 Miz_ImageClip.prototype.showInfo		= false;
 Miz_ImageClip.prototype.imgs			= new Array();
 Miz_ImageClip.prototype.bgElement		= 'miz-photogallery-image';
 Miz_ImageClip.prototype.bgPosition		= '50% 0';
 Miz_ImageClip.prototype.imgElementId		= 'img';
 Miz_ImageClip.prototype.imgElementAlign	= 'center';
 Miz_ImageClip.prototype.currentImgId		= 0;
 Miz_ImageClip.prototype.prevImgId		= null;
 Miz_ImageClip.prototype.isExecutable		= false;
 Miz_ImageClip.prototype.paging			= null;
 Miz_ImageClip.prototype.pagingId		= 'miz-photogallery-paging';
 Miz_ImageClip.prototype.pagingItems		= null;
 Miz_ImageClip.prototype.stageTimer		= null;
 Miz_ImageClip.prototype.stageOpacity		= 0;
 Miz_ImageClip.prototype.stageBaseFrms		= 16;
 Miz_ImageClip.prototype.photoSetName		= null;
 Miz_ImageClip.prototype.photoSetTitle		= "----";
 Miz_ImageClip.prototype.commentElementId	= 'miz-photogallery-comment';
 Miz_ImageClip.prototype.xmlPath		= "";
 Miz_ImageClip.prototype.loadTimerID		= null;
 Miz_ImageClip.prototype.typewriterTimer	= null;
 Miz_ImageClip.prototype.typewriterCount	= 0;
 Miz_ImageClip.prototype.typeContent		= new Array(2);
 Miz_ImageClip.prototype.typeCursor		= "|";
 Miz_ImageClip.prototype.typeSpeed		= 5;
 Miz_ImageClip.prototype.repositionTimer 	= null;

 Miz_ImageClip.prototype.init = function () {
  this.createInterface();
  this.reposition();
  this.xmlPath = '/data/imagegallery/xml/';
 }
 
 Miz_ImageClip.prototype.preloadImgs = function () {
  mizPreloadImgs(this.imgs);
 }

 Miz_ImageClip.prototype.gotoAndPlay = function (id) {
  if (!this.isExecutable) return;
  if (this.fadeInOutTimer) return;
  if (id != null) {
   this.pagingItems[this.currentImgId].className = "";
   this.prevImgId = this.currentImgId;
   this.currentImgId = id;
   this.pagingItems[this.currentImgId].className = "current";
  }
  this.fadeInOut();
 }

 Miz_ImageClip.prototype.toggleAutoPlay = function() {
  if (!this.isExecutable) return;
  if (this.autoPlay != false) {
   if (this.autoPlayTimer) clearTimeout(this.autoPlayTimer);
   this.setAutoPlay(false);
  } else {
   this.setAutoPlay(true);
  }
 }

 Miz_ImageClip.prototype.setAutoPlay = function(mode) {
  if (!this.isExecutable) return;
  if (this.autoPlayTimer) clearTimeout(this.autoPlayTimer);
  var autoPlayButton = miz$('miz-photogallery-autoplay');
  this.autoPlay = mode;
  autoPlayButton.className = (this.autoPlay) ? 'enabled' : '';
  if (this.autoPlay) this.autoPlayTimer = setTimeout(this.self + '.nextImg()', this.autoPlayWeit);
  return mode;
 }

 Miz_ImageClip.prototype.toggleComment = function() {
  if (!this.isExecutable) return;
  if (this.showInfo != false) {
   this.setCommentStatus(false);
   if (this.typewriterTimer) clearTimeout(this.typewriterTimer);
  } else {
   if (this.autoPlayTimer) clearTimeout(this.autoPlayTimer);
   this.setCommentStatus(true);
   this.typewriter();
  }
 }

 Miz_ImageClip.prototype.setCommentStatus = function(mode) {
  if (!this.isExecutable) return;
  var infoButton = miz$('miz-photogallery-info');
  var textComment = miz$(this.commentElementId);
  this.showInfo = mode;
  textComment.className = (this.showInfo) ? '' : 'hidden';
  infoButton.className = (this.showInfo) ? 'enabled' : '';
  return mode;
 }

 Miz_ImageClip.prototype.typewriter = function() {
  var textComment = miz$(this.commentElementId);
  textComment.innerHTML = "";
  this.typeContent[0] = this.photoSetTitle + ", " + this.imgs[this.currentImgId].title;
  this.typeContent[1] = "" + this.imgs[this.currentImgId].caption;
  if (this.typeContent[1]) this.typeContent[0] += ":";
  this.commentTypeSubTotal = [this.typeContent[0].length, this.typeContent[1].length];
  this.commentTypeTotal = this.commentTypeSubTotal[0] + this.commentTypeSubTotal[1];
  this.commentTypeCount = 0;
  this.typewriterTimer = setTimeout(this.self + ".typewriter_main()",16);
 }

 Miz_ImageClip.prototype.typewriter_main = function() {
  if (this.typewriterTimer) clearTimeout(this.typewriterTimer);
  var textComment = miz$(this.commentElementId);
  this.commentTypeCount += this.typeSpeed;
  if (this.commentTypeCount > this.commentTypeTotal) {
   this.commentTypeCount = this.commentTypeTotal;
  }
  if (this.commentTypeCount == this.commentTypeTotal) {
   textComment.innerHTML = "<p><em>" + csAutoMarkup(this.typeContent[0]) + "<\/em><\/p>" + 
   "<p>" + csAutoMarkup(this.typeContent[1]) + "<\/p>"
   if (this.autoPlay) this.autoPlayTimer = setTimeout(this.self + '.nextImg()', this.autoPlayWeit);
  } else if  (this.commentTypeCount <= this.commentTypeSubTotal[0]) {
   textComment.innerHTML = "<p>" + this.typeContent[0].slice(0,this.commentTypeCount) + this.typeCursor + "<\/p>";
  } else if (this.commentTypeCount > this.commentTypeSubTotal[0]) {
   textComment.innerHTML = "<p><em>" + csAutoMarkup(this.typeContent[0]) + "<\/em><\/p>" +
   " <p>" + this.typeContent[1].slice(0,this.commentTypeCount-this.commentTypeSubTotal[0]) + this.typeCursor + "<\/p>";
  }
  if (this.commentTypeCount < this.commentTypeTotal) {
   this.typewriterTimer = setTimeout(this.self + ".typewriter_main()",16);
  }
 }

 Miz_ImageClip.prototype.setTitleContent = function (title) {
  var titleElmt = miz$('miz-photogallery-title');
  titleElmt.innerHTML = csAutoMarkup(title);
 }

 Miz_ImageClip.prototype.nextImg = function () {
  if (!this.isExecutable) return;
  if (this.fadeInOutTimer) return;
  if (this.autoPlayTimer) clearTimeout(this.autoPlayTimer);
  this.pagingItems[this.currentImgId].className = "";
  this.prevImgId = this.currentImgId;
  this.currentImgId = (this.currentImgId < this.imgs.length-1) ? this.currentImgId+1 : 0;
  this.pagingItems[this.currentImgId].className = "current";
  this.fadeInOut();
 }

 Miz_ImageClip.prototype.prevImg = function () {
  if (!this.isExecutable) return;
  if (this.fadeInOutTimer) return;
  if (this.autoPlayTimer) clearTimeout(this.autoPlayTimer);
  this.pagingItems[this.currentImgId].className = "";
  this.prevImgId = this.currentImgId;
  this.currentImgId = (this.currentImgId > 0) ? this.currentImgId-1 : this.imgs.length-1;
  this.pagingItems[this.currentImgId].className = "current";
  this.fadeInOut();
 }

 Miz_ImageClip.prototype.fadeInOutFrms = function () {
  if (mizuyari.ua.isMac && mizuyari.ua.isGecko || mizuyari.ua.isWinIE60 ) {
   return this.fadeInOutBaseFrms / 3;
  } else {
   return this.fadeInOutBaseFrms;
  }
 }

 Miz_ImageClip.prototype.fadeInOut = function () {
  if (!this.isExecutable) return;
  if (this.fadeInOutTimer) return;
  if (this.autoPlayTimer) clearTimeout(this.autoPlayTimer);
  var textComment = miz$(this.commentElementId);

  mizSetBackgroundRepeat(this.bgElement,'no-repeat');
  if (navigator.userAgent.indexOf("Firefox") != -1) {
   mizSetImgSrc(this.imgElementId,this.imgs[this.prevImgId].image.src);
   mizSetTextAlign(this.imgElementId,this.imgElementAlign);
   mizSetBackgroundImage(this.bgElement,this.imgs[this.currentImgId].image.src);
   mizSetBackgroundPosition(this.bgElement,this.bgPosition);
   mizSetOpacity(this.imgElementId,100);
  } else {
   mizSetImgSrc(this.imgElementId,this.imgs[this.currentImgId].image.src);
   mizSetTextAlign(this.imgElementId,this.imgElementAlign);
   mizSetBackgroundImage(this.bgElement,this.imgs[this.prevImgId].image.src);
   mizSetBackgroundPosition(this.bgElement,this.bgPosition);
   mizSetOpacity(this.imgElementId,0);
  }
  this.fadeInOutOpacity = 0;
  this.fadeInOutTimer = setTimeout(this.self + '.fadeInOut_main()',16);
 }

 Miz_ImageClip.prototype.fadeInOut_main = function () {
  if (!this.isExecutable) return;
  if (this.fadeInOutTimer) clearTimeout(this.fadeInOutTimer);
  if (this.fadeInOutOpacity < 100) {
   this.fadeInOutOpacity += Math.floor(100/this.fadeInOutFrms()); if (this.fadeInOutOpacity > 100 ) this.fadeInOutOpacity = 100;
   this.fadeInOutTimer = setTimeout(this.self + '.fadeInOut_main()',16); 
   if (navigator.userAgent.indexOf("Firefox") != -1) {
    mizSetOpacity(this.imgElementId,100-this.fadeInOutOpacity);
   } else {
    mizSetOpacity(this.imgElementId,this.fadeInOutOpacity);
   }
  } else {
   if (navigator.userAgent.indexOf("Firefox") != -1) {
    mizSetImgSrc(this.imgElementId,this.imgs[this.prevImgId].image.src);
   }
   this.fadeInOutTimer = null;
   if (this.showInfo) {
    this.typewriter();
   } else {
    if (this.autoPlay) this.autoPlayTimer = setTimeout(this.self + '.nextImg()', this.autoPlayWeit);
   }
   return;
  }
 }

 Miz_ImageClip.prototype.stageFrms = function () {
  if (mizuyari.ua.isMac) {
   return this.stageBaseFrms / 4;
  } else {
   return this.stageBaseFrms;
  }
 }

 Miz_ImageClip.prototype.loadImages = function() {
  loading.showProgressBar();
  loading.slowstart();
  this.loadImages_main();
 }

 Miz_ImageClip.prototype.loadImages_main = function() {
  clearInterval(this.loadTimerID);
  if (this.isImgsLoaded()) {
   // trace("load complete");
   loading.fadeOut();
   this.loadComplete();
  } else {
   // trace("loading");
   this.loadTimerID = setInterval(this.self+".loadImages_main()", 250);
  }
 }

 Miz_ImageClip.prototype.loadComplete = function() {
  this.setPagingContent();
  this.isExecutable = true;
  this.setAutoPlay(false);
  this.setCommentStatus(false);
  this.gotoAndPlay(0);
 }

 Miz_ImageClip.prototype.isImgsLoaded = function() {
  var complete = true;
  var totalItems = this.imgs.length;
  var downloadedItems = 0;
  for (i=0; i<totalItems; i++) {
   if (!this.imgs[i].image.complete) {
    complete = false;
    // trace(i + ": " + complete);
   } else {
    downloadedItems++;
   }
  }
  var completePercent = Math.floor(downloadedItems / totalItems * 100);
  // trace(completePercent);
  loading.setProgressBarWidthByPercent(completePercent);
  loading.writeText('<p>preloading data: ' + downloadedItems + '/' + totalItems + ' images loaded.<\/p>');
  loading.start(completePercent);
  return complete;
 }

 Miz_ImageClip.prototype.setClipInfo = function(xdoc) {
  var albumElmt = xdoc.getElementsByTagName("album")[0];
  var imgElmt = xdoc.getElementsByTagName("img");
  this.photoSetTitle = albumElmt.getAttribute("title");
  var albumImages = new Array();
  for (i=0; i<imgElmt.length; i++) {
   albumImages[i] = {
    "title" : imgElmt[i].getAttribute('title'),
    "caption" : imgElmt[i].getAttribute('caption'),
    "image" : new Image(),
    "loaded" : false
   };
   albumImages[i].image.src = imgElmt[i].getAttribute('src');
  }
  this.imgs = albumImages;
 }

 Miz_ImageClip.prototype.reposition = function() { // reposition #070927
  if (mizuyari.ua.isWinIE60) return;
  imageClip.repositionTimer = setTimeout('imageClip.reposition_main()', 250);
 }

 Miz_ImageClip.prototype.reposition_main = function() { // reposition_main #070927
  if (this.repositionTimer) clearTimeout(this.repositionTimer);
  var stage = miz$('miz-photogallery-stage');
  var stageHeight = 660;
  var loading = miz$('miz-loading');
  var innerHeight = getWindowInnerHeight();
   if ((innerHeight >= stageHeight)) {
    loading.style.top = ((innerHeight - loading.clientHeight - 20) / 2) + "px";
    stage.style.top = ((innerHeight - stageHeight) / 2) + "px";
   } else {
    loading.style.top = "300px";
    stage.style.top = "0px";
   }
 }

 Miz_ImageClip.prototype.open = function(xml, styleId) {
  if (!this.isExecutable) return;
  this.isExecutable = false;
  var stage = miz$('miz-photogallery');
  var overlay = miz$('miz-overlay');
  hideObjects();
  hideSelectBoxes();
  this.setStyle(styleId);
  overlay.style.opacity = '0';
  mizuyari.removeClass(miz$('miz-overlay'),'hidden');
  this.photoSetName = xml;
  this.stageOpacity = 0;
  this.stageTimer = setTimeout(this.self + '.open_main1()',16);
 }

 Miz_ImageClip.prototype.open_main1 = function() {
  if (this.stageTimer) clearTimeout(this.stageTimer);
  var stage = miz$('miz-photogallery');
  var overlay = miz$('miz-overlay');
  if (this.stageOpacity < 80) {
   this.stageOpacity += Math.floor(100/this.stageFrms()); if (this.stageOpacity > 80 ) this.stageOpacity = 80;
   this.stageTimer = setTimeout(this.self + '.open_main1()',16); 
   mizSetOpacity(overlay.id,this.stageOpacity);
  } else {
   this.stageTimer = null;
   overlay.style.opacity = null;
   mizuyari.removeClass(miz$('miz-photogallery'),'hidden');
   var xmlurl = this.xmlPath + this.photoSetName + '.xml';
   sendRequest(imageClip_xmlLoaded,'','GET',xmlurl,true,true);
  }
 }

 Miz_ImageClip.prototype.open_main2 = function(res) {
  imageClip.setClipInfo(res);
  imageClip.setTitleContent(this.photoSetTitle);
  imageClip.loadImages();
 }

 Miz_ImageClip.prototype.close = function() {
  var stage = miz$('miz-photogallery');
  mizuyari.addClass(miz$('miz-photogallery'),'hidden');
  this.stageOpacity = 80;
  this.setTitleContent("");
  this.setAutoPlay(false);
  this.setCommentStatus(false);
  this.stageTimer = setTimeout(this.self + '.close_main()',100);
 }

 Miz_ImageClip.prototype.close_main = function() {
  if (this.stageTimer) clearTimeout(this.stageTimer);
  var overlay = miz$('miz-overlay');
  if (this.stageOpacity > 0) {
   this.stageOpacity -= Math.floor(100/this.stageFrms()); if (this.stageOpacity < 0 ) this.stageOpacity = 0;
   this.stageTimer = setTimeout(this.self + '.close_main()',16); 
   mizSetOpacity(overlay.id,this.stageOpacity);
  } else {
   this.stageTimer = null;
   overlay.style.opacity = null;
   mizuyari.addClass(miz$('miz-overlay'),'hidden');
   showSelectBoxes();
   showObjects();
   mizSetBackgroundImage(this.bgElement,"/gallery/clear.gif");
   mizSetImgSrc(this.imgElementId,"/gallery/clear.gif");
   this.dropPaging();
   return;
  }
 }

 Miz_ImageClip.prototype.setStyle = function(styleId) {
  if (styleId == 1) {
   mizuyari.addClass(miz$('miz-photogallery'),'man');
  } else {
   mizuyari.removeClass(miz$('miz-photogallery'),'man');
  }
 }
 
 Miz_ImageClip.prototype.createInterface = function() {
  var pageBody = miz$('page-body');

  var mizOverlay = document.createElement('div');
  mizOverlay.setAttribute("id","miz-overlay");
  mizOverlay.setAttribute("class","hidden");
  mizOverlay.setAttribute("className","hidden");

  var mizLoading = document.createElement('div');
  mizLoading.setAttribute("id","miz-loading");
  mizLoading.innerHTML =
   '<div id="miz-loading-text"></div>' +
   '<div id="miz-loading-progressbar"><img src="/gallery/progress_bar.gif" alt="" id="miz-loading-img" /></div>';

  var mizPhotogallery = document.createElement('div');
  mizPhotogallery.setAttribute("id","miz-photogallery");
  mizPhotogallery.setAttribute("class","hidden");
  mizPhotogallery.setAttribute("className","hidden");

  var mizPhotogalleryStage = document.createElement('div');
  mizPhotogalleryStage.setAttribute("id","miz-photogallery-stage");

  var mizPhotogalleryImage = document.createElement('div');
  mizPhotogalleryImage.setAttribute("id","miz-photogallery-image");
  mizPhotogalleryImage.innerHTML = '<img src="/gallery/clear.gif" alt="" id="img" />';

  var mizPhotogalleryPrevNext = document.createElement('ul');
  mizPhotogalleryPrevNext.setAttribute("id","miz-photogallery-prevnext");
  mizPhotogalleryPrevNext.innerHTML =
   '<li id="miz-photogallery-prevnext-next"><a href="javascript:void(0);" onclick="imageClip.nextImg(); return false;" onkeypress="imageClip.nextImg(); return false;">Next &raquo;</a></li>' +
   '<li id="miz-photogallery-prevnext-prev"><a href="javascript:void(0);" onclick="imageClip.prevImg(); return false;" onkeypress="imageClip.prevImg(); return false;">&laquo; Prev</a></li>';
  
  var mizPhotogalleryTitle = document.createElement('h1');
  mizPhotogalleryTitle.setAttribute("id","miz-photogallery-title");
  mizPhotogalleryTitle.innerHTML = '';

  var buttonClose = document.createElement('p');
  buttonClose.setAttribute("id","miz-photogallery-close");
  buttonClose.innerHTML = '<a href="javascript:void(0)" onclick="imageClip.close(); return false;">Close</a>';

  var textComment = document.createElement('div');
  textComment.setAttribute("id",this.commentElementId);
  textComment.setAttribute("class","hidden");
  textComment.setAttribute("className","hidden");
  textComment.innerHTML = '<p>n/a</p>';

  mizPhotogalleryController = document.createElement('div');
  mizPhotogalleryController.setAttribute("id", 'miz-photogallery-controller');
  mizPhotogalleryController.appendChild(mizPhotogalleryTitle);

  var mizPhotogalleryPaging = document.createElement('dl');
  var newDTElmt = document.createElement('dt');
  newDTElmt.innerHTML = "page:";
  var newDDElmt = document.createElement('dd');
  var newULElmt = document.createElement('ul');
  newULElmt.setAttribute("id", this.pagingId);
  mizPhotogalleryPaging.appendChild(newDTElmt);
  mizPhotogalleryPaging.appendChild(newDDElmt);

  var controller = document.createElement('ul');
  controller.setAttribute("id", 'miz-photogallery-buttons');
  var controller_autoplay = document.createElement('li');
  controller_autoplay.setAttribute("id", 'miz-photogallery-autoplay');
  controller_autoplay.innerHTML = '<button onclick="imageClip.toggleAutoPlay(); return false;">Auto Play</button>';
  var controller_info = document.createElement('li');
  controller_info.setAttribute("id", 'miz-photogallery-info');
  controller_info.innerHTML = '<button onclick="imageClip.toggleComment(); return false;">Credits</button>';
  controller.appendChild(controller_autoplay);
  controller.appendChild(controller_info);

  mizPhotogalleryController.appendChild(mizPhotogalleryPaging);
  mizPhotogalleryController.appendChild(controller);

  mizPhotogalleryStage.appendChild(mizPhotogalleryImage);
  mizPhotogalleryStage.appendChild(mizPhotogalleryPrevNext);
  mizPhotogalleryStage.appendChild(mizPhotogalleryController);
  mizPhotogalleryStage.appendChild(textComment);
  mizPhotogalleryStage.appendChild(buttonClose);
  mizPhotogallery.appendChild(mizPhotogalleryStage);

  pageBody.appendChild(mizOverlay);
  pageBody.appendChild(mizLoading);
  pageBody.appendChild(mizPhotogallery);

  progressBarInit();

  this.paging = miz$(this.pagingId);
  this.pagingItems = null;

  this.isExecutable = true;
 }

 Miz_ImageClip.prototype.dropPaging = function() {
  var parentElmt = miz$("miz-photogallery-controller").getElementsByTagName("DD")[0];
  var pagingElmt =  miz$(imageClip.pagingId);
  parentElmt.removeChild(pagingElmt);
 }

 Miz_ImageClip.prototype.setPagingContent = function () {
  var pagingElmt = miz$("miz-photogallery-controller").getElementsByTagName("DD")[0];

  var newULElmt = document.createElement('ul');
  newULElmt.setAttribute("id", this.pagingId);
  for (i=0; i<this.imgs.length; i++) {
   newLIElmt = document.createElement('li');
   newLIElmt.setAttribute("onclick", "imageClip.gotoAndPlay("+i+"); return false;");
   newLIElmt.setAttribute("onfocus", "imageClip.gotoAndPlay("+i+"); return false;");
   newLIElmt.innerHTML = '<a href="javascript:void(0);" onclick="imageClip.gotoAndPlay('+i+'); return false;" onkeypress="imageClip.gotoAndPlay('+i+'); return false;">' + (i+1) + '<\/a>';
   newULElmt.appendChild(newLIElmt);
  }
  pagingElmt.appendChild(newULElmt);
  this.paging = miz$(this.pagingId);
  this.pagingItems = this.paging.getElementsByTagName('li');
 }

 Miz_ImageClip.prototype.createPaging = function() {
  var newDIVElmt;
  var newULElmt;
  var newLIElmt;
  var newAElmt;
  var autoplayElmt;

  var controller = miz$('miz-photogallery-controller');

  newDLElmt = document.createElement('dl');
  newDTElmt = document.createElement('dt');
  newDTElmt.innerHTML = "page:";
  newDDElmt = document.createElement('dd');
  newDDElmt.innerHTML = "";

  newDDElmt.appendChild(newULElmt);
  newDLElmt.appendChild(newDTElmt);
  newDLElmt.appendChild(newDDElmt);

  controller.appendChild(newDLElmt);

  this.paging = miz$(this.pagingId);
  this.pagingItems = null;
 }

 return this;
}

function hideSelectBoxes() {
 var selectElmts = document.getElementsByTagName('select');
 for (i=0; i<selectElmts.length; i++) {
  selectElmts[i].style.visibility = 'hidden';
 }
}
function showSelectBoxes() {
 var selectElmts = document.getElementsByTagName('select');
 for (i=0; i<selectElmts.length; i++) {
  selectElmts[i].style.visibility = '';
 }
}


function hideObjects() {
 var objectElmts = document.getElementsByTagName('object');
 for (i=0; i<objectElmts.length; i++) {
  objectElmts[i].style.visibility = 'hidden';
 }

 var embedElmts = document.getElementsByTagName('embed');
 for (i=0; i<embedElmts.length; i++) {
  embedElmts[i].style.visibility = 'hidden';
 }
}
function showObjects() {
 var objectElmts = document.getElementsByTagName('object');
 for (i=0; i<objectElmts.length; i++) {
  objectElmts[i].style.visibility = '';
 }

 var embedElmts = document.getElementsByTagName('embed');
 for (i=0; i<embedElmts.length; i++) {
  embedElmts[i].style.visibility = '';
 }
}


function Miz_ProgressBar(objName) { // Miz_ProgressBar #070911
 this.self = objName;
}

Miz_ProgressBar.prototype = {
 "self" : this,
 "progressBarTimer" : null,
 "progressBarElmt" : null,
 "progressBarImage" : null,
 "progressBarWidth" : 1,
 "progressBarCurrentPercent" : 0,
 "progressBarCurrentWidth" : 0,
 "progressBarCurrentOpacity" : 0,
 "getProgressBarWidth" : function() {
  return this.progressBarElmt.clientWidth;
 },
 "setProgressBarWidthByPercent" : function(percent) {
  this.progressBarCurrentPercent = percent;
  this.progressBarCurrentWidth = eval(this.progressBarElmt.clientWidth / 100 * percent);
 },
 "getProgressBarCurrentWidth" : function(percent) {
  return eval(this.progressBarImage.clientWidth);
 },
 "getProgressBarCurrentPercent" : function() {
  return eval(this.progressBarImage.clientWidth / this.getProgressBarWidth() * 100);
 },

 "showProgressBar" : function() {
  this.progressBarElmt.style.visibility = 'visible';
  this.progressBarElmt.style.zIndex = '';
  this.progressBarCurrentOpacity = 100;
  mizSetOpacity(this.progressBarElmt.id, this.progressBarCurrentOpacity);
 },

 "hideProgressBar" : function() {
  this.progressBarElmt.style.visibility = 'hidden';
  this.progressBarElmt.style.zIndex = '0';
  this.progressBarCurrentOpacity = 0;
  mizSetOpacity(this.progressBarElmt.id, this.progressBarCurrentOpacity);
 },

 "slowstart" : function() {
  clearInterval(this.progressBarTimer);
  this.progressBarCurrentPercent += 0.125;
  this.drawProgressBar();
  if (this.progressBarCurrentPercent < 100) {
   this.setProgressBarWidthByPercent(this.progressBarCurrentPercent);
   this.progressBarTimer = setInterval(this.self+".slowstart()", 16);
  }
 },

 "start" : function(percent) {
  clearInterval(this.progressBarTimer);
  this.progressBarCurrentPercent++;
  this.drawProgressBar();
  if (this.progressBarCurrentPercent < percent) {
   this.progressBarTimer = setInterval(this.self+".start("+percent+")", 16);
  }
 },

 "drawProgressBar" : function() {
  if (this.progressBarCurrentPercent > 100) this.progressBarCurrentPercent = 100;
  this.setProgressBarWidthByPercent(this.progressBarCurrentPercent);
  this.progressBarImage.style.width = this.progressBarCurrentWidth + "px";
  this.progressBarImage.style.height = "1px";
 },

 "writeText" : function(html) {
  this.progressBarText.innerHTML = html;
 },
 
 "fadeIn" : function() {
  clearInterval(this.progressBarTimer);
  this.progressBarCurrentOpacity += 20;
  if (this.progressBarCurrentOpacity > 100) this.progressBarCurrentOpacity = 100;
  mizSetOpacity(this.progressBarElmt.id, this.progressBarCurrentOpacity);
  if (this.progressBarCurrentOpacity < 100) {
   this.progressBarTimer = setInterval(this.self+".fadeIn()", 16);
  }
 },

 "fadeOut" : function() {
  clearInterval(this.progressBarTimer);
  this.progressBarCurrentOpacity = 100;
  this.progressBarTimer = setInterval(this.self+".fadeOut_main()", 16);
 },

 "fadeOut_main" : function() {
  clearInterval(this.progressBarTimer);
  this.progressBarCurrentOpacity -= 20;
  if (this.progressBarCurrentOpacity < 0) this.progressBarCurrentOpacity = 0;
  mizSetOpacity(this.progressBarElmt.id, this.progressBarCurrentOpacity);
  if (this.progressBarCurrentOpacity > 0) {
   this.progressBarTimer = setInterval(this.self+".fadeOut_main()", 16);
  } else {
   this.hideProgressBar();
  }
 }

}


function mizSetImgSrc(id, src) {
 var obj = miz$(id);
 obj.src = src;
}

function mizSetBackgroundImage(id, src) {
 var obj = miz$(id).style;
 obj.backgroundImage = 'url(' + src + ')';
}

function mizSetBackgroundPosition(id, pos) {
 var obj = miz$(id).style;
 obj.backgroundPosition = pos;
}

function mizSetTextAlign(id, align) {
 var obj = miz$(id).style;
 obj.textAlign = align;
}

function mizSetBackgroundRepeat(id, method) {
 var obj = miz$(id).style;
 obj.backgroundRepeat = method;
}

function mizSetOpacity(id, opacity) { 
 var obj = miz$(id).style;
 obj.filter = "alpha(opacity=" + opacity + ")";
 obj.KhtmlOpacity = (opacity / 100);
 obj.MozOpacity = (opacity / 100);
 obj.opacity = (opacity / 100);
}

function mizPreloadImg(src) {
 if (document.images && src) (new Image()).src = src;
}

function mizPreloadImgs(srcs) {
 if (document.images && srcs) {
  for (i=0; i<srcs.length; i++) mizPreloadImg(srcs[i]);
 }
}

function csAutoMarkup(str) {
 if (mizuyari.ua.isSafari) {
  str = str.replace('&#38;','<span class="amp">&<\/span>');
 } else {
  str = str.replace('&','<span class="amp">&<\/span>');
 }
 str = str.replace('ISSUE','<span class="issue">ISSUE<\/span>')
 return str;
}

function imageClipInit() {
 imageClip = new Miz_ImageClip("imageClip");
 imageClip.init();
 mizuyari.addEvent(window, "resize", imageClip.reposition);
}
function imageClip_xmlLoaded(oj) {
 var res = oj.responseXML;
 imageClip.open_main2(res);
}

function progressBarInit() {
 loading = new Miz_ProgressBar("loading");
 loading.progressBarElmt = miz$("miz-loading");
 loading.progressBarImage = miz$("miz-loading-img");
 loading.progressBarText = miz$("miz-loading-text");
}
