
(function($) {

        $.fn.fade = function(optionsu) {

            options = {
                    name: optionsu.name,
                    pagination: optionsu.pagination,
                    paginationOn: optionsu.paginationOn,
                    transitionSpeed: 400,
                    homeInterval: optionsu.homeInterval
            }

            return this.each(function()
            {
                init(this, options);
            });

            function init(obj, options)
            {

                carouselTimeout = false;
                $currentService = 0;
                
                $('li', obj).each(function()
                {
                    $(this).css('display', 'none');
                });

                $('li', obj).eq(0).css('display', 'block').addClass('active');

                if(options.paginationOn)
                {
                    for(i=0; i<$("li", obj).size(); i++)
                    {
                        $(options.pagination).append('<li><a href="#">'+i+'</a></li>');
                    }

                    $('li:eq(0)', options.pagination).addClass('active');
                }

                function slide()
                {

                    var $oldService=$currentService;

                    $currentService++;

                    if ($currentService==($("li", obj).size()))
                    {
                            $currentService=0;
                    }

                    if(options.paginationOn)
                    {
                        for(i=0; i<$("li", obj).size(); i++)
                        {
                            $('li', options.pagination).removeClass('active');
                        }

                        $("li:eq("+$currentService+")", options.pagination).addClass('active');
                    }
                    
                    $("li:eq("+$oldService+")", obj).fadeOut(options.transitionSpeed, function()
                    {
                            $("li:eq("+$currentService+")", obj).fadeIn(options.transitionSpeed);
                            carouselTimeout=setTimeout(slide,options.homeInterval);
                    });

                }

                setTimeout(slide, options.homeInterval);

                if(options.paginationOn)
                {
                    paginationClick();
                }

                function paginationClick()
                {
                    $('li', options.pagination).each(function()
                    {
                        $(this).click(function()
                        {
                                
                                thisIndex=$(options.pagination).find("li").index(this);

                                if(options.paginationOn)
                                {
                                    for(i=0; i<$("li", obj).size(); i++)
                                    {
                                        $('li', options.pagination).removeClass('active');
                                    }

                                    $("li:eq("+thisIndex+")", options.pagination).addClass('active');
                                }

                                $("li:eq("+$currentService+")", obj).fadeOut(options.transitionSpeed, function()
                                {
                       
                                        $currentService=thisIndex;
                                        $("li:eq("+thisIndex+")", obj).fadeIn(options.transitionSpeed);
                                });
                                
                                return false;
                        });
                    })
                }
            }

        };

})(jQuery);


    /* jQuery
    ``````````````````````````````````````````````````````````````````````````` */


        $(document).ready(function() {

            $('#services').fade({
                    name: '#services',
                    pagination: '#services-circle',
                    paginationOn: true,
                    homeInterval: 10000
            });
            
            $('#testimonials').fade({
                    name: '#testimonials',
                    pagination: '#testimonials-circle',
                    paginationOn: true,
                    homeInterval: 20000
            });
            

                //    carouselTimeout=setTimeout(jQuery.nextService,$homeInterval);


            $('input, textarea').not('input[type="image"]').each(function() {

                $(this).each(function() {

                        var VALUE = $(this).attr('value');

                        $(this).focus(function() {
                                if ($(this).attr('value') == VALUE)
                                        $(this).attr('value', '');
                                $(this).addClass('selected');
                        });
                        $(this).blur(function() {
                                if ($(this).attr('value') == '')
                                        $(this).attr('value', VALUE);
                                $(this).removeClass('selected');
                        });
                });
            });

            function currentlyEq() 
            {
                current = 0;
                urls = this.location.hash;
                if(urls) {
                    $('#software li').each(function() {
                        attr = '#' + $('a', this).attr('id');
                        if(attr == urls) {
                            current = $(this).index();
                        }
                    });                                       
                }
                          
                return current;
            }

            $("#software").tabs({
                selected: currentlyEq(),
                fx: { 
                    height: 'toggle',
                    opacity: 'toggle',
                    duration: 'slow'
                },   
                
                select: function(event, ui) {$('#tab-spinner').fadeIn()},
                load:   function(event, ui) {$('#tab-spinner').fadeOut()}

            });

            $("#portfolio a[rel=image_group]").fancybox({
                    'transitionIn'	:	'elastic',
                    'transitionOut'	:	'elastic',
                    'speedIn'		:	600,
                    'speedOut'		:	200,
                    'overlayShow'	:	true,
                    'autoDimensions' : true,
                    'width' : 260,
                    'height' : 40,
                    'autoScale'           : false,
                    'hideOnContentClick': true,
                    'titlePosition' 	: 'over',
                    'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		    return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + ' <strong>' + title + '</strong></span>';
		}
            });

            
        });
