/*
function FCKeditor_OnComplete( editorInstance )
{
    editorInstance.Events.AttachEvent( 'OnPaste', cleanit ) ;
}
 
var counter = 0 ;
var ei;
var si;
function cleanit( edI )
{
    edI.ResetIsDirty();
	ei = edI;
	si = setInterval('cleanit1()', 500);
	return true;
}
function cleanit1(){
	if(ei.IsDirty()){
//	    var str = ei.GetHTML().replace(/(<(strong|[pP]|[bB]|[iI]|[hH][0-9])\b[^>]*>(.*?)<\/\2>)|<([A-Za-z][A-Za-z0-9]*)\b[^>]*>(.*?)<\/\4>/g, '$1$5' );
	    var str = ei.GetHTML();
		ei.SetHTML(str);
		clearInterval(si);
	}
}
*/

function fireReady() {
	jQuery.ready();jQuery.isReady=false;jQuery.readyList=[];
}
function setBG() {
	if (!$('body').css('background') || $('body').css('background')=='#ffffff') //last for opera
		$('body').css('background','url(/GFX/portale_v3/personalizzati/sf_portale.gif) repeat-x 0 0');
}
function BMove(id) {
	setTimeout(function(){
		var bnr = jQuery('#'+id),
			img = jQuery('img',bnr),
			dst = document.getElementById(id.replace('L','PO'));
		if (img.get(0) && img.eq(0).attr('src').indexOf('empty')>=0) return; //per evitare spaziature che dipendono da immagini vuote
		if (dst) {
			dst.appendChild(document.getElementById(id));
			bnr.show();
			setTimeout(function(){fixPngs()},1000); //per autopromo
		}
	},10); //non-blocking
}

function asap(find,funct) {
	var	jR	= jQuery.isReady,
		items	= jQuery(find);
	items.filter("[asap!=1]").attr({asap:1}).each(funct);
	if (jR) {
		items.removeAttr('asap');
	} else {
		setTimeout(function(){asap(find,funct)},80);
	}
};
/*
asap("[class*=trim_]",function(){
	trimFn.call(this);
});
*/
function enableLayout(obj) {
	var jT	= jQuery(obj),
		p	= jT.parents(':hidden'),
		lh	= p.slice(-1), //lh should be a block...
		ocss = {};
	p.show();
	var	h = {position:"absolute",width:lh.width(),visibility:"hidden"}; //use visibility for left/top calc
	for (t in h) { ocss[t] = lh.css(t) };
	lh.css(h);
	jT.restore = function(){ lh.css(ocss); p.hide() };
	return jT;
}

/*	Trimma il testo dentro le classi del tipo trim_x
	se x è un numero positivo, lo usa come numero di righe da trimmare,
	altrimenti utilizza il primo block element con overflow hidden
	Ignora tutto ciò che è dentro le classi trimkeep */
var trimObjs = null;
var trimFn = function(){
	var ff2		= $.browser.mozilla && parseFloat($.browser.version)<1.9,
		mark	= $("<span>.</span>").css({display:(ff2?'-moz-inline-stack':'inline-block'),width:'1px','vertical-align':'bottom'}),
		jT		= $(this).addClass('mkjT'),
		t,s,l	= parseInt('0'+this.className.split(/rim_/)[1].split(/\s/)[0]),
		block	= jT.parents().filter(function(){
			return $(this).css("display")!="inline" && (l || $(this).css("overflow")=='hidden')
		}).eq(0),
		BClone	= block.clone().insertBefore(block)//.hide(), //hide after insert cause IE loses display:block on inlines
		jTClone	= enableLayout($('.mkjT', BClone)),
		tText	= jTClone.text(),
		LH		= mark.prependTo(jTClone).offset().top - mark.css('vertical-align','top').offset().top + mark.height(),
		yLimit	= mark.prependTo(l?jTClone:BClone).offset().top + (l? LH*l : block.height() ) - LH + 2,
		app 	= jTClone.next(".trimkeep").andSelf().eq(0),
		start	= 0;
	if ( mark.appendTo(app).offset().top >= yLimit ) {
		for ( t=tText.length; t; start+=mark.appendTo(app).offset().top < yLimit ? t:0 )
			jTClone.html( s=tText.substr(0,start+(t=t+(t>1)>>1)) + "(...)" );
		jT.html(s);
	}
	jTClone.restore();
	jT.removeClass('mkjT');
	BClone.remove();
}
function trimObj(n) { trimFn.call(trimObjs[n]) }

