﻿function HideAllCategory() {
    imgRoot = SiteRootPath + "images/";
    $('#divAllCategory').hide();
    $('#imgCatMenu').attr('src', imgRoot + 'Btn_main_viewall_arrow.gif');
    $('#imgCategory').attr('src', imgRoot + 'Btn_main_viewall.gif');
}

function ToggleAllCategory() {
    //HideCategoryMenu();
    //imgRoot = SiteRootPath + "images/";
    $('#divAllCategory').toggle();
    
    //$('#imgCatMenu').attr('src', imgRoot + 'Btn_main_closeall_right.gif');
    //$('#imgCategory').attr('src', imgRoot + 'Btn_main_closeall.gif');

    
}

function ShowCategoryMenu() {//alert('hi');
    HideAllCategory();
    imgRoot = SiteRootPath + "images/";
    //$('.divCat:first').show();
    $('#imgCatMenu').attr('src', imgRoot + 'Btn_main_viewall_arrow_over.gif');
    $('#imgCategory').attr('src', imgRoot + 'Btn_main_viewall_over.gif');
    /*
    if ($('.divCat').length <= 1) {
        //position = $('#imgCategory').position();
        //height = $('#imgCategory').height();
        //$('.divCat:first').css('top', position.top + height);
        //$('.divCat:first').css('left', position.left);
    }
    //$('#divCatMain').cs
    //$('#divCatMain').appendTo('#tdcatmenucontainer');
    */
    $('#divCatMain').show();
}

function HideCategoryMenu() {
    imgRoot = SiteRootPath + "images/";
    $('.divCat:first').hide();
    
    $('#imgCatMenu').attr('src', imgRoot + 'Btn_main_viewall_arrow.gif');
    $('#imgCategory').attr('src', imgRoot + 'Btn_main_viewall.gif');
}

function hideSubMenu(id) {
    if (checkMouseIn('divTopSub' + id))
        return;

    $('#divTopSub' + id).hide();
}

// toggle category
function HideCategory() {
    $('#divAllCategory').hide();

    imgfn = $('.divCat:first').is(':visible') ? 'Btn_main_viewall_over.gif' : 'Btn_main_viewall.gif';
    $('#imgCategory').attr('src', '<%=Page.ResolveUrl("~/images/") %>' + imgfn);
    $('#imgCategory2').hide();

}


function ToggleCategoryAll() {

	$('#divAllCategory').toggle();

	imgRoot = SiteRootPath + "images/";
	showcatflag = $('#spanShowMainCategoryMenu').text();

	if ($('#divAllCategory').is(':visible')) {
		$('#imgCategory').attr('src', imgRoot + 'Btn_main_closeall.gif');
		
		$('#imgCatMenu').attr('src', imgRoot + 'Btn_main_closeall_right.gif');
		
		
	}
	else {
		//alert('++' + showcatflag + '++');
		
		if(showcatflag == '1') {
			$('#imgCategory').attr('src', imgRoot + 'Btn_main_viewall_over.gif');
			$('#imgCatMenu').attr('src', imgRoot + 'Btn_main_viewall_arrow_over.gif');
		}
		else {
			$('#imgCategory').attr('src', imgRoot + 'Btn_main_viewall.gif');
			$('#imgCatMenu').attr('src', imgRoot + 'Btn_main_viewall_arrow.gif');
		}
	}

	
}

/*------------------------------------------
my account sub menu & notice
--------------------------------------------*/
function showMyAccount(alink) {
    $('#divMyAccount').show();
    pos = $('.LinkMyAccount:first').position();
    $('#divMyAccount').css('left', pos.left - 15);
    $('#divMyAccount').css('top', pos.top + 12);


}

function showLoginPopup() {
    $('#divLoginPopup').show();
    pos = $('#aSignIn').position();

    $('#divLoginPopup').css('left', pos.left);
    $('#divLoginPopup').css('top', pos.top + 12);
    //alert($('#divLoginPopup input:first').attr('id'));
    $('#divLoginPopup input:first').focus();
}

