﻿$ektron(document).ready(function() {
    //  q = "t=" + $ektron("#ctl00_content_uxotherrelated_hid").val() + "&type=N"
    //getData("div.related_news_items", "_relatedItems.aspx", q, "GET");

    $ektron('#related_detail_container ul > li > span').click(function() {
        $ektron("#related_detail_container ul > li > span").attr("class", "nonactive");
        var pos = $ektron(this).attr("name");
        pos = pos.substring(1);
        var q;
        tabEvent(this, "div.related_tab_container");
        switch (pos) {
            case "0":
                break;
            case "1":
                q = "t=" + $ektron("#ctl00_content_uxotherrelated_hid").val() + "&type=S";
                getRelatedData("div.related_headlines", "_relatedItems.aspx", q, "GET", "divsupimg", 0);
                break;
            case "2":
                q = "t=" + $ektron("#ctl00_content_uxotherrelated_hid").val() + "&type=P";
                getRelatedData("div.related_products", "_relatedItems.aspx", q, "GET", "divprodimg", 1);
                break;
            case "3":
                q = "t=" + $ektron("#ctl00_content_uxotherrelated_hid").val() + "&type=C";
                getData("div.related_class_items", "_relatedItems.aspx", q, "GET");
                break;
        }
        //setLoads();


    });


    function getRelatedData(divClass, ajaxPage, dataParms, ajaxType, divtoinject, type) {
        loaderSwitch(divClass);
        $ektron.ajax
    ({
        type: ajaxType,
        url: rootFolder + ajaxPage,
        data: dataParms,
        cache: false,
        success:
                function(ret) {
                    if (ret != "NA") {
                        $ektron(divClass).fadeOut(350, function() {
                            $ektron(divClass).html(ret).fadeIn(350);
                        });
                    }
                    else {
                        $ektron(divClass).html("");
                        if (type == 0) { $ektron("div.related_suppliers").html("Were sorry, there are no related suppliers at this time"); }
                        else
                        { $ektron("div.related_product_items").html("Were sorry, there are no related products at this time"); }
                    }

                },
        error:
            function(xReq, stat) {
                $ektron(divClass).fadeOut(350, function() {
                    $ektron(divClass).html("Unable to process request at this time").fadeIn(350);
                });
            }
    });

    }

    function setLoads() {
        eLoad("div.related_headlines", "div.related_suppliers", "_relatedsupplier.aspx", "id", "GET", "rel_sup_nonactive", "rel_sup_active", "value", "div", true);
        eLoad("div.related_products", "div.related_product_items", "_relatedproduct.aspx", "id", "GET", "prodrel_sup_nonactive", "prodrel_sup_active", "value", "div", true);

    }

});