var isDebug = false, loaded = false, url = "";
function initPage(data){
	if(data&&!data.status){
		$.allset.initWindos(data);
        $.initBaseSet(data);
        (function() {
            SM.ajax('SysOption', 'ChangeTheme', '', '', function(status, txt, json) {
                console.log(json.themeSrc);
                //	document.body.style.backgroundImage="url('"+json.themeSrc+"')";
                $('.wrap_dx')[0].style.backgroundColor = json.bgColor;
                $('.wrap_dx')[0].style.background = (json.layout&&json.layout==1)?("url(" + json.themeSrc + ") repeat top left"):("url(" + json.themeSrc + ")no-repeat top left");
				if(json.posX){
					$('.wrap_dx')[0].style.backgroundPositionX = json.posX;
				}
				if(json.posY){
					$('.wrap_dx')[0].style.backgroundPositionY = json.posY;
				}				
            });
            SM.ajax('SysOption', 'RequestConfigData', '', '', function(status, txt, json) {
                $.setLoginStaut({ "PresenceAfterLogon": json.PresenceAfterLogon });
                $.allset.setLoginStaut({ "PresenceAfterLogon": json.PresenceAfterLogon });
                $.setCheckBox({ key: "AutoLogon", value: json.AutoLogon });
                $("#MoveFolder").val(json.CachePath);
                PcAPI.setCacheTempSize({ size: json.CacheSize });
                $.allset.setClearFolderRadio({ "SaveMyDocument": json.SaveMyDocument });
            });
        })();
		setTimeout(function(){
        if (data.Position == 1) {
            $("li[forcon='wrap_all_set_con']>a").trigger("click");
            $("a:contains('天气设置')").parent().addClass("visit");
            $(".allset_inf").animate({ scrollTop: 1902 }, 1);
        }
        if (data.Position == 2) {
            $("li[forcon='wrap_all_set_con']>a").trigger("click");
            $("a:contains('提醒')").parent().addClass("visit");
            $(".allset_inf").animate({ scrollTop: 754 }, 1);
        }
		},50);
	}else{
		setTimeout(function(){
			var data = PcAPI.InitConfigData();
			initPage(data);
			},50);
		
	}

}
function AfterSMCompleted() {
    if (!loaded) {
        console.log('V5OptionSetting After sm.Created..');
        initPage();
        loaded = true;
    }
}
$(document).ready(function() {

});
(function($) {
    (function() {
        $('#tabs_set li').each(function(k, v) {
            $(v).bind('click', changeTab);
        });

        function changeTab(e) {
            $('#tabs_set li').each(function(k, v) {
                if (e.target.tagName == "A") {
                    if (v.firstChild === e.target) {
                        $(v).addClass("on");
                        $("#" + $(v).attr("forcon")).show();
                        //修复当切换到全部设置时候，滚动条定位问题。
                        if ($(v).attr("forcon") == "wrap_all_set_con")
                            window.location = $(".all_set").find(".visit a").attr("href");
                    } else {
                        $(v).removeClass("on");
                        $("#" + $(v).attr("forcon")).hide();
                    }
                }

            });
        }
    })();

    $(document).bind("keydown", function(e) {
        if (window.event) // IE
        {
            keynum = e.keyCode
        } else if (e.which) // Netscape/Firefox/Opera
        {
            keynum = e.which
        }
        if (e.ctrlKey && keynum == 65) {
            return false;
        }
    });
})(jQuery)