/*
 Notice:
 Please scroll to the end of this file 
 if you like to do modification 
 to make this applet be fit in your homepage

-----------------------------------------
          J a v a  p a r t :
 Normally there shouldn't be any reason 
      to change anything in here
*/


	var start_year;
var seal;
var tone;
var kin;		//1..260 kin index
	var moon_of_13;
	var day_of_28;
	var curr_date;
	var curr_month;
	var curr_year;
	var xx;
	var xy;
var moon;
var mday;
var wday;
var week;

/////////////////////////////////////////////////////
// auxiliary functions
function yearmore() {
	var drop_year = curr_year - 2002;
	for (var count = 1; count <= drop_year; count++) {
		seal += 5;
		kin  += 105;
		tone++;
		
		if (tone >= 14) tone = 1;
			
		if (seal >= 20) seal = 4;
			
		if (kin > 260)    kin -= 260;			
	}	
}

function dropyear() {
	seal -= 5;
	tone -= 1;
	kin  -= 105;
	if (kin  <= 2) kin += 260; 
		
	if (tone <= 0) tone =  13;
		
	if (seal <= 3) seal =  19; 	
}

function d_months() {
	switch(d_month) {
		case(d_month="Jan"): d_month="0"; break;
		case(d_month="Feb"): d_month="1"; break;
		case(d_month="Mar"): d_month="2"; break;
		case(d_month="Apr"): d_month="3"; break;
		case(d_month="May"): d_month="4"; break;
		case(d_month="Jun"): d_month="5"; break;
		case(d_month="Jul"): d_month="6"; break;
		case(d_month="Aug"): d_month="7"; break;
		case(d_month="Sep"): d_month="8"; break;
		case(d_month="Oct"): d_month="9"; break;
		case(d_month="Nov"): d_month="10"; break;
		case(d_month="Dec"): d_month="11"; break;
	}
}
	
function calculate_dates() {


	start_year	= 10;
	seal		=  9;
	tone		= 10;
	kin			= 49;
	moon_of_13	= 1;
	day_of_28	= 1;
	curr_date	= d_date;
	curr_month	= d_month + 1;
	curr_year	= d_fullyear;
	xx			= 7;
	xy			= 26;
	moon		= 1;
	mday		= 1;
	wday		= 1;
	week		= 1;

	if (curr_year > 2002) {
		yearmore();
	}
	if (curr_month < 7) {
		dropyear();
	}
	if ((curr_month==7) && (curr_date < 26)) {
		dropyear();
	}


	while ((xx!=curr_month) || (xy!=curr_date)) {

		kin++;
		xy++;
		seal++;
		tone++;
		mday++;
		wday++;
		if (wday>7) {
			wday=1;
			week++; }

		if (mday>28) {
			mday=1;
			moon++; }
		
		if (seal==20) {
			seal=0; }
			
		if (tone==14) {
			tone=1; }
		
		if (kin==261) {
			kin=1; }
		
		if (xy>months[xx]) {
			xx++;
			xy=1;
			if (xx==13) {
				xx=1; }
		}
	}	//While
}


/////////////////////////////////////////////////////
// Start
var moons=new Array(
	/* 0*/	"errorincode", 
	/* 1*/	"Magnetic", 
	/* 2*/	"Lunar", 
	/* 3*/	"Electric", 
	/* 4*/	"Self-Existing", 
	/* 5*/	"Overtone", 
	/* 6*/	"Rhythmic", 
	/* 7*/	"Resonant", 
	/* 8*/	"Galactic", 
	/* 9*/	"Solar", 
	/*10*/	"Planetary", 
	/*11*/	"Spectral", 
	/*12*/	"Crystal", 
	/*13*/	"Cosmic");

