/************************************************************************
 *iTgButtonAnimator jQuery Plugin
 *@author Swashata Ghosh
 *@requires jQuery Framework 1.4.2 and easing if using
 *@returns jQuery this
 *@version 1.0.2
 *@param
 *  find_child -> The child element on which the animation would be applied
 *  animation -> The animation method
 *  fadeOpacity -> The final opacity upto which the button will be fade
 *  slideRange -> The range of all Slide animations
 *  animationInSpeed -> Mouseover animation speed
 *  animationOutSpeed -> Mouseout animation speed
 *  easing -> The easing function
 *@plugin_home <http://www.intechgrity.com/?p=319>
 
 Change Log:
 V 1.0.1 => Birth of the Plugin
 V 1.0.2 => Fixed the IE error due to height: '+='op.sliderange+'px'
 ************************************************************************
 **********************************************************************
   *******************************LICENSE********************************
 **********************************************************************
 ************************************************************************
Copyright (c) 2010 Swashata Ghosh, http://www.intechgrity.com/

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*************************************************************************
************************************************************************/



(function($){
    $.fn.itgButtonAnimator = function(options) {
        
        //default parameters
        var op = {
            find_child : 'a',
            animation : 'slide_up_fade', //fade, slide_up, slide_down, slide_up_fade, slide_down_fade
            fadeOpacity : 0.3,
            slideRange : 15,
            animationInSpeed : 400,
            animationOutSpeed : 200,
            easing : 'linear'
        };
        
        //Extend it
        op = $.extend({}, op, options);
        
        
        
        //Loop using jQuery each()
        return this.each(function(){
            //Some shortcuts
            var itg_But = $(this); //jQuery Object
            var itg_but = this; //DOM Object
            
            //First apply default CSS if needed
            
            if((op.animation == 'slide_up') || (op.animation == 'slide_down') || (op.animation == 'slide_up_fade') || (op.animation == 'slide_down_fade')) {
                $(this).find(op.find_child).css({'display': 'block', 'float': 'left'});
            }
            
            //set the target
            var target_anim = itg_But.find(op.find_child);
            
            //set the animation
            switch(op.animation) {
                case 'fade' :
                    target_anim.bind('mouseover', function(){
                        $(this).stop(true).css({opacity: 1}).animate({opacity: op.fadeOpacity}, op.animationInSpeed, op.easing);
                    });
                    itg_But.find(op.find_child).bind('mouseout', function(){
                        $(this).stop(true).css({opacity: op.fadeOpacity}).animate({opacity: 0.3}, op.animationOutSpeed, op.easing);
                    });
                    break;
                case 'slide_up':
                    target_anim.css({paddingTop : op.slideRange+'px', paddingBottom: 0});
                    target_anim.bind('mouseover', function(){
                        $(this).stop(true).animate({paddingBottom : op.slideRange+'px', paddingTop : 0}, op.animationInSpeed, op.easing);
                    });
                    target_anim.bind('mouseout', function(){
                        $(this).stop(true).animate({paddingBottom : 0, paddingTop : op.slideRange+'px'}, op.animationOutSpeed, op.easing);
                    });
                    break;
                case 'slide_down':
                    target_anim.css({paddingTop: 0, paddingBottom: op.slideRange+'px'});
                    target_anim.bind('mouseover', function(){
                        $(this).stop(true).animate({paddingTop: op.slideRange+'px', paddingBottom: 0}, op.animationInSpeed, op.easing);
                    });
                    target_anim.bind('mouseout', function(){
                        $(this).stop(true).animate({paddingTop:0, paddingBottom: op.slideRange+'px'}, op.animationOutSpeed, op.easing);
                    });
                    break;
                case 'slide_up_fade':
                    target_anim.css({paddingTop : op.slideRange+'px', paddingBottom: 0, opacity: 0.3});
                    target_anim.bind('mouseover', function(){
                        $(this).stop(true).animate({paddingBottom : op.slideRange+'px', paddingTop : 0, opacity: op.fadeOpacity}, op.animationInSpeed, op.easing);
                    });
                    target_anim.bind('mouseout', function(){
                        $(this).stop(true).animate({paddingBottom : 0, paddingTop : op.slideRange+'px', opacity: 0.3}, op.animationOutSpeed, op.easing);
                    });
                    break;
                case 'slide_down_fade':
                    target_anim.css({paddingTop: 0, paddingBottom: op.slideRange+'px', opacity: 0.3});
                    target_anim.bind('mouseover', function(){
                        $(this).stop(true).animate({paddingTop: op.slideRange+'px', paddingBottom: 0, opacity: op.fadeOpacity}, op.animationInSpeed, op.easing);
                    });
                    target_anim.bind('mouseout', function(){
                        $(this).stop(true).animate({paddingTop:0, paddingBottom: op.slideRange+'px', opacity: 0.3}, op.animationOutSpeed, op.easing);
                    });
                    break;
                default:
                alert('Sorry the animation method '+op.animation+' is not available');
            }
        });
        
    };
})(jQuery);
