/**
 * @author Выскорко Максим (Simex-T)
 */


var galleryOptions = {
    slideshowGroup: 'gallery',
    wrapperClassName: 'dark',
    dimmingOpacity: 1,
    align: 'center',
    transitions: ['expand', 'crossfade'],
    fadeInOut: true,
    wrapperClassName: 'borderless floating-caption',
    marginLeft: 100,
    marginBottom: 80,
    numberPosition: 'caption'
  };

var gallery_index = null;

window.onload=function(){
  
  stl = document.createElement("link");
  stl.rel = "stylesheet";
  stl.type="text/css";
  stl.href="highslide/highslide.css";
  
  document.body.appendChild(stl);
  
  if(navigator.appName == "Microsoft Internet Explorer"){
  	stl = document.createElement("link");
    stl.rel = "stylesheet";
    stl.type="text/css";
    stl.href="highslide/highslide-ie6.css";
    document.body.appendChild(stl);
  }
  
  script = document.createElement("script");
  script.type = "text/javascript"
  script.src="highslide/highslide-with-gallery.js";
  document.body.appendChild(script);
  
  
  }
  
function init(){
  hs.showCredits = 0;
  hs.padToMinWidth = true;
  hs.marginBottom = 105;
  hs.autoplay = true;
  hs.easingClose = true;
  hs.Expander.prototype.onBeforeClose = function (sender) {
   return confirm("Do you really want to close this nice image?");
}

  //hs.align = 'center';
  if (hs.registerOverlay) {
    // The white controlbar overlay
    hs.registerOverlay({
      thumbnailId: 'thumb3',
      overlayId: 'controlbar',
      position: 'top right',
      hideOnMouseOut: true
    });
    // The simple semitransparent close button overlay
    hs.registerOverlay({
      thumbnailId: 'thumb2',
      html: '<div class="closebutton" onclick="return hs.close(this)" title="Close"></div>',
      position: 'top right',
	  repeat : true,
      fade: 2 // fading the semi-transparent overlay looks bad in IE
    });
	with(hs.lang){
	  fullExpandTitle = "Music on/off"
	  number: 'Photo %1 of %2'
	  fullExpandText = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="70" height="20" id="play" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="allowFullScreen" value="false" /><param name="movie" value="play.swf?" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="song=take_five.mp3" /><embed src="play.swf?" flashvars="song=take_five.mp3" quality="high" bgcolor="#ffffff" width="70" height="20" name="play" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>'
	}
  }
  
  
  

  if (hs.addEventListener && hs.Outline) hs.addEventListener(window, 'load', function () {
   new hs.Outline('rounded-white');
   new hs.Outline('glossy-dark');
  });


  

  if (hs.addSlideshow) hs.addSlideshow({
    slideshowGroup: 'gallery',
    interval: 4000,
    repeat: true,
    useControls: true,
    overlayOptions: {
      className: 'text-controls',
      position: 'bottom center',
      relativeTo: 'viewport',
      offsetY: -10
	  
    }

  });
  
  hs.Expander.prototype.onInit = function() {
   hs.marginBottom = (this.slideshowGroup == 'gallery') ? 150 : 15;
  }
  
  
  function getXmlHttp(){
    var xmlhttp;
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (E) {
        xmlhttp = false;
      }
    }
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
      xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
  }

  var xmlhttp = getXmlHttp();
  xmlhttp.open('GET', 'gallery.xml', false);
  xmlhttp.send(null);
  
  var lang = document.getElementById('gdto_slideshow').getAttribute("param")
  if(xmlhttp.status == 200) {
    var gallery = xmlhttp.responseXML.getElementsByTagName('node')[0].getElementsByTagName(lang)[0];
    var images = gallery.getElementsByTagName('image');
	var div = document.createElement("div");
	
	div.className = "gallery-examples highslide-gallery";
	div.style.display = "none"
    for(var i = 0;  i< images.length; i++){
  	  var src = images[i].getAttribute('src');
	  var value = "";
      var value = images[i].childNodes[0].nodeValue;
	  var div_elem = document.createElement("div");
	  div_elem.className = "thumbwrapper";
	  
	  var a = document.createElement("a");
	  
	  a.onclick = function(){
		return hs.expand(this, galleryOptions)
	  }
	  a.className = "highslide";
	  a.href = src;
	  a.innerHTML = value
	  
	  if (i == 0) {
	  	gallery_index = a;
	  }
	  	  
	  div_elem.appendChild(a)
	  div.appendChild(div_elem);
	  var div_title = document.createElement('div')
	  div_title.className = "highslide-caption";
	  div_title.innerHTML = value;
	  div_elem.appendChild(div_title);
	  
    }
    
	document.body.appendChild(div);
	ShowGalleryGDTO()
  }
}

function ShowGalleryGDTO(){
  hs.expand(gallery_index, galleryOptions);
}

