jQuery.fn.center = function(absolute){return this.each(function(){var t=jQuery(this);t.css({position:absolute ? 'absolute':'fixed',left:'50%',top:'50%'}).css({marginLeft:'-'+(t.outerWidth()/2)+'px',marginTop:'-'+(t.outerHeight()/2)+'px'});if (absolute){t.css({marginTop:parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(),marginLeft:parseInt(t.css('marginLeft'), 10) + jQuery(window).scrollLeft()});}});};
//
function FullScreenObjectPreview(o,type){
	Check_FullScreenObjectPreview();
	var objHTML = '<div class="preview_header"><div class="title">#title#</div><div class="close"><a onclick="Close_FullScreenObjectPreview();"></a></div></div>';
  $('#objpreview').removeClass();
  //type='image' --> preview immagine (passo percorso immagine)
  if (type=='image'){
	  var img=new Image();img.src=o;var wLimit=$(document).width()-100;var hLimit=$(document).height()-60;var wImg=img.width;var hImg=img.height;
		if (wImg>wLimit){hImg=Math.round(hImg*wLimit/wImg,0);wImg=wLimit;}
		if (hImg>hLimit){wImg=Math.round(wImg*hLimit/hImg,0);hImg=hLimit;}
    $('#objpreview').addClass('image');
    objHTML = objHTML.replace('#title#','Anteprima immagine');
    objHTML+='<img src="' + img.src + '" width="' + wImg + '" src="' + hImg + ' border="0">';
	  $('#objpreview').html(objHTML);
	  $('#objpreview').width(wImg);
		$('#objpreview>div.preview_header').width(wImg);
		Open_FullScreenObjectPreview();
  }
  //type='page' --> preview pagina (passo percorso pagina da caricare)
	if (type=='page'){
	  $('#objpreview').addClass('page');
    objHTML = objHTML.replace('#title#','Pagina');
		$.ajax({url:o, success: function(data){objHTML+=data;$('#objpreview').html(objHTML);Open_FullScreenObjectPreview();}});
	}
}
//
function Check_FullScreenObjectPreview(){if($('#screen').length==0){$('body').append('<div id="screen"></div>');}if($('#objpreview').length==0){$('body').append('<div id="objpreview"></div>');}}
//
function Open_FullScreenObjectPreview(){Check_FullScreenObjectPreview();$('#screen').css({"cursor":"pointer","display":"block",opacity:0,"width":$(document).width(),"height":$(document).height()});$('#screen').attr('title','Chiudi');$('#objpreview').hide();FullScreenObjectLevelsHideShow('hidden');$('#screen').stop().animate({opacity:0.7},1000,function(){$('#objpreview').center();$('#objpreview').slideDown();});$('#screen').click(function(){ Close_FullScreenObjectPreview();});}
//
function Close_FullScreenObjectPreview(){$('#objpreview').slideUp();$('#screen').stop().animate({opacity:0},1000,function(){FullScreenObjectLevelsHideShow('visible');});setTimeout('$("#screen").css({"display":"none"})',1500);$('#screen').click(function(){});}
//
function FullScreenObjectLevelsHideShow(state){try{if(state==''){return;};$('SELECT,EMBED,OBJECT').each(function(){$(this).css({'visibility':state});});}catch(e){}}


//Scroll fino all'elemento indicato
function ScrollTo(a){var b=0;if(isIE){b=$("#"+a).offset().top;var c='$("#"+a)';for(h=1;h<=$("#"+a).parents().length;h++){c+='.parent()';b+=eval(c+'.offset().top')}}else{b=$("#"+a).offset().top}if($("#"+a).length==0){return}$('html,body').animate({scrollTop:b},'slow')}

// Verifica se è incluso un js ed eventualmente lo include
function detectJsScript(jsInclude){jsInclude=jsInclude.toLowerCase();if(!document.scripts){for(h=0;h<document.getElementsByTagName("script").length;h++){if(document.getElementsByTagName("script")[h].src.toLowerCase().indexOf(jsInclude)>0){return}}}else{for(h=0;h<document.scripts.length;h++){if(document.scripts[h].src.toLowerCase().indexOf(jsInclude)>0){return}}}var newScript=document.createElement('script');newScript.language="JavaScript";newScript.type='text/javascript';newScript.src=jsInclude;document.getElementsByTagName("head")[0].appendChild(newScript);}
