// BROWSER DETECT CODE 
var d, dom, ie, ie4, ie5x, moz, mac, win, lin, old, ie5mac, ie5xwin, op;

d = document;
n = navigator;
na = n.appVersion;
nua = n.userAgent;
win = ( na.indexOf( 'Win' ) != -1 );
mac = ( na.indexOf( 'Mac' ) != -1 );
lin = ( nua.indexOf( 'Linux' ) != -1 );

if ( !d.layers ){
	dom = ( d.getElementById );
	op = ( nua.indexOf( 'Opera' ) != -1 );
	konq = ( nua.indexOf( 'Konqueror' ) != -1 );
	saf = ( nua.indexOf( 'Safari' ) != -1 );
	moz = ( nua.indexOf( 'Gecko' ) != -1 && !saf && !konq);
	ie = ( d.all && !op );
	ie4 = ( ie && !dom );

	/*
	ie5x tests only for functionality. ( dom||ie5x ) would be default settings. 
	Opera will register true in this test if set to identify as IE 5
	*/

	ie5x = ( d.all && dom );
	ie5mac = ( mac && ie5x );
	ie5xwin = ( win && ie5x );
	
}

var menuTitles = ['Home', 'Download', 'Buy', 'Support', 'Contact'];
var submenuTitles = [['What is cuePics?', 'How does it work?', 'Who is it for?', 'Feature List', 'Supported File Formats', 'Minimum Recommended Specifications', 'Why QuickTime?', 'Awards', 'Picture Power'], ['Summary', 'Windows Version', 'Mac Version', 'Version History'], ['How to Buy'], ['Support', 'FAQs', 'Version History'], ['Contact']];
var sectionFileRefs = [['01_home_01_overview', '01_home_02_description', '01_home_03_who_for', '01_home_04_features', '01_home_05_file_formats', '01_home_06_minimum_specs', '01_home_07_why_quicktime', '01_home_08_awards', '01_home_09_picture_power'], ['02_download_01_download', '02_download_02_windows', '02_download_03_mac', '02_download_04_version_history'], ['03_buy_01_buy'], ['04_support_01_support', '04_support_02_faqs', '04_support_03_version_history'], ['05_contact_01_contact']];

