﻿//////////////////////
// 0 : Category
// 1 : Item
// 2 : Sub item
// 3 : store all links belongs to that category
var menu_item = new Array(
///////////////////////////////////////////////////////////////////////////// Products
"0", "Productos", "http://es.cayintech.com/digital_signage_products/digital_signage_products.html",
"1", "Reproductor<br>multimedia", "",
"2", "SMP-WEB4", "http://es.cayintech.com/digital_signage_products/digital_signage_player_smpweb4_features.html", 
"2", "SMP-WEBDUO", "http://es.cayintech.com/digital_signage_products/digital_signage_player_smpwebduo_features.html", 
"2", "SMP-PRO4", "http://es.cayintech.com/digital_signage_products/digital_signage_player_smppro4_features.html", 
"1", "Servidor", "", 
"2", "CMS-Performance", "http://es.cayintech.com/digital_signage_products/digital_signage_server_cmsperformance_features.html", 
"2", "CMS-Mini", "http://es.cayintech.com/digital_signage_products/digital_signage_server_cmsmini_features.html", 
"1", "Software", "", 
"2", "SuperReporter 2", "http://es.cayintech.com/digital_signage_products/digital_signage_software_superreporter_features.html", 
"2", "SuperMonitor 3", "http://es.cayintech.com/digital_signage_products/digital_signage_software_supermonitor_features.html", 
"1", "Aplicación de<br>software xPost", "", 
"2", "lobbyPost", "http://es.cayintech.com/digital_signage_products/digital_signage_software_lobbypost_features.html", 
"2", "meetingPost", "http://es.cayintech.com/digital_signage_products/digital_signage_software_meetingpost_features.html", 
"2", "wayfinderPost", "http://es.cayintech.com/digital_signage_products/digital_signage_software_wayfinderpost_features.html", 
"3","","/digital_signage_products/",

///////////////////////////////////////////////////////////////////////////// Solutions
"0", "Soluciones", "http://es.cayintech.com/digital_signage_solutions/digital_signage_integration.html",
"2", "Interactivo", "http://es.cayintech.com/digital_signage_solutions/interactive_digital_signage.html", 
"2", "Integración web", "http://es.cayintech.com/digital_signage_solutions/web_digital_signage.html", 
"2", "Tiendas", "http://es.cayintech.com/digital_signage_solutions/digital_signage_barcode.html", 
"2", "Salida de vídeo dual", "http://es.cayintech.com/digital_signage_solutions/dual_video_output.html", 
"2", "Canal en directo", "http://es.cayintech.com/digital_signage_solutions/live_feed_digital_signage.html",
"2", "3G & GPS", "http://es.cayintech.com/digital_signage_solutions/mobile_and_place-based_digital_signage.html",
"3","","/digital_signage_solutions/",
///////////////////////////////////////////////////////////////////////////// Applications
"0", "Aplicaciones", "http://es.cayintech.com/digital_signage_applications/digital_signage_markets.html",
"2", "Educación", "http://es.cayintech.com/digital_signage_applications/education_digital_signage.html", 
"2", "Hoteles", "http://es.cayintech.com/digital_signage_applications/hospitality_digital_signage.html", 
"2", "Museos", "http://es.cayintech.com/digital_signage_applications/museum_digital_signage.html", 
"2", "Comercios", "http://es.cayintech.com/digital_signage_applications/retail_digital_signage.html", 
"2", "Entretenimiento", "http://es.cayintech.com/digital_signage_applications/entertainment_digital_signage.html", 
"2", "Transporte", "http://es.cayintech.com/digital_signage_applications/transportation_digital_signage.html", 
"2", "Asistencia Sanitaria", "http://es.cayintech.com/digital_signage_applications/healthcare_digital_signage.html", 
"2", "Empresas", "http://es.cayintech.com/digital_signage_applications/corporate_digital_signage.html", 
"2", "Administración", "http://es.cayintech.com/digital_signage_applications/government_digital_signage.html", 
"2", "Centro de convenciones", "http://es.cayintech.com/digital_signage_applications/conference_digital_signage.html", 
"3","","/digital_signage_applications/",
///////////////////////////////////////////////////////////////////////////// News
"0", "Noticias", "http://es.cayintech.com/news/digital_signage_news_2012.html",
"2", "Notas de prensa", "http://es.cayintech.com/news/digital_signage_news_2012.html",
"2", "Casos prácticos", "http://es.cayintech.com/news/digital_signage_case_studies.html",
"3","","/news/",
///////////////////////////////////////////////////////////////////////////// Soporte
"0", "Soporte", "http://es.cayintech.com/technical_support/t_s_index.php",
///////////////////////////////////////////////////////////////////////////// About CAYIN
"0", "Acerca de CAYIN", "http://es.cayintech.com/about/overview.html",
"2", "Generalidades", "http://es.cayintech.com/about/overview.html", 
"2", "Asociación", "http://es.cayintech.com/about/partnership.html", 
"2", "Contacto", "http://es.cayintech.com/about/contact.html", 
///////////////////////////////////////////////////////////////////////////// PartnerNet
"0", "PartnerNet", "http://partner.cayintech.com/index.jsp",


null,null,null
); 

