// JavaScript Document

var count = 0;
var imgno = 0;
timerid = 0;

function changeBackgroundColor(objDivID,backColour)
{
	
	var t = testForObject("lowerbox");
	var s = testForObject("lowerwrap");
	
	if(t) document.getElementById('lowerbox').style.backgroundColor = backColour;
	if(s) document.getElementById('lowerwrap').style.backgroundColor = backColour;
	
	
	if(document.cookie && document.cookie !="")
	{
		// cookie exists, read the data, need splitting
		var each_cookie = document.cookie.split(";");
		
		for(i=0;i<each_cookie.length;i++)
		{
			if(each_cookie[i].indexOf("bg_colour_cookie") > -1) 
			{
				var bg_colour_data = each_cookie[i];
			}
			if(each_cookie[i].indexOf("font_size_cookie") > -1) 
			{ 
				var font_size_data = each_cookie[i];
				var new_font_size = font_size_data.split("=");
				var font_size = new_font_size[1];
			}
		}
		
		if(bg_colour_data && font_size_data)
		{
			document.cookie = "font_size_cookie=" + font_size;
			document.cookie =  "bg_colour_cookie=" + escape(backColour);
		}
		else document.cookie = "bg_colour_cookie=" + escape(backColour);
		
	}
	else document.cookie = "bg_colour_cookie=" + escape(backColour);		
	
}

function changetext(fontSize) 
{  
    text = document.getElementById('textshift');  
	text.style.fontSize = fontSize; 
	
	if(document.cookie && document.cookie !="")
	{
		// cookie exists, read the data, need splitting
		var each_cookie = document.cookie.split(";");
		
		for(i=0;i<each_cookie.length;i++)
		{
			if(each_cookie[i].indexOf("bg_colour_cookie") > -1) 
			{
				var bg_colour_data = each_cookie[i];
				var bg_colour = bg_colour_data.split("=");
				var colour = bg_colour[1];
			}
			if(each_cookie[i].indexOf("font_size_cookie") > -1) 
			{ 
				font_size_data = each_cookie[i];
			}
		}
		
		if(bg_colour_data && font_size_data)
		{
			document.cookie = "font_size_cookie=" + escape(fontSize);
			document.cookie = "bg_colour_cookie=" + colour;			
		}
		else document.cookie = "font_size_cookie=" + escape(fontSize);
		
	}
	else document.cookie = "font_size_cookie=" + escape(fontSize);
}  

function process(backColour)
{
	var strCookie = backColour;	
}


function testForObject(Id, Tag)
{
  var o = document.getElementById(Id);
  if (o)
  {
    if (Tag)
    {
      if (o.tagName.toLowerCase() == Tag.toLowerCase())
      {
        return o;
      }
    }
    else
    {
      return o;
    }
  }
  return null;
}



function setsize_colour()
{
	
	if(document.cookie && document.cookie != "")
	{
		var cookie_stuff = unescape(document.cookie);
		
		cookie_stuff = cookie_stuff.replace(/'/g,"");
	
		if(cookie_stuff != '')
		{
			// The cookie is set, change bg colour & text size accordingly
			
			// Grab text size and bg colour from the cookie if they exist
			
			// we will need to check if its the front or an inner page -
			
			var each_cookie = cookie_stuff.split(";");
			
		
			for (i=0; i<each_cookie.length; i++)
			{
				if (each_cookie[i].indexOf("bg_colour_cookie") > -1){var bg_colour_data = each_cookie[i];}
				if (each_cookie[i].indexOf("font_size_cookie") > -1){var font_size_data = each_cookie[i];}
			}
			
			
			if(bg_colour_data && bg_colour_data != "")
			{
				
				var bg_colour = bg_colour_data.split("=");
				var colour = bg_colour[1];
				
				// test if inner or front page
				var t = testForObject("lowerbox");
				var s = testForObject("lowerwrap");
				
				if(t) changeBackgroundColor('lowerbox',colour);
				if(s) changeBackgroundColor('lowerwrap',colour);
				
				//alert("Colour: " + colour);
				
			}
			
			if(font_size_data && font_size_data != "")
			{
				var new_font_size = font_size_data.split("=");
				var font_size = new_font_size[1];
				
				//alert(font_size + " -2");
				
				// needs to include font size grabbed from cookie if it exists
				changetext(font_size);
				
				//alert("Font size: " + font_size);
			}
		}
	}
}

function writetext(what,div){
	document.getElementById(div).innerHTML=''+what+'';
}

function updateSlide(slideNo)
{
	MM_swapImage('mainpic1','',imagearray[slideNo]);
	
	// Line below doesnt seem to work properly, wrote own function instead
	//MM_setTextOfLayer('refno_data','',imagecaption[1][slideNo]);
	
	writetext(imagecaption[1][slideNo],'refno_data');
}

function playShow(suspended)
{
	
	var arrLength = imagearray.length;
	var suspended = (suspended == null) ? false : suspended;
	
	if(!suspended)
	{
		if(count == arrLength-1)
		{
			count = 0;
		}
		else
		{
			count++;	
		}
		
		timerid = setTimeout('playShow()',2000);	
		
		updateSlide(count);
		
	}
	else
	{
		clearTimeout(timerid);
		return;
	}
	
	
}

function stopShow()
{
	clearTimeout(timerid);	
}