function writeSubMenu(sectionNo, subsectionNo)
{
	var html = '';
	
	html += '<div style="padding: 20px 0px 0px 0px">';
	if (submenuTitles[sectionNo - 1].length > 1)  //if only one sub-menu command then don't show menu
	{
		//html += '<div style="height: 300px">';
		for (var i = 1; i <= submenuTitles[sectionNo - 1].length; i++)
		{
			if (i == subsectionNo)
			{
				html += '<div class="t_submenu_inactive">';
				if (i != 1) html += '<br>';
				html += submenuTitles[sectionNo - 1][i - 1];
				html += '</div>';
			}
			else
			{
				html += '<div class="t_submenu">';
				if (i != 1) html += '<br>';
				html += '<a href="' + getSectionFileName(sectionNo, i) + '">' + submenuTitles[sectionNo - 1][i - 1] + '</a>';
				html += '</div>';
			}
		}
		//html += '</div>';
		//Write horizontal divider
		html += '<div style="width: 85%; padding: 20px 0px 0px 0px; margin: 0 auto;">';
		html += '<hr>';
		html += '</div>';
	}
	//Write news section
	var boxOffset;
	if (sectionNo == 3 || sectionNo == 5)
		topgap = '0px';
	else
		topgap = '20px';
	html += '<div style="padding: ' + topgap + ' 0px 0px 0px"><img src="' + getRelativePath(sectionNo, subsectionNo, "pic") + '/facebook_newsalert.jpg" alt="Facebook News Alert" width="163" height="93" hspace="0" vspace="0" border="0" align="middle"></div>';
	html += '<div id="box_demo" class="t_content" style="margin-left: auto; margin-right: auto; margin-top: 5px; width: 77%; padding: 5px 10px 5px 10px; font-size: 9pt; line-height:12pt; background-color: #e7e7e7">';
	html += '<div style="padding: 0px 0px 10px 0px; color:#005ab2;"><b>Latest News</b></div>';
	html += 'cuePics used on the <a style="font-size:9pt" href="http://www.crossoverlabs.org" target="_blank">Crossover Kids</a> workshop to brainstorm ideas for pitches to the BBC, Disney, Nickelodeon and Jetix.';
	if (sectionNo != 2)
		html += '<br><br>Download a demo version <a href="' + getSectionFileName(2, 1) + '" target="_self" style="font-size: 9pt">here</a>.';
	html += '</div>';
	html += '<div id="box_demo" class="t_content" style="margin-left: auto; margin-right: auto; margin-top: 10px; width: 77%; padding: 10px 10px 10px 10px; font-size: 9pt; line-height: 9pt; background-color: #e7e7e7">';
	html += '<div style="margin-top: 5px; margin-bottom: 0px;">';
	html += '	<div style="text-align:center">';
	html += '<img src="' + getRelativePath(sectionNo, subsectionNo, "pic") + '/tucows.gif" width="114" height="22" hspace="0" vspace="0" border="0" align="top">';
	html += '</div>';
	html += '<div style="font-size: 8pt; text-align:center; padding: 5px 0 0 0">';
	html += 'Awarded 4 (out of 5) cows<br>from <a href="http://www.tucows.com" target="_blank" style="font-size: 8pt">Tucows</a>';
	html += '</div>';
	html += '</div>';
	html += '<div style="margin-top: 15px; margin-bottom: 0px;">';
	html += '<div style="text-align:center">';
	html += '<img src="' + getRelativePath(sectionNo, subsectionNo, "pic") + '/sofotex_5_star_rating.gif" width="121" height="61" hspace="0" vspace="0" border="0" align="top">';
	html += '</div>';
	html += '<div style="font-size: 8pt; text-align:center; padding: 5px 0 0 0">';
	html += 'Awarded 5 (out of 5) stars<br>from <a href="http://www.sofotex.com" target="_blank" style="font-size: 8pt">Sofotex</a>';
	html += '</div>';
	html += '</div>';
	html += '<div style="margin-top: 10px; margin-bottom: 0px;">';
	html += '	<div style="text-align:center">';
	html += '<a href="http://www.brothersoft.com/cuepics-245225.html" target="_blank"><img src="http://author.brothersoft.com/softimg/pick_100.gif" width="90" height="70" hspace="0" vspace="0" border="0"></a>';
	html += '</div>';
	html += '<div style="font-size: 8pt; text-align:center; padding: 5px 0 0 0">';
	html += 'Editor\'s pick from <a href="http://www.brothersoft.com" target="_blank" style="font-size: 8pt">Brothersoft</a>';
	html += '</div>';
	html += '</div>';
	html += '</div>';
	html += '</div>';
	document.write(html);
}

function writeTopFrame()
{
	var html = getTopFrameHTML();
	
	document.write(html);
}

function getTopFrameHTML()
{
	var html = '';
	var currentSectionAndSubsectionNos, currentSectionNo, currentSubsectionNo;
	
	currentSectionAndSubsectionNos = getCurrentSectionAndSubsectionNos();
	currentSectionNo = currentSectionAndSubsectionNos[0];
	currentSubsectionNo = currentSectionAndSubsectionNos[1];
	html += '<table width="744" border="0" cellpadding="0" cellspacing="0">';
	html += '	<tr valign="top">';
	html += '		<td width="182" align="left">';
	html += '			<div class="box_bannerLeft">';
	if (currentSectionNo == 1 && currentSubsectionNo == 1)
		relPath = 'pic/';
	else
		relPath = '../pic/';
	html += '				<a href="' + getSectionFileName(1, 1) + '"><img src="' + relPath + 'frame_top_left.jpg" width="180" height="90" hspace="0" vspace="0" border="0" align="left"></a>';
	html += '			</div>';
	html += '		</td>';
	html += '		<td width="562" align="left">';
	html += '			<div class="box_bannerRight">';
	html += '				<div class="box_menu">';
	//html += '					<div style="background: url(pic/banner_top_right.jpg) repeat">';
	for (var i = 1; i <= menuTitles.length; i++)
	{
			if (i == currentSectionNo)
				html += '<span class="t_menu_off">' + menuTitles[i - 1] + '</span>';  //<a href="' + getSectionFileName(i, 1) + '">' + menuTitles[i - 1] + '</a></span>';
			else
				html += '<span class="t_menu"><a href="' + getSectionFileName(i, 1) + '">' + menuTitles[i - 1] + '</a></span>';
			if (i <= menuTitles.length - 1)
				html += '<span class="t_menu" style="cursor: default"> | </span>';
	}
	//html += '					</div>';
	html += '				</div>';
	html += '			</div>';
	html += '		</td>';
	html += '	</tr>';
	html += '</table>';
	return html;
}


