var RefenceURL = document.location.protocol +'//www.copernic.com/';
var RefImgURL = document.location.protocol +'//images.copernic.com/';

var _mylanguage = 'en';

function loadMenu(selmenu, ismenu, isheader) {
	var req;
	var MenuDiv;
	
	var _aMenu = new Array ("home-on", "products-en-on", "company-en-on", "store-en-on", "support-en-on", "partners-en-on", "community-en-on");

	if (selmenu >= 0) { _aMenu[selmenu] = _aMenu[selmenu].substring(0, _aMenu[selmenu].length -3) + "-selected"; }
	
	if (ismenu || ismenu == undefined) { getembedmenu(_aMenu, true); } else {  getembedmenu(_aMenu, false); }
	if (isheader || isheader == undefined) { getembedheader(true); } else { getembedheader(false); }
	getembedfooter(isheader);
}

function getembedheader(p_displayHeader) {
	var currentAd = document.location.href.split('/en/')[1];

	if (p_displayHeader) {
		if (currentAd) {
			var _lcontent;
			var futurindex, lastindex = 0;
			var isindex = currentAd.split('/index.html').length -1;
	
			_lcontent = '<a href="' +RefenceURL +'en/' +'index.html">Home</a>';
			
			if (isindex) {
				while((futurindex = currentAd.indexOf('/', lastindex)) > 0) {
					if (currentAd.indexOf('/', futurindex +1) > 0) {
						_lcontent += ' > <a href="' +RefenceURL +'en/' + currentAd.substring(0,futurindex) +'/index.html">' +getAdValue(currentAd.substring(lastindex, futurindex)) +'</a>';
					} else { break;	}
					lastindex = futurindex +1;
				}
				_lcontent += " > " +getAdValue(currentAd.substring(lastindex, futurindex));
			} else {
				while((futurindex = currentAd.indexOf('/', lastindex)) > 0) {
					_lcontent += ' > <a href="' +RefenceURL +'en/' + currentAd.substring(0,futurindex) +'/index.html">' +getAdValue(currentAd.substring(lastindex, futurindex)) +'</a>';
					lastindex = futurindex +1;
				}
				_lcontent += " > " +getAdValue(currentAd.substring(lastindex).split('.html')[0]);
			}
		} else {
			_lcontent = "Home";
			currentAd = "index.html";
		}
		
		document.getElementById('copernic-header').innerHTML = 
			'<div align="right" style="width:870px; margin:auto;">' +
			'<table cellpadding="0" cellspacing="0"><tr>' +
				'<td>' +_lcontent +'</td>' +
				'<td><span id="header-location">&nbsp;</span></td>' +
				'<td width="45"><img src="' +RefImgURL +'c9/template/header-star.gif" alt="" width="45" height="15"/></td>' +
				'<td>English&nbsp;&nbsp;|&nbsp;&nbsp;<a href="' +RefenceURL +'fr/' +currentAd + '">Fran&ccedil;ais</a></td>' +
			'</tr></table>' +
			'</div>';
	} else {
		document.getElementById('copernic-header').innerHTML = 
			'<div align="right" style="width:870px; height:25px; margin:auto;">' +
			'<img src="' + RefImgURL + '1-pixel.gif" alt="" width="1" height="1" />' +
			'</div>';
	}
}