var menu_focus=0;
var area_pop=0;

/////////////////////////////////////////////////////////////////////////////
// Change main icons to main-banner2.gif when current url 
// contain the same filename
//
function doWindowOnLoad()
{
	str = document.location.href;
	var str_array = str.split("/");
	var file_tmp = str_array[str_array.length-1];
	var file_array = file_tmp.split("#?");
	var file = file_array[0];
	var icon_index = 0;
	var update = 0;

	if( file != "")
	{
		for(i=0;i<menu_item.length;)
		{
			if(menu_item[i] == "0") // check current url filename equal to Category link
			{
				update=0;	
				icon_index++;
				
				if(menu_item[i+2].indexOf(file) >=0)
					update=1;

				i=i+3;
			}

			for(k=i;k<menu_item.length;k=k+3) // check current url filename equal to sub item link
			{
				if(menu_item[k] == "0")
					break;
				else if(menu_item[k] == "2")
				{				
					if(menu_item[k+2].indexOf(file) >=0)
						update=1;
				}
				else if(menu_item[k] == "3" && update == 0)
				{	
					if(str.indexOf(menu_item[k+2]) >=0)
					{						
						update=1;	
						break;
					}				
				}
				i=i+3;
			}
		
			obj_name="main-icon-"+icon_index;
			if(update == 1)	
				document.getElementById(obj_name).style.background  = "url('../Images/main-banner2.gif')";
			else
				document.getElementById(obj_name).style.background  = "url('../Images/main-banner1.gif')";
		}
	}
}

/////////////////////////////////////////////////////////////////////////////
// When click on document body, will hide menu
function doOnClickBody()
{	
	if(menu_focus==0)
	{
		var obj = document.getElementById("smenu");
		obj.style.display="none";
	}
}

/////////////////////////////////////////////////////////////////////////////
// menu div
function smenu_output()
{
	document.write("<div id='smenu' onMouseOver='menu_focus=1;' onMouseOut='hide_menu(event,this)' style='position:absolute;display:none;z-index:999;'></div>");
}

/////////////////////////////////////////////////////////////////////////////
// get the category link
function getCategoryUrl(category)
{
	for(i=0;i<menu_item.length;i=i+3)
	{
		if(menu_item[i] == "0" && menu_item[i+1] == category)
		{
			return menu_item[i+2];
		}
	}
}


function toHide()
{
//alert(area_pop);
//alert("area_index="+area_index+" area_pop="+area_pop+" menu_focus="+menu_focus);
	if(menu_focus == 0 && area_pop == 0)
	{
		var obj = document.getElementById("smenu");
		obj.style.display="none";
	}

}