function run_sapphire(idx) {
    newidx = (eval(idx) + 1) % sapphireCount;
    //$('#testlabel').text(newidx);
    $('#divBannerSapphire_' + idx).hide('slide', { direction: 'up' }, 1500);
    $('#divBannerSapphire_' + newidx).slideToggle(1500);
    //$('#imgBannerSapphire_' + newidx).show('slide', {direction: "up"}, 1000);

    setTimeout("run_sapphire('" + newidx + "')", sapphireChangeInterval);
}



function ShowProgress(b) {
    if (b)
        $('#divProgress').show();
    else
        $('#divProgress').hide();
}

function AdjustCategory() {
    pos = $('#tableTopMenu').position();
    h = $('#tableTopMenu').height();
    $('#divAllCategory').css('left', pos.left - 1);
    $('#divAllCategory').css('top', pos.top + h);
    if ($('#divACResult').is(':visible'))
        showACResult();
}


function PositionAutocompleteWGrouping() {
    /* for AutoComplete with Grouping */
    textboxOffset = $('#tbQuery').offset();
    textboxOffset = $("input[id$=tbQuery]").offset();
    $('#suggestions').css('left', textboxOffset.left + 0);
    $('#suggestions').css('top', textboxOffset.top + 24);
}

function AdjustPosition() {
    AdjustCategory();
    AdjustStatusBar();
    PositionPhotoTagButton();
    PositionAutocompleteWGrouping();
    
    
}

function ProcessPostPageLoad() {
    //$('#divLoadingItemMessage').hide();
}

function PositionPhotoTagButton() {//alert('hi');
    if ($('.mainBannerArea').length <= 0)
        return;
        
    $('#divPhotoTag').show();
    height1 = $('#divPhotoTag').height();
    /*
    pos = $('.mainBannerArea:first').position();
    width = $('.mainBannerArea:first').width();
    height = $('.mainBannerArea:first').height();
    */
    pos = $('#tdMainBannerArea').position();
    width = $('#tdMainBannerArea').width();
    height = $('#tdMainBannerArea').height();
    $('#divPhotoTag').css('left', pos.left + width);
    $('#divPhotoTag').css('top', pos.top + height - height1);
}

function AdjustStatusBar() {
    winHeight = $(window).height();
    winWidth = $(window).width();
    sbHeight = $('#divStatusBar').height();
    sbWidth = $('#divStatusBar').width();

    $('#divStatusBar').css('top', winHeight - sbHeight);
    $('#divStatusBar').css('left', (winWidth - sbWidth) / 2);
}

function hideMyAccount() {

    //$('#divMyAccount').width();
    //$('#divMyAccount').height();
    if (checkMouseIn('divMyAccount') || checkMouseIn('divMessageBox'))
        return;

    $('#divMyAccountMessageBox').hide();
    //hflogin = $get('<%=hfLoginPopup.ClientID %>');
    //hflogin.value = '0';
}

function showMessageBox(alink) {
    pos = $('#divMyAccount').position();
    width = $('#divMyAccount').width();
    height = $('#divMyAccount').height();
    //alert(pos.top + ' ' + pos.left);
    $('#divMessageBox').css('top', pos.top);
    $('#divMessageBox').css('left', pos.left + width + 1);


}

function showCartItem() {
    var pos = $('#tableTopMenu').position();
    var w0 = $('#tableTopMenu').width();
    //alert($('#divCartItem').length);
    var w1 = $('#divCartItem').width();
    

    //$('#divCartItem').show();
    //alert(pos.top + ' ' + pos.left + ' ' + w0 + ' ' + w1);
    $('#divCartItem').css('top', pos.top - 10);
    $('#divCartItem').css('left', pos.left + w0 - w1);
    $('.tdopacity50').css('opacity', 0.5);

    $('#divCartItem').show('slide', { direction: 'up' }, 200);
}

function hideCartItem() {
    pos = $('#divCartItem').position();
    h = $('#divCartItem').height();
    w = $('#divCartItem').width();
    //alert(mouseX + ' ' + mouseY + ' ' + pos.left + ' ' + pos.top + ' ' + w + ' ' + h);
    if (checkMouseIn('divCartItem'))
        setTimeout('hideCartItem()', 5000);
    else    
        $('#divCartItem').hide('slide', { direction: 'up' }, 200);
}

function _hideCartItem() {
    $('#divCartItem').hide();
}
