
// Implementation

    $(document).ready(function(){

        $('.accordion').accordion();
        $('.slider').slider({ speed : "normal", slideBy : parseInt($('.slider').find('.nbslides').val()), labelA: $('.slider').find('.labelA').val(), labelB: $('.slider').find('.labelB').val(), title: $('.slider').find('.title').val() });
        //$('.tooltip').tooltip();
        $('.anchor').animatedlink();
        $('a[rel="bookmark"]').bookmark();
        //$('a.asset').fancybox();

    });


(function($) {

    $.fn.animatedlink = function(options){

        var settings = $.extend({}, $.fn.animatedlink.defaults, options);

        return this.each(function(){
            var caller = $(this);
            caller.click(function(event) {
                event.preventDefault();
                var locationHref = window.location.href;
                var elementClick = caller.attr("href");

                var destination = $(elementClick).offset().top;
                $("html:not(:animated),body:not(:animated)").animate({scrollTop: destination}, settings.speed, function() {
                    window.location.hash = elementClick;
                });
                return false;
            });
        });
    }


    $.fn.animatedlink.defaults = {
        speed: 1000
    }

})(jQuery);

(function(jQuery){
    jQuery.fn.extend({
        accordion: function() {
            return this.each(function() {

                var accordion = $(this);
                accordion.find('.trigger').each(function(){
                    var trigger = $(this);
                    var target = trigger.next('.target');
					target.hide();
                    trigger.toggle(function() {
                        trigger.addClass("active");
                        target.slideDown("slow").fadeIn("fast");
                    }, function() {
                        trigger.removeClass("active");
                        target.slideUp("slow").fadeOut("fast");
                    });

                });

            });
        }
    });
})(jQuery);

(function($) {

    $.fn.tooltip = function(options){

        var tips = this;
        var opts = $.extend({}, $.fn.tooltip.defaults, options);

        var hideDelayTimer = 200;
        var beingShown = false;
        var shown = false;

        return tips.each(function(){

            var trigger = $(this);
            var target = trigger.next('.tips');

            trigger.mouseover(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown) {
                    // don't trigger the animation again
                   return;
                } else {
                    $('.tips').hide();
                    beingShown = true;

                    target.css({
                        top: 0,
                        left: trigger.width() + 10,
                        display: 'block'
                    }).animate({
                        top: '-=' + opts.distance + 'px',
                        opacity: 1
                    }, opts.time, 'swing', function() {
                        beingShown = false;
                        shown = true;
                    });
                }

                return false;
            }).mouseout(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
                    target.animate({
                        top: '-=' + opts.distance + 'px',
                        opacity: 0
                    }, opts.time, 'swing', function () {
                        shown = false;
                        target.css('display', 'none');
                    });

                }, opts.hideDelay);

                return false;
            });


        });
    }

    $.fn.tooltip.defaults = {
        distance: 0,
        time: 250,
        hideDelay: 500
    }

})(jQuery);

(function($) {

    $.fn.slider = function(options){

        var settings = $.extend({}, $.fn.slider.defaults, options);

        return this.each(function(){
            var slider = $(this);
            var ul = jQuery( "ul:eq(0)", slider );
	        var li = ul.children();
	        if ( li.length > settings.slideBy ) {
		        var $next = jQuery( ".next > a", slider );
		        var $back = jQuery( ".back > a", slider );
		        var liWidth = jQuery( li[0] ).width();
		        var animating = false;
		        ul.css( "width", ( li.length * liWidth ) );
		        $next.click(function() {
			        if ( !animating ) {
				        animating = true;
				        offsetLeft = parseInt( ul.css( "left" ) ) - ( liWidth * settings.slideBy );
				        if ( offsetLeft + ul.width() > 0 ) {
					        $back.css( "display", "block" );
					        ul.animate({
						        left: offsetLeft
					        }, settings.speed, function() {
						        if ( parseInt( ul.css( "left" ) ) + ul.width() <= liWidth * settings.slideBy ) {
							        $next.css( "display", "none" );
						        }
						        animating = false;
					        });
				        } else {
					        animating = false;
				        }
			        }
			        return false;
		        });
		        $back.click(function() {
			        if ( !animating ) {
				        animating = true;
				        offsetRight = parseInt( ul.css( "left" ) ) + ( liWidth * settings.slideBy );
				        if ( offsetRight + ul.width() <= ul.width() ) {
					        $next.css( "display", "block" );
					        ul.animate({
						        left: offsetRight
					        }, settings.speed, function() {
						        if ( parseInt( ul.css( "left" ) ) == 0 ) {
							        $back.css( "display", "none" );
						        }
						        animating = false;
					        });
				        } else {
					        animating = false;
				        }
			        }
			        return false;
		        });
		        $next.css( "display", "block" )
			        .parent().after( [ "<p class=\"view_all\">", settings.title, " - total ", li.length, " ( <a href=\"#\">", settings.labelA, "</a> )</p>" ].join( "" ) );
    		        jQuery( ".view_all > a", slider ).click(function() {
			        if ( jQuery( this ).html() == settings.labelA ) {
				        ul.css( "width", "auto" ).css( "left", "0" );
				        $next.css( "display", "none" );
				        $back.css( "display", "none" );
				        jQuery( this ).html( settings.labelB );
			        } else {
				        jQuery( this ).html( settings.labelA );
				        ul.css( "width", ( li.length * liWidth ) );
                        $next.css( "display", "block" );
			        }
			        return false;
		        });
	        } else {
                jQuery( ".next > a", slider ).css( "display", "none" );
                jQuery( ".back > a", slider ).css( "display", "none" );          
            }
        });
    }


    $.fn.slider.defaults = {
        title: "",
        labelA: "view all",
        labelB: "view less",
        speed : "normal",
        slideBy : 2
    }

})(jQuery);


(function($) {

    $.fn.bookmark = function(){

        return this.each(function(){
            var root = $(this);
            root.click(function(e){

                var url = root.attr('href');
                var title = root.attr('title');

                if (document.all) {
                    window.external.AddFavorite(url, title);
                } else if (window.sidebar) {
                    window.sidebar.addPanel(title, url, "");
                }

                e.preventDefault();
                return false;

            });
        });
    }

})(jQuery);

