function apriPop(url, name, w, h) {
	var l = Math.floor((screen.width-w)/3);
	var t = Math.floor((screen.height-h)/3);
	window.open(url,name,"width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
}

function trim(stringa){
	while (stringa.substring(0,1) == ' '){
		stringa = stringa.substring(1, stringa.length);
	}
	while (stringa.substring(stringa.length-1, stringa.length) == ' '){
		stringa = stringa.substring(0,stringa.length-1);
	}
	return stringa;
}

// memorizzo l'immagine del lavoro che è attiva
var imgLavoriPrec = '';

function submenu(){

	if($('#imgMain').attr('src') != undefined)
		imgLavoriPrec = trim($('#imgMain').attr('src'));

	$(" #nav ul ").css({display: "none"}); // Opera Fix

	$(" #nav li").hover(function(){

		$(this).find('ul:first').css({visibility: "visible",display: "none"}).show(400);
		$(this).find('ul:first li.submenu:first').css('margin-top', "40px");

		$('#imgMain').attr({'src': $(this).find('img:first').attr('src')});

	},function(){

		$(this).find('ul:first').css({visibility: "hidden"});

		if(imgLavoriPrec != '')
			$('#imgMain').attr({'src': imgLavoriPrec});

	});
}

function setSH() {

	var myElements = ".btSh";

	$(myElements).each(function(i) {

		$(this).click(function() {

			if($(this).next('div').css('display') == 'none')
				$(this).next('div').show('slow');
			else
				$(this).next('div').hide('slow');
		});

	});

}
/*
function getImgSrc(pElId, pSz) {

	alert(pElId.length);

	var newSrc = $('#imgMain').attr('src');

	var sToMatch = "phpThumb";



	// se l'immagine è manipolata con phpThumb
	if(newSrc.search(sToMatch) > 0) {

		$('#'+pElId).attr('onclick', 'document.getElementById(\'imgMain\').src=\''+newSrc+'\'');

		newSrc = newSrc.replace('480', pSz);
		newSrc = newSrc.replace('480', pSz);
	}
	else {
		newSrc = './phpThumb/phpThumb.php?src=../'+newSrc+'&w='+pSz+'&h='+pSz+'&zc=1&aoe=1';

		$('#'+pElId).attr('onclick', 'document.getElementById(\'imgMain\').src=\'./phpThumb/phpThumb.php?src=../'+newSrc+'&w=480&h=480&zc=1&aoe=1\'');
	}



	return newSrc;

}
*/

var imgSrcM = new Array(4);
var imgSrcT = new Array(4);

var imgSz = new Array(3);

imgSz[1] = 70;
imgSz[2] = 40;
imgSz[3] = 29;

function drawLavThumbs() {

	for(var i=0; i<4; i++) {

		// per default assegno a imgMain il primo elemento
		if(i==0) {
			$('#imgMain').attr('src', imgSrcM[i]);
		}
		else {
			if(imgSrcT[i] != undefined) {
				$('#th'+i).attr('src', './phpThumb/phpThumb.php?src=../'+imgSrcT[i]+'&w='+imgSz[i]+'&h='+imgSz[i]+'&zc=1&aoe=1');
			}
		}
	}

	// non si capisce perchè nel ciclo for non fuzniona quanto segue

	$('#th'+1).click(function() {

		imgSrcM_tmp = imgSrcM[0];
		imgSrcT[-1] =  imgSrcT[0];

		imgSrcM[0] = imgSrcM[1];
		imgSrcT[0] =  imgSrcT[1];

		imgSrcM[1] = imgSrcM_tmp;
		imgSrcT[1] =  imgSrcT[-1];

		if(imgSrcT[1] != undefined) {
			$('#th'+1).attr('src', './phpThumb/phpThumb.php?src=../'+imgSrcT[1]+'&w='+imgSz[1]+'&h='+imgSz[1]+'&zc=1&aoe=1');
			$('#imgMain').attr('src', imgSrcM[0]);
		}

	});

	$('#th'+2).click(function() {

		imgSrcM_tmp = imgSrcM[0];
		imgSrcT[-1] =  imgSrcT[0];

		imgSrcM[0] = imgSrcM[2];
		imgSrcT[0] =  imgSrcT[2];

		imgSrcM[2] = imgSrcM_tmp;
		imgSrcT[2] =  imgSrcT[-1];

		if(imgSrcT[2] != undefined) {
			$('#th'+2).attr('src', './phpThumb/phpThumb.php?src=../'+imgSrcT[2]+'&w='+imgSz[2]+'&h='+imgSz[2]+'&zc=1&aoe=1');
			$('#imgMain').attr('src', imgSrcM[0]);
		}

	});

	$('#th'+3).click(function() {

		imgSrcM_tmp = imgSrcM[0];
		imgSrcT[-1] =  imgSrcT[0];

		imgSrcM[0] = imgSrcM[3];
		imgSrcT[0] =  imgSrcT[3];

		imgSrcM[3] = imgSrcM_tmp;
		imgSrcT[3] =  imgSrcT[-1];

		if(imgSrcT[3] != undefined) {
			$('#th'+3).attr('src', './phpThumb/phpThumb.php?src=../'+imgSrcT[3]+'&w='+imgSz[3]+'&h='+imgSz[3]+'&zc=1&aoe=1');
			$('#imgMain').attr('src', imgSrcM[0]);
		}

	});


}


// ------------------------------------------------------------------

$(document).ready(function() {

	setupZoom();

	submenu();

	setSH();

	$('#tbThEv').css('width', '319px'); // era 409
	$('#riqC').css('width', '205px');

	if($.browser.msie) {
		if(jQuery.browser.version == '6.0') {
			$('#tbThEv').css('width', '316px'); // era 406
			$('#riqC').css('width', '198px');

			$('li.submenu_v:first-child').css('margin-top', '12px');

			$('#riqNews').css('scrollbar-face-color', '#FF1E00');
			$('#riqNews').css('scrollbar-shadow-color', '#FFA500');
			$('#riqNews').css('scrollbar-highlight-color', '#FFFFFF');
			$('#riqNews').css('scrollbar-3dlight-color', '#FFFFFF');
			$('#riqNews').css('scrollbar-darkshadow-color', '#FFFFFF');
			$('#riqNews').css('scrollbar-track-color', '#FFFFFF');
			$('#riqNews').css('scrollbar-arrow-color', '#FFFFFF');

		}
	}


});

