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" title="chiudi"><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 = objHTML.replace('#title#','');
    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')}


// Prototype e funzioni js di utilità generale
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }
String.prototype.noPixel = function(){ return this.toString().toLowerCase().replace('px','').trim().num();}
String.prototype.pathNormalize = function(t) {var s=this;if (t.toLowerCase()=='relative'){s=s.replace(/\\/g, '/').replace(/\/\//g, '\\');}else{s=s.replace(/\//g, '\\').replace(/\\\\/g, '\\');}return s.toLowerCase();}
String.prototype.getExtension = function(){var ext=this.replace(/^\s+|\s+$/g,'');ext=ext.toString().toLowerCase();ext=ext.substring(ext.lastIndexOf('.'),ext.length);return ext;}
String.prototype.HtmlParse = function(){$('body').append('<div id="String_prototype_HtmlParse">'+this+'</div>');var hParse=$('#String_prototype_HtmlParse').text();$('#String_prototype_HtmlParse').remove();return hParse;}
String.prototype.char = function(i){return this.substring(i-1,i);}
String.prototype.left = function(i){return this.substring(0,i);}
String.prototype.right = function(i){if(i>this.length){return '';}return this.substring((this.length-i),this.length);}
String.prototype.rightTo = function(i){if(i>this.length){return '';}return this.substring(i-1,this.length);}
String.prototype.mid = function(i,l){return this.substring(i-1,(i-1)+l);}
String.prototype.num = function(){var n=parseFloat(this);if(isNaN(n)){return NaN;}return n;}
String.prototype.DateToNumber = function(){var d=this;if(d.length!=10){return 0;}var n=d.right(4)+d.mid(4,2)+d.left(2);if(isNaN(n)){n=0;}return n;}


