/* Author: Christoph Knoth

*/

var windowWidth = $(window).width(); //retrieve current window width
var windowHeight = $(window).height(); //retrieve current window height
//var documentWidth = $(document).width(); //retrieve current document width
//var documentHeight = $(document).height(); //retrieve current document height
var vScrollPosition = $(document).scrollTop(); //retrieve the document scroll ToP position
var hScrollPosition = $(document).scrollLeft(); //retrieve the document scroll Left position

var topoffset = -0.05; 

var windowRatio = windowWidth / windowHeight

var maxRatioImage = 0.75
var maxRatioFigure = 0.75

function onm_window_parameters(){ //called on viewer reload, screen resize or scroll
    windowWidth = $(window).width(); //retrieve current window width
    windowHeight = $(window).height(); //retrieve current window height
    //documentWidth = $(document).width(); //retrieve current document width
    //documentHeight = $(document).height(); //retrieve current document height
    vScrollPosition = $(document).scrollTop(); //retrieve the document scroll ToP position
    hScrollPosition = $(document).scrollLeft(); //retrieve the document scroll Left position
}; //end function onm_window_parameters()


var i=1;
var j=1;
var showNavi = false;

caption = $("#slideshow-count");


function onAfter(curr,next,opts) {

	var text = i + ' of ' + opts.slideCount;
    caption.html(text);
            
	if(i === opts.slideCount && showNavi === false ) { 
		$("#previous").css('visibility','visible').hide().fadeIn("slow");
		$("#next").css('visibility','visible').hide().fadeIn("slow");
		showNavi = true;
	}
	i++;
	j++;
	if (i - 1 == opts.slideCount){i = 1;}
}

$(window).resize(function() {
	onm_window_parameters();
});


$(document).ready(function() {

	//add special class to p if images is in it
	$("img").closest('p').addClass("image-p");
	
	
	// Show title of work on hover
	$(".thumb").mouseover(function() {
	    $('#colophon').text( $(this).find("h1").text() );
	}).mouseout(function(){
		$('#colophon').text("");
	});
	
	
	// start gallery/slideshow
	$('.single-works .entry-content').cycle({ 
	    fx:     'none', 
    	speed:  300, 
	    next:   '.single-works .entry-content', 
    	timeout: 0,
    	before: function() {
        	$(this).css({top: '50%', marginTop: -$(this).height()/2});
		},
    	after: onAfter,
    	autostop: 1
   	});

	//
		//
	$("figcaption a").click(function () { 
		//window.location.href = $("figcaption a").attr('href');
	        window.open($("figcaption a").attr('href'));
        	return false;
	});
	
	// scroll to the image on the first click   	
   	$('.single-works .entry-content').click(function() {
   	
		if (j <= 3){
			$.scrollTo(".entry-title", 400, {offset: {top:-20, left:0} });
		}
	});
});
