

//pages array
var pages = new Array(
	"http://avariciarpg.com/comic/pages/old/001.jpg",
	"http://avariciarpg.com/comic/pages/old/002.jpg",
	"http://avariciarpg.com/comic/pages/old/003.jpg",
	"http://avariciarpg.com/comic/pages/old/004.jpg",
	"http://avariciarpg.com/comic/pages/old/005.jpg";
	"http://avariciarpg.com/comic/pages/old/006.jpg",
	"http://avariciarpg.com/comic/pages/old/007.jpg",
	"http://avariciarpg.com/comic/pages/old/008.jpg",
	"http://avariciarpg.com/comic/pages/old/009.jpg",
	"http://avariciarpg.com/comic/pages/old/010.jpg",
	"http://avariciarpg.com/comic/pages/old/011.jpg",
	"http://avariciarpg.com/comic/pages/old/012.jpg",
	"http://avariciarpg.com/comic/pages/old/013.jpg",
	"http://avariciarpg.com/comic/pages/old/014.jpg",
	"http://avariciarpg.com/comic/pages/old/015.jpg",
	"http://avariciarpg.com/comic/pages/old/016.jpg",
	"http://avariciarpg.com/comic/pages/old/017.jpg",
	"http://avariciarpg.com/comic/pages/old/018.jpg",
	"http://avariciarpg.com/comic/pages/old/019.jpg",
	"http://avariciarpg.com/comic/pages/old/020.jpg",
	"http://avariciarpg.com/comic/pages/old/021.jpg",
	"http://avariciarpg.com/comic/pages/old/022.jpg",
	"http://avariciarpg.com/comic/pages/old/023.jpg",
	"http://avariciarpg.com/comic/pages/old/024.jpg",
	"http://avariciarpg.com/comic/pages/old/025.jpg");

/////////////////////////////////////////////////////////////////

var comicFilename = "oldcomic.php";

function fabricariComics_loadComic() {
	//get page
	var page = getQueryVariable("page");
	
	//validate page
	if (page == "" || page == null) {
		page = 1;
	}
	else if (page < 1) {
		page = pages.length;
	}
	else if (page > pages.length) {
		page = 1;
	}
	
	//set comic
	var img_comic = document.getElementById("img_comic");
	img_comic.src = pages[(page - 1)];
	
	//set links
	var firstPage = 1;
	var prevPage = (parseInt(page) - 1);
	var nextPage = (parseInt(page) + 1);
	var lastPage = (pages.length);
	
	if (prevPage < 1) prevPage = (pages.length)
	if (nextPage > pages.length) nextPage = 1;
	
	var a_firstPage = document.getElementById("a_firstPage");
	var a_prevPage = document.getElementById("a_prevPage");
	var a_nextPage = document.getElementById("a_nextPage");
	var a_lastPage = document.getElementById("a_lastPage");
	var a_comic = document.getElementById("a_comic");
	
	if (a_firstPage != null) {
		a_firstPage.href = comicFilename + "?page=" + firstPage;
	}
	if (a_prevPage != null) {
		a_prevPage.href = comicFilename + "?page=" + prevPage;
	}
	if (a_nextPage != null) {
		a_nextPage.href = comicFilename + "?page=" + nextPage;
	}
	if (a_lastPage != null) {
		a_lastPage.href = comicFilename + "?page=" + lastPage;
	}
	if (a_comic != null) {
		a_comic.href = comicFilename + "?page=" + nextPage;
	}
	
	//load select_comic list
	var select_comic = document.getElementById("select_comic");
	if (select_comic != null) {
		select_comic.options.length = 0;
		
		for (i = 0; i < pages.length; i++) {
			var selectedComic = (parseInt(page) == (i+1)) ? true : false;
			select_comic.options[i] = new Option("Page " + (i+1), comicFilename + "?page=" + (i+1), false, selectedComic);
		}
	}
	
	//preload images
	if (document.images)
    {
      var nextImage = new Image(); 
      nextImage.src = pages[(nextPage - 1)];
      var prevImage = new Image(); 
      prevImage.src = pages[(prevPage - 1)];
      var lastImage = new Image(); 
      lastImage.src = pages[(lastPage - 1)];
      var firstImage = new Image(); 
      firstImage.src = pages[(firstPage - 1)];
    }
}

function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		
		if (pair[0] == variable) {
			return pair[1];
		}
	}
} 

function fabricariComics_selectPage(select_comic) {
	var select_comicValue = select_comic.options[select_comic.options.selectedIndex].value;
	document.location = select_comicValue;
}