function getembedmenu(_aMenu, ismenu) {
	var tMenu;

	tMenu =	'<table cellpadding="0" cellspacing="0" class="mainmenu" width="100%"><tr>';
			if (ismenu) {
	tMenu = tMenu +
			'<td align="left" valign="top"><a href="' +RefenceURL +'index.html" id="menu-item-home"><img src="' +RefImgURL +'c9/template/menu/' +_aMenu[0] +'.gif" border="0" onmouseover="javascript:menumouse(this, true);" onmouseout="javascript:menumouse(this, false);" alt="Copernic Home" width="156" height="84" /></a></td>' +
			'<td align="left" valign="top"><a href="' +RefenceURL +'en/products/index.php" id="menu-item-products"><img src="' +RefImgURL +'c9/template/menu/' +_aMenu[1] +'.gif" border="0" onmouseover="javascript:menumouse(this, true);" onmouseout="javascript:closetimer();" alt="Products" width="123" height="84" /></a></td>' +
			'<td align="left" valign="top"><a href="' +RefenceURL +'en/company/index.html" id="menu-item-company"><img src="' +RefImgURL +'c9/template/menu/' +_aMenu[2] +'.gif" border="0" onmouseover="javascript:menumouse(this, true);" onmouseout="javascript:closetimer();" alt="Company" width="123" height="84" /></a></td>' +
			'<td align="left" valign="top"><a href="' +RefenceURL +'en/store/index.php" id="menu-item-store"><img src="' +RefImgURL +'c9/template/menu/' +_aMenu[3] +'.gif" border="0" onmouseover="javascript:menumouse(this, true);" onmouseout="javascript:closetimer();" alt="Store" width="123" height="84" /></a></td>' +
			'<td align="left" valign="top"><a href="' +RefenceURL +'en/support/index.php" id="menu-item-support"><img src="' +RefImgURL +'c9/template/menu/' +_aMenu[4] +'.gif" border="0" onmouseover="javascript:menumouse(this, true);" onmouseout="javascript:menumouse(this, false);" alt="Support" width="123" height="84" /></a></td>' +
			'<td align="left" valign="top"><a href="' +RefenceURL +'en/partners/index.html" id="menu-item-partners"><img src="' +RefImgURL +'c9/template/menu/' +_aMenu[5] +'.gif" border="0" onmouseover="javascript:menumouse(this, true);" onmouseout="javascript:closetimer();" alt="Partners" width="123" height="84" /></a></td>' +
			'<td align="left" valign="top" style="border-color:#cbd5d9;"><a href="' +RefenceURL +'en/community/index.php" id="menu-item-community"><img src="' +RefImgURL +'c9/template/menu/' +_aMenu[6] +'.gif" border="0" onmouseover="javascript:menumouse(this, true);" onmouseout="javascript:menumouse(this, false);" alt="Community" width="123" height="84" /></a></td>';
			} else {
	tMenu = tMenu +
			'<td align="left" valign="top" style="border:none;"><a href="' +RefenceURL +'en/index.html" id="menu-item-home"><img src="' +RefImgURL +'c9/template/menu/' +_aMenu[0] +'.gif" border="0" onmouseover="javascript:menumouse(this, true);" onmouseout="javascript:menumouse(this, false);" alt="Copernic Home" width="156" height="84" /></a></td>';
			}
	tMenu = tMenu +
			'</tr></table>' +
			'<div style="position:absolute; top:0px; left:-250px;"><img src="' +RefImgURL +'c9/template/background-waves.jpg" alt="" border="0" width="250" height="100" /></div>' +
			'<div style="position:absolute; top:84px;"><img src="' +RefImgURL +'c9/template/shadow-menu.png" alt="" width="900" height="17" /></div>' +
			'<div class="sousmenu" id="sousmenu">' +getembedsubmenus() +'</div>';
	
	document.getElementById('copernic-menu').innerHTML = tMenu;
}