function check_area(e,o,dobj_id)
{
//alert("area_index="+area_index+" area_pop="+area_pop+" menu_focus="+menu_focus);
	var obj1 = document.getElementById(dobj_id);
	obj1.className="main_b";

	if(window.navigator.userAgent.indexOf("Firefox")>=1) { 
		var x = e.clientX + document.body.scrollLeft;
		var y = e.clientY + document.body.scrollTop ;
		var left = o.offsetLeft ;
		var top = o.offsetTop;
		var w = o.offsetWidth;
		var h = o.offsetHeight;

		if(y < top || y >= (h + top) || x >= left + w || x<=left ) 
		{ 	
			setTimeout("toHide()", 100);			
		}
	}

     /* IE */
	if(o.contains(event.toElement ) == false ) 
	{
		setTimeout("toHide()", 100);	
    }
}


/////////////////////////////////////////////////////////////////////////////
// Ouput main category icons
function menu_output()
{
	document.write("<a href='"+getCategoryUrl('Productos')+"' class='main_b'		onMouseOut='area_pop=0;check_area(event,this,\"main-icon-1\");' onMouseOver='area_pop=1;show_menu(\"Productos\",\"main-icon-1\")'>	<div class='main_b'	id='main-icon-1'>Productos</div>		<div id='main-line'></div></a>");
    document.write("<a href='"+getCategoryUrl('Soluciones')+"' class='main_b'		onMouseOut='area_pop=0;check_area(event,this,\"main-icon-2\");' onMouseOver='area_pop=2;show_menu(\"Soluciones\",\"main-icon-2\")'>	<div class='main_b'	id='main-icon-2'>Soluciones</div>	<div id='main-line'></div></a>");
    document.write("<a href='"+getCategoryUrl('Aplicaciones')+"' class='main_b'	onMouseOut='area_pop=0;check_area(event,this,\"main-icon-3\");' onMouseOver='area_pop=3;show_menu(\"Aplicaciones\",\"main-icon-3\")'><div class='main_b'	id='main-icon-3'>Aplicaciones</div>	<div id='main-line'></div></a>");
    document.write("<a href='"+getCategoryUrl('Noticias')+"' class='main_b'			onMouseOut='area_pop=0;check_area(event,this,\"main-icon-4\");' onMouseOver='area_pop=4;show_menu(\"Noticias\",\"main-icon-4\")'>		<div class='main_b'	id='main-icon-4'>Noticias</div>			<div id='main-line'></div></a>");
	document.write("<a href='"+getCategoryUrl('Soporte')+"' class='main_b'			onMouseOut='area_pop=0;check_area(event,this,\"main-icon-5\");' onMouseOver='area_pop=5;show_menu(\"Soporte\",\"main-icon-5\")'>		<div class='main_b'	id='main-icon-5'>Soporte</div>			<div id='main-line'></div></a>");
    document.write("<a href='"+getCategoryUrl('Acerca de CAYIN')+"' class='main_b'			onMouseOut='area_pop=0;check_area(event,this,\"main-icon-6\");' onMouseOver='area_pop=6;show_menu(\"Acerca de CAYIN\",\"main-icon-6\")'>		<div class='main_b'	id='main-icon-6'>Acerca de CAYIN</div>	<div id='main-line'></div></a>");
    document.write("<a href='"+getCategoryUrl('PartnerNet')+"' class='main_b'		onMouseOut='area_pop=0;check_area(event,this,\"main-icon-7\");' onMouseOver='area_pop=7;show_menu(\"PartnerNet\",\"main-icon-7\")' target='_blank'><div class='main_b' id='main-icon-7'>PartnerNet</div><div id='main-line'></div></a>");
}


