var maxSS;
var currentSS;

function preload_home(max) {
	imgObj1 = new Image();
	imgObj2 = new Image();
	imgObj3 = new Image();
	
	for(var i=1; i<=max; i++) {
		imgObj1.src = "http://eso-ns.perfectworld.com/media/images/common/home_v2_background_0" + i + "a.jpg";
		imgObj2.src = "http://eso-ns.perfectworld.com/media/images/common/menu2_login_0" + i +".gif";
		imgObj3.src = "http://eso-ns.perfectworld.com/media/images/common/menu2_download_0" + i + ".gif";
	}
}

function preload_sub(max) {
	imgObj = new Image();
	
	for(var i=1; i<=max; i++) {
		imgObj.src = "http://eso-ns.perfectworld.com/media/images/common/sub_background_0" + i + ".jpg";
	}
}

function preload_ss(max)
{
	imgObj = new Image();
	
	for(var i=1; i<=max; i++) {
		imgObj.src = "http://eso-ns.perfectworld.com/media/images/home/screenshot/image_screenshot" + i + ".jpg";
	}
}

function load_background_home(num)
{
	var url = "http://eso-ns.perfectworld.com/media/images/common/home_v2_background_0" + num + "a.jpg";
	document.getElementById("p_homebg").style.background = "url(" + url + ")  no-repeat top";
	var url2 = "http://eso-ns.perfectworld.com/media/images/common/menu2_login_0" + num +".gif"
	document.getElementById("p_menu2_login_id").style.background = "url(" + url2 + ")  no-repeat top";
	var url3 = "http://eso-ns.perfectworld.com/media/images/common/menu2_download_0" + num + ".gif";
	document.getElementById("download_front_link").src = url3;
}

function load_background_sub(num)
{
	var url = "http://eso-ns.perfectworld.com/media/images/common/sub_background_0" + num + ".jpg";
	document.getElementById("p_subbg").style.background = "url(" + url + ") no-repeat top";
	var url2 = "http://eso-ns.perfectworld.com/media/images/common/menu2_login_0" + num +".gif"
	document.getElementById("p_menu2_login_id").style.background = "url(" + url2 + ")  no-repeat top";
	var url3 = "http://eso-ns.perfectworld.com/media/images/common/menu2_download_0" + num + ".gif";
	document.getElementById("download_front_link").src = url3;
}

function preload_images(isHome, max, _maxSS, randSS)
{
	if(isHome) {
		preload_home(max);
		preload_ss(_maxSS);
		currentSS = randSS;
		maxSS = _maxSS;
	} else {
		preload_sub(max);
	}
}

function load_background(isHome, num)
{
	if(isHome) {
		load_background_home(num);
	} else {
		load_background_sub(num);
	}
}

function pick_next_image()
{
	var next = currentSS + 1;
	if(next > maxSS) {
		next = 1;
	}
	currentSS = next;
	change_ss(next);
}

function pick_prev_image()
{
	var prev = currentSS - 1;
	if(prev < 1) {
		prev = maxSS;
	}
	currentSS = prev;
	change_ss(prev);
}

function change_ss(num)
{
	document.getElementById("ss_link").href = "http://eso-ns.perfectworld.com/media/images/home/screenshot/fullview/image" + num+ ".jpg";
	document.getElementById("ss_image").src = "http://eso-ns.perfectworld.com/media/images/home/screenshot/image_screenshot" + num + ".jpg";
}