function getembedsubmenus() {
	var submenutotal = '';

	submenutotal += '<div id="sub-menu-products" class="mtt" onmouseout="javscript:closetimer();" onmouseover="javascript:getdropdown();" style="left:156px;">' +
					'<div onclick="javascript:openlink(this);"><a href="' +RefenceURL + 'en/products/index.php">Copernic Products</a></div>' +
					'<div class="division">PC</div>' +
					'<div onclick="javascript:openlink(this);"><a href="' +RefenceURL + 'en/products/desktop-search/index.html">Copernic Desktop Search</a></div>' +
					'<div onclick="javascript:openlink(this);"><a href="' +RefenceURL + 'en/products/summarizer/index.html">Copernic Summarizer</a></div>' +
					'<div class="division">Web</div>' +
					'<div onclick="javascript:openlink(this);"><a href="' +RefenceURL + 'en/products/agent/index.html">Copernic Agent</a></div>' +
					'<div onclick="javascript:openlink(this);"><a href="' +RefenceURL + 'en/products/tracker/index.html">Copernic Tracker</a></div>' +
					'<div class="division">Mobile</div>' +
					'<div onclick="javascript:openlink(this);"><a href="' +RefenceURL + 'en/products/mycopernic/index.html">myCopernic</a></div>' +
					'<div onclick="javascript:openlink(this);"><a href="' +RefenceURL + 'en/products/mycopernic/onthego.html">myCopernic on the Go!</a></div>' +
					'<div class="division">Downloads</div>' +
					'<div onclick="javascript:openlink(this);"><a href="' +RefenceURL + 'en/products/desktop-search/home/download.html">Copernic Desktop Search - Home</a></div>' +
					'<div onclick="javascript:openlink(this);"><a href="' +RefenceURL + 'en/products/agent/download.html">Copernic Agent - Personal</a></div>' +
					'<div onclick="javascript:openlink(this);"><a href="' +RefenceURL + 'en/downloads/index.html">All Copernic Downloads</a></div>' +
					'</div>';
					
	submenutotal += '<div id="sub-menu-company" class="mtt" onmouseout="javscript:closetimer();" onmouseover="javascript:getdropdown();" style="left:280px;">' +
					'<div onclick="javascript:openlink(this);"><a href="' +RefenceURL + 'en/company/index.html">About Copernic</a></div>' +
					'<div onclick="javascript:openlink(this);"><a href="' +RefenceURL + 'en/company/careers/index.html">Careers</a></div>' +
					'<div onclick="javascript:openlink(this);"><a href="' +RefenceURL + 'en/company/wherefindus.html">Contact Copernic</a></div>' +
					'</div>';
	
	submenutotal += '<div id="sub-menu-store" class="mtt" onmouseout="javscript:closetimer();" onmouseover="javascript:getdropdown();" style="left:404px;">' +
					'<div onclick="javascript:openlink(this);"><a href="' +RefenceURL + 'en/store/index.php">Copernic Store</a></div>' +
					'<div onclick="javascript:openlink(this);"><a href="' +RefenceURL + 'en/store/discounts.php">Discounts</a></div>' +
					'<div onclick="javascript:openlink(this);"><a href="' +RefenceURL + 'en/company/wherefindus.html?sales">Contact Sales</a></div>' +
					'</div>';
					
	submenutotal += '<div id="sub-menu-partners" class="mtt" onmouseout="javscript:closetimer();" onmouseover="javascript:getdropdown();" style="left:652px;">' +
					'<div onclick="javascript:openlink(this);"><a href="' +RefenceURL + 'en/partners/index.html">Partners</a></div>' +
					'<div onclick="javascript:openlink(this);"><a href="' +RefenceURL + 'en/partners/technology.html">Technology Partners</a></div>' +
					'<div onclick="javascript:openlink(this);"><a href="' +RefenceURL + 'en/partners/affiliate.html">Copernic Affiliate Program</a></div>' +
					'<div onclick="javascript:openlink(this);"><a href="' +RefenceURL + 'en/partners/reseller.html">Copernic Reseller Program</a></div>' +
					'<div onclick="javascript:openlink(this);"><a href="' +RefenceURL + 'en/partners/reseller.html#find">Find a Reseller</a></div>' +
					'<div onclick="javascript:openlink(this);"><a href="' +RefenceURL + 'en/partners/media.html">Media</a></div>' +
					'</div>';

	return submenutotal;
}

function openlink(mylink) { window.location = mylink.getElementsByTagName('a')[0].href; }

