﻿
$(document).ready(function() {
    var Play_list_a = "#play_list a";
    var Play_list_a_not = "#play_list a:not(:first-child)";
    var Play_list_a_first = "#play_list a:first-child";
    var Play_text_li_first = "#play_text li:first-child";
    var Play_text_li = "#play_text li";
    var Play_info = "#play_info";
    var Play = "#play";
    bcheck = false;
    dynamicdisplay(Play_list_a, Play_list_a_not, Play_list_a_first, Play_text_li_first, Play_text_li, Play_info, Play);

    SetSelect();
})

function dynamicdisplay(Play_list_a, Play_list_a_not, Play_list_a_first, Play_text_li_first, Play_text_li, Play_info, Play) {
    var t = n = 0, count = $(Play_list_a).size();
    $(function() {
        $(Play_list_a_not).hide();
        $(Play_info).html($(Play_list_a_first).find("img").attr('alt'));
        $(Play_text_li_first).css({ "background": "#fff", 'color': '#000' });
        $(Play_info).click(function() { document.location.href = $(Play_list_a_first).attr('href') }); //window.open($(Play_list_a_first).attr('href'), "_parent")
        //        $(Play_text_li).click(function() {
        //            var i = $(this).text() - 1;
        //            n = i;
        //            if (i >= count) return;
        //            $(Play_info).html($(Play_list_a).eq(i).find("img").attr('alt'));
        //            $(Play_info).unbind().click(function() { document.location.href = $(Play_list_a).eq(i).attr('href') })//  window.open($(Play_list_a).eq(i).attr('href'), "_parent")
        //            $(Play_list_a).filter(":visible").fadeOut(500).parent().children().eq(i).fadeIn(1000);
        //            $(this).css({ "background": "#fff", 'color': '#000' }).siblings().css({ "background": "#000", 'color': '#fff' });
        //        });
        $(Play_text_li).each(function(mm) {
            $(this).click(function() {
                var i = mm;
                n = i;
                if (i >= count) return;
                $(Play_info).html($(Play_list_a).eq(i).find("img").attr('alt'));
                $(Play_info).unbind().click(function() { document.location.href = $(Play_list_a).eq(i).attr('href') })//  window.open($(Play_list_a).eq(i).attr('href'), "_parent")
                $(Play_list_a).filter(":visible").fadeOut(500).parent().children().eq(i).fadeIn(1000);
                $(this).css({ "background": "#fff", 'color': '#000' }).siblings().css({ "background": "#000", 'color': '#fff' });
            });
        });
        t = setInterval(function() {
            n = n >= (count - 1) ? 0 : ++n;
            $(Play_text_li).eq(n).trigger('click');

        }, 5000);
        // $(Play).hover(function() { clearInterval(t) }, function() { t = setInterval(function() { showAuto(Play_list_a, Play_text_li); }, 5000); });

    })
}

function dynamicdisplay222(Play_list_a, Play_list_a_not, Play_list_a_first, Play_text_li_first, Play_text_li, Play_info, Play) {
    var t1 = n1 = 0, count1 = $(Play_list_a).size();
    //alert(Play_list_a);
    $(function() {
        $(Play_list_a_not).hide();
        $(Play_info).html($(Play_list_a_first).find("img").attr('alt'));
        $(Play_text_li_first).css({ "background": "#fff", 'color': '#000' });
        $(Play_info).click(function() { window.open($(Play_list_a_first).attr('href'), "_blank") });
        $(Play_text_li).click(function() {
            var i1 = $(this).text() - 1;
            n1 = i1;
            if (i1 >= count1) return;
            $(Play_info).html($(Play_list_a).eq(i1).find("img").attr('alt'));
            $(Play_info).unbind().click(function() { window.open($(Play_list_a).eq(i1).attr('href'), "_blank") })
            $(Play_list_a).filter(":visible").fadeOut(500).parent().children().eq(i1).fadeIn(1000);
            $(this).css({ "background": "#fff", 'color': '#000' }).siblings().css({ "background": "#000", 'color': '#fff' });
        });
        t1 = setInterval(function() {
            // alert(Play_list_a+n1);
            n1 = n1 >= (count1 - 1) ? 0 : ++n1;
            $(Play_text_li).eq(n1).trigger('click');

        }, 3000);
        // $(Play).hover(function() { clearInterval(t) }, function() { t = setInterval(function() { showAuto(Play_list_a, Play_text_li); }, 5000); });

    })
}

function showAuto(Play_list_a1, Play_text_li1) {
    //    var Play_list_a_ab = "#play_list a";;
    //    var Play_text_li_ab = "#play_text li";
    var count = $(Play_list_a1).size();
    n = n >= (count - 1) ? 0 : ++n;
    $(Play_text_li1).eq(n).trigger('click');
}

