var root_url = 'http://www.9c.com/';

var WEB = WEB || {};

WEB.handle = {};

//title:标题，msg:信息，fun_1:确定之后执行 fun_2:取消之后执行
WEB.frame = function (title, msg){
	$.dialogRemove();
	var arg_count = arguments.length;
	var t = ''; //临时html代码
	var tpl = '<div class="shadow"></div>'+
					'<div class="popup_box">'+
						'<div class="box">'+
							'<h1 class="popup_title"><span class="r"><a href="javascript://" onclick="$.dialogRemove()"><img src="'+root_url+'public/images_v2/b.gif" class="close" /></a></span>'+title+'</h1>'+
							'<div class="popup_con">'+
							'<div class="popDelFrd"><p style="padding:28px 0 17px">'+msg+'</p></div>'+
								'<div class="btndiv">'+
									'<a class="btn box_ok" href="javacript://">确 定</a>'+
									'<a class="btn cancel box_cancel" href="javascript://">取 消</a>'+
								'</div>'+
							'</div>'+
						'</div>'+
					'</div>';

	$.dialog({lit:true, content:tpl, mask : "block"});
	var ok = $('.box_ok');
	var nk = $('.box_cancel');

	if (arg_count > 2){
		WEB.handle['fun_1'] = arguments[2] ? arguments[2]  : function (){};
		ok.click(function() {clearTimeout(WEB.frame.__timer);WEB.handle.fun_1();$.dialogRemove();return false});

		if (arg_count > 3){
			WEB.handle['fun_2'] = arguments[3] ? arguments[3] : function (){};
			nk.click(function() {WEB.handle.fun_2();$.dialogRemove();return false});
		} else{
			nk.hide();
			ok.parent().parent().addClass('simply');
		}
	} else{
		ok.click(function() {clearTimeout(WEB.frame.__timer);$.dialogRemove();return false});
		ok.parent().parent().addClass('simply');
		nk.hide();
	}
	if (arg_count == 2) {
		WEB.frame.__timer = setTimeout(function() {				
			$('#tip_position').fadeOut('500', function() {
				$(this).remove();
				$('#tip_mask').remove();
				WEB.handle.fun_1 && WEB.handle.fun_1();
			});
			
		}, 2500);
	}
};

$(function() {
	$('.bookmark').click(function() {
		var url = document.location.href;
		var title = "9c网页游戏";	
		if( document.all ) {
			try{
				   window.external.addFavorite(url, title); 
			} 
			catch (e1){ 
				try{
					window.external.addToFavoritesBar(url, title); 
				} 
				catch (e2){
					alert('加入收藏失败，请您手工加入。');
				}
			} 
		} else if (window.external) { 
			window.sidebar.addPanel(title, url,""); 
		} else {
			alert('加入收藏失败，请您手工加入。');
		}
	})

	$('.homepage').click(function() {
		var url = "http://www.9c.com";
		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( "该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true" ); 
				} 
			}
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage', url);
		}
	})

	jQuery.fn.extend({
		scroll: function(h, n, time, a_time) {
			var i = 1;
			var m_h = h;
			var num = n;
			var self = this;

			var s_dl = setInterval(hor_scroll, time);

			function hor_scroll(){
				if (i == num+1){
					i = 1;
					self.css('marginTop', 0);
				}

				s_top = m_h * i++;
		
				self.animate({marginTop : -s_top}, a_time);
			}

			self.hover(
				function() {
					clearInterval(s_dl);
				},
				function (){
					s_dl = setInterval(hor_scroll, time);
				}
			);
		}
	});
})





	
