//-------------------------------------------------
//		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 ($) {

    $(document).ready(function () {
        $('#mycolldown').mouseenter(function () {
            $(this).attr('src', '/images/my-collection/pink-mouseover-down.jpg');
        });
        $('#mycolldown').mouseleave(function () {
            $(this).attr('src', '/images/my-collection/black-down.jpg');
        });
        $('#mycollup').mouseenter(function () {
            $(this).attr('src', '/images/my-collection/pink-rollover-up.jpg');
        });
        $('#mycollup').mouseleave(function () {
            $(this).attr('src', '/images/my-collection/black-up.jpg');
        });
        $('#productcommentscrollup').mouseenter(function () {
            $(this).attr('src', '/images/my-collection/pink-rollover-up.jpg');
        });
        $('#productcommentscrollup').mouseleave(function () {
            $(this).attr('src', '/images/my-collection/black-up.jpg');
        });
        $('#productcommentscrolldown').mouseenter(function () {
            $(this).attr('src', '/images/my-collection/pink-mouseover-down.jpg');
        });
        $('#productcommentscrolldown').mouseleave(function () {
            $(this).attr('src', '/images/my-collection/black-down.jpg');
        });
                
        $('.associatedProductContainer').hide();
        var mycount1 = $('.associatedProductContainer').size();
        var pagesCountedAndRounded = Math.ceil(mycount1 / 6);
        $(".pageB").text(pagesCountedAndRounded);
        var currentPage = 1;
        var firstPageVariable = 6;
        //check if the total number of nodes in the repeater is more than 10. if it is the currentpageintplus4 needs to say something different.
        if (mycount1 < 6) {

            firstPageVariable = mycount1;
            $('.productNavigationBar').hide();
        }

        $('.totalPagesInt').text(pagesCountedAndRounded);

        if (currentPage == 1) {
            $('.currentPageInt').text('1');

            $('.currentPageIntPlus4').text(firstPageVariable);
            //$('#previouPage').hide();
            var i = 1;
            while (i < 7) {

                $("#productInList" + i).show();
                i++;
            }
            checkPageReference();

        }
        $(".nextPage").click(function () {
            checkPageReference()
            $('.previouPage img').show();
            if (ieversion != 2) {
                $(".associatedProductContainer").animate({ opacity: "0" });
            }
            firstInQueue = (currentPage * 6) + 1;
            lastInQueue = firstInQueue + 6;
            $('.currentPageIntPlus4').text(firstInQueue);
            if (lastInQueue > mycount1 || lastInQueue == mycount1) {
                //alert("");
                //$('.nextGrey').show();
                $('.nextPage img').hide();
                while (lastInQueue > mycount1) {

                    lastInQueue--;
                }
            }

            $('.currentPageInt').text(firstInQueue);

            currentPage++;
            $('.currentPageIntPlus4').text(lastInQueue);
            for (d = 0; d <= mycount1; d++) {
                $("#productInList" + d).hide();
            }
            $("#productInList" + firstInQueue).show();
            $("#productInList" + (firstInQueue + 1)).show();
            $("#productInList" + (firstInQueue + 2)).show();
            $("#productInList" + (firstInQueue + 3)).show();
            $("#productInList" + (firstInQueue + 4)).show();
            $("#productInList" + (firstInQueue + 5)).show();

            //$("#productInList" + (firstInQueue + 10)).show();

            //$('#previouPage').show();
            //$('#lastgrey').hide();
            if (ieversion != 2) {
                $(".associatedProductContainer").animate({ opacity: "1" });
            }
            if ($('.currentPageIntPlus4').text() == mycount1.toString()) {
                $('.nextPage').hide();
                $('.nextGrey').show();
            } else {
                $('.nextPage').show();
                $('.nextGrey').hide();
            }
            if ($('.currentPageInt').text() == '1') {
                $('.previouPage').hide();
                $('.lastgrey').show();

            } else {
                $('.previouPage').show();
                $('.lastgrey').hide();
            }
            checkPageReference();
            if (ieversion == 2) {
                //alert("ie6");
                jqPngFix();
            }
        });
        $(".previouPage").click(function () {
            $('.nextPage img').show();
            if (ieversion != 2) {
                $(".associatedProductContainer").animate({ opacity: "0" });
            }
            currentPage = currentPage - 1;

            if (currentPage == 1) {
                for (d = 0; d <= mycount1; d++) {
                    $("#productInList" + d).hide();
                }
                $('.currentPageInt').text('1');
                $('.currentPageIntPlus4').text('6');
                $('.nextPage').attr('disabled', 'disabled');
                $('.previouPage img').hide();
                //$('#lastgrey').show();
                //$('#nextGrey').hide();
                //$('#nextPage').show();
                var i = 1;
                while (i < 7) {

                    $("#productInList" + i).show();
                    i++;
                }
            } else {
                firstInQueue = (currentPage * 6) - 5;
                lastInQueue = firstInQueue + 6;

                if (lastInQueue > mycount1 || lastInQueue == mycount1) {
                    $('.nextPage').attr('disabled', 'disabled');
                    // $('#nextGrey').show();
                    // $('#nextPage').hide();
                    while (lastInQueue > mycount1) {
                        lastInQueue--;
                    }
                }

                $('.currentPageInt').text(firstInQueue);


                $('.currentPageIntPlus4').text(lastInQueue);
                for (d = 0; d < mycount1; d++) {
                    $("#productInList" + d).hide();
                }
                // $("#PictureID" + firstInQueue).show();
                $("#productInList" + (firstInQueue + 1)).show();
                $("#productInList" + (firstInQueue + 2)).show();
                $("#productInList" + (firstInQueue + 3)).show();
                $("#productInList" + (firstInQueue + 4)).show();
                $("#productInList" + (firstInQueue + 5)).show();

                //$("#PictureID" + (firstInQueue + 10)).show();
            }
            if (ieversion != 2) {
                $(".associatedProductContainer").animate({ opacity: "1" });
            }
            if ($('.currentPageIntPlus4').text() == mycount1.toString()) {
                $('.nextPage').hide();
                $('.nextGrey').show();
            } else {
                $('.nextPage').show();
                $('.nextGrey').hide();
            }
            if ($('.currentPageInt').text() == '1') {
                $('.previouPage').hide();
                $('.lastgrey').show();

            } else {
                $('.previouPage').show();
                $('.lastgrey').hide();
            }
            checkPageReference();
            if (ieversion == 2) {

                jqPngFix();

            }
        });

        //camera ready style paging

        $('.divEntryContainer').hide();
        var mycount = $('.divEntryContainer').size();
        $('#crstotalPagesInt').text(mycount);

        if (currentPage == 1) {
            $('#crscurrentPageInt').text('1');

            $('#crscurrentPageIntPlus4').text('10');
            //$('#previouPage').hide();
            var i = 1;
            while (i < 11) {

                $("#PictureID" + i).show();
                i++;
            }
        }
        $("#crsNextGallery").click(function () {
            $(".divEntryContainer").animate({ opacity: "0" });
            firstInQueue = (currentPage * 10) + 1;
            lastInQueue = firstInQueue + 10;
            $('#crscurrentPageIntPlus4').text(firstInQueue);
            if (lastInQueue > mycount || lastInQueue == mycount) {
                //$('#nextGrey').show();
                //$('#nextPage').hide();
                while (lastInQueue > mycount) {

                    lastInQueue--;
                }
            }

            $('#crscurrentPageInt').text(firstInQueue);

            currentPage++;
            $('#crscurrentPageIntPlus4').text(lastInQueue);
            for (d = 0; d <= mycount; d++) {
                $("#PictureID" + d).hide();
            }
            //$("#productInList" + firstInQueue).show();
            $("#PictureID" + (firstInQueue + 1)).show();
            $("#PictureID" + (firstInQueue + 2)).show();
            $("#PictureID" + (firstInQueue + 3)).show();
            $("#PictureID" + (firstInQueue + 4)).show();
            $("#PictureID" + (firstInQueue + 5)).show();
            $("#PictureID" + (firstInQueue + 6)).show();
            $("#PictureID" + (firstInQueue + 7)).show();
            $("#PictureID" + (firstInQueue + 8)).show();
            $("#PictureID" + (firstInQueue + 9)).show();
            $("#PictureID" + (firstInQueue + 10)).show();

            //$('#previouPage').show();
            //$('#lastgrey').hide();
            $(".divEntryContainer").animate({ opacity: "1" });
            if ($('#crscurrentPageIntPlus4').text() == mycount.toString()) {
                $('#crsNextGallery').hide();
                $('#Img2').show();
            } else {
                $('#crsNextGallery').show();
                $('#Img2').hide();
            }
            if ($('#crscurrentPageInt').text() == '1') {
                $('#crsPreviousPage').hide();
                $('#Img1').show();

            } else {
                $('#crsPreviousPage').show();
                $('#Img1').hide();
            }
        });
        $("#crsNextPage").click(function () {
            $('#crscurrentPageIntPlus4').text(firstInQueue);
            currentPage--;
            if (currentPage == 1) {
                $('#crsNextGallery').removeAttr('disabled');
                for (d = 0; d <= mycount; d++) {
                    $("#productInList" + d).hide();
                }
                $('#currentPageInt').text('1');
                $('#currentPageIntPlus4').text('4');
                $('#previouPage').hide();
                $('#lastgrey').show();
                $('#nextGrey').hide();
                $('#nextPage').show();
                var i = 1;
                while (i < 5) {

                    $("#productInList" + i).show();
                    i++;
                }
            } else {
                firstInQueue = (currentPage * 4) + 1;
                lastInQueue = firstInQueue + 4;

                if (lastInQueue > mycount || lastInQueue == mycount) {

                    //$('#nextGrey').show();
                    //$('#nextPage').hide();
                    $('#crsNextGallery').attr('disabled', 'disabled');
                    while (lastInQueue > mycount) {
                        lastInQueue--;
                    }
                }

                $('#currentPageInt').text(firstInQueue);


                $('#currentPageIntPlus4').text(lastInQueue);
                for (d = 0; d < mycount; d++) {
                    $("#productInList" + d).hide();
                }
                $("#productInList" + firstInQueue).show();
                $("#productInList" + (firstInQueue + 1)).show();
                $("#productInList" + (firstInQueue + 2)).show();
                $("#productInList" + (firstInQueue + 3)).show();
                $("#productInList" + (firstInQueue + 4)).show();


            }

        });

        $("#crsPreviousPage").click(function () {
            $(".divEntryContainer").animate({ opacity: "0" });
            currentPage--;
            if (currentPage == 1) {
                for (d = 0; d <= mycount; d++) {
                    $("#PictureID" + d).hide();
                }
                $('#crscurrentPageInt').text('1');
                $('#crscurrentPageIntPlus4').text('10');
                $('#crsNextGallery').attr('disabled', 'disabled');
                //$('#previouPage').hide();
                // $('#lastgrey').show();
                //$('#nextGrey').hide();
                //$('#nextPage').show();
                var i = 1;
                while (i < 11) {

                    $("#PictureID" + i).show();
                    i++;
                }
            } else {
                firstInQueue = (currentPage * 10) + 1;
                lastInQueue = firstInQueue + 10;

                if (lastInQueue > mycount || lastInQueue == mycount) {
                    $('#crsNextGallery').attr('disabled', 'disabled');
                    // $('#nextGrey').show();
                    // $('#nextPage').hide();
                    while (lastInQueue > mycount) {
                        lastInQueue--;
                    }
                }

                $('#crscurrentPageInt').text(firstInQueue);


                $('#crscurrentPageIntPlus4').text(lastInQueue);
                for (d = 0; d < mycount; d++) {
                    $("#PictureID" + d).hide();
                }
                // $("#PictureID" + firstInQueue).show();
                $("#PictureID" + (firstInQueue + 1)).show();
                $("#PictureID" + (firstInQueue + 2)).show();
                $("#PictureID" + (firstInQueue + 3)).show();
                $("#PictureID" + (firstInQueue + 4)).show();
                $("#PictureID" + (firstInQueue + 5)).show();
                $("#PictureID" + (firstInQueue + 6)).show();
                $("#PictureID" + (firstInQueue + 7)).show();
                $("#PictureID" + (firstInQueue + 8)).show();
                $("#PictureID" + (firstInQueue + 9)).show();
                //$("#PictureID" + (firstInQueue + 10)).show();
            }
            $(".divEntryContainer").animate({ opacity: "1" });
            if ($('#crscurrentPageIntPlus4').text() == mycount.toString()) {
                $('#crsNextGallery').hide();
                $('#Img2').show();
            } else {
                $('#crsNextGallery').show();
                $('#Img2').hide();
            }
            if ($('#crscurrentPageInt').text() == '1') {
                $('#crsPreviousPage').hide();
                $('#Img1').show();
            } else {
                $('#crsPreviousPage').show();
                $('#Img1').hide();
            }

        });


    });
})(jQuery);
function checkPageReference() {
    switch ($("#topcurrentPageInt").text()) {
        case '1':
            $(".pageA").text('1');
            break;
        case '7':
            $(".pageA").text('2');
            break;
        case '13':
            $(".pageA").text('3');
            break;
        case '19':
            $(".pageA").text('4');
            break;
        case '26':
            $(".pageA").text('5');
            break;
        case '32':
            $(".pageA").text('6');
            break;
        case '38':
            $(".pageA").text('7');
            break;
        case '44':
            $(".pageA").text('8');
            break;
        case '50':
            $(".pageA").text('8');
            break;
        case '56':
            $(".pageA").text('8');
            break;
        case '62':
            $(".pageA").text('8');
            break;
        case '68':
            $(".pageA").text('8');
            break;
        case '74':
            $(".pageA").text('8');
            break;
        default:
            $(".pageA").text('1');
    }
}

