// 页面
function Page(){
	
	Page.Site = "/";
	Page.ImgUrl = "http://img1.91huo.cn/zn.sj/mini/soft/0906/";
	
	//标签图
	Page.TabImg = { normal:Page.ImgUrl + "soft_tab_bg1.gif", current:Page.ImgUrl + "soft_tab_bg2.gif", mouseover:Page.ImgUrl + "soft_tab_bg3.gif" };
	
	//底部文字
	Page.FootInfo = "本功能所涉及内容均由CP提供，提供内容的CP已承诺承担由于内容的合法性及健康性所引起的争议和法律责任";
	
	//广告轮播参数
	Page.FlashPic = { picWidth:320, numImg:Page.ImgUrl + "trun_num.gif", focusImg:Page.ImgUrl + "trun_num_focus.gif" };
	
	//内容轮播参数
	Page.FlashContent = { conWidth:505, arrowLeftImg:Page.ImgUrl + "index_icon1.gif", arrowRightImg:Page.ImgUrl + "index_icon2.gif", focusLeft:Page.ImgUrl + "index_icon3.gif", focusRight:Page.ImgUrl + "index_icon4.gif" };
	
	//预加载图片
	Page.PreviewPics = [
		Page.ImgUrl + "soft_top_focus.gif",
		Page.ImgUrl + "btn2bg2.gif",
		Page.ImgUrl + "soft_btn1bg2.gif",
		Page.ImgUrl + "soft_icon4.gif",
		Page.ImgUrl + "soft_list_btnlbg2.gif",
		Page.ImgUrl + "soft_list_btnrbg2.gif",
		Page.ImgUrl + "soft_nav_btnbg2.gif",
		Page.ImgUrl + "soft_tab_bg3.gif",
		Page.ImgUrl + "index_icon4.gif",
		Page.ImgUrl + "index_icon3.gif",
		Page.ImgUrl + "trun_num_focus.gif",
		Page.ImgUrl + "soft_buy_btn2.gif",
		Page.ImgUrl + "soft_down_btn2.gif",
		Page.ImgUrl + "soft_exchange_btn2.gif"
	];
}Page();

//头部导航初始化
Page.TopInit = function(){
	var items = Fun.$tag("li", Fun.$id("top_menu")), float = Fun.$id("top_float_menu"), float_item = Fun.$tag("li", float), time;
	function mouseclick(){ if(this.id){ (this.innerHTML.indexOf("分享上传") > -1 || this.innerHTML.indexOf("上传软件") > -1) ? window.open(this.id) : window.location.href = this.id; } }
	Page.TopInit.SetFloatMenuShow = function(obj){ clearTimeout(time); Fun.$position(obj, float, 0, 30); float.style.display = "block"; }
	Page.TopInit.SetFloatMenuHidden = function(){ time = setTimeout(function(){float.style.display = "none";}, 200); }
	float.onmouseover = function(){ clearTimeout(time); }
	float.onmouseout = function(){ time = setTimeout(function(){float.style.display = "none";}, 200); }
	for(var i = 0; i < items.length; i++) if(items[i].innerHTML == "我的地盘") items.remove(items[i]);
	Fun.$action(items, null, null, mouseclick); Fun.$action(float_item, null, null, mouseclick);
};

//标签切换相关
Page.SetTab = function(){
	var tabs = Fun.$tag("li", Fun.$cl("tab_top", "ul")[0]),  divs = Fun.$cl("tab_con", "div"), tempTab, tempCon;
	function mouseover(){ if(tempTab != this){ this.style.backgroundImage = "url(" + Page.TabImg.mouseover + ")"; } }
	function mouseout(){ if(tempTab != this){ this.style.backgroundImage = "url(" + Page.TabImg.normal + ")"; } }
	Page.SetTab.mouseclick = function(obj){
		if(tempTab != obj){
			tempTab.style.backgroundImage = "url(" + Page.TabImg.normal + ")";
			tempCon.style.display = "none"; tempTab.style.cursor = "pointer";
			tempTab = obj; tempCon = divs[parseInt(obj.className)];
			tempTab.style.cursor = "auto";
			obj.style.backgroundImage = "url(" + Page.TabImg.current + ")";
			tempCon.style.display = "block";
		}
	}
	if(tabs.length > 0){
		tempTab = tabs[0]; tempCon = divs[0];
		tempTab.style.backgroundImage = "url(" + Page.TabImg.current + ")";
		tempTab.style.cursor = "auto";
		tempCon.style.display = "block";
		for(var i = 0; i < tabs.length; i++) tabs[i].className = i.toString();
		Fun.$action(tabs, mouseover, mouseout);
	}
};

