

$(document).ready(function(){
	
		//set wrapper size
	setsize();			
	onresize = setsize;

	
	
	
	//bg
	$('<div id="bgbl" style="position:absolute;bottom:0px;left:0px;background-image:url(img/bgbl.png);width:150px;height:150px;"></div><div id="bgbr" style="position:absolute;bottom:0px;right:0px;background-image:url(img/bgbr.png);width:150px;height:150px;"></div><div id="bgb" style="position:absolute;bottom:0px;background-image:url(img/bgb.png);width:99%;height:150px;"></div><div id="bgtl" style="position:absolute;top:0px;left:0px;background-image:url(img/bgtl.png);width:150px;height:150px;"></div><div id="bgtr" style="position:absolute;top:0px;right:0px;background-image:url(img/bgtr.png);width:150px;height:150px;"></div><div id="bgt" style="position:absolute;top:0px;background-image:url(img/bgt.png);width:99%;height:150px;"></div><div id="bgl" style="position:absolute;left:0px;background-image:url(img/bgl.png);width:150px;height:99%;"></div><div id="bgr" style="position:absolute;right:0px;background-image:url(img/bgr.png);width:150px;height:99%;z-index:0;"></div><div style="position:absolute;bottom:0px;left:50%;margin-left:-305px;z-index:20;overflow:hidden"><img src="img/legal.gif" style="margin-bottom:-3px" /></div>').prependTo('#wrapper');

	$('<div class="home"><a href="'+document.getElementsByTagName('base')[0].href+'"><img src="img/home.jpg" alt="Home" /></a></div>').prependTo('#wrapper');

	//white line & box rotation 
	if($('body').attr('class')=='index'){
		$('#container').prepend('<div style="position:absolute;left:49%;width:2px;background-color:white;height:79%;bottom:0px;z-index:6;"></div>');
		$('.m3 .menuline').css('display', 'none');
		/* Box rotation non si usa piu. Puo essere necessario in futuro.
		var s = Math.random() * 2;
		if(s>1){
			$('#box_three').html('<img src="img/home_entra_antipatici.jpg" alt="" style="height:100%;position:relative;left:-2%" /><a class="" href="gli-antipatici/libro.html" style=""><img class="homepul" src="img/home_uncappello_pul.jpg" alt="" style="height:15%;position:absolute;bottom:13%;left:38%" /></a>')
		}
		*/
	}
	else{
		$('#container').prepend('<div style="position:absolute;left:32%;width:2px;background-color:white;height:100%;z-index:6;"></div>');
		$('.m2 .menuline').css('display', 'none');
	}
	
	space();
	
	$('#wrapper').css({visibility:'visible'});
	
	var cic = 0;
	var noi = document.location.toString().split('?')[1];
	if($('#galleryleft').attr('class')){
		noi = $('#galleryleft').attr('class');
	};
	var saklama = 0;
	$('#left ul li').each(function(){
		if($(this).attr('class')=='titolo'){
			cic++;
			$(this).click(function(){
				$('#left').css('overflow-x', 'hidden');
				var mx = $(this).attr('class').replace('titolo ', '').replace('selected', '');
				$('#left ul li:not(.titolo)').hide();
				$('#left ul li.'+mx).show('slow', function(){
				});
			})
		}
		else{
			$(this).click(function(){document.location=document.getElementsByTagName('base')[0].href+$(this).children('a').attr('href')});
			if($('#galleryleft').attr('class')){
				var urlcontrol = $(this).children('a').attr('href').search($('#galleryleft').attr('class'))>-1;
			}
			else{
				var urlcontrol = document.location.toString().search('/' + $(this).children('a').attr('href'))>0;
			}
			
			if(urlcontrol){
				saklama = cic;
				$(this).addClass('selected');
			}
			else{
				$(this).mouseover(function(){
					$(this).addClass('selected');
				}).mouseout(function(){
					$(this).removeClass('selected');
				})		
			}				
			if (cic>0){
				$(this).hide();
			}		
			if($(this).children('a').attr('href')=='un-cappello-pieno-di-ciliege/libro.html'){
				$(this).children('a').attr('href', 'un-cappello-pieno-di-ciliege/la-saga/libro.html');
			}
		}
		$(this).addClass('m'+cic);
	});
	$('#left ul li.m'+saklama).show();
	$('body.video li.m2').show();
	
	//modifica francesco
	/*
	$("#button_bur").click(function() {
		$("li.book_bur").show();
	});
	*/
	var aBur=[
		/intervista-con-la-storia/gi,
		/oriana-fallaci-legge-lettera-un-bambino-mai-nato/gi,
		/gli-antipatici/gi,
		/il-sesso-inutile/gi,
		/i-sette-peccati-di-hollywood/gi,
		/lettera-un-bambino-mai-nato/gi,
		/quel-giorno-sulla-luna/gi,
		/penelope-alla-guerra/gi,
		/la-rabbia-e-lorgoglio/gi,
		/insciallah/gi
	];
	
	
	if ($(aBur).map(function() { return document.location.toString().match(this)!=null ? this : null }).size()>0) {
		$("#left ul").wrap('<div style="height:76%;width:100%" class="wrap_libri"></div>');

		$("li.book_bur").show();
	} else {
		$("li.book_bur").hide();
	}

       
	if (document.location.toString().match(/libro_bur/gi)!=null) {
	       //$("li.book_bur").slideDown(1100,function() {});
      		$("#left ul").wrap('<div style="height:76%;width:100%" class="wrap_libri"></div>');

		 setTimeout(function() {
			$("li.book_bur").show(600,function() {});
		},200);
	
	} 
	
	
	//modifica francesco
	
	
	
	
	$('#vidaper').fadeOut(6000, function(){
		vidname = $(this).attr('src').toString().replace('img/aperturavideo_', '').replace('.jpg', '');
		$('#video').prepend('<object id="" width="100%" height="100%" data="player.swf?'+Math.floor(Math.random()*1000)+'" type="application/x-shockwave-flash" style="margin-top:2px"><param name="quality" value="high"/><param name="wmode" value="transparent"/><param name="allowScriptAccess" value="always"/><param name="flashvars" value="live=true&debug=false&configPath=config.xml&playlistPath=playlist_'+vidname+'.xml?'+Math.floor(Math.random()*1000)+'"/><param name="movie" value="player.swf?'+Math.floor(Math.random()*1000)+'"/></object>');

});
	// libro con audio
	if (document.location.toString().match(/oriana-fallaci-legge-lettera-un-bambino-mai-nato/gi)!=null) {
		$('body').append('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="0" height="0"><param name="movie" value="mini_player_flash.swf?xml=dati.xml"><param name="quality" value="high"><embed src="mini_player_flash.swf?xml=dati.xml" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="0" height="0"></embed></object>');
//$('body').append('<object type="application/x-shockwave-flash" data="player_mp3_mini.swf" width="200" height="20"><param name="movie" value="player_mp3_mini.swf" /><param name="bgcolor" value="#ff0000" /><param name="FlashVars" value="mp3=http://media2.corriere.it/extras/fallaci/audio/Lettera_a_un_bambino_mai_nato.mp3;autoplay=1" /></object>');

	}
	
	
		$('.menu li').each(function(){
			var efvalue = document.location.toString().match(".+/(.+).\html$");
			if(efvalue){
				efvalue = efvalue[1];
				if(efvalue=='foto' || efvalue=='video'){efvalue = 'foto-video'}
				if(efvalue=='libro_bur'){efvalue = 'libro'}
			}
			else{efvalue=''}
			$(this).click(function(){document.location=document.getElementsByTagName('base')[0].href+$(this).children('a').attr('href')});
			if($(this).children('a').attr('href').replace('.html', '') == efvalue){
				$(this).addClass('selected');
			}
			else{
				$(this).mouseover(function(){
					$(this).addClass('selected');
				}).mouseout(function(){
					$(this).removeClass('selected');
				})		
			}
		})
	

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

if($('#mainphoto img').length>0){
	var efvalue = document.location.toString().match(".+/(.+).\html$")[1];
	//modifica francesco	
	  if (efvalue=='libro_bur') efvalue="libro";
	//modifica francesco
	setCookie('effect', efvalue, '', '/');
	setCookie('img', $('#mainphoto img').attr('src'), '', '/');
}
else{
	var efvalue = document.location.toString().match(".+/(.+).\html$");

	if(efvalue){
		efvalue = efvalue[1];
		if(efvalue=='foto' || efvalue=='video'){efvalue = 'foto-video'}
		
		var effect = getCookie('effect');
		if(effect==efvalue){
			var img = getCookie('img');
			setCookie('effect', '', '', '/');
			setCookie('img', '', '', '/');
		   	$('<div id="mainphoto"><img src="'+img+'" alt="" /></div>').appendTo('#right');
	   		$('#mainphoto img').animate({marginLeft: "-100%", opacity:"0.6"}, 1500, function(){
	    		$('#mainphoto').remove();
	  		});
		}
	}
}
	




		$('.menu img').click(function(){
		document.location=$(this).parents('li').children('a').attr('href');
	})
	
	
				$('a.guardaor').click(function(){
				$('<div id="guardawin" style="position:absolute;width:100%;z-index:6;overflow:hidden;"></div>').appendTo('#container');
				$('<div id="blackscreen"><img src="'+$(this).attr('href')+'" style="" /></div>').appendTo('#guardawin').width('100%').animate({left:'0%'}, 3000, function(){
					$(this).css({overflow:'auto',overflowX:'hidden'});
					$('<img id="close" src="img/close.gif" style="position:absolute;left:20px;top:20px;cursor:pointer;display:none" />').appendTo('#guardawin').fadeIn('slow').click(function(){
						$(this).hide();
						$('#blackscreen').css({overflow:'hidden'}).animate({left:'100%'}, 3000, function(){$('#guardawin').remove()});
					})
				});
				return false;
			});
	
	
	
				$('#leggionline img').css({cursor:'pointer'}).toggle(function(){
				$('#abstractbook').slideDown(3000);
				//document.getElementById('leggionline').scrollIntoView(true)
			}, function(){
				//$('#abstractbook').slideUp('slow')
			});
			
			space();
			
			
			
			$('body.cappello #content h3:contains("La saga")').css('border', 'none');
	
	
	
	$('.homepul').mouseover(function(){
	$(this).attr('src', $(this).attr('src').replace('.jpg', '_on.jpg'))
}).mouseout(function(){
	$(this).attr('src', $(this).attr('src').replace('_on.jpg', '.jpg'))
})
	
	
})






	
				
	
	
	

	
	

	
	
		function space(){
		$('<div style="height:20px"></div>').appendTo('#cont');
	}	
	
		

	
	
	


	
	


		

	
	
	
	function setsize(){
		
		var ch = document.body.clientHeight;
		if (ch < 560){ch=560}
		var cw = document.body.clientWidth;
		if (cw < 990){cw=990}
		var rat = ch/cw;
		var wrapper = document.getElementById('wrapper');
		var erat = 0.565;
		
		if(rat<erat){
			wrapper.style.height = ch + 'px';
			var nwidth = Math.round(ch / erat);
			wrapper.style.width = nwidth + 'px';
			wrapper.style.top = '0px';
			wrapper.style.left = (cw-nwidth)/2 + 'px';
		}
		else{
			wrapper.style.width = cw + 'px';
			var nheight = cw * erat;
			wrapper.style.height = nheight + 'px';
			wrapper.style.left = '0px';
			wrapper.style.top = (ch-nheight)/2 + 'px';
			//alert(ch+','+cw+','+rat+','+erat);	
			//alert(cw+','+wrapper.clientWidth);
		}
		
	}

	




			

			


	


	