function getembedfooter(ismenu){
	if (ismenu || ismenu == undefined) {
		document.getElementById('copernic-footer').innerHTML = 
			'<div class="footer">' +
			'<table cellpadding="0" cellspacing="0" width="100%"><tr><td>' +
				'<table cellpadding="0" cellspacing="0"><tr>' +
					'<td style="padding-left:0px;"><a href="' +RefenceURL +'en/products/index.html">Products</a></td>' +
					'<td><a href="' +RefenceURL +'en/downloads/index.html">Downloads</a></td>' +
					'<td><a href="' +RefenceURL +'en/company/privacy/privacy.html">Privacy Policy</a></td>' +
					'<td><a href="' +RefenceURL +'en/company/wherefindus.html">Contact Us</a></td>' +
					'<td style="border:none;"><a href="' +RefenceURL +'en/company/careers/index.html">Careers</a></td>' +
				'</tr></table>' +
				'<div>&copy; 1996 - 2012 Copernic Inc. All Rights <a href="http://ws.copernic.com/copern/ws/redir?r_fcid=417&r_fcp=topnavigation&qcat=web&qkw=copernic" style="color:#8C8C8C; text-decoration:none; cursor:text;">Reserved</a>.</div>' +
			'</td><td align="right" valign="bottom">' +
				'<img src="' +RefImgURL +'c9/template/logo-copernic.gif" alt="Copernic" width="96" height="18" />' +
			'</td></tr></table>' +
			'<table cellpadding="0" cellspacing="0"><tr>' +
				'<td style="padding-top:15px;">Follow us on these major social networks:</td>' +
				'<td style="padding-top:15px;"><a href="http://www.facebook.com/copernic"><img src="' +RefImgURL +'c9/template/logo-facebook.jpg" alt="Facebook" border="0" width="14" height="14" /></a></td>' +
				'<td style="padding-top:15px;"><a href="http://www.twitter.com/copernic"><img src="' +RefImgURL +'c9/template/logo-twitter.jpg" alt="Twitter" border="0" width="14" height="14" /></a></td>' +
				'<td style="padding-top:15px;"><a href="' +RefenceURL +'en/community/index.php">Copernic Community</a></td>' +
			'</tr></table>' +
			'</div>';
	} else {
		document.getElementById('copernic-footer').innerHTML = 
			'<div class="footer">' +
			'<table cellpadding="0" cellspacing="0" width="100%"><tr><td>' +
				'<table cellpadding="0" cellspacing="0"><tr>' +
					'<td style="padding-left:0px; border:none;">&nbsp;</td>' +
				'</tr></table>' +
				'<div>&copy; 1996 - 2012 Copernic Inc. All Rights <a href="http://ws.copernic.com/copern/ws/redir?r_fcid=417&r_fcp=topnavigation&qcat=web&qkw=copernic" style="color:#8C8C8C; text-decoration:none; cursor:text;">Reserved</a>.</div>' +
			'</td><td align="right" valign="bottom">' +
				'<img src="' +RefImgURL +'c9/template/logo-copernic.gif" alt="Copernic" width="96" height="18" />' +
			'</td></tr></table>' +
			'<table cellpadding="0" cellspacing="0"><tr>' +
				'<td style="padding-top:15px;">Follow us on these major social networks:</td>' +
				'<td style="padding-top:15px;"><a href="http://www.facebook.com/copernic"><img src="' +RefImgURL +'c9/template/logo-facebook.jpg" alt="Facebook" border="0" width="14" height="14" /></a></td>' +
				'<td style="padding-top:15px;"><a href="http://www.twitter.com/copernic"><img src="' +RefImgURL +'c9/template/logo-twitter.jpg" alt="Twitter" border="0" width="14" height="14" /></a></td>' +
				'<td style="padding-top:15px;"><a href="' +RefenceURL +'en/community/index.php">Copernic Community</a></td>' +
			'</tr></table>' +
			'</div>';
	}
}

function getAdValue(tPathName) {
	switch (tPathName) {
		case 'desktop-search': tPathName = 'copernic desktop search'; break;
		case 'mycopernic': tPathName = 'myCopernic'; break;
		case 'onthego': tPathName = 'on the Go!'; break;
		case 'buy-cds-pro': tPathName = 'cds professional'; break;
		case 'buy-cds-corpo': tPathName = 'cds corporate'; break;
		case 'buy-onthego': tPathName = 'myCopernic on the Go!'; break;
		case 'buy-pro': tPathName = 'agent professional'; break;
		case 'buy-upgrade-pro': tPathName = 'agent professional upgrade'; break;
		case 'buy-personal': tPathName = 'agent personal'; break;
		case 'buy-summarizer': tPathName = 'summarizer'; break;
		case 'buy-tracker': tPathName = 'tracker'; break;
		case 'trial': tPathName = 'free trial'; break;
		case 'company': tPathName = 'about Copernic'; break;
		case 'wherefindus': tPathName = 'contact us'; break;
		case 'financial': tPathName = 'financial releases'; break;
		case 'volume-discounts': tPathName = 'volume discounts'; break;
		case 'discount-educational': tPathName = 'educational &amp; government discounts'; break;
		case 'whats-new': tPathName = 'what\'s new'; break;
		case 'cds-compare': tPathName = 'compare'; break;
		case 'releaseslog': tPathName = 'releases log'; break;
		case 'findreseller': tPathName = 'find a reseller'; break;
		case 'buy-bundle-prosumma': tPathName = 'agent professional &amp; summarizer bundle'; break;
		case 'buy-bundle-persosumma': tPathName = 'agent personal &amp; summarizer bundle'; break;
		case 'buy-bundle-protracker': tPathName = 'agent professional &amp; tracker bundle'; break;
		case 'buy-bundle-trio': tPathName = 'Copernic value pack'; break;
		case 'buy-cds-corpo-reseller': tPathName = 'become a reseller'; break;
		case 'bundle-agent': tPathName = 'bundle'; break;
	}

	tPathName = tPathName.replace(/^(.)|\s(.)(?!(. ))(?!(.. ))/g,function(s){
		return s.toUpperCase();
	});

	return tPathName;
}