//获取URL地址参数
function $url(name){
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"), r = window.location.search.substr(1).match(reg);
	if (r != null) return unescape(r[2]); return null;
}

//图片预读加载
Page.Preview = function(){ for(var i = 0; i < Page.PreviewPics.length; i++) document.writeln("<div class=\"preview\"><img src=\"" + Page.PreviewPics[i] + "\" alt=\"\" \/><\/div>"); };

Page.Foot = function(){ document.writeln("<div class=\"footer\">" + Page.FootInfo + "<\/div>"); };

//页面初始化
Page.Init = function(){
	Page.Preview();
};

//页面共用滚动效果
Page.Turn = function(){
	Object.extend = function(destination, source){ for (var property in source)destination[property] = source[property]; return destination; }
	var Class = { create: function(){ return function() { this.initialize.apply(this, arguments); }}};
	Page.Turn.TransformView = Class.create();
	Page.Turn.TransformView.prototype = {
		//容器对象,滑动对象,切换参数,切换数量
		initialize: function(container, slider, parameter, count, options) {
			if(parameter <= 0 || count <= 0) return;
			var oContainer = Fun.$id(container), oSlider = Fun.$id(slider), oThis = this;
			this.Index = 0;//当前索引
			this._timer = null;//定时器
			this._slider = oSlider;//滑动对象
			this._parameter = parameter;//切换参数
			this._count = count || 0;//切换数量
			this._target = 0;//目标参数
			this.SetOptions(options);
			this.Up = !!this.options.Up;
			this.Step = Math.abs(this.options.Step);
			this.Time = Math.abs(this.options.Time);
			this.Auto = !!this.options.Auto;
			this.Pause = Math.abs(this.options.Pause);
			this.onStart = this.options.onStart;
			this.onFinish = this.options.onFinish;
			oContainer.style.overflow = "hidden";
			oContainer.style.position = "relative";
			oSlider.style.position = "absolute";
			oSlider.style.top = oSlider.style.left = 0;
		},
		//设置默认属性
		SetOptions: function(options) {
			this.options = {//默认值
				Up:			true,//是否向上(否则向左)
				Step:		5,//滑动变化率
				Time:		10,//滑动延时
				Auto:		true,//是否自动转换
				Pause:		2000,//停顿时间(Auto为true时有效)
				onStart:	function(){},//开始转换时执行
				onFinish:	function(){}//完成转换时执行
			};
			Object.extend(this.options, options || {});
		},
		Start: function(){
			if(this.Index < 0) this.Index = this._count - 1; else if(this.Index >= this._count) this.Index = 0;
			this._target = -1 * this._parameter * this.Index;
			this.onStart(); this.Move();
		},
		Move: function(){
			clearTimeout(this._timer);
			var oThis = this, style = this.Up ? "top" : "left", iNow = parseInt(this._slider.style[style]) || 0, iStep = this.GetStep(this._target, iNow);
			if (iStep != 0) {
				this._slider.style[style] = (iNow + iStep) + "px";
				this._timer = setTimeout(function(){ oThis.Move(); }, this.Time);
			} else {
				this._slider.style[style] = this._target + "px";
				this.onFinish();
				if (this.Auto) { this._timer = setTimeout(function(){ oThis.Index++; oThis.Start(); }, this.Pause); }
			}
		},
		GetStep: function(iTarget, iNow) {
			var iStep = (iTarget - iNow) / this.Step;
			if (iStep == 0) return 0;
			if (Math.abs(iStep) < 1) return (iStep > 0 ? 1 : -1);
			return iStep;
		},
		Stop: function(iTarget, iNow) {
			clearTimeout(this._timer);
			this._slider.style[this.Up ? "top" : "left"] = this._target + "px";
		}
	};
};Page.Turn();

//首页大图轮播
Page.TurnPic = function(){
	var trunPic = Fun.$id("index_con1_con_turnPic"), trunNum = Fun.$id("index_con1_con_turnNum"), div = trunPic.parentNode, pics = Fun.$tag("li", trunPic), nums = Fun.$tag("li", trunNum);
	trunPic.style.width = (pics.length * Page.FlashPic.picWidth) + "px";
	var turn = new Page.Turn.TransformView(div, trunPic, Page.FlashPic.picWidth, pics.length, { onStart:function(){ Fun.$each(nums, function(o, i){ if(turn.Index == i) o.style.backgroundImage = "url(" + Page.FlashPic.focusImg + ")"; });}, Up:false, onFinish:function(){ Fun.$each(nums, function(o, i){ if(turn.Index != i) o.style.backgroundImage = "url(" + Page.FlashPic.numImg + ")" }); } });
	
	Fun.$each(nums, function(o, i){
		o.onmouseover = function(){ turn.Auto = false; turn.Index = i; turn.Start(); }
		o.onmouseout = function(){ turn.Auto = true; turn.Start(); }
	});
	turn.Start();
};

