﻿$(function () {

	var step, middle;
	step = 100 / ($("#flip li").length - 1);
	middle = ($("#flip li").length - 1) / 2

	$('#flip').jcoverflip({
		current: middle,
		change: function (event, ui) {
			jQuery('#scrollbar').slider('value', ui.to * step);
		}
	});

	$("#slider").slider({
		value: 50,
		stop: function (event, ui) {
			if (event.originalEvent) {
				var newVal = Math.round(ui.value / step);
				jQuery('#flip').jcoverflip('current', newVal);
				jQuery('#slider').slider('value', newVal * step);
			}
		}
	});

	$("#flip a").click(function () {

		var imageLink, pdfLink, video;
		imageLink = $(this).attr("href");
		video = $(this).attr("rel");

		if (video == 'video') {

			$(".lightbox").html('<object width="640" height="385"><param name="movie" value="' + imageLink + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="' + imageLink + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>');
			$(".lightbox").prepend('<a href="#" class="close">X</a><br />');
			$(".lightbox").addClass('vidBox');
			$(".lightbox").show();

		}else{
			pdfLink = imageLink.replace('/large', '');
			pdfLink = pdfLink.replace('.jpg', '.pdf');

			$(".lightbox").html('<img src="' + imageLink + '" alt="" />');
			$(".lightbox").append('<br /><a href="' + pdfLink + '">Download as pdf file</a>');
			$(".lightbox").prepend('<a href="#" class="close">X</a><br />');
			$(".lightbox").show();
		}

		$(".close").click(function () {
			$(".lightbox").hide();
			return false;
		});

		return false;
	});
});
