// Menu
var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

function jsddm_open()
{	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}

function jsddm_close()
{	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{	closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}}

$(document).ready(function()
{	$('#jsddm > li').bind('mouseover', jsddm_open);
	$('#jsddm > li').bind('mouseout',  jsddm_timer);});

document.onclick = jsddm_close;
// End menu

$(document).ready(function() {
    
    $('#faq_category').change(function() {
        var optVal = $('#faq_category').val();
        var page = $('#page').val();
        
        $('.faq_main').html('<img src="catalog/view/theme/default/image/ajax-loader.gif" />');
        $.ajax({
            type: "GET",
            url: "index.php?route=faq/faq/ajaxFaqs",
            data: "faq_category_id=" + optVal + "&page=" + page,
            success: function(result){
                $('.faq_main').html(result);
            }
        });
    });

    var activeCat = $('#activeTab').val();
    $('#'+activeCat).addClass('active');

    var activeEle = $('#activeTabMod').val();
    $('#'+activeEle).addClass('active');

    // chuyen thanh dung init va live click lay tung element theo tab1, tab2_tabid_catid
    /*$('ul.tabs li').live('click', function() {
        alert('ac');
    });*/

    /*$('.faq').change(function() {
        $('#loading').html('<img src="catalog/view/theme/default/image/ajax-loader.gif" />');
        var faqId = $("select.faq option:selected").val();
        $.ajax({
            type: "GET",
            url: "index.php?route=faq/faq/detail",
            data: "faq_id=" + faqId,
            success: function(result){
                $('#load_faq').html(result);
                $('#loading').html('');
            }
        });
    });*/

});

function quickSearch() {
    var filter_keyword = $('#filter_keyword').attr('value');
    document.quick_search.action = 'index.php?route=product/search&keyword=' + filter_keyword;
}

function ajaxChangeTab(tabid, catid) {
    /*var activeEle = $('#activeTab').val();
    $('#'+tabid).addClass('active');
    $('#'+activeEle).removeClass('active');
    $('#activeTab').val(tabid);*/
    
    $('ul.tabs li').removeClass('active');
    $('#'+tabid).addClass('active');

    $('#ajaxContent').html('<img src="catalog/view/theme/default/image/ajax-loader.gif" />');

    $.ajax({
        type: "GET",
        url: "index.php?route=product/category/ajaxcategory",
        data: "catid=" + catid,
        success: function(result){
            $('#ajaxContent').html(result);

            // reinit fancybox
            $("a[rel=product_group]").fancybox({
                'transitionIn'        : 'none',
                'transitionOut'        : 'none',
                'titlePosition'     : 'over',
                'titleFormat'        : function(title, currentArray, currentIndex, currentOpts) {
                    return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
                }
            });
        }
    });

}

function ajaxServiceDetail(tabid, catid) {
    var activeEle = $('#activeTabMod').val();
    $('#'+tabid).addClass('active');
    $('#'+activeEle).removeClass('active');
    $('#activeTabMod').val(tabid);

    $('#ajax_service').html('<img src="catalog/view/theme/default/image/ajax-loader.gif" />');
    $.ajax({
        type: "GET",
        url: "index.php?route=service/service/ajaxdetail",
        data: "catid=" + catid,
        success: function(result){
            $('#ajax_service').html(result);            
        }
    });
}

function loadSlideProduct(act, category_id, not_product_id) {
    var limit = $('#limit').val();
    $.ajax({
        type: "GET",
        url: "index.php?route=product/product/loadslideproduct",
        data: "act=" + act + "&category_id=" + category_id + "&not_product_id=" + not_product_id + "&limit=" + limit,
        success: function(result){
            $('#loadNewProduct').html(result);
        }
    });
}

function loadSlideProductDetail(act, category_id, not_product_id) {
    var limit = $('#limit').val();
    $.ajax({
        type: "GET",
        url: "index.php?route=product/product/loadslideproductdetail",
        data: "act=" + act + "&category_id=" + category_id + "&not_product_id=" + not_product_id + "&limit=" + limit,
        success: function(result){
            $('#loadNewProduct').html(result);
        }
    });
}


















