/*======================================================================*\
|| #################################################################### ||
|| # PMNet Version 3.0												  #	||
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2003-2008 John Slone. All Rights Reserved. 			  #	||
|| # This file may not be redistributed in whole or significant part. # ||
|| #  																  # ||
|| #################################################################### ||
\*======================================================================*/

/* epguide.js */

var viewEpisode = function(eid, imglist) {

	// Variables
	this.tab = null;
	this.epid = eid;
	this.imglist = imglist;
	this.imgsperpage = 15;
	
	// Functions
	this.init = function()
	{
		// Initialize the things that are needed on the page
		
		// Start the tab set
		this.tab = new TabSet($("#epTabs"), '/ajax_epguide.php', 'eptab', {'epid' : this.epid});
		/*
		this.tab.updatefunctions['Edits'] = function(){
			//v = $('#'+Main.secondTarget);
		};
		*/
		this.tab.init();
		this.picsPanel();
	}
	
	// Sliding images
	this.picsPanel = function()
	{
		if ( this.imglist != '' )
		{
			$tx = this;
			
			$("#pictureboxes").cycle({
				fx : 'scrollUp',
				pagerAnchorBuilder : $tx.buildAnchor,
				pager : '.picturePages',
				timeout : 0,
				before : function(b,a,op) { $tx.fillInNextSet(b,a,op); }
			});
			$("#pictureboxes").css('display','block').css('height','1080px').css('width','100%');
			
		}
	}
	
	this.buildAnchor = function(i,el)
	{
		if ( ((i+1) % 50) == 0 )
		{
			return '<a href="#">'+(i+1)+'</a><br />';
		}
		else
		{
			return '<a href="#">'+(i+1)+'</a>';
		}
	}
	
	
	this.showpics = function()
	{
		//$("#pictureboxes").css('display','block').css('position','absolute');
	}
	
	this.fillInNextSet = function(b,a,op)
	{
		// What page are we going to?
		oldp = $(b).attr('id').substring(7);
		p = $(a).attr('id').substring(7);

		// How big are the current images?
		wid = $($(b).find('img')[0]).width();
		hei = $($(b).find('img')[0]).height();
		
		// Get list of pictures for this page
		x = this.imglist.split(/\|\|/)
		start = (p - 1) * this.imgsperpage;
		if ( $(a).find('img').length < 1 )
		{
			for ( i = 1; i <= this.imgsperpage; i++ )
			{
				j = start + i;
				if ( x[j] != undefined )
				{
					$(a).append("<img src=\"/images/episodes/"+this.epid+"/"+x[j]+"\" class=\"episodepicture\" alt=\"Episode Picture\" style=\"width:"+wid+"px;height:"+hei+"px;\" />");
				}
			}
		}
		$("#pictureboxes").css('display','block').css('height','1080px').css('width','100%');
		return true;

	}
	
	
	// Initialize
	this.init();
	
	return this;
}

var viewOpEd = {
	perpage : 0,
	opid : 0,
	
	ready : function(imglist,perpage,opid)
	{
		this.imglist = imglist;
		this.perpage = perpage;
		this.opid = opid;
		$(".pokeSprite").hover(function(){
			if ( $("#namedisplaybox").length < 1 )
			{
				$("#pmBody").append('<div id="namedisplaybox" style="display:none;"><div class="llll"></div><div class="pokeNameArrow"></div></div>');
			}
			a = $("#namedisplaybox");
			if ( $(this).attr('alt') == '' )
			{
				$(this).attr('alt') = $(this).attr('title');
			}
			a.find('div.llll').html($(this).attr('alt'));
			a.css('top',$(this).offset()['top']-a.height()-10);
			a.css('left',$(this).offset()['left']+$(this).width()/2-a.width()/2-10);
			a.css('display','block');
		},
		function(){
			a = $("#namedisplaybox").css('display','none');
		});

		if ( this.imglist != '' )
		{	
			this.picsPanel();
		}
	},
	
	picsPanel : function()
	{
		$tx = this;
		
		$("#picsPanel").cycle({
			fx : 'scrollUp',
			pagerAnchorBuilder : $tx.buildAnchor,
			pager : '.picturePages',
			timeout : 0,
			before : function(b,a,op) { $tx.fillInNextSet(b,a,op); }
		});
		$("#picsPanel").css('display','block').css('height','800').css('width','100%');
	},
	
	fillInNextSet : function(b,a,op)
	{
		//alert(b);
		// What page are we going to?
		oldp = $(b).attr('id').substring(7);
		p = $(a).attr('id').substring(7);

		
		// Get list of pictures for this page
		x = this.imglist.split(/\|\|/)
		start = (p - 1) * this.perpage;
		if ( $(a).find('img').length < 1 )
		{
			for ( i = 1; i <= this.perpage; i++ )
			{
				j = start + i;
				if ( x[j] != undefined )
				{
					$(a).append("<img src=\"/images/oped/"+this.opid+"/"+x[j]+"\" class=\"episodepicture\" alt=\"\" />");
				}
			}
		}
		//$("#picsPanel").css('display','block').css('width','740').css('height','700px').css('overflow','auto');
		//$("#picsPanel").css('display','block').css('height','800').css('width','100%').css('overflow','auto');
		return true;
	},
	
	buildAnchor : function(i,el)
	{
		if ( ((i+1) % 50) == 0 )
		{
			return '<a href="#">'+(i+1)+'</a><br />';
		}
		else
		{
			return '<a href="#">'+(i+1)+'</a>';
		}
	},
	
	getLyrics : function(langid, songid, el)
	{
		p = $(el).parents('.mytitlebox').find("div.lyricsbox");
		$.ajax({
			url : '/ajax.php',
			data : { 'action' : 'getlyrics', 'songid' : songid, 'langid' : langid, 'src' : 'epguide'},
			success : function(d) { viewOpEd.addLyrics(d, p); }
		});
		return false;
	},
	
	addLyrics : function(data, el)
	{
		$(el).html(data);
	},
	
	updateLyrics : function(sel, songid)
	{
		p = $(sel).parents('.mytitlebox').find("div.lyricsbox");
		da = $(sel).parents('form.lyricsform').serialize();
		$.ajax({
			url : '/ajax.php',
			data : da,
			success : function(d) { viewOpEd.addLyrics(d, p); }
		});
	}
}


/*======================================================================*\
|| ####################################################################
|| # File Revision:    $Revision: 1364 $
|| # Last Change:      $LastChangedDate: 2011-10-05 17:56:43 -0700 (Wed, 05 Oct 2011) $
|| # Last Commit By:   $Author: JDS $
|| ####################################################################
\*======================================================================*/
