﻿var thumb_open = true;
var sid = 0;
var stop_auto = false;
var hotnews_current_id = 0;
var hotnews_auto_run_delay = 8000;


function hotnews_init() {	
/*
	if (typeof(hotnews_data) == 'undefined') return false;
	
	document.getElementById('hotnews-panel').ondblclick = hotnews_panel_open;
	document.getElementById('hotnews-panel-button').onclick = hotnews_panel_open;
	document.getElementById('hotnews').onmouseover = function () {
		stop_auto = true;
	};
	
	document.getElementById('hotnews').onmouseout = function () {
		stop_auto = false;
	};
*/	
	/* load all image */
	
	for (var i=0; i < hotnews_data.length; i++) {
		eval('image'+i+' = new Image(); image'+i+'.src = "'+hotnews_data[i].bg+'"');
	}	
	
	/* start auto run */
	var myInterval = window.setInterval("hotnews_auto_run()", hotnews_auto_run_delay);
	
}

function hotnews_panel_open () {
	if (thumb_open == false) {
		document.getElementById('hotnews-panel').style.marginTop = (263 - 65 - 14) + 'px';
		document.getElementById('hotnews-thumb').style.display = 'block';
		document.getElementById('hotnews-panel-button').className = 'open';
		thumb_open = true;
	}
	else { 
		document.getElementById('hotnews-panel').style.marginTop = (263 - 14) + 'px';
		document.getElementById('hotnews-thumb').style.display = 'none';
		document.getElementById('hotnews-panel-button').className = 'close';
		thumb_open = false;
	}
}

function hotnews_change(i) {
	document.getElementById('hotnews-title').innerHTML = hotnews_data[i].title;
	document.getElementById('hotnews-title').href = hotnews_data[i].link;
	document.getElementById('hotnews-quote').innerHTML = hotnews_data[i].quote;
	document.getElementById('hotnews-link').href = hotnews_data[i].link;
	document.getElementById('hotnews').style.backgroundImage ='url("'+hotnews_data[i].bg+'")';
	
	document.getElementById('hotnews-img-' + hotnews_current_id).className = '';
	document.getElementById('hotnews-img-' + i).className = 'selected';
	
	document.getElementById('hotnews-dot-' + hotnews_current_id).className = '';
	document.getElementById('hotnews-dot-' + i).className = 'selected';
	
	hotnews_current_id = i;
	
	sid = i;
}


function hotnews_auto_run() {
	if (stop_auto == false) {		
		if (sid >= hotnews_data.length) sid = 0;		
		hotnews_change(sid);
		sid++;
	}
	//alert(sid);
}

function hotnews_go() {
	/*alert(hotnews_data[sid].link);*/
	document.location = hotnews_data[sid].link;
}


function setHomepage()
{
	if (document.all)
	{
	document.body.style.behavior='url(#default#homepage)';
	document.body.setHomePage('http://248.vn/');
	
	}
	else if (window.sidebar)
	{
		if(window.netscape)
		{
			try
			{
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			}
			catch(e)
			{
				alert("Do chế độ bảo mật của trình duyệt web, để có thể sử dụng chức năng này bạn làm theo các bước sau:\n 1. Gõ vào thanh địa chỉ: about:config\n 2.Thay đổi giá trị signed.applets.codebase_principal_support thành true");
			}
		}
		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage','http://248.vn/');
	}
}