function getPosition_left(object_name) 
{ 
	  var e = document.getElementById(object_name);
      var   t=e.offsetTop; 
      var   l=e.offsetLeft; 
	  var   w=e.offsetWidth;
	  var	h=e.offsetHeight;

      while(e=e.offsetParent) 
      { 
            t+=e.offsetTop; 
            l+=e.offsetLeft; 
      } 

  	  var   b=t+h;
      //alert( "top= "+t+ "\nleft= "+l+"\nwidth= "+w+ "\nheight= "+h+"\nb="+b); 

	  return l
} 

function getPosition_bottom(object_name) 
{ 
	  var e = document.getElementById(object_name);
      var   t=e.offsetTop; 
      var   l=e.offsetLeft; 
	  var   w=e.offsetWidth;
	  var	h=e.offsetHeight;

      while(e=e.offsetParent) 
      { 
            t+=e.offsetTop; 
            l+=e.offsetLeft; 
      } 

  	  var   b=t+h;
      //alert( "top= "+t+ "\nleft= "+l+"\nwidth= "+w+ "\nheight= "+h+"\nb="+b); 

	  return b;
} 

function popup_menu(category,obj_bpos)
{

	var obj = document.getElementById("smenu");
	obj.style.display="none";

	var string=""
	var item_count=0;
	string+="<div width='500px'><table border='0' cellpadding='2' cellspacing='0' bgcolor='#979797' id='listtable' >";

	for(i=0;i<menu_item.length;i=i+3)
	{
		if(menu_item[i] == "0" && menu_item[i+1] == category)
		{			
			for(k=i+3;k<menu_item.length;k=k+3)
			{
				if(menu_item[k] == "0")
					break;
				else if(menu_item[k] == "1")
				{
					string+="<tr><td height='20' align='center' class='list1'>"+menu_item[k+1]+"</td></tr>";
					item_count++;
				}
				else if(menu_item[k] == "2")
				{
					string+="<tr><td height='20' onMouseOut='this.style.background=\"#979797\"' onMouseOver='this.style.background=\"#797979\"' align='center' class='list2'><a href='"+menu_item[k+2]+"' class='list2'>"+menu_item[k+1]+"</a><br /></td></tr>";				
					item_count++;
				}
			}
			break;
		}
	}
	string+="</table></div>";

	obj.innerHTML=string;

	return item_count;
}


function show_menu(category,object_id)
{
	var obj_bpos = getPosition_bottom(object_id);
	var obj_lpos = getPosition_left(object_id);
	var item_count = popup_menu(category,obj_bpos);

	var obj1 = document.getElementById(object_id);
	obj1.className="mainbutton2";

	if(item_count >0)
	{		
		var obj = document.getElementById("smenu"); // menu
		obj.style.top=obj_bpos+"px";
		obj.style.left=obj_lpos+"px";		
		obj.style.display="block";
		
		var obj_table = document.getElementById("listtable"); // table
		var obj_icon = document.getElementById(object_id); // icon		
		
		if(obj.offsetWidth < obj_icon.offsetWidth)
			obj_table.style.width = obj_icon.offsetWidth+"px";
		else
			obj_table.style.width = (obj.offsetWidth+10)+"px";
			
	}
}

function hide_menu(e,o) 
{ 
	if(window.navigator.userAgent.indexOf("Firefox")>=1) { 
		var x = e.clientX + document.body.scrollLeft;
		var y = e.clientY + document.body.scrollTop ;
		var left = o.offsetLeft;
		var top = o.offsetTop;
		var w = o.offsetWidth;
		var h = o.offsetHeight;
		
		if(y < top || y >= (h + top) || x >= left + w || x<=left ) { 
			var obj = document.getElementById("smenu");
			obj.style.display="none";
			menu_focus=0;
			//alert("Firefox mouseout");
		}
	}

     /* IE */
	if(o.contains(event.toElement ) == false ) 
	{
		var obj = document.getElementById("smenu");
		obj.style.display="none";
		menu_focus=0;
		//alert("IE mouseout");	
    }
}
