$(document).ready(function () {

    $('#mycarousel').jcarousel({
        auto: 1, // Time in seconds to scroll
        scroll: 1, // How many to scroll by each time
        animation: 2000,
        wrap: 'circular'
    });

    $('input[title]').each(function () {
        if ($(this).val() === '') {
            $(this).val($(this).attr('title'));
        }

        $(this).focus(function () {
            if ($(this).val() == $(this).attr('title')) {
                $(this).val('');
            }
        });
        $(this).blur(function () {
            if ($(this).val() === '') {
                $(this).val($(this).attr('title'));
            }
        });
    });

    // for backwards compatability
    $('#top-menu li:last-child').css('border-right', 'none');
    $('#mainmenu li:last-child').css('margin-right', '0px');

    if ($.browser.msie && $.browser.version.substr(0, 1) < 10) {
        $('#mainmenu li:last-child a').not('.dropmenu li').css('padding-right', '23px').css('padding-left', '24px');
    } else {
        $('#mainmenu li:last-child a').not('.dropmenu li').css('padding-right', '25px').css('padding-left', '25px');
    }

    // Gives the rounded corners for all browsers that dont support them
    $('#shop-nav').corner('8px');
    $('#shop-nav-inner').corner('8px top');
    $('#shop-nav-inner').corner('8px bottom cc:#fff');
    $('#currency').corner('5px cc:#d7ad49');
    $('.blackbutton').corner('5px');
    $('.redbutton').corner('5px');
    $('#mainmenu li').corner('5px top');
    $('.tab_container').corner('keep tr br bl 5px');
    $('.category-name a').corner('3px');
    $('#select-author-header').corner('5px');
    $('#select-author-box').corner('5px');
    $('.post-comment').corner('3px');
    $('.become-member').corner('3px');
    $('.togglebio').corner('3px');
    $('.forum-outer').corner('8px');
    $('.forum-outer2').corner('8px');
    $('.forum-inner').corner('8px');
    $('.forum-inner2').corner('8px');
    $('.forum-footer').corner('8px');



    $('.post-comment').toggle(function () {
        $('.postcomment').slideDown('slow');
    }, function () {
        $('.postcomment').slideUp('slow');
    });

    $('.post-bottomcomment').toggle(function () {
        $('.postbottomcomment').slideDown('slow');
    }, function () {
        $('.postbottomcomment').slideUp('slow');
    });

    $('.post-bottomcommentreverse').toggle(function () {
        $('.postbottomcommentreverse').slideUp('slow');
    }, function () {
        $('.postbottomcommentreverse').slideDown('slow');
    });


    // New author tabs
    $('.authorNav a').click(function () {
        // Get this tab
        var thisTab = $(this).href
    });

    try {
        // Tabs code
        $(".tab_content").hide(); //Hide all content
        $(".authorNav a:first").addClass("active").show(); //Activate first tab
        $(".tab_content:first").show(); //Show first tab content

        $('.authorNav a').click(function () {

            if ($(this).hasClass("toggleRedActive")) {
                $(".authorNav a").removeClass("toggleRedActive").addClass('toggleRed'); //Remove any "active" class
                $(".authorNav a").each(function () {
                    $(this).html($(this).html().replace("close", "show"));
                });

                $('.author-page').slideUp();
            } else {
                $(".authorNav a").removeClass("toggleRedActive").addClass('toggleRed'); //Remove any "active" class
                $(".authorNav a").each(function () {
                    $(this).html($(this).html().replace("close", "show"));
                });
                $(this).removeClass('toggleRed').addClass('toggleRedActive'); //Add "active" class to selected tab

                var thisButton = $(this).html();
                if (thisButton.indexOf("show") !== -1) {
                    thisButton = thisButton.replace("show", "close");
                    $(this).html(thisButton);
                }

                $('.author-page').slideDown();
                $(".tab_content").hide(); //Hide all tab content
                var activeTab = $(this).attr("href"); //Find the href attribute value to identify the active tab + content
                $(activeTab).fadeIn(); //Fade in the active ID content
            }
            return false;
        });
    }
    catch (err) { }

    $('#formsubmit').click(function () { $('#login-form').submit(); });
    $('#searchform .submit').click(function () {
        $('#searchform').submit();
    });

    $('#mainmenu ul li').hover(function () {
        $(this).children('.dropmenu').each(function () {
            $(this).show();
        });
    }, function () {
        $(this).children('.dropmenu').each(function () {
            $(this).hide();
        });
    });



    $(".tab_content").hide(); //Hide all content
    $("ul.tabs li a:first").addClass("active").show(); //Activate first tab
    $(".tab_content:first").show(); //Show first tab content

    //On Click Event
    $("ul.tabs li a").click(function () {

        $("ul.tabs li a").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content

        var activeTab = $(this).attr("href"); //Find the href attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active ID content
        return false;
    });

    $('.alternate-images li a').click(function () {
        $('.product_image img').attr('src', $(this).attr('href'));
        return false;
    });


    $('#shopping-basket .blackbutton').hover(function () {
        $('.basketHover').show();
    }, function () {
        $('.basketHover').hide();
    });
    $('.basketHover').hover(function () {
        $(this).show();
    }, function () {
        $(this).hide();
    });

});

function AlterBasket(productID) {
    $.ajax({
        type: "GET",
        url: "/Ajax/AlterBasket.aspx",
        data: "basketID=" + productID + "&amp;rand=" + Math.random(),
        success: function (msg) {
            $(".product" + productID).text("");
            $("#spnDeliveryStatus" + productID).html(msg);
            $(".quickbasket").load('/Ajax/QuickBasket.aspx?rand=' + Math.random());
            $(".numItems").load('/Ajax/ItemCount.aspx?rand=' + Math.random());
            $(".footer-price").load('/Ajax/SubTotal.aspx?rand=' + Math.random());

        },
        error: function (msg) {
            $("#spnDeliveryStatus" + productID).html(msg);
        }


    });

    return false;
}



function OpenLastTab() {
    $(document).ready(function () {
        $("ul.tabs li a").removeClass("active");
        $(".tab_content").hide(); //Hide all content
        $("ul.tabs li a:last").addClass("active").show(); //Activate first tab
        $(".tab_content:last").show(); //Show first tab content
    });

}

function OpenTestimonial() {
    $(document).ready(function () {
        $('#test').trigger('click');
    });
}
