// JavaScript Document
//Qflix Utility Script
var rootURL = getBaseURL("/")
//alert(pageID);

menuObj.prototype.baseURL= rootURL;  //'http://172.17.0.1/'  //set the base url for all links below...

var menuRoot //set in drawMenu Op
//var pageID  //page ID
//new menuObj(1,"welcome","index.html",1,new Array(),'<img name="welcomeIMG" border=0  src="http://back40.roganstreet.com/minigame/images/LHnav/LHhome_off.gif">'),
							
var menuItems = new Array(
new menuObj('1.0',"Overview","overview/default.html",1,new Array('1.1','1.2','1.3','1.4','1.5'),null,false),
//new menuObj(2000,"Legal","legal/privacypolicy.html",1,new Array(2100,2200),'<img name="gamesIMG" border=0   src="' + rootURL + 'images/LHnav/LHgames_off.gif">'),
new menuObj('2.0',"Licensing","licensing/licensing.html",1,new Array('2.1','2.4'),null,false),
new menuObj('3.0',"Consumers","consumers/consumers.html",1,new Array('3.1'),null,false),
new menuObj('4.0',"Partners","partners/partners.html",1,new Array('4.1','4.2','4.3'),null,false),
new menuObj('5.0',"Press","press/press.html",1,new Array('5.1','5.2'),null,false),
new menuObj('6.0',"About Us","aboutus/default.html",1,new Array('6.5','6.6'),null,false),
new menuObj('7.0',"Qfix FAQ","faq/faq.html",1,null,null,false),

new menuObj('1.1',"What is Qflix?","overview/whatisqflix.html",2,null,null,false),
new menuObj('1.2',"How Qflix Works","overview/howqflixworks.html",2,null,null,false),
new menuObj('1.3',"Qflix Value Proposition","overview/qflixvalueproposition.html",2,null,null,false),
new menuObj('1.4',"Qflix Technical Description","overview/techdescription.html",2,null,null,false),
new menuObj('1.5',"Contact Us","qualification/contactus.html",2,null,null,false),

new menuObj('2.1',"Licensing Overview","licensing/licensingoverview.html",2,new Array('2.1.1','2.1.2'),null,false),
//new menuObj('2.2',"Value Chain","licensing/certification.html",2,null,null,false),

new menuObj('2.1.1',"Licenses","licensing/licenses.html",3,null,null,false),
new menuObj('2.1.2',"Certification","licensing/certification.html",3,null,null,false),

new menuObj('2.4',"Value Chain","licensing/valuechain.html",2,new Array('2.4.1','2.4.2','2.4.3','2.4.4','2.4.5','2.4.6','2.4.7','2.4.8','2.4.9'),null,false),

new menuObj('2.4.1',"Content Owner/Studio","licensing/contentownerstudio.html",3,new Array('2.4.1.1',0),null,false),
new menuObj('2.4.1.1',"Hollywood Screeners Program","licensing/hollywoodscreeners.html",4,null,null,false),
new menuObj('2.4.1.2',"Process Description & Workflow","licensing/contentownerstudio_proc.html",4,null,null,false),
new menuObj('2.4.1.3',"Licensing, Qualification & Certification Kit Description","licensing/contentownerstudio_desc.html",4,null,null,false),
new menuObj('2.4.1.4',"Screener Kit Description","licensing/contentownerscreenerkit.html",4,null,null,false),

new menuObj('2.4.2',"Post Production Professional","licensing/postproductionpro.html",3,null,null,false),
new menuObj('2.4.2.1',"Process Description & Workflow","licensing/postproductionpro_proc.html",4,null,null,false),
new menuObj('2.4.2.2',"Licensing, Qualification & Certification Kit Description","licensing/postproductionpro_desc.html",4,null,null,false),

new menuObj('2.4.3',"Service Provider","licensing/catvdbstelco.html",3,null,null,false),
new menuObj('2.4.3.1',"Process Description & Workflow","licensing/catvdbstelco_proc.html",4,null,null,false),
new menuObj('2.4.3.2',"Licensing, Qualification & Certification Kit Description","licensing/catvdbstelco_desc.html",4,null,null,false),

new menuObj('2.4.4',"Disc Drive Manufacturer","licensing/discdrivemanufacture.html",3,null,null,false),
new menuObj('2.4.4.1',"Process Description & Workflow","licensing/discdrivemanufacture_proc.html",4,null,null,false),
new menuObj('2.4.4.2',"Licensing, Qualification & Certification Kit Description","licensing/discdrivemanufacture_desc.html",4,null,null,false),

new menuObj('2.4.5',"Media Manufacturer","licensing/mediamanufacture.html",3,null,null,false),
new menuObj('2.4.5.1',"Process Description & Workflow","licensing/mediamanufacture_proc.html",4,null,null,false),
new menuObj('2.4.5.2',"Licensing, Qualification & Certification Kit Description","licensing/mediamanufacture_desc.html",4,null,null,false),

new menuObj('2.4.6',"System Manufacturer","licensing/systemmanufacture.html",3,null,null,false),
new menuObj('2.4.6.1',"Process Description & Workflow","licensing/systemmanufacture_proc.html",4,null,null,false),
new menuObj('2.4.6.2',"Licensing, Qualification & Certification Kit Description","licensing/systemmanufacture_desc.html",4,null,null,false),

new menuObj('2.4.7',"Software Developer","licensing/softwaredev.html",3,null,null,false),
new menuObj('2.4.7.1',"Process Description & Workflow","licensing/softwaredev_proc.html",4,null,null,false),
new menuObj('2.4.7.2',"Licensing, Qualification & Certification Kit Description","licensing/softwaredev_desc.html",4,null,null,false),

new menuObj('2.4.8',"Retailer","licensing/retailer.html",3,null,null,false),
new menuObj('2.4.8.1',"Process Description & Workflow","licensing/retailer_proc.html",4,null,null,false),
new menuObj('2.4.8.2',"Licensing, Qualification & Certification Kit Description","licensing/retailer_desc.html",4,null,null,false),

new menuObj('2.4.9',"Systems Integrator","licensing/systemsintegrator.html",3,null,null,false),
new menuObj('2.4.9.1',"Process Description & Workflow","licensing/systemsintegrator_proc.html",4,null,null,false),
new menuObj('2.4.9.2',"Licensing, Qualification & Certification Kit Description","licensing/systemsintegrator_desc.html",4,null,null,false),

new menuObj('3.0',"Consumers","consumers/consumers.html",2,null,null,false),
//new menuObj('3.1',"Partner List - Alphabetic","partners/partnerlistalpha.html",2,null,null,false),
//new menuObj('3.2',"Partner List - Category","partners/partnerlistcategory.html",2,null,null,false),
//new menuObj('3.3',"Find Qflix Certified Products","partners/findcertifiedproducts.html",2,null,null,false),
//new menuObj('3.4',"Partner Management","partners/partnermanagement.html",2,null,null,false),


new menuObj('4.1',"Qflix Press","press/qflixpress.html",2,new Array('4.1.1','4.1.2','4.1.3'),null,false),
new menuObj('4.2',"Partner Release","press/partnerpress.html",2,new Array('4.2.1','4.2.2','4.2.3'),null,false),

new menuObj('5.1.1',"Press Releases","press/qflixreleases.html",3,null,null,false),
new menuObj('5.1.2',"Qflix in the News","press/qflixinthenews.html",3,null,null,false),
new menuObj('5.1.3',"See us @:Event Schedule","press/qflixevents.html",3,null,null,false),

new menuObj('5.2.1',"Press Releases","press/partnerreleases.html",3,null,null,false),
new menuObj('5.2.2',"Qflix in the News","press/partnerinthenews.html",3,null,null,false),
new menuObj('5.2.3',"See us @:Event Schedule","press/partnerevents.html",3,null,null,false),

new menuObj('8.1',"Copyright 2005 Sonic Solutions","legal/copyright.html",2,null,null,false),
new menuObj('8.2',"Terms of Use","legal/termsofuse.html",2,null,null,false),
new menuObj('8.3',"Privacy Policy","legal/privacypolicy.html",2,null,null,false),
new menuObj('8.4',"Trademarks and Copyrights","legal/copyright.html",2,null,null,false),

new menuObj('6.1',"Qflix","aboutus/aboutqflix.html",2,null,null,false),
new menuObj('6.2',"Management","aboutus/management.html",2,null,null,false),
new menuObj('6.3',"Careers","aboutus/careers.html",2,null,null,false),
new menuObj('6.4',"Investors","aboutus/investors.html",2,null,null,false),
//new menuObj('6.5',"Start Here","qualification/qualify.html",2,new Array('6.5.1',0),null,false),
new menuObj('6.6',"Contact Qflix","qualification/contactus.html",2,new Array('6.6.1',0),null,false),
new menuObj('6.5.1',"Thank You","qualification/thankyou_qualify.html",3,null,null,true),
new menuObj('6.6.1',"Thank You","qualification/thankyou_contact.html",3,null,null,true),

new menuObj('7.0',"Search","search/search.html",2,null,null,false)

)
							
							
					
