﻿$(document).ready(function () {

    //uncheck radios when changing groups on quote-request.aspx
    $("input[name=ctl00$cphMain$CARD1]").live('click', function () {
        $("input[name=ctl00$cphMain$CARD2]").attr("checked", false);
        $("input[name=ctl00$cphMain$CARD2]").attr("previousstate", "false");
    });

    $("input[name=ctl00$cphMain$PAPER1]").live('click', function () {
        $("input[name=ctl00$cphMain$PAPER2]").attr("checked", false);
        $("input[name=ctl00$cphMain$PAPER2]").attr("previousstate", "false");
    });

    //Check the Carrier stock radio when choosing one of its childs.
    $("input[name=ctl00$cphMain$PAPER5]").live('click', function () {
        $("input[name=ctl00$cphMain$PAPER4]").attr("checked", true);
        $("input[name=ctl00$cphMain$PAPER4]").attr("previousstate", "true");

        if ($(this).attr("previousstate") == "true") {
            $("input[name=ctl00$cphMain$PAPER5]").attr("previousstate", "false");

            $(this).attr("previousstate", "true");
        }
        else {
            $("input[name=ctl00$cphMain$PAPER5]").attr("previousstate", "false");

            $(this).attr("previousstate", "false");
        }
    });

    //Uncheck radio when clicking.
    $("input:radio").live('click', function () {
        if ($(this).attr("previousstate") == "true")
         {
            $("input[name="+this.name+"]").attr("previousstate", "false");
            $(this).attr("checked", false);
            $(this).attr("previousstate", "false");
        }
        else {
            $("input[name="+this.name+"]").attr("previousstate", "false");
            $(this).attr("checked", true);
            $(this).attr("previousstate", "true");
        }
    });

    //Make you sure you cannot select radios in a non selected category on quote-request.aspx
    $("input[name=ctl00$cphMain$CARD2]").live('click', function () {
        var ParentID = "";

        if ($(this).parent().attr("id") != "") {
            ParentID = $(this).parent().attr("id");
        }
        else {
            ParentID = $(this).parent().parent().attr("id");
        }

        $("input[name=ctl00$cphMain$CARD1]").attr("previousstate", "false");
        $("#" + ParentID + " input[name=ctl00$cphMain$CARD1]:first").attr("checked", true);
        $("#" + ParentID + " input[name=ctl00$cphMain$CARD1]:first").attr("previousstate", "true");
    });

    $("input[name=ctl00$cphMain$PAPER2]").live('click', function () {
        var ParentID = "";

        if ($(this).parent().attr("id") != "") {
            ParentID = $(this).parent().attr("id");
        }
        else {
            ParentID = $(this).parent().parent().attr("id");
        }

        $("input[name=ctl00$cphMain$PAPER1]").attr("previousstate", "false");
        $("#" + ParentID + " input[name=ctl00$cphMain$PAPER1]:first").attr("checked", true);
        $("#" + ParentID + " input[name=ctl00$cphMain$PAPER1]:first").attr("previousstate", "true");
    });

    $("input[name=ctl00$cphMain$PAPER4]").live('click', function () {
        $("input[name=ctl00$cphMain$PAPER5]").attr("checked", false);
        $("input[name=ctl00$cphMain$PAPER5]").attr("previousstate", "false");
    });

    //Rollover effect on links
    $("a.simplehover img, img.simplehover").mouseover(function () {
        $(this).attr("src", $(this).attr("src").replace("-off.", "-on."));
    }).mouseout(function () {
        $(this).attr("src", $(this).attr("src").replace("-on.", "-off."));
    });

    $('input[title!=""]').hint();

    $(".yoxview").yoxview({ lang: language, autoHideInfo: false, autoHideMenu: false, buttonsFadeTime: 0 });

    $('#mycarousel').jcarousel({ buttonNextHTML: "<div>" + Next + "</div>", buttonPrevHTML: "<div>" + Previous + "</div>", start: 1 });

    $('#newsSlideShow').cycle({
        cleartype: 1,
        prev: '.NewsPrev',
        next: '.NewsNext',
        timeout: 0,
        containerResize: 0
    });

    //Validation
    /*$("form").validity(function () {
        $(".txtname").require();
        $(".txttopic").require();
        $(".txtemail").require().match("email");
        $(".txttelephone").require().match("phone");
    });*/

    //Add effect when you just sent an form request. 
    $(".form-confirmation").effect("pulsate", { times: 3 }, 1000);

    $('ul.sf-menu').superfish({
        delay: 500,                            // one second delay on mouseout 
        animation: { opacity: 'show', height: 'show' },  // fade-in and slide-down animation 
        speed: 'fast',                          // faster animation speed 
        autoArrows: true,                           // disable generation of arrow mark-up 
        dropShadows: true                            // disable drop shadows 
    });

    $("a[name^='faq-']").each(function () {
        $(this).click(function () {
            if ($("dd[name^='" + this.name + "']").is(':hidden')) {
                $("dd[name^='" + this.name + "']").slideDown('fast');
                $(this).parent().addClass('open');

            } else {
                $("dd[name^='" + this.name + "']").slideUp('fast');
                $(this).parent().removeClass('open');
            }
            return false;
        });
    });
});

function mycarousel_initCallback(carousel) {
    jQuery('#mycarousel-next').bind('click', function () {
        carousel.next();
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function () {
        carousel.prev();
        return false;
    });
};