//首页内容切换
Page.TurnContent = function(){
	var trunCon = Fun.$id("index_con2_scroll_con"), trunTxt = Fun.$id("index_con2_lcon_tab"), turnArrow = Fun.$id("index_con2_lcon_arrow"), cons = Fun.$cl("index_con2_scroll_conc", "div", trunCon), txts = Fun.$tag("li", trunTxt), left = Fun.$cl("left_arrow", "li", turnArrow)[0], right = Fun.$cl("right_arrow", "li", turnArrow)[0];
	trunCon.style.width = (Page.FlashContent.conWidth * cons.length) + "px";
	var turn = new Page.Turn.TransformView(trunCon.parentNode, trunCon, Page.FlashContent.conWidth, cons.length, { onStart:function(){ Fun.$each(txts, function(o, i){ if(turn.Index == i) o.style.color = "#c30"; }); }, Up:false, onFinish:function(){ Fun.$each(txts, function(o, i){ if(turn.Index != i) o.style.color = "#333" }); }, Auto:false });
	Fun.$each(txts, function(o, i){
		o.onmouseover = function(){ turn.Auto = false; turn.Index = i; turn.Start(); }
		o.onmouseout = function(){ turn.Auto = false; turn.Start(); }
	});
	left.onclick = function(){ turn.Auto = false; turn.Index = (turn.Index < 1) ? 0 : turn.Index - 1; turn.Start(); }
	right.onclick = function(){ turn.Auto = false; turn.Index = (turn.Index > cons.length - 1) ? cons.length - 1 : turn.Index + 1; turn.Start(); }
	turn.Start();
};

Page.ImgSwap = function(obj, img, swapImg){
	obj.onmouseover = function(){ this.src = swapImg; }
	obj.onmouseout = function(){ this.src = img; }
}
//首页软件勾选
Page.softchk = function(chk_id){
	var chk_obj = Fun.$id("addsoft_"+chk_id), chkSameFav_obj = Fun.$id("chkSameFav_"+chk_id);
	if ( chkSameFav_obj.checked == true ){
		chkSameFav_obj.checked = false;
		chk_obj.className="addsoft";
	}
	else
	{
		chkSameFav_obj.checked = true;
		chk_obj.className="addsoft_check";	
	}
};

//设置软件广告后置
Page.SetGGInside = function(orgID, targetID){
	var org = document.getElementById(orgID), target = document.getElementById(targetID);
	if(org) if(target) target.innerHTML = org.innerHTML;
}

