﻿$(function(){
	$('.links_select').change(function(v){
		var url = $(v.currentTarget).val();
		if (url != -1) {
			window.open(url, '_blank');
		}
	});
	correctPNG();
	
	$('div.a46 .a47a').click(function() {
		$('div.a46 .a47a').removeClass('current');
		$(this).addClass('current');
		var index = $('div.a46 .a47a').index(this);
		$('div.a46 .lie').hide().get(index).style.display = 'block';
	});
	
	$('.post img').each(function(i, o) {
		if ($('.post').width() > 700) {
			if ($(o).width() > 900) {
				$(o).width(900);
			}
		} else {
			if ($(o).width() > 610) {
				$(o).width(610);
			}
		}
	});
	
	$('#download-page-featured li:odd').addClass('alternate');
	
	$('.li_3th_sub').hover(function(){
		$('div.div_4th_sub').hide();
		$(this).children().next('div.div_4th_sub').show();
	}, function(){
		//$(this).children().next('div.div_4th_sub').hide();
	});

});

var setHomepage = function(url) {// 设置首页
    if (document.all) {
        document.body.style.behavior = 'url(#default#homepage)';
        document.body.setHomePage(url);
    } else if (window.sidebar) {
        if (window.netscape) {
            try {
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            } catch (e) {
                alert("由于您浏览器的安全设置过高阻止了该功能。\n您可以手动把本站设为首页。");
            	return;
			}
        }
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
        prefs.setCharPref('browser.startup.homepage', url);
    }
};

var addFavorite = function(url, name) { // 加入收藏夹
    if (document.all) {
        window.external.addFavorite(url, name);
    } else if (window.sidebar) {
        window.sidebar.addPanel(name, url, "");
    }
};

var correctPNG = function() {
    var arVersion = navigator.appVersion.split("MSIE");
    var version = parseFloat(arVersion[1]);
    if ((version >= 5.5 && version < 7) && (document.body.filters)) {
        for (var j = 0; j < document.images.length; j++) {
            var img = document.images[j];
            var imgName = img.src.toUpperCase();
            if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
                var imgID = (img.id) ? "id='" + img.id + "' " : "";
                var imgClass = (img.className) ? "class='" + img.className + "' " : "";
                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
                var imgStyle = "display:inline-block;" + img.style.cssText;
                if (img.align == "left") {
                    imgStyle = "float:left;" + imgStyle;
                }
                if (img.align == "right") {
                    imgStyle = "float:right;" + imgStyle;
                }
                if (img.parentElement.href) {
                    imgStyle = "cursor:hand;" + imgStyle;
                }
                var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
                img.outerHTML = strNewHTML;
                j = j - 1;
            }
        }
    }
};

var turnPage = function(pageNo) {
	var i_pageNo = document.getElementById('pageNo');
	i_pageNo.value = pageNo;
	i_pageNo.form.submit();
};

var changeDirectory = function(url) {
	location.href = url;
};

var submitMail = function() {
	$('#subject').val($('#form_subject').val());
	$('#body').val('姓　　名：' + $('#form_name').val() + '\n联系电话：' + $('#form_tel').val() + '\n内　　容：' + $('#form_body').val());
	//$('#form_mailbox').submit();
	var url = $('#form_mailbox').attr('action') + '?subject=' + ($('#subject').val() || ' ') + '&body=' + ($('#body').val() || ' ');
	if (url.length > 2047) {
		alert('编码后的发送信息大小 2048 字节，无法发送！');
		return;
	}
	url = encode(url);
	location.href = url;
};

function encode(str){
	return str.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"&#x$2;")});
}