/* jquery gradient plugin */
jQuery.fn.gradient = function(settings) {
return this.each(function(){
	settings = jQuery.extend({
		rightcol:	'#000000',
		leftcol:	'#ffffff',
		topcol:		'#000000',
		bottomcol:	'#ffffff',
		direction:	'H'
	}, settings || {});

	var el = enableLayout(this),
		width = el.width()+parseInt(el.css('padding-left'))+parseInt(el.css('padding-right')),
		height = el.height()+parseInt(el.css('padding-top'))+parseInt(el.css('padding-bottom')),
		hor = (settings.direction=='H');
	el.restore();

	if (!width || !height) return

	if (hor) {
		var uno = settings.rightcol, due = settings.leftcol, w = width
	} else {
		var uno = settings.bottomcol, due = settings.topcol, w = height
	}

	if (jQuery.browser.msie) {
		var theSlice = $('<div class="gradient"></div>').css({'width':width,'height':height,
		filter:"progid:DXImageTransform.Microsoft.Gradient(GradientType="+(hor?1:0)+",StartColorStr=\""+due+"\",EndColorStr=\""+ uno+"\")"});
	} else {
		var theSlice = jQuery('<canvas width='+width+' height='+height+'></canvas>');
		if (theSlice.get(0).getContext) {
			var ctx = theSlice.get(0).getContext('2d'),
				grad = ctx.createLinearGradient(0,0,hor?width:0,hor?0:height);
			grad.addColorStop(0, due);
			grad.addColorStop(1, uno);
			ctx.fillStyle = grad;
			ctx.fillRect(0,0,width,height);
		}
	}

	jQuery(this).prepend(theSlice.css({position:'absolute',left:0,top:0,'z-index':-1}))
		.css({zoom:1,'z-index':1,background:'none'});
	if (jQuery(this).css('position')!='absolute') jQuery(this).css('position','relative');

});
};

function fixPngs() {
	//Fix PNG for IE6 & 5.5
	IEVersion = parseFloat(navigator.userAgent.split("MSIE ")[1]); /*jQ 1.2.6 bug #1867 */
	if ($.browser.msie && parseFloat($.browser.version)<7 && document.body.filters) {
		$('img.pngFix').each(function(){
			var i=this, el = enableLayout(i);
			$('<span style='+i.style.cssText+'></span>').attr({id:i.id,title:(i.title?i.title:i.alt)}).addClass(i.className).css({
				display:el.css('display'),visibility:'visible',width:el.width(),height:el.height(),zoom:1,
				filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'"+i.src+"\', sizingMethod='crop')"
			}).replaceAll(i);
			el.restore();
		})
	}
}
// Generic onload handling
jQuery(function($){
/*@cc_on
document.execCommand("BackgroundImageCache", false, true)
@*/

	fixPngs();

	//Trim
	var trimObjs = $("[class*=trim_]"); 
	var trimidx = 0;
	(function(){
		if (trimidx < trimObjs.length ) {
			trimFn.call(trimObjs[trimidx++]);
			setTimeout(arguments.callee,1);
		}
	})();
		

	$('.rollover').each(function() {
		//Preload Images
		(this.n = new Image()).src = this.src;
		(this.h = new Image()).src = this.src.replace(/\.([^\.]*)$/,"_over.$1");
	}).hover(
		function(){ this.src = this.h.src },
		function(){ this.src = this.n.src }
	)

	// Popup (es: class="popup_500x400")
	$('a[class*=popup]').click(function() {
		var k='', a=this.className.split(/opup_/)[1]
		if(a!='blank'){
			k='resizable=yes,toolbar=no,directories=no,scrollbars=yes,status=no'
			if(a){
				var c=a.split(/x|\s/)
				k+=',width='+c[0]+',height='+c[1]
			}
		}
		sUrl=$(this).attr('href')
		tg=$(this).attr('target');if(!tg)tg=''
		if(sUrl) var oPopup = window.open(sUrl,tg,k)
		if(oPopup)oPopup.focus()
		return (oPopup)?false:true
	});

	//$('.bigBox').gradient({ topcol:'#f2f2f2', bottomcol:'#ccddee', direction:'V' });
	$('#details').gradient({ topcol:'#f2f2f2', bottomcol:'#ccddee', direction:'V' });
	//$('#LoginArea').gradient({ topcol:'#ee7777', bottomcol:'#cc8899', direction:'V' });
});