/****************************公共功能模块****************************/
function Fun(){
	Fun.IEVerPattern = /MSIE( )(\d+(\.\d+)?)/;
	//判断是否IE
	Fun.$ie = (document.all);
	//获取IE版本号
	Fun.$IEVer = (Fun.IEVerPattern.test(window.navigator.userAgent)) ? parseFloat(RegExp.$2) : null;
	//获取ID对象值：（对象ID名）
	Fun.$id = function(id){ return ("string" == typeof id) ? document.getElementById(id) : id; }
	//获取tag对象名集合：（对象Tag标签名）[父对象限定]
	Fun.$tag = function(tagName, parent){ return (parent) ? parent.getElementsByTagName(tagName) : document.getElementsByTagName(tagName) ; }
	//获取Class样式名对象集合：（class样式名），[Tag标签限定]，[父对象限定]
	Fun.$cl = function(cl, objName, parentNodeObj){
		var retnode = [], myclass = new RegExp('\\b' + cl + '\\b'), elem = (parentNodeObj == null) ? document.getElementsByTagName(objName) : parentNodeObj.getElementsByTagName(objName), classes;
		for (var j = 0; j < elem.length; j++) { classes = elem[j].className; if (myclass.test(classes)) retnode.push(elem[j]); }
		return retnode;
	}
	//设置链接文本：（待设置的文本），[链接目标地址]，[链接目标窗口]，[样式]
	Fun.$link = function(txt, url, target, style){ return (url) ? "<a href=\"" + url + "\" " + ((style) ? "style=\"" + style + "\"" : "") + ((target) ? " target=\"" + target + "\"" : "") + ">" + txt + "<\/a>" : txt; }
	//设置对象集合事件：（待设置的对象集合），[鼠标覆盖事件]，[鼠标移开事件]，[鼠标点击事件]，
	Fun.$action = function(objArray, mouseoverHandle, mouseoutHandle, mouseclickHandle){
		if(!objArray || objArray.length < 1) return;
		for(var i = 0; i < objArray.length; i++){
			if(mouseoverHandle) objArray[i].onmouseover = mouseoverHandle;
			if(mouseoutHandle) objArray[i].onmouseout = mouseoutHandle;
			if(mouseclickHandle) objArray[i].onclick = mouseclickHandle;
		}
	}
	//设置目标相对浮动：（对比源对象），（待设置目标对象），[左偏移量]，[上偏移量]
	Fun.$position = function(obj, targetObj, leftOffset, topOffset){
		var temp = obj.offsetParent, left = obj.offsetLeft, top = obj.offsetTop;
		leftOffset = (leftOffset) ? leftOffset : 0; topOffset = (topOffset) ? topOffset : 0;
		while(temp = temp.offsetParent){ left += temp.offsetLeft; top += temp.offsetTop; }
		targetObj.style.left = (left + leftOffset) + "px";targetObj.style.top = (top + topOffset) + "px";
	}
	//设置添加收藏效果：（收藏地址），（收藏标题）
	Fun.$fav = function(url, title){ try{ (Fun.$ie) ? window.external.addFavorite(url, title) : window.sidebar.addPanel(url, title); }catch(e){ alert("收藏失败！请手动操作"); } }
	//设置设为首页效果：（触发源对象），（首页地址）
	Fun.$home = function(obj, url){ try{ obj.style.behavior = "url(#default#homepage)"; obj.setHomePage(url); }catch(e){ if(window.netscape) try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); }catch(e){ alert("您的浏览器不支持此功能！"); } } }
	//获取地址栏中域名
	Fun.$domain = function(url){ return (url.indexOf("http") > -1) ? url.split("/")[2] : url.split("/")[0]; }
	Fun.$each = function(list, fun){ for (var i = 0; i < list.length; i++) { fun(list[i], i); }}
} Fun();


function SelectAll(chkBoxName, checked) {
    var chxBoxs = document.getElementsByName(chkBoxName);
    for (var i = 0; i < chxBoxs.length; i++) {
        if (checked != undefined) {
            chxBoxs[i].checked = checked;
        }
        else {
            chxBoxs[i].checked = !chxBoxs[i].checked;
        }
    }
}
function BatchDownload(platform, chkBoxName, isSupport) {
    isSupport = 1;
    if (isSupport >= 0) {
        var chxBoxs = document.getElementsByName(chkBoxName);
        var ids = '0';
        for (var i = 0; i < chxBoxs.length; i++) {
            var chxBox = chxBoxs[i];
            if (chxBox != null && chxBox.checked) {
                ids += ',' + chxBox.value;
            }
        }
        if (ids.length > 1) {
            window.location.href = 'http://pc.360zhushou.com/soft/all/Controller.ashx?Action=batchDownload&platform=' + platform + '&ids=' + ids;
        }
        else {
            alert('您还未选择任何想要下载的软件.');
        }
    }
    else {
        alert('您须要下载最新的手机助手版本，才能使用该功能。');
    }
}
function ChangeSelectAllState(chkAllId, chkBoxName) {
    var chxBoxs = document.getElementsByName(chkBoxName);
    var ids = '0';
    var checkCount = 0;
    for (var i = 0; i < chxBoxs.length; i++) {
        var chxBox = chxBoxs[i];
        if (chxBox != null && chxBox.checked) {
            checkCount++;
        }
    }
    if (checkCount == chxBoxs.length) {
        $(chkAllId).attr('checked', 'true');
        $(chkAllId).attr('indeterminate', '');
    }
    else if (checkCount > 0) {
        $(chkAllId).attr('indeterminate', 'true');
    }
    else {
        $(chkAllId).attr('indeterminate', '');
        $(chkAllId).attr('checked', '');
    }
}

function ShowLoginDialog(url, title) {
    $('#dialog .iframe iframe').attr('src', url);
    $('#dialog').show();
    $('#dialog .iframe iframe').css('width', '360px');
    if (title) {
        $('#dialog .dialog_title').html(title);
    }
}
function SubmitPayingFrom(formId) {
    $('#' + formId).submit();
    $('#dialog').show();
}
function HideLoginDialog() {
    $('#dialog').hide();
}