function menuObj(p_id,p_display,p_URL,p_level,p_children,p_imgstr,p_exclusive){
	this.id=p_id;
	this.display=p_display;
	this.URL=p_URL;
	this.level=p_level;
	this.children= p_children;
	this.state = 0; //0=closed (default), 1 = open, 2 = active
	this.imgstr= p_imgstr;
	this.exclusive = p_exclusive; // false = sow all teh time, true = show in nav ONLY on the page it represents
	this.getURL = (this.baseURL + this.URL);
	return this
}

for(nn=0;nn < menuItems.length; nn++){
	trimChildren(nn);
}


function trimChildren(p_index){
	if(menuItems[p_index].children != null){
		if(menuItems[p_index].children[1] == 0){  // the second value is 0 indicating a single entry, so needs a trim
			menuItems[p_index].children.length = 1
		}
	}
}


function getBaseURL(p_delim){
	//strip everything off the end of the base url...
	var tmpURL =new String(document.location )
	//first sve the protocol header
	var tmpProtocol = tmpURL.substring(0,tmpURL.indexOf("://") + 3); 
	//next, get the root slash
	var tmpRoot =tmpURL.substring(tmpProtocol.length)  //
	if(tmpRoot.indexOf("back40") != -1){
		tmpRoot = tmpRoot.substring(0,(tmpRoot.indexOf(p_delim) + p_delim.length))  //search for trailing slash for domain root
		tmpURL = tmpProtocol + tmpRoot
	}else{
		tmpRoot = tmpRoot.substring(0,(tmpRoot.indexOf("/") + 1))  //search for trailing slash for domain root
		tmpURL = tmpProtocol + tmpRoot
	}
	return tmpURL
}