var _selectedMenu;
var _closetimer;

function menumouse(tMenu, isover, dontclose) {
	if (tMenu.src.split('-on.')[1] && isover) {
		tMenu.src = tMenu.src.split('-on.gif')[0] +'-over.gif';
	} else if (tMenu.src.split('-over.')[1]) {
		tMenu.src = tMenu.src.split('-over.gif')[0] +'-on.gif';
	}

	if (isover) { getdropdown(tMenu); }
}

function getdropdown(tMenu) {
	window.clearTimeout(_closetimer); _closetimer = null;

	if (tMenu) {
		var curSection = tMenu.alt.toLowerCase();

		if (document.getElementById('sub-menu-' +curSection) != _selectedMenu) {
			if (_selectedMenu) {
				_selectedMenu.style.display = 'none';
				menumouse(document.getElementById('menu-item-' +_selectedMenu.id.substring(9)).getElementsByTagName('img')[0], false, true);
			}
			if (document.getElementById('sub-menu-' +curSection)) {
				_selectedMenu = document.getElementById('sub-menu-' +curSection);
				_selectedMenu.style.display = 'block';
				fadeobject(_selectedMenu.id, true);
			} else {
				_selectedMenu = null;
			}
		}
	}
}

function closetimer () {
	_closetimer = window.setTimeout(
		function hidedropdown() {
			if (_selectedMenu) { 
				fadeobject(_selectedMenu.id, false);
				menumouse(document.getElementById('menu-item-' +_selectedMenu.id.substring(9)).getElementsByTagName('img')[0], false, true);
				_selectedMenu = null;
			}
		}, 500);
	setOpacity(_selectedMenu, 1);
}


var timer_fadeArray = new Array();

function fadeobject(thisID, isfadein, no, isdisplayafterfade, fadestep) {
	var finalopacity = -1;
	
	if (fadestep == undefined) { fadestep = 0.2; }

	if (no == undefined) {
		for (no = timer_fadeArray.length; no > 0; no=no-1) {
			if (thisID == timer_fadeArray[no-1][0]) {
				break;
			}
		}
		if (no == 0) { timer_fadeArray.push(new Array(thisID, 1)); no = timer_fadeArray.length; }
		no = no -1;
	}
	
	var curOpacity = getOpacity(document.getElementById(thisID));

	if (isfadein) {
		curOpacity = (curOpacity*1) +fadestep;
		if (curOpacity >= 1) { finalopacity = 1; }
	} else {
		curOpacity = (curOpacity*1) -fadestep;
		if (curOpacity < fadestep) {
			finalopacity = 0; curOpacity = 0;
			if (!isdisplayafterfade) { document.getElementById(thisID).style.display = "none"; }
		}
	}

	if (finalopacity < 0) {
		setOpacity(document.getElementById(thisID), curOpacity);
		timer_fadeArray[no][1] = setTimeout("fadeobject('" +thisID +"', " +isfadein +", " +no +", " +isdisplayafterfade +", " +fadestep +")", 40);
	} else {
		setOpacity(document.getElementById(thisID), finalopacity);
		if (document.getElementById(thisID).style.filter && finalopacity == 1) { document.getElementById(thisID).style.removeAttribute('filter'); }
	}

	return no;
}

function getOpacity(tObject){
	if(tObject.style.opacity != undefined){
		return tObject.style.opacity;
	} else if(tObject.style.MozOpacity != undefined){
		return tObject.style.MozOpacity;
	} else if (tObject.style.filter != undefined){
		if (tObject.style.filter.length > 0) {
			return tObject.style.filter.substring(14, tObject.style.filter.length -1) / 100;
		} else {
			return 1;
		}
	}
}
function setOpacity(tObject, opacity){
	if(tObject.style.opacity != undefined){
		tObject.style.opacity = opacity;
	}else if(tObject.style.MozOpacity != undefined){
		tObject.style.MozOpacity = opacity;
	}else if (tObject.style.filter != undefined){
		tObject.style.filter = "alpha(opacity=" + opacity * 100 + ")";
	}
}