function leftflow(){
	lheight = $('#left').height()
	cheight = $('#left ul').height()
	if(cheight > lheight){
		$('<div id="scrollbottom" style="position:absolute;bottom:0px;width:100%;height:36px;background-color:#F2DA80"><img src="img/scrbot.gif" width="29" height="17" alt="" style="margin-left:30px;margin-top:6px;cursor:pointer" id="scrbot"><img src="img/scrtop.gif" width="29" height="17" alt="" style="cursor:pointer" id="scrtop"></div>').appendTo('#left');
		$('#scrtop').mouseover(function(){anim = window.setInterval('move(-1)', 50)}).mouseout(function(){stop();})
		$('#scrbot').mouseover(function(){anim = window.setInterval('move(1)', 50)}).mouseout(function(){stop();})
	}
	else{
		$('#scrollbottom').remove();
	}
}	


function move(a){
	var mar = parseInt($('#left ul').css('marginTop'));
	dist = 5 * a;
	mar = mar-dist;
	$('#left ul').css('marginTop', mar);
	//alert(lheight+','+cheight+','+mar);
	if((a==1 && (cheight < (lheight - mar) - 36))){
		window.clearInterval(anim);
	}
	if((a==-1 && mar==0)){
		window.clearInterval(anim);
	}		
}

function stop(){
	window.clearInterval(anim);
}

