﻿/// <reference path="../includes/jquery/jquery-1.4.1-vsdoc.js" />

$(document).ready(function () {
	//reframe("<%=mySett.my_site_root %>");
	$("a[rel^='prettyPhoto']").prettyPhoto();
	$("a").each(function () { if (this.href.indexOf("youtube.com") != -1) { $(this).prettyPhoto(); }; });
	$(".maxPhoto").each(function () { maxPhoto(this); });
	$("a.fancy").fancybox({
		'hideOnContentClick': true
	});
});

$(window).resize(function () {
	$(".maxPhoto").each(function () { maxPhoto(this); });
});

function maxPhoto(photoObj) {
	if (parseInt($(photoObj).height()) > 100) {
		var maxAvailWidth = $(photoObj).parent().width();
		var maxAvailHeight = $(photoObj).parent().height();
		var actImgWidth = $(photoObj).width();
		var actImgHeight = $(photoObj).height();
		var newImgWidth = 0;
		var newImgHeight = 0;
		// calcolo la larghezza dell'immagine nel caso usassi per essa tutta l'altezza disponibile
		var newImgWidth = parseInt((maxAvailHeight * actImgWidth) / actImgHeight);
		if (newImgWidth > maxAvailWidth) {
			newImgWidth = maxAvailWidth;
			newImgHeight = parseInt((actImgHeight * newImgWidth) / actImgWidth);
		}
		else {
			newImgHeight = maxAvailHeight;
		}
		$(photoObj).width(newImgWidth);
		$(photoObj).height(newImgHeight);
	}
	else
		window.setTimeout(function () { maxPhoto(photoObj); }, 100);
}