function showURL()
{
	//var urlArray = window.location.split('/');
	//alert(window.location);
	//alert(urlArray[urlArray.length - 1]);
}

function getRelativePath(sectionNo, subsectionNo, folderName)
{
	var currentSectionAndSubsectionNos = getCurrentSectionAndSubsectionNos(), currentSectionNo, currentSubsectionNo;
	
	currentSectionNo = currentSectionAndSubsectionNos[0];
	currentSubsectionNo = currentSectionAndSubsectionNos[1];
	if (currentSectionNo == 1 && currentSubsectionNo == 1) //currently at index page, so work out new page relative to this
	{
		return './' + folderName;
	}
	else //currently in pages folder, so work out new page relative to this
	{
		return '../' + folderName;
	}
}

function getSectionFileName(sectionNo, subsectionNo)
{
	var currentSectionAndSubsectionNos = getCurrentSectionAndSubsectionNos(), currentSectionNo, currentSubsectionNo;
	
	currentSectionNo = currentSectionAndSubsectionNos[0];
	currentSubsectionNo = currentSectionAndSubsectionNos[1];
	if (currentSectionNo == 1 && currentSubsectionNo == 1) //currently at index page, so work out new page relative to this
	{
		if (sectionNo == 1 && subsectionNo == 1)
			return './index.html';
		else
			return 'page/' + sectionFileRefs[sectionNo - 1][subsectionNo - 1] + '.html';
	}
	else //currently in pages folder, so work out new page relative to this
	{
		if (sectionNo == 1 && subsectionNo == 1)
			return '../index.html';
		else
			return sectionFileRefs[sectionNo - 1][subsectionNo - 1] + '.html';
	}
}

function getCurrentSectionAndSubsectionNos()
{
	var urlArray = window.location.href.split('/');
	var sectionNo, subsectionCharNo, subsectionNo;
	
	currentFileName = urlArray[urlArray.length - 1];
	if (currentFileName.indexOf('.html') == -1) currentFileName = 'index.html';
	switch (currentFileName)
	{
		case '', 'index.html':
			return [1, 1];
			break;
			
		default:
		  sectionNo = parseInt(currentFileName.charAt(1));
		  subsectionCharNo = 3 + (menuTitles[sectionNo - 1]).length + 3;
			subsectionNo = parseInt(currentFileName.charAt(subsectionCharNo - 1));
			return [sectionNo, subsectionNo];
			break;	
	}
}

