/* for CELES Apio Animation */
(function($){

	jQuery.fn.createSlice = function(size,leng,bgURL,op){
		var h = $(this).height();
		for(var i=0;i<leng;i++){
			$(this).append('<div class="slice"></div>')
		}
		var sliceDivs = $(this).children();
		sliceDivs.css('background','url('+bgURL+') no-repeat');
		sliceDivs.each(function(i){
			$(this).css({
				width: size+'px',
				height: h+'px',
				backgroundPosition: '-'+i*size+'px 0'
			});
			if(op == 'fix'){
				$(this).css({position:'absolute',top:0,left:i*size+'px'});
			}
			if(op == 'float'){
				$(this).css({float:'left'});
			}
		});
		return this;
	}

	jQuery.fn.sliceOut = function(pause,func){
		var last = $(this).children().length - 1;
		$(this).children().each(function(i){
			$(this).delay(pause+(100*i)).hide(300,function(){	// MXXsec = 2400 = 100*21+300
				$(this).remove();
				if(i == last){func.resolve();}
			});
		});
		return this;
	}

	jQuery.fn.fixPosi = function(set){
		var conf = {
			center : true,
			middle : true
		};
		if(set) $.extend(conf, set);
		if(conf.center){ $(this).css({left:getCenterPosi($(this))+'px'}); }
		if(conf.middle){ $(this).css({top:getMiddlePosi($(this))+'px'}); }
		return this;
	}

	jQuery.fn.fixZoom = function(tWidht,time){
		var w = $(this).width();
		var h = $(this).height();
		var tw = tWidht;
		var th = (tw * h)/w;
		var wPosi = ( w - tw )/2;
		var hPosi = ( h - th )/2;
		$(this).animate({width:tw+'px', height:th+'px', left:wPosi+'px', top:hPosi+'px', opacity:0}, time, 'swing');
	}

/*
		jQuery.fn.effectZoom = function(widht,height){
			var wPosi = ( $(this).width() - widht )/2;
			var hPosi = ( $(this).height() - height )/2;
			$(this).animate({width:widht+'px', height:height+'px', left:wPosi+'px', top:hPosi+'px'}, 2000, 'linear');
		}
*/
/*
		jQuery.fn.effectA = function(flag){
			var tPosi = getTopPosi($(this)) + 'px';
			var lPosi = getLefPosi($(this)) + 'px';
			var hVector = '+=' + tPosi;
			if(flag){	// It enters from the left.
				wVector = '-=' + lPosi;
			}else{		// It enters from the right.
				wVector = '+=' + lPosi;
			}
			$(this)
				.animate({top:hVector,left:wVector,opacity:1}, 3000, 'linear')
				.delay(500)
				.animate({top:hVector,left:wVector,opacity:0}, 3000, 'linear');
		}
*/

	function getCenterPosi(target){
		return ( target.parent().width() - $(target).width() )/2;
	}
	function getMiddlePosi(target){
		return ( target.parent().height() - $(target).height() )/2;
	}


})(jQuery);

