// Base
var common = {

	id : function(id) { return document.getElementById(id); },

	load : function (url) { 
		var head = document.getElementsByTagName('head');
		var scriptTag = document.createElement('script'); 
		scriptTag.src = url; 
		scriptTag.type = 'text/javascript'; 
		head[0].appendChild(scriptTag);
	},

	setHomepage : function () {
        try {
                document.body.style.behavior='url(#default#homepage)';
				document.body.setHomePage(document.URL);
        } catch(e) {
                if(window.netscape) {
                        try {
                                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                        } catch(e)  {
                                alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入\"about:config\"并回车\n然后将 [signed.applets.codebase_principal_support]设置为'true'");
                        }
                        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                        prefs.setCharPref('browser.startup.homepage',document.URL);
                 }
        }
	},

	addFavorite : function() {
		try {
			window.external.addFavorite(document.URL, document.title);
		} catch(e) {
			try {
				window.sidebar.addPanel(document.title, document.URL, "");
			} catch(e) {
				alert("加入收藏失败，请使用Ctrl+D进行添加");
			}
		}
	},

	swf : function(swf, width, height, body, wmode, quality) {
		if(swf == '') {
			return false;
		}
		var width = width || 400;
		var height = height || 300;
		var quality = quality || 'high';
		var wmode = wmode || 'opaque';
		var content = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + width +'" height="' + height + '">' + 
			'<param name="allowScriptAccess" value="sameDomain">' + 
			'<param name="movie" value="' + swf + '">' + 
			'<param name="quality" value="' + quality + '">' + 
			'<param name="bgcolor" value="#000000">' + 
			'<param name="menu" value="false">' + 
			'<param name=wmode value="' + wmode + '">' + 
			'<embed src="' + swf + '" wmode="' + wmode + '" menu="false" bgcolor="#000000" quality="high" width="'+ width +'" height="'+ height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' + 
			'</object>';
		var swfBody = document.getElementById(body);
		if(swfBody) {
			swfBody.innerHTML = content;
		} else {
			document.write(content);
		}
	}

}

// 直接运行
if(navigator.appVersion.match("MSIE 6") != null && PNGFix) 
	PNGFix.fix('*');
$(function() {
	$('.setHomepage').click(function() { common.setHomepage(); });
	$('.addFavorite').click(function() { common.addFavorite(); });
    if ($('#banner')) $('#banner').smallslider({showButtons:false, showText:false});
    if ($('#news-slider')) $('#news-slider').smallslider({showButtons:false,time:4000});
});

