/**
*	Site-specific configuration settings for Highslide JS
*/
hs.graphicsDir = 'highslide/graphics/';
hs.showCredits = false;
hs.outlineType = 'custom';
hs.dimmingOpacity = 0.9;
hs.fadeInOut = true;
hs.align = 'center';

// Add the slideshow controller
hs.addSlideshow({
	slideshowGroup: 'group1',
	interval: 5000,
	repeat: true,
	useControls: true,
	fixedControls: 'fit',
	overlayOptions: {
		opacity: '0.65',
		position: 'bottom center',
		offsetX: '0',
		offsetY: '-15',
		hideOnMouseOut: true
	}
});

var config1 = 
{
	slideshowGroup: 'group1',
	transitions: ['expand', 'crossfade']
};


hs.skin.controls = '<div class="highslide-controls"><ul>'+
   '<li class="highslide-previous">'+
      '<a href="#" title="{hs.lang.previousTitle}">'+
      '<span>{hs.lang.previousText}</span></a>'+
   '</li>'+
   '<li class="highslide-play">'+
      '<a href="#" title="{hs.lang.playTitle}">'+
      '<span>{hs.lang.playText}</span></a>'+
   '</li>'+
   '<li class="highslide-pause">'+
      '<a href="#" title="{hs.lang.pauseTitle}">'+
      '<span>{hs.lang.pauseText}</span></a>'+
   '</li>'+
   '<li class="highslide-next">'+
      '<a href="#" title="{hs.lang.nextTitle}">'+
      '<span>{hs.lang.nextText}</span></a>'+
   '</li>'+
   '<li class="highslide-move">'+
      '<a href="#" title="{hs.lang.moveTitle}">'+
      '<span>{hs.lang.moveText}</span></a>'+
   '</li>'+
   '<li class="highslide-full-expand">'+
      '<a href="#" title="{hs.lang.fullExpandTitle}">'+
      '<span>{hs.lang.fullExpandText}</span></a>'+
   '</li>'+
   '<li class="highslide-downloadoriginal">'+
      '<a href="#" title="Download original file (d)" onclick="return downloadOriginal(this)">'+
      '<span>Download original file (d)</span></a>'+
   '</li>'+
   '<li class="highslide-showinfo">'+
      '<a href="#" title="Show photo information" onclick="return showExif(this)">'+
      '<span>Show photo information</span></a>'+
   '</li>'+
   '<li class="highslide-close">'+
      '<a href="#" title="{hs.lang.closeTitle}" >'+
      '<span>{hs.lang.closeText}</span></a>'+
   '</li>'+
'</ul></div>';

function showExif(opener)
{
	var exp = hs.getExpander(opener);
	return hs.htmlExpand(opener, {contentId: "exif-window", preserveContent: false}, exp.custom);
}

function downloadOriginal(opener)
{
	var exp = hs.getExpander(opener);
	var url = exp.a.href.replace(/\/s1600\//g,"/d/");  //TODO: get the s1600 from PHP config?
	window.open(url);
	return false;
}

hs.Expander.prototype.onAfterGetContent = function (sender) 
{   
	if (this.custom.exif != null) 
	{
		var tableCells = sender.content.getElementsByTagName("td");
		
		tableCells[1].innerHTML = this.custom.exif.make;
		tableCells[3].innerHTML = this.custom.exif.model;
		tableCells[5].innerHTML = this.custom.exif.fstop;
		tableCells[7].innerHTML = this.custom.exif.exp;
		tableCells[9].innerHTML = this.custom.exif.focal;
		tableCells[11].innerHTML = this.custom.exif.iso;
		tableCells[13].innerHTML = (this.custom.exif.flash ? "yes" : "no");
	}
	else
	{
		var exifBody = sender.content.getElementsByClassName("highslide-body");
		exifBody[0].innerHTML = "Sorry, there is no more information about this photo";
	}

    var album = /[?&]album=([^&#]*)/.exec(window.location.href);
    var tagname = /[?&]tag=([^&#]*)/.exec(window.location.href);
	var photoid = this.custom.id;
	
	var links = sender.content.getElementsByClassName("photolink");

	var started = false;
	
	var idLink = '';
	
	if (album != null && album[1] != null) 
	{
		idLink += "?album=" + album[1];
		started = true;
	}

	if (tagname != null && tagname[1] != null) 
	{
		tagname[1].replace(/\x20/g, '%20');
		
		idLink += (started ? "&" : "?");
		idLink += "tag=" + tagname[1];
		started = true;
	} 

	idLink += (started ? "&" : "?");
	idLink += "id=" + photoid;

	links[0].href += idLink;

};

hs.Expander.prototype.onBeforeClose = function(sender) 
{
   if (sender.contentId != "exif-window") 
   {
   		closeExifWindow();
   }
   return true;
}

function closeExifWindow()
{
    for (var i = 0; i < hs.expanders.length; i++) 
	{
        var exp = hs.expanders[i];
        
        if (exp && exp.contentId == "exif-window") 
		{
            exp.close();
			return;
        }
    }
}

hs.addEventListener(window, "load", function() 
{
   var autoload = /[?&]id=([^&#]*)/.exec(window.location.href);
   if (autoload) document.getElementById(autoload[1]).onclick();
});