var moon_days=new Array(
	/* 0*/	"0", 
	/* 1*/	"Dali 1", 
	/* 2*/	"Seli 2", 
	/* 3*/	"Gamma 3", 
	/* 4*/	"Kali 4", 
	/* 5*/	"Alpha 5", 
	/* 6*/	"Limi 6", 
	/* 7*/	"Silio 7", 
	/* 8*/	"Dali 8", 
	/* 9*/	"Seli 9", 
	/*10*/	"Gamma 10", 
	/*11*/	"Kali 11", 
	/*12*/	"Alpha 12", 
	/*13*/	"Limi 13", 
	/*14*/	"Silio 14", 
	/*15*/	"Dali 15", 
	/*16*/	"Seli 16", 
	/*17*/	"Gamma 17", 
	/*18*/	"Kali 18", 
	/*19*/	"Alpha 19", 
	/*20*/	"Limi 20", 
	/*21*/	"Silio 21", 
	/*22*/	"Dali 22", 
	/*23*/	"Seli 23", 
	/*24*/	"Gamma 24", 
	/*25*/	"Kali 25", 
	/*26*/	"Alpha 26", 
	/*27*/	"Limi 27", 
	/*28*/	"Silio 28");

var months=new Array(
	/* 0*/	"0", 
	/* 1*/	"31", 
	/* 2*/	"28", 
	/* 3*/	"31", 
	/* 4*/	"30", 
	/* 5*/	"31", 
	/* 6*/	"30", 
	/* 7*/	"31", 
	/* 8*/	"31", 
	/* 9*/	"30", 
	/*10*/	"31", 
	/*11*/	"30", 
	/*12*/	"31");

var sol_seals=new Array(
	/* 0*/	"Sun", 
	/* 1*/	"Dragon", 
	/* 2*/	"Wind", 
	/* 3*/	"Night", 
	/* 4*/	"Seed", 
	/* 5*/	"Serpent", 
	/* 6*/	"World-bridger", 
	/* 7*/	"Hand", 
	/* 8*/	"Star", 
	/* 9*/	"Moon", 
	/*10*/	"Dog", 
	/*11*/	"Monkey", 
	/*12*/	"Human", 
	/*13*/	"Skywalker", 
	/*14*/	"Wizard", 
	/*15*/	"Eagle", 
	/*16*/	"Warrior", 
	/*17*/	"Earth", 
	/*18*/	"Mirror", 
	/*19*/	"Storm");
	
var seal_color=new Array(
	/* 0*/	"Yellow", 
	/* 1*/	"Red", 
	/* 2*/	"White", 
	/* 3*/	"Blue", 
	/* 4*/	"Yellow", 
	/* 5*/	"Red", 
	/* 6*/	"White", 
	/* 7*/	"Blue", 
	/* 8*/	"Yellow", 
	/* 9*/	"Red", 
	/*10*/	"White", 
	/*11*/	"Blue", 
	/*12*/	"Yellow", 
	/*13*/	"Red", 
	/*14*/	"White", 
	/*15*/	"Blue", 
	/*16*/	"Yellow", 
	/*17*/	"Red", 
	/*18*/	"White", 
	/*19*/	"Blue");	

var gal_tones=new Array(
	/* 0*/	"errorincode", 
	/* 1*/	"Magnetic", 
	/* 2*/	"Lunar", 
	/* 3*/	"Electric", 
	/* 4*/	"Self-Existing", 
	/* 5*/	"Overtone", 
	/* 6*/	"Rhythmic", 
	/* 7*/	"Resonant", 
	/* 8*/	"Galactic", 
	/* 9*/	"Solar", 
	/*10*/	"Planetary", 
	/*11*/	"Spectral", 
	/*12*/	"Crystal", 
	/*13*/	"Cosmic"); 


// init Date vars
var d = new Date();

var d_date = d.getDate();
var d_month = d.getMonth();
var d_fullyear = d.getFullYear();

// do 13 moon & tzolkin calculations
calculate_dates();


/*
=================================================
  U S E R  P A R T  - 
  you may do modifications in here if you feel so

*/
document.write(

'<a href="http://www.tortuga.com/findkin" target="_blank">'+
	'<img id="tzolkin-script" src="http://www.tortuga.com/dreamspell/sealstones/kin/small/' + kin + '.gif" '+
		'border=0 hspace=5 Title="'+
		'Moon ' + moon + ' Day ' + mday +
		//"<br><b>Gregorian Date: </b>" + greg_month[curr_month] + " " + curr_date + ", " + curr_year+
		' - Tzolkin: ' +seal_color[seal]+ ' ' +gal_tones[tone]+ ' ' +sol_seals[seal]+ '"' +
	'>'+
'</a>'

); // <<- ! ;)

/*
Note add this in your css-file :

		img#tzolkin-script { 
			left:20px; 
		}

	to configure kin image
*/

