/* 
*	Plugin for www.pontevecchiobologna.it
* 
*	@author: 	Federico pizzutto - http://www.pngised.net
*	@date: 		2009-04-16
*
* 	LICENSE
*	Quest'opera è stata rilasciata sotto la licenza Creative Commons Attribuzione-Condividi allo stesso modo 2.5 Italia.
*	Per leggere una copia della licenza visita il sito web http://creativecommons.org/licenses/by-sa/2.5/it/
*	o spedisci una lettera a Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
*/

// 
//	ACCORDION function for nested Unordered list
//	@required easing jQuery plugin
//	http://www.learningjquery.com/2007/10/a-plugin-development-pattern

(function($) {
    $.fn.accordion = function(options) {
        defaults = {
            open: 99,
            lnkel: "h3",
            sliders: "ul"
        }
        var options = $.extend({}, defaults, options);

        esto = $(this);
        var toggleElement = esto.children(options.sliders);
        var toggler = esto.children(options.lnkel);
        toggleElement.not(":eq(" + options.open + ")").hide();
        toggler.click(function(e) {
            var target = $(e.target);
            if (target.next().is(":hidden")) {
//                toggleElement.slideUp({ duration: 1000, easing: "easeOutQuint" });
//                target.next().slideDown({ duration: 1000, easing: "easeOutExpo" });
                toggleElement.slideUp({ duration: 700 });
                target.next().slideDown({ duration: 700 });
            };
            return false;
        });
    };
})(jQuery);


// 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");
    $(".commento:odd").addClass(" odd");
    $("#ctl00_txtCerca").search();
    $("#insideAnnuncio").rotateNews({sliders: ".annuncio"});
});
