
// INPUT REPLACE TEXT
$.fn.search = function() {
    return this.focus(function() {
        if (this.value == this.defaultValue) {
            this.value = "";
        }
    }).blur(function() {
        if (!this.value.length) {
            this.value = this.defaultValue;
        }
    });
};


// GESTIONE ANNUNCI SLIDER
(function($) {
    $.fn.rotateNews = function(options) {
        defaults = {
            visibile: 0,
            interval: 5000,
            sliders: ".posts"
        }
        var options = $.extend({}, defaults, options);

//        h = $(options.sliders + ":first").height() + 15;
//        $(this).height(h);

        init = function(el) {
            stopNews(el);
            el.items = $(options.sliders, el);
            //hide all not firts
            el.items.not(":eq(" + options.visibile + ")").hide().end();
            el.currentitem = 0;
            startNews(el);
        };
        startNews = function(el) {
            el.newsfn = setInterval(function() { cicla(el) }, options.interval);
        };
        stopNews = function(el) {
            clearInterval(el.newsfn);
        };
        pauseNews = function(el) {
            el.pause = true;
        };
        resumeNews = function(el) {
            el.pause = false;
        };
        cicla = function(el) {
            // don't run if paused
            if (el.pause) return;
            // pause until animation has finished
            el.pause = true;
            // hide current item
            $(el.items[el.currentitem]).fadeOut("slow", function() {
                $(this).hide();
                // move to next item and show
                el.currentitem = ++el.currentitem % (el.items.size());
                $(el.items[el.currentitem]).fadeIn("slow", function() {
                    el.pause = false;
                });
            });
        };
        return this.each(function() {
            //if(this.nodeName.toLowerCase()!= "ul") return;
            init(this);
        }
        ).hover(function() {
            // pause if hovered over
            pauseNews(this);
        },
	        function() {
	            // resume when not hovered over
	            resumeNews(this);
	        }
        );

    };
})(jQuery);

//// ONLOAD
//$(document).ready(function() {
//    $("html").addClass("js");
//    //$(".accordion").accordion();   
//});

