﻿
$(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 SetWorldWidePartner() {
    var maxHeight = 0;
    $("#play_list_1 img").each(function(i) {
        if ($(this).height() > maxHeight)
            maxHeight = $(this).height();
    })
    $("#play_list_1").height(maxHeight);
}

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;
    }
}

// first version 
////function SetSelect() {
////    $(".nav3 a").each(function(i) {
////        var c = $(this).attr("href");
////        if (c.indexOf(QueryString("c")) < 0) {
////            if ($(this).parent("li").hasClass("group")) {
////             
////            }
////            else {
////                $(this).parent("li").css({ "border-left": "solid 7px rgb(255,255,255)" });
////            }
////        }
////        else {
////            $(this).parent("li").css({ "border-left": "solid 7px rgb(156,186,214)" });
////        }
////    });

////    var value = ".nav3 a[href*='" + QueryString("c") + "']";
////    //  alert('c');
////    //   alert(value);
////    $(value).each(function(i) {
////        $(this).parent("li").css({ "border-left": "solid 7px rgb(156,186,214)" }); //, "text-decoration": "none"
////        // alert(value);
////    });
////}

//second version
function SetSelect() {
    ////    $(".nav3 a").each(function(i) {
    ////        var c = $(this).attr("href");
    ////        if (c.indexOf(QueryString("c")) < 0) {
    ////            if ($(this).parent("td").hasClass("group")) {
    ////                //    $(this).parent("li").css({ "border-left": "solid 7px rgb(156,186,214)" });
    ////            }
    ////            else {
    ////                //    $(this).parent("li").css({ "border-left": "solid 7px rgb(255,255,255)" });
    ////            }
    ////        }
    ////        else {

    ////        }
    ////    });

    //////////////////    var value = ".nav3 a[href*='" + QueryString("c") + "']";
    //////////////////    $(value).each(function(i) {
    //////////////////        if ($(this).parent("td").hasClass("group")) {
    //////////////////            $(this).parent("td").children("a").css({ "background-color": "rgb(156,186,214)" });
    //////////////////        }
    //////////////////        else if ($(this).parent("td").hasClass("next")) {
    //////////////////        $(this).parent("td").children("a").css({ "background-color": "rgb(219,230,241)" });

    //////////////////            $(this).parent("td").parent("tr").prevAll().children("td.group:first").each(function(i) {
    //////////////////                    $(this).children("a").css({ "background-color": "rgb(156,186,214)" });
    //////////////////            })
    //////////////////        }
    //////////////////    });

    var value = ".nav4 a[href*='" + QueryString("c") + "']";
    $(value).each(function(i) {
        if ($(this).parent("li").hasClass("first")) {
            //  $(this).parent("li").children("a").addClass("expanded");
            $(this).parent("li").children("a").addClass("selected");
            $(this).parent("li").parent("ul").parent("div.slide").css({ "display": "block" });
            $(this).parent("li").parent("ul").parent("div.slide").prev().each(function(i) {
                //  $(this).children("a").addClass("expanded"); "li.item:first"
                $(this).addClass("expanded");
            })
        }
        else {
            if ($(this).attr("id") == "firstlevel") {
                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 {      }
        }
    });

    var path = ".nav4 a[href*='" + QueryString("p") + "']";
    $(path).each(function(i) {
        if ($(this).parent("li").hasClass("first")) {
            $(this).parent("li").children("a").addClass("selected");
            $(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");
            })
        }
        else {
            if ($(this).attr("id") == "firstlevel") {
                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 { }
        }
    });
}

function MenuClick() {
    $("a[id=firstlevel]").each(function(i) {
        $(this).click(function() {
            $("a[id=firstlevel]").each(function(i) {
                $(this).parent("li").children("div.slide").css({ "display": "none" });
                $(this).removeClass("expanded");
            });
            if ($(this).parent("li").children("div.slide").children("ul").html() == "") {
            }
            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;
}





