/*======================================================================*\
|| #################################################################### ||
|| # PMNet Version 3.0												  #	||
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2003-2008 John Slone. All Rights Reserved. 			  #	||
|| # This file may not be redistributed in whole or significant part. # ||
|| #  																  # ||
|| #################################################################### ||
\*======================================================================*/

/* characters.js */

// Main characters object

var Chars = {
	
	showAlpha : function(el)
	{
		var let = $(el).attr('rel');
		
		t = $("#charTable");
		t.find('tbody').html('<tr><td class="c" colspan="4"><img src="/images/templates/progress_circle.gif" alt="Working" /></td></tr>');
		
		$.ajax({
			url : '/ajax.php',
			data : { 'action' : 'getcharalpha', 'letter' : let },
			success : function(d)
			{
				t.find('tbody').html(d);
			}
		});
		// Now, update the 'active' link
		$("#letterSelectionList a.pagenav_link_active").removeClass('pagenav_link_active').addClass('pagenav_link');
		$(el).addClass('pagenav_link_active');
		return false;
	}
}

var CharView = {
	
	init : function()
	{
		$("#characterPanel").accordion({autoHeight : false, collapsible : true});
	}
	
}

var CharPics = {
	
	alldone : false,
	cid : 0,
	usedids : new Array(0),
	
	
	isScrolledIntoView : function(elem)
	{
		
		var docViewTop = $(window).scrollTop();
		var docViewBottom = docViewTop + $(window).height();

		var elemTop = $(elem).offset().top;
		var elemBottom = elemTop + $(elem).height();

		return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom));
		
			
		return ( $(window).scrollTop() + $(window).height() ) >= $(elem).position().top
	},
	
	ready : function(characterid)
	{
		this.cid = characterid;
		
		$(window).scroll(function(){
			/*
			if ( ( $(window).scrollTop() + $(window).height() ) >= $('div#bottomline').position().top )
			{
				if ( !this.alldone )
				{
					CharPics.loadMoreImages();
				}
			}
			*/
			if ( CharPics.isScrolledIntoView($('div#bottomline')) && !CharPics.alldone )
			{
				CharPics.loadMoreImages();
			}
		});
	},
	
	loadMoreImages : function()
	{
		
		d = $("div#piclist").find('div.characterLatestPic:last');
		lastimg = ($(d).attr('id').substring(3));
		
		if ( jQuery.inArray(lastimg, this.usedids) != -1 )
		{
			return false;
		}
		
		this.usedids.push(lastimg);
		$.ajax({
			url : '/ajax_epguide.php',
			data : { 'action' : 'getcharimgs', 'lastimgid' : lastimg, 'characterid' : CharPics.cid },
			success : function(d)
			{
				if ( $(d).find('last').length > 0 )
				{
					CharPics.alldone = true;
				}
				if ( $(d).find('content').length > 0 )
				{
					$("div#bottomline").before($(d).find('content').text());
				}
			}
		});
	}
}


/*======================================================================*\
|| ####################################################################
|| # File Revision:    $Revision: 1515 $
|| # Last Change:      $LastChangedDate: 2011-12-26 17:31:28 -0800 (Mon, 26 Dec 2011) $
|| # Last Commit By:   $Author: JDS $
|| ####################################################################
\*======================================================================*/
