//Import JS Libraries
TTF.Common.include('js', 'libs/ui/scroller/jCarouselLite/jcarousellite_1.0.1.min.js', true);
//TTF.Common.include('css', 'libs/ui/dialog/floatpopup/float_popup.css',true);

$j(document).ready(function() {
    handleEvent();
    initScroller();

    //TTF.Common.include('js', 'libs/ui/dialog/floatpopup/float_popup.js',true);
});


//------------------------------------------------------------------------------

function handleEvent() {
    //TIm san pham theo thuong hieu
    $j('#brand_id').change(function() {
       var url = TTF.Common.base_url + 'web/index.php?do=product/ctrl:listProducts&cid=' + $j(this).val();
       window.location = url;
       return false;
    });

    //TIm san pham theo khoang gia
    $j('#price_range').change(function() {
       var url = TTF.Common.base_url + 'web/index.php?do=product/ctrl:listProducts&price_range=' + $j(this).val();
       window.location = url;
       return false;
    });

    $j('#search').keypress(function(e) {
        var code = (e.keyCode ? e.keyCode : e.which);
         if(code == 13) { //Enter keycode
              searchProduct();
              return false;
         }
    });


    $j('#search').focus(function() {$j(this).val('');});

    $j('#btn_search').click(function() {
        searchProduct();
        return false;
    });

    //hien thi hinh anh danh muc khi di chuot len dm goc-----------
    $j('.root_cat_link').mouseover(function() {
        var cat_root = $j(this).attr('rel');

        $j.get(TTF.Common.base_url + 'web/index.php?do=product/ajax:getFeaturedProductByCategoryId&cid=' + cat_root, function(data) {
            if (data != '') $j('#cat_img_' + cat_root).html(data);
        });
    });

    //hien thi sp tieu khi di chuyen chuot len danh muc con -----------
    $j('.child_cat_link').mouseover(function() {
        var cat = $j(this).attr('rel').split('>');
        var cat_root = cat[0];
        var cat_child = cat[1];

        $j.get(TTF.Common.base_url + 'web/index.php?do=product/ajax:getFeaturedProductByCategoryId&cid=' + cat_child, function(data) {
            if (data != '') $j('#cat_img_' + cat_root).html(data);
        });
    });

}


function searchProduct() {
    if ($j('#search').val() == '') {
        $j('#search').val('nhập tên sản phẩm cần tìm...');
    }
    else {
        $j('#frm_search').submit();
    }
}


function showProductTip() {
    //show tooltip
    $j("a.cluetip").cluetip({
        clickThrough: true,
        ajaxCache: false,
        positionBy: 'bottomTop',
        showTitle: false,
        //dropShadow: true,
        width: 300
    });

}


function initImagePreview() {
    //View Full Product Image
    TTF.Common.include('js', 'libs/ui/tooltip/imagepreview.js',true);
    imagePreview();
}

function initLightBox() {
    TTF.Common.include('js', 'libs/ui/lightbox/jquery.lightbox-0.5.js',true);
    TTF.Common.include('css', 'libs/ui/lightbox/jquery.lightbox-0.5.css',true);

    $j('a[rel=lightbox]').lightBox({
        fixedNavigation: true
    });
}

function initScroller() {
    $j(".auto .jCarouselLite").jCarouselLite({
        auto: 1500,
        speed: 1000,
         visible: 5
    });

}