function buildMenuList(p_id){
	//alert("id=" + getSiblings(p_id));
	//alert(menuItems[getIndexbyID(getSiblings(p_id))].display);
	var curPageID= p_id
	var curLevel = menuItems[getIndexbyID(curPageID)].level
	var tmpPageID
	while(curLevel > 1){
		tmpPageID = getSiblings(curPageID);	
		if(menuItems[getIndexbyID(tmpPageID)].children != null){  //found siblings ID
			menuItems[getIndexbyID(tmpPageID)].state = 1;
			curPageID = tmpPageID
			curLevel = menuItems[getIndexbyID(tmpPageID)].level
		}else{
			curLevel = 1
		}
	}	
}

function getSiblings(p_id){
	for(nn=0;nn < menuItems.length;nn++){
		if(menuItems[nn].children != null){  //found a list, lets check it out!
			for(cc=0;cc < menuItems[nn].children.length;cc++){
				if(menuItems[nn].children[cc] == p_id){  //on any hit, we've found the list of siblings
					return menuItems[nn].id //return the ID
				}
			}
		}
	}
}

function getIndexbyID(p_id){
	for(ii=0;ii<menuItems.length;ii++){
		if(menuItems[ii].id==p_id){
			return (ii);
		}
	}
}

function goNav(p_id){
	document.location = menuItems[getIndexbyID(p_id)].getURL;
}

