// JavaScript Document

$(document).ready(function() {

Date.prototype.getWeek = function() {
var onejan = new Date(this.getFullYear(),0,1);
return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7);
} 

var today = new Date();
var weekno = today.getWeek(); 

	weekno = weekno + 0;

	temp1 = (weekno) % 12;
	temp2 = (weekno) % 6;
	temp3 = (weekno) % 6;

	imagenum1 = linkdecoder(temp1);
	imagenum2 = linkdecoder2(temp2);
	imagenum3 = linkdecoder3(temp3);
	
	if (imagenum2 == imagenum1)
	{
		temp2 = temp2 + 1;
		if (temp2 >= 6) {
			temp2 = 0;	
		}

		imagenum2 = linkdecoder2(temp2);
	}
	
	if (imagenum3 == imagenum1)
	{
		temp3 = temp3 + 1;
		if (temp3 >= 6) {
			temp3 = 0;	
		}

		imagenum3 = linkdecoder3(temp3);
	}
	
	imagenum1 = 'primary' + imagenum1;
	imagenum2 = 'secondary' + imagenum2;
	imagenum3 = 'secondary' + imagenum3;
	
	
//	alert(String(temp));

//	imagelink = linkdecoder(temp);
//	imagelink = 'primary' + imagelink;
//	imagelinks.push(imagelink);

	attr1 = attrdecoder(temp1);
	attr2 = attrdecoder(temp2);
	attr3 = attrdecoder( (temp3 + 6) ); //Needs incremented once a year.


	$("#primary").removeClass('primaryshape').addClass(imagenum1);
	$("#primary").attr("href", attr1);
	$("#secondary").removeClass('secondarymatter').addClass(imagenum2);
	$("#secondary").attr("href", attr2);
	$("#tertiary").removeClass('secondarycatcher').addClass(imagenum3);
	$("#tertiary").attr("href", attr3);
	
	return;
	
});

function linkdecoder(imagenum)
{
	switch (imagenum) {
			case 0:
				return 'blaster';
			break;
			case 1:
				return 'height';
			break;
			case 2:
				return 'match';
			break;
			case 3:
				return 'ruler';
			break;
			case 4:
				return 'matter';
			break;
			case 5:
				return 'photoninvaders';
			break;
			case 6:
				return 'quiz';
			break;
			case 7:
				return 'cross';
			break;
			case 8:
				return 'rummy';
			break;
			case 9:
				return 'shape';
			break;
			case 10:
				return 'wordsearch';
			break;
			case 11:
				return 'catcher';
			break;
			default:
				return 'blaster';		
	}
}

function linkdecoder2(imagenum)
{
	switch (imagenum) {
			case 0:
				return 'blaster';
			break;
			case 1:
				return 'height';
			break;
			case 2:
				return 'match';
			break;
			case 3:
				return 'ruler';
			break;
			case 4:
				return 'matter';
			break;
			case 5:
				return 'photoninvaders';
			break;
			default:
				return 'blaster';		
	}
}

function linkdecoder3(imagenum)
{
	switch (imagenum) {
			case 0:
				return 'quiz';
			break;
			case 1:
				return 'cross';
			break;
			case 2:
				return 'rummy';
			break;
			case 3:
				return 'shape';
			break;
			case 4:
				return 'wordsearch';
			break;
			case 5:
				return 'catcher';
			break;
			default:
				return 'quiz';
	}
}

function attrdecoder(imagenum)
{
	switch (imagenum) {
			case 0:
				return "javascript:popup('blaster.html','baryonblaster','width=600px,height=450px,scrollbars=0')";
			break;
			case 1:
				return "javascript:popup('height_popup01.html','height','width=700px,height=510px,scrollbars=0')";
			break;
			case 2:
				return "javascript:popup('match.html','match','width=700px,height=500px,scrollbars=0')";
			break;
			case 3:
				return "javascript:popup('rulergame.html','ruler','width=700px,height=550px,scrollbars=0')";
			break;
			case 4:
				return "javascript:popup('matter.html','matter','width=700px,height=500px,scrollbars=0')";
			break;
			case 5:
				return "javascript:popup('photovoltaic.html','photovoltaic0708','width=800px,height=552px,scrollbars=0')";
			break;
			case 6:
				return "javascript:popup('quiz_intro.html','quiz','width=600px,height=500px,scrollbars=0')";
			break;
			case 7:
				return "javascript:popup('crossword_menu.html','crossword','width=640px,height=400px,scrollbars=0')";
			break;
			case 8:
				return "javascript:popup('rummy2.html','rummy','width=864px,height=597px,scrollbars=0')";
			break;
			case 9:
				return "javascript:popup('shapesleuth.html','shapesleuth','width=650px,height=500px,scrollbars=0')";
			break;
			case 10:
				return "javascript:popup('wordsearch.html','wordsearch','width=700px,height=500px,scrollbars=0')";
			break;
			case 11:
				return "javascript:popup('catcher.html','catcher','width=550px,height=400px,scrollbars=0')";
			break;
			default:
				return "javascript:popup('blaster.html','baryonblaster','width=600px,height=450px,scrollbars=0')";		
	}
}


