/*
 * 	ozListManager - jQuery plugin
 *	written by fabio munhoz [oz]	
 *	http://fabiomunhoz.com
 *
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */
 

(function($){
    $.fn.ozListManager = function(options) {
 
	 // default options
	 var defaults = {
		 firstItem: 'first',
		 lastItem: 'last',
		 mouseOver: 'hover',
		 active: 'active',
		 activeHover: 'activeHover',
		 oddEven: true,
		 oddItem: 'odd',
		 evenItem: 'even'
	 };
 
	 options = $.extend(defaults, options);
 
	 return this.each(function(){
		 
		 format = function  (el, i, total)
		 {
			
			// odd even
			if(options.oddEven)
			{
				if(i % 2 == 0 )
				{
					$(el).addClass(options.oddItem);
				}
				else if(i % 2 > 0)
				{
					$(el).addClass(options.evenItem);
				}
			}
            
            // first
			if(i == 0 )
			{
				$(el).addClass(options.firstItem);
			}
			// last
			else if(i == (total-1 ))
			{
				$(el).addClass('last');
			}
            
			// hover
			$(el).hover(
			  function () {
				 if( $(this).attr('rel') == "active" )
				 { 
					$(this).addClass("activeHover");
					$(this).removeClass("active");
					$(this).removeClass("hover");
				 }
				 else 
				 {
					$(this).addClass("hover");
				 } 
			    
			  },
			  function () {
				 if( $(this).attr('rel') == "active" )
				 { 
					$(this).removeClass("activeHover");
					$(this).addClass("active");
					$(this).removeClass("hover");
				 }
				 else
				 {
					$(this).removeClass("hover");
				 }			  
			  }
			);
			// click
			$(el).click(
			  function () {
				 if( $(this).attr('rel') == "active" )
				 { 
					$(this).removeClass("active"); 
                    $(this).removeClass("hover"); 
					$(this).attr("rel","");
				 	$(this).removeClass("activeHover"); 
			  	 }
				 else 
				 {
					$(this).addClass("active"); 
				 	$(this).attr("rel","active");
                    $(this).removeClass("hover"); 
				 } 
			  }
			);
		 }
		if($(this).has("tr").length > 0) var tag = 'tr'; 
		if($(this).has("li").length > 0) var tag = 'li';
		if($(this).has("dt").length > 0) var tag = 'dt';
		// loop nas tags encontradas
		var el = $(this).find(tag);
		var totEl = el.length;
		// formata as linhas encontradas com a função format
		el.each(function(index)
		{
			format ($(this), index, totEl)
		})
        
		// DL necessita de 2 tags, dt e dd, sendo necessário repetir o procedimento
		if(tag == 'dt') 
		{
			var el2 = $(this).find('dd');
			var totEl2 = el2.length;
			el2.each(function(index)
			{
				format ($(this), index, totEl2)
			})
		}
        
        // Para o thead, é incluida uma class 'ex: th1,th2' para que seja possível customizar a largura de cada coluna via css
        if(tag == 'tr')
        {
            $(this).parent().find('th').each( function ( index ){
                $(this).addClass('th' + index)
            })
        }
		
		 
	 });
    };
})(jQuery);

/*
 * 	ozAccordion - jQuery plugin
 *	written by fabio munhoz [oz]	
 *	http://fabiomunhoz.com
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */
 

(function($){
    $.fn.ozAccordion = function(options) {
 
	 // default options
	 var defaults = {
		 easing         :   'easeOutCubic',
         duration       :   500,
         headerStyle    :   'accordion-heading',
         contentStyle   :   'accordion-content',
         openIndex      :   null /* starting index at 0 */
	 };
 
	 options = $.extend(defaults, options);
 
	 return this.each(function(index){
		 
		 //find the heading ex: h2,h3
        var accordionHeading = $(this);
        
        //jQuery's next() method finds the next sibling element
        var accordionContent = accordionHeading.next();
        
        accordionHeading
            .addClass(options.headerStyle)
            .prepend('<span class="' + options.headerStyle + '-status"></span>')
            .wrapInner('<a href="#" class="' + options.headerStyle + '-toggle" role="button"></a>');
            
        accordionContent.addClass(options.contentStyle);
        
        var _height = accordionContent.height();
        
        accordionHeading.bind('close', function(){

            $(this)
                //add closed class
                .addClass(options.headerStyle + '-closed')
                //change the text of the accessible context span to "Show "
                .find('.' + options.headerStyle + '-status').text('Show ');
            
            accordionContent
            
                // animate to 1px height then add class that closes the content
                .stop().animate(
                    { opacity: 0 , height: '1px' }, 
                    { duration: options.duration, specialEasing: { opacity: 'linear', height: options.easing }, 
                    complete: function() { $(this).addClass(options.contentStyle + '-closed'); }
                })
            
                //set aria-hidden attr to true
                .attr('aria-hidden',true);
        });
        
        accordionHeading.bind('open', function(){
            
            $(this)
                //remove closed class
                .removeClass(options.headerStyle + '-closed')
                //change the text of the accessible context span to "Hide "
                .find('.' + options.headerStyle + '-status').text('Hide ');
                
            accordionContent
            
                // returns to the original height and opacity, then removes the close class
                .stop().animate(
                    { opacity: 1 , height: _height }, 
                    { duration: options.duration, specialEasing: { opacity: 'linear', height: options.easing }, 
                    complete: function() { $(this).removeClass(options.contentStyle + '-closed'); }
                })
                
                //set aria-hidden attr to false
                .attr('aria-hidden',false);
        });
        
        if(options.openIndex != null)
        {
            options.openIndex == index ? accordionHeading.trigger('open') : accordionHeading.trigger('close');
        }
        else
        {
            accordionHeading.trigger('close');
        }
        
        accordionHeading.click(function(){
        
            //if the heading has a close class, open it
            $(this).is('.' + options.headerStyle + '-closed') ? $(this).trigger('open') : $(this).trigger('close');
            
             //return false to prevent default anchor click
            return false;
        });
		 
	 });
    };
})(jQuery);


