﻿$(document).ready(function () {
    /*BEGIN - search form*/
    var defaultTextSearch = "Tìm kiếm";
    $("#q, #q1")
    .focus(function () {
        if ($(this).val() == defaultTextSearch)
            $(this).val("");
    })
    .blur(function () {
        if ($.trim($(this).val()) == "")
            $(this).val(defaultTextSearch);
    })
    .val(defaultTextSearch);
    /*END - search form*/

    /*BEGIN - dropdown menu*/
    $("ul.dropdown li")
    .mouseover(function () {
        $("ul.dropdown li").removeClass("acTiveLi");
        $(this).addClass("acTiveLi");
    })
    .mouseout(function () {
        $("ul.dropdown li").removeClass("acTiveLi");
        $("ul.dropdown li:first").next().addClass("acTiveLi");
    });

    $("ul.dropdown li:first").next().addClass("acTiveLi");
	$("ul.dropdown li:first").last().removeClass("acTiveLi");
    /*END - dropdown menu*/

    /*BEGIN - detect category de set css*/
    var path = self.location.pathname;

    if (path.length > 1) {
        path = path.substr(1);
        path = path.substr(0, path.indexOf("/"));

        $("#SubCategories a[href='/" + path + "/']").addClass("activedsub");
    };
    /*END - detect category*/

    /*BEGIN - paging cho category tren navigation bar*/
    var categories = $("#SubCategories a");
    if (categories.length > 9) {
        var page = 1;
        var currentPage = 1;
        for (var i = 0; i < categories.length; i++) {
            $("#" + categories.eq(i).attr("id"))
        .attr("rel", "category_page_" + page.toString());

            if ($("#" + categories.eq(i).attr("id")).hasClass("activedsub"))
                currentPage = page;

            if (i % 9 == 8 || (i == categories.length - 1 && i % 9 != 8)) {
                var a = $("<a href=\"#\">Tiếp ...</a>")
            .attr("rel", "category_page_" + page.toString())
            .click(function () {
                $("#SubCategories a").hide();
                var pageShow = parseInt($(this).attr("rel").replace("category_page_", "")) + 1;
                if ($("#SubCategories a[rel='category_page_" + pageShow + "']").length == 0)
                    pageShow = 1;
                $("#SubCategories a[rel='category_page_" + pageShow + "']").show();
                return false;
            });

                $("#" + categories.eq(i).attr("id")).after(a);
                page++;
            }
        }

        currentPage--;
        if (currentPage == 0)
            currentPage = parseInt($("#SubCategories a:last").attr("rel").replace("category_page_", ""));
        $("#SubCategories a[rel='category_page_" + currentPage + "']:last").trigger("click");
    }
    /*END - paging cho category tren navigation bar*/
});

function InputFocus(textdefault, control) {
    text = control.value;
    if (text == textdefault) control.value = "";
}
function InputBlur(textdefault, control) {
    text = control.value;
    if (text == "") control.value = textdefault;
} 