function setExclusiveState(){
	for(ii=0; ii< menuItems.length; ii++){
		if(menuItems[ii].exclusive){
			menuItems[ii].state = -1
		}
	}
}

function drawMenu(){
	//pageID = getPageIDbyURL();
	//alert(pageID);
	
	buildMenuList(pageID);
	setExclusiveState();

	menuItems[getIndexbyID(pageID)].state=2 //set the active menu item

	var tmpStr = ''
	var tmpRoot = 0
	var tmpSub = 0
	var tmpDetail = 0
	var headerStr=""
	var footerStr=""
	var tranImg='<img src="' + rootURL + '/images/global/sp_tran.gif" width=6 height=1 border=0>'
	var header = true  //set the render mode to true
	var rr = 0
	while(menuItems[rr].level == 1){
		if(header){  //in header mode
			if(menuItems[rr].state >= 1){
				tmpRoot = rr
				menuRoot = tmpRoot
				header= false
				//headerStr += '<a name="' + menuItems[rr].display + '" href="'+ menuItems[rr].getURL +'">' + menuItems[rr].display + '</a>'                        
			}else{
				//headerStr += '<a name="' + menuItems[rr].display + '" href="'+ menuItems[rr].getURL +'" onmouseover="hiliteMe(\'' + menuItems[rr].display + 'IMG\',\'ovr\');" onmouseout="hiliteMe(\'' + menuItems[rr].display + 'IMG\',\'out\');">' + menuItems[rr].display + '</a><br>'
             
			}
		}else{
			//footerStr += '12<a name="' + menuItems[rr].display + '" href="'+ menuItems[rr].getURL +'" onmouseover="hiliteMe(\'' + menuItems[rr].display + 'IMG\',\'ovr\');" onmouseout="hiliteMe(\'' + menuItems[rr].display + 'IMG\',\'out\');">' + menuItems[rr].display + '</a><br>'

		}
		rr++  //ad to rr
	}
    //we have a header and footer, now lets get the sub menu items

	if(menuItems[tmpRoot].children != null){

	tmpStr = ''
	tmpStr += '<br/><div name="menuItems" class="menuItems">'
	// level 2 items here......
	for(xx=0; xx< menuItems[tmpRoot].children.length;xx++){
		tmpSub = getIndexbyID(menuItems[tmpRoot].children[xx])
		if(menuItems[tmpSub].state == 0){
				//<div name="open" class="menuClose">1
				tmpStr += '<div class="menuClose1"><a name="testme" class=menuClose href="' + menuItems[tmpSub].getURL + '">' + menuItems[tmpSub].display + '</a></div>'; //</div>
		}else{
			if(menuItems[tmpSub].state == 1){
				tmpStr += '<div name="open" class="menuOpen1"><a name="testme" class=menuOpen href="' + menuItems[tmpSub].getURL + '">' + menuItems[tmpSub].display + '</a></div>'
			}else{
				tmpStr += '<div name="testme" class="menuActive1" >' + menuItems[tmpSub].display + '</div>'
			}
					
			// level 3 items here.....
			if(menuItems[tmpSub].children != null){
					for(ss=0; ss<menuItems[tmpSub].children.length; ss++){
						var tmpDetail = getIndexbyID(menuItems[tmpSub].children[ss])
						
						if(menuItems[tmpDetail].state == 0){
							tmpStr += '<div class="menuClose2"><a name="testme" class="menuClose" href="' + menuItems[tmpDetail].getURL + '">' + menuItems[tmpDetail].display + '</a></div>';
						}else{
							if(menuItems[tmpDetail].state == 2){  // we assume its open, we are looking for active only
							tmpStr += '<div name="testme" class=menuActive2 >' + menuItems[tmpDetail].display + '</div>';
							}else if (menuItems[tmpDetail].state == 1){
							tmpStr += '<div name="open" class=menuOpen2><a name="testme" class=menuOpen  href="' + menuItems[tmpDetail].getURL + '">' + menuItems[tmpDetail].display + '</a></div>'
							}
						// level 4 items here....
						if(menuItems[tmpDetail].children != null){
							for(cc=0; cc<menuItems[tmpDetail].children.length; cc++){
								var tmpFinal = getIndexbyID(menuItems[tmpDetail].children[cc])

								
								if(menuItems[tmpFinal].state == 0){
									tmpStr += '<div class=menuClose3><a name="testme" class=menuClose href="' + menuItems[tmpFinal].getURL + '">' + menuItems[tmpFinal].display + '</a></div>';
								}else{
								
								
									if(menuItems[tmpFinal].state == 2){  // we assume its open, we are looking for active only
										tmpStr += '<div name="testme" class=menuActive3 >' + menuItems[tmpFinal].display + '</div>';
									}else if (menuItems[tmpFinal].state == 1){
								
										tmpStr += '<div name="open" class=menuOpen3><a name="testme" class=menuOpen  href="' + menuItems[tmpFinal].getURL + '">'+ menuItems[tmpFinal].display + '</a></div>'
									}
								}
							}
						}
						}
					}
				}	
			}
		}
	}
	tmpStr += '</div>'
	//compile the header, menu itmes and footer for the complete package :)
	return (headerStr  + tmpStr + footerStr)
	//return tmpStr
}