/*
 * 	ozShowCaseMenu - jQuery plugin
 *	written by fabio munhoz [oz]	
 *	http://fabiomunhoz.com
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */
 

(function($){
    $.fn.ozShowCaseMenu = function(options) {
    
     
        // default options
        var defaults = {
             easing         :   'easeOutCubic',
             duration       :   500,
             fadeTo         :   0.5
        };
        
        options = $.extend( defaults, options );
        var element =  this
        return this.each(function(index){
            
            
            $(this).hover(function() // mouse over
            {
                
                $(element).not(this).stop().animate(
                    {"opacity": options.fadeTo}, 
                    { queue: false, duration: options.duration }, options.easing
                );
                
                $(this).stop().animate(
                    {"opacity": 1}, 
                    { queue: false, duration: options.duration }, options.easing
                );
                
            }, function() // mouse out
            {
                 $(element).stop().animate(
                    {"opacity": 1}, 
                    { queue: false, duration: options.duration }, options.easing
                );
            }); 
		 
	    });
       
    };
})(jQuery);

/*
 * 	ozTooltip - jQuery plugin
 *	written by fabio munhoz [oz]	
 *	http://fabiomunhoz.com
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */
 

(function($){
    $.fn.ozTooltip = function(options) {
 
	 // default options
	 var defaults = {
		 easing         :   'easeOutCubic',
         duration       :   500,
         moveTo         :   -160,
         returns        :   -180
	 };
 
	 options = $.extend(defaults, options);
 
	 return this.each(function(index){
    	 var el = $(this);
         var tooltip = $(this).next()
    	 tooltip.css({ opacity: 0 , display: 'none', top: (options.returns) + 'px'})
		 $(el).hover(function() // mouse over
	     {
			
    		tooltip.stop().css({ display: "block" }).animate(
                {"opacity": 1,"top": (options.moveTo ) + 'px'}, 
                { queue: false, duration: options.duration }, options.easing
            );
	     }, function() // mouse out
	     {
	    	 tooltip.stop().animate(
                {"opacity": 0,"top": (options.returns) + 'px' }, 
                { queue: false, duration: options.duration ,complete: 
                        function() { $(this).css({ display: "none" }) }
                }, options.easing);
	     }); 
		 
	 });
    };
})(jQuery);

/*
 * 	ozNavForms - jQuery plugin
 *	written by fabio munhoz [oz]	
 *	http://fabiomunhoz.com
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */
 

