﻿// JavaScript Document
//-------------------------------------------------
// Quick Pager jquery plugin
// Created by dan and emanuel @geckonm.com
// www.geckonewmedia.com
//
// v1.1
// 18/09/09 * bug fix by John V - http://blog.geekyjohn.com/
//-------------------------------------------------

(function ($) {

    $.fn.quickPager = function (options) {

        var defaults = {
            pageSize: 1,
            currentPage: 1,
            holder: null,
            pagerLocation: "after"
        };

        var options = $.extend(defaults, options);


        return this.each(function () {


            var selector = $(this);
            var pageCounter = 1;

            selector.wrap("<div class='simplePagerContainer'></div>");

            selector.children().each(function (i) {

                if (i < pageCounter * options.pageSize && i >= (pageCounter - 1) * options.pageSize) {
                    $(this).addClass("simplePagerPage" + pageCounter);
                }
                else {
                    $(this).addClass("simplePagerPage" + (pageCounter + 1));
                    pageCounter++;
                }

            });

            // show/hide the appropriate regions
            selector.children().hide();
            selector.children(".simplePagerPage" + options.currentPage).show();

            if (pageCounter <= 1) {
                return;
            }

            //Build pager navigation
            var pageNav = "<ul class='simplePagerNav'>";
            for (i = 1; i <= pageCounter; i++) {
                if (i == options.currentPage) {
                    pageNav += "<li class='currentPage simplePageNav" + i + "'><a rel='" + i + "' href='#'>" + i + "</a></li>";
                }
                else {
                    pageNav += "<li class='simplePageNav" + i + "'><a rel='" + i + "' href='#'>" + i + "</a></li>";
                }
            }
            pageNav += "</ul>";

            if (!options.holder) {
                switch (options.pagerLocation) {
                    case "before":
                        selector.before(pageNav);
                        break;
                    case "both":
                        selector.before(pageNav);
                        selector.after(pageNav);
                        break;
                    default:
                        selector.after(pageNav);
                }
            }
            else {
                $(options.holder).append(pageNav);
            }

            //pager navigation behaviour
            selector.parent().find(".simplePagerNav a").click(function () {

                clearInterval(varCounter);
                $('div ul.paging li').css({ opacity: 1.0 });
                //grab the REL attribute
                var clickedLink = $(this).attr("rel");
                options.currentPage = clickedLink;

                if (options.holder) {
                    $(this).parent("li").parent("ul").parent(options.holder).find("li.currentPage").removeClass("currentPage");
                    $(this).parent("li").parent("ul").parent(options.holder).find("a[rel='" + clickedLink + "']").parent("li").addClass("currentPage");
                }
                else {
                    //remove current current (!) page
                    $(this).parent("li").parent("ul").parent(".simplePagerContainer").find("a.currentPage").removeClass("currentPage");
                    //Add current page highlighting
                    $(this).parent("li").parent("ul").parent(".simplePagerContainer").find("a[rel='" + clickedLink + "']").addClass("currentPage").parent("li");
                }

                //hide and show relevant links
                selector.children().hide();
                selector.find(".simplePagerPage" + clickedLink).show();

                return false;
            });
        });
    }


})(jQuery);

function webs_destacades() {

    $("div#focusprev a").addClass("focusnone");

    var cont = 0;
    var total = $("#boxes ul li").length / 6;

    if ((Math.round(total) - total) >= 0) { total = Math.round(total) }
    else { total = Math.round(total) + 1 };


    $("div#focusprev").mouseover(function () {
        $(this).css("cursor", "pointer");

    });


    $("div#focusnext").mouseover(function () {
        $(this).css("cursor", "pointer");

    });


    $("div#focusnext").click(function () {

        if (cont == 0) {
            $("div#focusprev a").removeClass("focusnone");
            $("div#focusnext a").addClass("focusnone");
        }
        if (cont < total - 1) {

            $("#boxes ul").animate({ "left": "-=965px" }, 'normal');

            cont++;
            if (cont == total - 1) { //$("div#focusnext").fadeOut('slow'); 
            }
        }
    });

    $("div#focusprev").click(function () {
        if (cont < total) {
            $("div#focusnext a").removeClass("focusnone");
            $("div#focusprev a").addClass("focusnone");
        }

        if (cont <= total && cont != 0) {
            $("#boxes ul").animate({ "left": "+=965px " }, 'normal');
            cont--;
        }
        if (cont == 0) { //$("div#focusprev").fadeOut('slow'); 
        }
    });
}


function theRotator() {
    //Set the opacity of all images to 0
    $('div ul.paging li').css({ opacity: 0.0 });

    //Get the first image and display it (gets set to full opacity)
    $('div ul.paging li:first').css({ opacity: 1.0 });

    //Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
    varCounter = setInterval('rotate()', 5000);
}

function rotate() {
    //Get the first image
    var current = ($('div ul.paging li.show') ? $('div ul.paging li.show') : $('div ul.paging li:first'));
    var currentboton = ($('div ul.simplePagerNav li.currentPage') ? $('div ul.simplePagerNav li.currentPage') : $('div ul.simplePagerNav li:first'));


    if (current.length == 0) current = $('div ul.paging li:first');
    if (currentboton.length == 0) currentboton = $('div ul.simplePagerNav li:first');

    //Get next image, when it reaches the end, rotate it back to the first image
    var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div ul.paging li:first') : current.next()) : $('div ul.paging li:first'));
    var nextboton = ((currentboton.next().length) ? ((currentboton.next().hasClass('currentPage')) ? $('div ul.simplePagerNav li:first') : currentboton.next()) : $('div ul.simplePagerNav li:first'));

    //Set the fade in effect for the next image, the show class has higher z-index
    next.css({ opacity: 0.0 })
	.addClass('show')
	.animate({ opacity: 1.0 }, 1000);

    nextboton.addClass('currentPage');
    nextboton.children('a').addClass('currentPage');

    //Hide the current image
    current.animate({ opacity: 0.0 }, 1000)
	.removeClass('show');

    currentboton.removeClass('currentPage');
    currentboton.children('a').removeClass('currentPage');
};