function getImg(p_src,p_mode){
	var tmpSrc = p_src.substring(0,p_src.indexOf('.'))
	var tmpReturn
	if(p_mode == 1){
		tmpReturn = (tmpSrc + '_on.gif">');
	}else{
		tmpReturn = p_src
	}
	return tmpReturn
}


function popWin(p_name,p_mode){  //
	var tmpObj = document.images[p_name]
	//alert(tmpObj);
	switch (p_mode) {
		case "_blank":
		var tmpSrcIndex = document.images[p_name].src.lastIndexOf('/',document.images[p_name].src.length);
		var tmpObjSrc =  document.images[p_name].src.substring(tmpSrcIndex)
		
		var tmpSrc = tmpObjSrc.split('.');
  			window.open(document.images[p_name].src.substring(0,tmpSrcIndex) + tmpSrc[0] + '_LG.' + tmpSrc[1],p_name);
			break;
		case "_custom":
			window.open(p_name,p_name);
			break;
		default:
			alert("didn't get that:" + p_name)
	}
}

function drawPopCorn(){
	var tmpStr = menuItems[menuRoot].display + " | " + menuItems[getIndexbyID(pageID)].display
	return tmpStr.toUpperCase()
}

function hiliteMe(p_name,p_mode){  //mode="ovr" = rollover,"out" = mouseleave; p_obj = this
	var tmpObj = document.images[p_name]
	//alert(tmpObj);
	switch (p_mode) {
		case "ovr":
			tmpObj.src=getImageSrc(tmpObj.src,"ovr")
			break;
		case "out":
			tmpObj.src=getImageSrc(tmpObj.src,"off")
			break;
		default:
			alert("didn't get that:" + p_name)
	}
}

