/*
 * jQuery UI Effects +
 *
 * Copyright 2011, Dmitry Sherbina
 *
 * Depends:
 *	jquery.effects.core.js
 */
(function( $, undefined ) {

$.effects.blindup = function(o) {

	return this.queue(function() {

		// Create element
		var el = $(this), props = ['position','top','left','right','bottom','opacity'];//

		// Set options
		var mode = $.effects.setMode(el, o.options.mode || 'hide'); // Set Mode
		var direction = o.options.direction || 'up'; // Default Direction

		// Adjust
		$.effects.save(el, props); el.show(); // Save & Show
		var wrapper = $.effects.createWrapper(el).css({overflow:'hidden'}); // Create Wrapper
		var ref = (direction == 'up' || direction == 'down') ? 'top' : 'left';
        var ref2 = (direction == 'up' || direction == 'down') ? 'height' : 'width';
		var motion = (direction == 'down' || direction == 'right') ? 'pos' : 'neg';
		var distance = (ref == 'top' ? el.outerHeight({margin:true}) : el.outerWidth({margin:true}));
		if (mode == 'show') {
            wrapper.css(ref2,0).css(ref, motion == 'pos' ? wrapper.css(ref) : wrapper.css(ref, wrapper.cssUnit(ref)[0]+distance)); // Shift
            el.css(ref, motion == 'pos' ? 0 : -distance)
        }
		// Animation
        var animation2={};
        if (motion == 'neg' )   animation2[ref] = (mode == 'show' ? ('-=') : ('+=')) + distance;
        animation2[ref2] = (mode == 'show' ? distance : 0);
            
		// Animate
        if (motion == 'neg'){
            var animation = {};
            animation[ref] = (mode == 'show' ? ('+=' ) : ('-=')) + distance;
            el.animate(animation, {queue:false, duration: o.duration, easing:o.options.easing});
        };
        wrapper.animate(animation2, { queue: false, duration: o.duration, easing: o.options.easing, complete: function() {
			if(mode == 'hide') el.hide(); // Hide
			$.effects.restore(el, props); $.effects.removeWrapper(el); // Restore
			if(o.callback) o.callback.apply(el[0], arguments); // Callback
			el.dequeue();
		}});
	});
};

})(jQuery);

