var xmlHttp;

function showBiog()
{
	document.getElementById("biog").style.display = 'block';
	document.getElementById("biog_image").style.display = 'none';
	document.getElementById("biog_close").style.display = 'block';
}
function closeBiog()
{
	document.getElementById("biog").style.display = 'none';
	document.getElementById("biog_image").style.display = 'block';
	document.getElementById("biog_close").style.display = 'none';
}

function createXMLHttpRequest()
{
	if(window.ActiveXObject)
	{
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		if(window.XMLHttpRequest)
		{
			xmlHttp = new XMLHttpRequest();
		}
	}
}

function getNews(direction)
{
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = return_news;
	
	newsID = document.getElementById("newsID").innerHTML;
	
	url = "getNews.php?direction=" + direction + "&id=" + newsID;
	//alert(url);
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function gallery_get(direction, id)
{
	if(document.getElementById("flashcontent"))
	{
		document.getElementById("flashcontent").style.display = 'none';
	}

	document.getElementById("gallery_image").style.display = 'inline';
	
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = return_image;
	
	imageURL = document.getElementById("gallery_image").src;
	
	url = "getImage.php?direction=" + direction + "&id=" + id + "&url=" + imageURL;
// alert(url)
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
function return_image()
{
	if(xmlHttp.readyState == 4)
	{
		if(xmlHttp.status == 200)
		{
			xmlObj = xmlHttp.responseXML;

			imageObj = xmlObj.getElementsByTagName("image");
			if(imageObj.length > 0)
			{
				imageTitle = imageObj[0].getElementsByTagName("title")[0].firstChild.nodeValue;
				imageURL = imageObj[0].getElementsByTagName("url")[0].firstChild.nodeValue;
				
				//alert(document.getElementById("gallery_image").src)
				document.getElementById("gallery_image").src=imageURL;
				document.getElementById("gallery_image").alt=imageTitle;
				document.getElementById("image_title").innerHTML=imageTitle;
			}
		}
	}
}

function return_news()
{
	if(xmlHttp.readyState == 4)
	{
		if(xmlHttp.status == 200)
		{
			//alert(xmlHttp.responseText)
			xmlObj = xmlHttp.responseXML;
			
			// logic here for extracting the information from the news xml
			newsObj = xmlObj.getElementsByTagName("news");
			if(newsObj.length > 0)
			{
				newsTitle = newsObj[0].getElementsByTagName("title")[0].firstChild.nodeValue;
				newsID = newsObj[0].getElementsByTagName("id")[0].firstChild.nodeValue;
				newsDate = newsObj[0].getElementsByTagName("date")[0].firstChild.nodeValue;
				newsContent = newsObj[0].getElementsByTagName("content")[0].firstChild.nodeValue;
				newsDivision = newsObj[0].getElementsByTagName("division")[0].firstChild.nodeValue;

				document.getElementById("newsID").innerHTML = newsID;
				newsHolder = document.getElementById("news_content");
				newsDivs = newsHolder.getElementsByTagName("div");
				for(i=0; i<newsDivs.length; i++)
				{
					switch(newsDivs[i].className)
					{
						case 'date':
						{
							newsDivs[i].innerHTML = newsDate;
							break;
						}
						case 'title':
						{
							newsDivs[i].innerHTML = newsTitle;
							break;
						}
						case 'content':
						{
							newsDivs[i].innerHTML = newsContent;
							break;
						}
					}
				}
			}
		}
	}
}

function changeState(obj, state1, state2)
{
	// if the entire string of one state exists within another (e.g. over & overRed) then the longer string should occur first in the state list sent as a parameter to this function
	if(obj.src.indexOf(state1) > -1)
	{
		obj.src = obj.src.replace(state1, state2);
	}
	else
	{
		obj.src = obj.src.replace(state2, state1);
	}
	return true;
}
/*
function changeHeadings(page, subsection)
{
	switch(page)
	{
		case 'index.php':
		{
			if(typeof sIFR == "function"){
    				sIFR.replaceElement("h1", named({sFlashSrc: "./sifr.swf", sColor: "#000000", sCase: "upper", nPaddingTop: "0", nPaddingBottom: "15", nPaddingLeft: "0", nPaddingRight: "0", sHoverColor: "#ee009b", sBgColor: "#c50028"}));
			};
			break;
		}
		case 'directors.php':
		{
			if(typeof sIFR == "function"){
				sIFR.replaceElement("h2", named({sFlashSrc: "./sifr_small.swf", sColor: "#000000", sCase: "upper", nPaddingTop: "0", nPaddingBottom: "0", nPaddingLeft: "0", nPaddingRight: "0", sHoverColor: "#ffffff", sBgColor: "#c50028"}));
			};
			if(typeof sIFR == "function"){
				sIFR.replaceElement("h1", named({sFlashSrc: "./sifr.swf", sColor: "#ef019c", sCase: "upper", nPaddingTop: "0", nPaddingBottom: "0", nPaddingLeft: "0", nPaddingRight: "0", sBgColor: "#320c0a"}));
			};
			break;
		}
		case 'contact.php':
		{
			if(typeof sIFR == "function"){
				sIFR.replaceElement("h2", named({sFlashSrc: "./sifr_small.swf", sColor: "#000000", sCase: "upper", nPaddingTop: "0", nPaddingBottom: "0", nPaddingLeft: "0", nPaddingRight: "0", sHoverColor: "#ffffff", sBgColor: "#c50028"}));
			};
			if(typeof sIFR == "function"){
				sIFR.replaceElement("h1", named({sFlashSrc: "./sifr.swf", sColor: "#ffffff", sCase: "upper", nPaddingTop: "0", nPaddingBottom: "0", nPaddingLeft: "0", nPaddingRight: "0", sBgColor: "#2b0826"}));
			};
			break;
		}
		case 'longform.php':
		case 'about.php':
		{
			if(typeof sIFR == "function"){
				sIFR.replaceElement("h2", named({sFlashSrc: "./sifr_small.swf", sColor: "#02c5d1", sCase: "upper", nPaddingTop: "0", nPaddingBottom: "0", nPaddingLeft: "0", nPaddingRight: "0", sHoverColor: "#ffffff", sBgColor: "#006372"}));
			};
			if(typeof sIFR == "function"){
				sIFR.replaceElement("h1", named({sFlashSrc: "./sifr.swf", sColor: "#02c5d1", sCase: "upper", nPaddingTop: "0", nPaddingBottom: "0", nPaddingLeft: "0", nPaddingRight: "0", sHoverColor: "#ffffff", sBgColor: "#006372"}));
			};
			break;
		}
		case 'production.php':
		{
			if(typeof sIFR == "function"){
				sIFR.replaceElement("h2", named({sFlashSrc: "./sifr_small.swf", sColor: "#ffffff", sCase: "upper", nPaddingTop: "0", nPaddingBottom: "0", nPaddingLeft: "0", nPaddingRight: "0", sHoverColor: "#000000", sBgColor: "#bc0071"}));
			};
			if(typeof sIFR == "function"){
				sIFR.replaceElement("h1", named({sFlashSrc: "./sifr.swf", sColor: "#ffffff", sCase: "upper", nPaddingTop: "0", nPaddingBottom: "0", nPaddingLeft: "0", nPaddingRight: "0", sHoverColor: "#000000", sBgColor: "#bc0071"}));
			};
			break;
		}
	}
}
*/
function showClip(uri, colour)
{
	clipArea = document.getElementById("video");
	
	videoCode = '<object width="532" height="333" type="application/x-shockwave-flash" data="player.swf" id="flashcontent" style="visibility: visible;">';
	videoCode += '<param name="scale" value="noScale"/>';
	videoCode += '<param name="allowfullscreen" value="true"/>';
	videoCode += '<param name="allowscriptaccess" value="always"/>';
	videoCode += '<param name="bgcolor" value="' + colour + '"/>';
	videoCode += '<param name="flashvars" value="sourcePath=' + uri + '&amp;autoplay=true&amp;skinBackgroundColor=0x666666&amp;skinBackgroundAlpha=0.5&amp;volume=1&amp;skin=yourflvskin.swf"/>';
	videoCode += '</object>';

	clipArea.innerHTML = videoCode;
}

function showImage(num)
{
	/*iid = 'main_image_' + num;
	
	main_images = document.getElementById('video').getElementsByTagName('img');
	for(i=0; i<main_images.length; i++)
	{
		main_images[i].style.display = 'none';
		main_images[i].style.zIndex = 14;
		main_images[i].style.opacity = 0;
	}
	
	document.getElementById(iid).style.display = 'inline';
	document.getElementById(iid).style.zIndex = 15;
	document.getElementById(iid).style.opacity = 1;*/
	$('#gallery').cycle(num);
}

function showClipList(listName, listHeaderObj)
{

	tables = document.getElementsByTagName("table");
	// loop through tables as we only need to change those that have the clips class
	
	for(var i=0; i<tables.length; i++)
	{
		table_class = tables[i].className;	// cannot use a true DOM checker, as IE can screw it up with the class attribute
		if(table_class == 'clips')
		{
			tables[i].style.display = 'none';		// again, ie screws this up so we have to use the traditional method to change the style
		}
	}

	reels = document.getElementById("reels");
	headings = reels.getElementsByTagName("div");
	for(i=0; i<headings.length; i++)
	{
		headings[i].className = 'inactive';
	}
	listHeaderObj.className = 'active';

	document.getElementById(listName).style.display = 'table';
	reel_clips = document.getElementById(listName).getElementsByTagName('a');

	

	// this bit added to display the image gallery/video player when the gallery/showreel label is clicked

	if(listHeaderObj == 'Image Gallery' || listHeaderObj.innerHTML == 'Image Gallery')
	{
		document.getElementById("flashcontent").style.display = 'none';
// 		document.getElementById("gallery_image").style.display = 'inline';
		document.getElementById("gallery").style.display = 'block';
		document.getElementById("main_image_0").style.display = 'inline';
	}
	else
	{
// 		if(document.getElementById("gallery_image"))
// 		{
// 			document.getElementById("gallery_image").style.display = 'none';
// 		}
		if(document.getElementById("main_image_0"))
		{
			document.getElementById("main_image_0").style.display = 'none';
		}
		document.getElementById("flashcontent").style.display = 'block';
		url = reel_clips[0].href;
		location.href = url;
	}
}