function getImageSrc(p_src,p_delta){  //looks for the "_" back from the "."and works backward to create name
	var tmpString = new String(p_src);
	var tmpData = tmpString.substring(0,tmpString.lastIndexOf("_",tmpString.length));  //get everything before the last "_"
	var tmpType =  tmpString.substring(tmpString.lastIndexOf(".",tmpString.length));  //get everything after the "."
	//alert('rollover=' + tmpData + '_' + p_delta + tmpType)
	return(tmpData + '_' + p_delta + tmpType);
}

	
	
	
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
	if (init==true) with (navigator) {
		if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    		document.MM_pgW=innerWidth;
			document.MM_pgH=innerHeight;
			onresize=MM_reloadPage; 
		}
	}else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function drawLegalFooter(){
	var tmpHTML = '<table width="100%"><tr>';
	tmpHTML += '<td><span class="legalFooter">&copy;2006-2007 Sonic Solutions</span></td>';
	tmpHTML += '<td><a href="javascript:goNav(\'8.2\');" class="legalFooter">Terms of use</a></td>';
	tmpHTML += '<td><a href="javascript:goNav(\'8.3\');" class="legalFooter">Privacy Policy</a></td>';
	tmpHTML += '<td><a href="javascript:goNav(\'6.6\');" class="legalFooter">Contact Us</a></td>';
	tmpHTML += '</tr></table>';
	return tmpHTML;
}

function topNavClass(p_label,p_id){
	this.id = p_id;
	this.label = p_label;
	return this;
}

function drawTopNav(){
	// draw the top nav based o the active root menu item
	var tmpHTML = '<div> \n'
	var tmpNavList = new Array(	new topNavClass('home','0'),
									new topNavClass('Overview','1'),
									new topNavClass('For Licensees','2'),
									new topNavClass('For Consumers','3'),
									new topNavClass('Partners','4'),
									new topNavClass('Press','5'),
									new topNavClass('About Us','6'),
									new topNavClass('Qflix FAQ','7'))
	
	var tmpIndex = pageID.split('.'); // get the root page
	for(nn = 1;nn < tmpNavList.length ;nn++){
		if(tmpIndex[0] != tmpNavList[nn].id){
			tmpHTML += '<span style="padding-left:12px;padding-right:12px"><img src="/images/spacer.gif" height="14" width="1">'
			tmpHTML += '<a href="javascript:goNav(\'' + tmpNavList[nn].id + '.0\');" class="topNav">' + tmpNavList[nn].label + '</a></span> \n'
		}else{
			tmpHTML +='<span style="border:3px solid #a1b7cc;padding-left:12px;padding-right:12px;background-color:#a1b7cc;color:#ffffff;"><img src="/images/spacer.gif" height="14" width="1">'
			tmpHTML += '<a href="javascript:goNav(\'' + tmpNavList[nn].id + '.0\');" class="topNav" style="color:#ffffff;">' + tmpNavList[nn].label + '</a></span> \n'
		}
	}
	tmpHTML += '</div>'
	//tmpHTML += '<input type="text" size="24" name="searchTerms" style="height:14px;"><img src="/images/global/go_right.gif" border=0 hspace=2 align="absmiddle"></a></div>'
	document.write(tmpHTML);
};

function drawLeftNavHeader(){
		// draw the top nav based o the active root menu item
	var tmpIndex = pageID.split('.'); // get the root page
	var tmpHTML = '<a class="topNavHeader" href="javascript:goNav(\'' + tmpIndex[0] + '.0\');"><div class="topNavHeader">'
	var tmpNavList = new Array(	new topNavClass('home','0'),
									new topNavClass(''),
									new topNavClass(''),
									new topNavClass(''),
									new topNavClass(''),
									new topNavClass(''),
									new topNavClass(''),
									new topNavClass(''))
	
	
	for(nn = 1;nn < tmpNavList.length ;nn++){
		if(tmpIndex[0] == tmpNavList[nn].id){
			tmpHTML += tmpNavList[nn].label.toUpperCase() 
		}
	}
	tmpHTML += '</div></a>'
	document.write(tmpHTML);
}
	