(function($){
    $.fn.ozNavForms = function(options) {
 
	 // default options
	 var defaults = {
         duration       :   500
	 };
 
	 options = $.extend(defaults, options);
     var total = 0        
	 return this.each(function(index){
     
        var input = $(this);
        var pasteEventName = ($.browser.msie ? 'paste' : 'input');
		
		function placeHolder ()
		{
				var text = (input.val()).toLowerCase();
				if(text == 'digite aqui') 
				{
					input.val('')
				}
		}
        
        function ChangeFields (e) {
        
            e=e||window.event;
            var k=e.charCode||e.keyCode||e.which;
            if (k >= 8 && k <= 46) { // default keys, see http://www.cambiaresearch.com/c4/702b8cd1-e5b0-42e6-83ac-25f0306e3e25/Javascript-Char-Codes-Key-Codes.aspx
                // prevents after delete, the cursor moves to another element
                return true;
            }
            else
            {
                var maxLength =  input.attr('maxlength');
                var actualLength = input.val().length;
                    
                if( actualLength >= (maxLength) )
                {
                    input.removeClass('active').addClass('inactive')
                    var thisIndex = Number(input.attr('tabindex'));
                    var nextField = $("*[tabindex=" + (thisIndex + 1) + "]")
                    nextField.focus();
                    nextField.addClass ('active')
                }
            }
            
        }
        
        function _selectNext (_el)
        {
            var thisIndex = Number(_el.attr('tabindex'));
            var nextField = $("*[tabindex=" + (thisIndex + 1) + "]");
            nextField.focus();
            nextField.addClass ('active')
        }
        
        function selected ()
        {
            // prevents after selects text, the cursor moves to another element
            return false;
        }
        
        function preventDefault(e) {
            if (e.preventDefault) { //standard browsers
                e.preventDefault()
            } else { // internet explorer
                e.returnValue = false
            }
        }
        
        input.bind("click",placeHolder);
		
        if(input.is('input[type=text]') || input.is('input[type=file]'))
        {
           input.bind("keypress",ChangeFields); 
           input.bind("select",selected);
		   
           input.bind(pasteEventName, function(e) {
                setTimeout(function(e) { 
                    ChangeFields(e); 
                }, 0);
           });
        }
        else if(input.is('select'))
        {
            input.change(function() {
                _selectNext($(this))
            });
        }
        
        /* if not using themes */
        /*
        else if(input.is('input[type=radio]'))
        {
            var label = input.next();
            input.click(function(e) {
                _selectNext($(this));
            })
            label.click(function(e) {
                preventDefault(e)
                input.attr('checked','checked')
                _selectNext(input);
            })
        }
        
        else if(input.is('input[type=checkbox]'))
        {
            var _parent = input.parent().parent();
            var allChecks = $(_parent).length;
            var itensChecked = 0;
            checkAttr = function (){
                itensChecked = 0;
                $(_parent).find('input[type=checkbox]').each( function (){
                    if($(this).attr('rel') == 'checked')
                    {
                        itensChecked++;
                    }
                })
                if( itensChecked >= allChecks) {
                    _selectNext(input);
                }
                else{
                    return false;
                }
                
            }
            
            var label = input.next();
            input.click(function(e) {
               if($(this).attr('rel') == 'checked')
               {
                    $(this).attr('rel','')
                    $(this).attr('checked','')
               }
               else{
                    $(this).attr('rel','checked')
                    $(this).attr('checked','checked')
               }
               checkAttr();
            })
            label.click(function(e) {
                preventDefault(e)
               if(input.attr('rel') == 'checked')
               {
                    input.attr('rel','')
                    input.attr('checked','')
               }
               else{
                   input.attr('rel','checked')
                   input.attr('checked','checked')
               }
                checkAttr();
            })
        }
        */
        
        /* if using uniform theme */
        else if(input.is('input[type=radio]'))
        {
            var label = $(this).parent().find('label');
            input.click(function(e) {
                _selectNext($(this));
            })
            label.click(function(e) {
                _selectNext(input);
            })
        }
        
        else if(input.is('input[type=checkbox]'))
        {
            var _parent = input.parent().parent();
            var allChecks = $(_parent).find('input[type=checkbox]').length;
            var itensChecked = 0;
            //trace(itensChecked)
            checkAttr = function (){
                itensChecked = 0
                $(_parent).find('.checker span').each( function (){
                    if($(this).hasClass('checked'))
                    {
                        itensChecked++;
                    }
                })
                if( itensChecked == allChecks - 1) {
                    _selectNext(input);
                }
                else{
                    return false;
                }
                
            }
            
            var label = input.parent().find('label');
            input.click(function(e) {
               checkAttr();
            })
            label.click(function(e) {
                checkAttr();
            })
        }
        
	 });
    };
})(jQuery);


//]]>


/**
 * jQuery isHovered (http://mktgdept.com/jquery-ishovered)
 * A jQuery plugin to test if an element is currently hovered
 *
 * v0.0.1 - 11 June 2010
 *
 * Copyright (c) 2010 Chad Smith (http://twitter.com/chadsmith)
 * Dual licensed under the MIT and GPL licenses.
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.opensource.org/licenses/gpl-license.php
 *
 * Test if an element is hovered using: $(selector).isHovered() or $.isHovered(selector)
 *
 **/
;(function(b,c){b('*').hover(function(){b(this).data(c,1)},function(){b(this).data(c,0)}).data(c,0);b[c]=function(a){return b(a)[c]()};b.fn[c]=function(a){a=0;b(this).each(function(){a+=b(this).data(c)});return a>0}})(jQuery,'isHovered');