function SubCategoryImageDisplay() {
    var maxValue = 0;
    //p[id = 'pimage']
    $(".P_Image > .ProductsImageStyle").each(function(i) {
        if ($(this).height() > maxValue)
            maxValue = $(this).height();
    })

    $(".P_Image > .ProductsImageStyle").each(function(i) {
        $(".P_Image").height(maxValue);
        var values = ($(".P_Image").height() - $(this).height()) / 2;
        $(this).css({ "padding-top": values });
    })
}

function TopCategoryImageDisplay() {
    var maxHeight = 0;
    $(".content-txtbox-noshade .ProductsImageStyle").each(function() {
        if ($(this).height() > maxHeight)
            maxHeight = $(this).height();
    })

    $("div[id=abc]").each(function(i) {
        $(this).height(maxHeight + 80);
    })

}

function SelectAllCheckBox() {
    bcheck = !bcheck;
    if (bcheck == null)
        bcheck = true;

    $("div[id=CheckBoxDiv] > :checkbox").each(function(i) {
        $(this).attr("checked", bcheck);
    })
}

function SetWorldWidePartner() {
    var maxHeight = 0;
    $("#play_list_1 img").each(function(i) {
        if ($(this).height() > maxHeight)
            maxHeight = $(this).height();
    })
    $("#play_list_1").height(maxHeight);
    //    $("#play_list_1 img").each(function(i) {
    //        var a = (maxHeight - $(this).height()) / 2;
    //        $(this).css({ "margin-top": a });
    //    })
}

function QueryString(fieldName) {
    var urlString = document.location.search;
    if (urlString != null) {
        var typeQu = fieldName + "=";
        var urlEnd = urlString.indexOf(typeQu);
        if (urlEnd != -1) {
            var paramsUrl = urlString.substring(urlEnd + typeQu.length);
            var isEnd = paramsUrl.indexOf('&');
            if (isEnd != -1) {
                return paramsUrl.substring(0, isEnd);
            }
            else {
                return paramsUrl;
            }
        }
        else {
            return null;
        }
    }
    else {
        return null;
    }
}



//second version
function SetSelect() {
    var value = ".nav4 a[href*='" + QueryString("c") + "']";
    $(value).each(function(i) {
        if ($(this).parent("li").hasClass("first")) {
            $(this).parent("li").children("a").addClass("selected");
            $(this).parents("li:not(.first)").children("a:first").addClass("expanded");
            //alert($(this).parents("li:not(.first)").children("a:first").hasClass("expanded"));
            //            $(this).parent("li").parent("ul").parent("div.slide").css({ "display": "block" });
            //            $(this).parent("li").parent("ul").parent("div.slide").prev().each(function(i) {
            //                $(this).addClass("expanded"); });
            $(this).parents("div.slide").each(function(i) { $(this).css({ "display": "block" }) });
        }
        else {
            if (($(this).attr("id") == "firstlevel") || ($(this).attr("id") == "seclevel")) {
                if ($(this).parent("li").children("div.slide").children("ul").html() == "") {
                    $(this).parent("li").children("div.slide").hide();
                    $(this).parent("li").children("a").addClass("expanded");
                }
                else {
                    $(this).parent("li").children("a").addClass("expanded");
                    $(this).parent("li").children("div.slide").css({ "display": "block" });
                }
            } else {

            }
            //   alert("succ");
        }
    });
}

function MenuClick() {
    var count = $("a[id=firstlevel]").size();
    $("a[id=firstlevel]").each(function(m) {
        $(this).click(function() {
            $("a[id=firstlevel]").each(function(i) {
                $(this).parent("li").children("div.slide").css({ "display": "none" });
                $(this).removeClass("expanded");
                $(".rootGroup a.selected").each(function(i) { $(this).removeClass("selected"); })
            });
            if ($(this).parent("li").children("div.slide").children("ul").html() == "") {
                $(this).addClass("expanded");
            }
            else {
                $(this).parent("li").children("div.slide").css({ "display": "block" });
                $(this).addClass("expanded");
                //   alert($(this).parent("li").children("div.slide").children("ul").html());
            }
//            if (m == count - 3) {
//                alert(m);
//                alert(count);
//                $("#ContactUsDetail").hide();
//                $("#loginDiv").hide();
//                $("div[id$=ContactFormDiv]").show();
//            }
//            else if (m == count - 4) {
//                $("#ContactUsDetail").hide();
//                $("div[id$=ContactFormDiv]").hide();
//                $("#loginDiv").show();
//            }
        });
    });

    $("a[id=seclevel]").each(function(i) {
        $(this).click(function() {
            $("a[id=seclevel]").each(function(i) {
                $(this).parent("li").children("div.slide").css({ "display": "none" });
                $(this).removeClass("expanded");
                $("div.slide a.selected").each(function(i) { $(this).removeClass("selected"); })
            });
            if ($(this).parent("li").children("div.slide").children("ul").html() == "") {
                $(this).addClass("expanded");
            }
            else {
                $(this).parent("li").children("div.slide").css({ "display": "block" });
                $(this).addClass("expanded");
                //   alert($(this).parent("li").children("div.slide").children("ul").html());
            }
        });
    });
}

function ChangeTitle(title) {
    document.title = title;
}