//open picture popup window
function popUpPicture(pictureFileName, width, height)
{
	//var pic;
	var url, html = '';
	var currentSectionAndSubsectionNos = getCurrentSectionAndSubsectionNos(), currentSectionNo, currentSubsectionNo;
	
	currentSectionNo = currentSectionAndSubsectionNos[0];
	currentSubsectionNo = currentSectionAndSubsectionNos[1];
	if (currentSectionNo == 1 && currentSubsectionNo == 1) //currently at index page, so work out pages relative to this
	{
		popupURL = 'page/show_screen.html';
		relURL = '';
	}
	else
	{
		popupURL = 'show_screen.html';
		relURL = '../';
	}
		
	newWindow = window.open('','newWin','width=' + width + ',height=' + height + ',toolbar=no,location=no,directories=no,status=0,menubar=0,scrollbars=no,resizable=no,top=40,left=200');
	
	window.focus();
	
	html += '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">';
	html += '<html>';
	html += '<head>';
	html += '<title>cuePics Screen Examples</title>';
	html += '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">';
	html += '<link rel="stylesheet" type="text/css" href="' + relURL + 'script_css/text.css">';
	html += '<link rel="stylesheet" type="text/css" href="' + relURL + 'script_css/elements.css">';
	html += '</head>';
	html += '<body>';
	html += '<center>';
	html += '<img src="' + relURL + 'pic/' + pictureFileName + '.jpg">';
	html += '</center>';
	html += '</body>';
	html += '</html>';
	d = newWindow.document;
	d.open();
	d.write(html);
	d.close();
	
	newWindow.focus();
	//pic = newWindow.document.screenPicture;  //newWindow.document.getElementById('screenPicture');
	//newWindow.document.screenPicture.src = 'pic/' + pictureFileName + '.html';
}

 // close window
function closeWin()
{
	self.close();
}

//focus mother window
function focusMom()
{
	opener.focus();
}

// SET BROWSER SCROLL BAR TO TOP & SET PAGE TO TOP: 
 function scrollToTop() 
{	
	//MAC
	parent.document.body.scrollTop = 0;
	// PC
	parent.scrollTo(0,0);
	scrollTo(0,0);	
}

//NOT USED
// LOAD main PAGE and submenu
function loadPage(urlRef)
{
	//move scroll bar to top
	//MAC
	parent.document.body.scrollTop = 0;
	// PC
	parent.scrollTo(0,0);

	//load page to main frame
	var pageUrl;
	
	pageUrl = "./page/" + urlRef + ".html";
	window.parent.frames['mainFrame'].location = pageUrl;
}

//NOT USED
function scrollToAnchor(anchorNo)
{
	var d = window.parent.frames['mainFrame'].document;
	if (saf || moz)
	{
		y = findPos(d.anchors[anchorNo - 1])[1];
		//alert(y);
		parent.scrollTo(0,y);
	}
	else
	{
		y = (d.anchors[anchorNo - 1]).offsetTop;
		//alert(y);
		parent.scrollTo(0,y);
	}
}

//NOT USED
function findPos(obj) {
	var curleft = curtop = 0;
	
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

// CHANGE IFRAME HEIGHT depending on it's contents.--------------------------------------------------------------------------------

//NOT USED
function changeHeightA()
{
	if ( ie5mac || saf || moz ) {
		
		var cLevel1 = this.document.body.offsetHeight;
		//alert (cLevel1);
		
		var pLevel0 = parent.document.getElementById('divRightCol').style.height;
		//alert (pLevel0);
		// take out "px" from the string.  
		x = pLevel0.slice(0, -2);
		// convert to number from string.
		x = parseInt(x);
		// make parent frame height 0, and add child document height
		x = x - x + cLevel1;
		//newHeight  = xa + "px";
		newHeightA  = x;
		//alert (newHeightA);
		// for iFrame bottom - name: "bottomCol"
		parent.document.getElementById('divRightCol').style.height = newHeightA + "px"; 	
	}
	else if ( ie5xwin ){
		// for iFrame right- name: "rightCol"
	  	var cLevel1_a = this.document.body.scrollHeight;
 		parent.document.getElementById('divRightCol').style.height = cLevel1_a + "px"; 		
	}
	else if ( ie4 ){
		alert("This browser is not optimal for viewing this web site. Code: ie4");
		parent.document.getElementById('divRightCol').style.height = 5000 + "px";
	}
	else if ( d.layers ){// Netscape 4
		alert("This browser is not optimal for viewing this web site. Code: netscape4");
		parent.document.getElementById('divRightCol').style.height = 5000 + "px";
	}	
	else {
		alert("This browser is not optimal for viewing this web site. Code:else");
		parent.document.getElementById('divRightCol').style.height = 5000 + "px";
	}
}