/*------ prototype.js-------*/
/*---Created by: Ely Tejeda N ----- On:20090903-----*/
//-------------------------------------------------------------------------------------------
//DESIGN VALUES
var minHeight=450;
var navBarImagesDir="http://www.probooks.com.mx/assets/images/navBar/";//minimum Height 
//INITIALIZE
var images=new Array();
//START
navBarPreLoader();
//END
function navBarPreLoader()//Preloads images from navBar
{
	var sources=new Array("botonInicioOver.jpg","botonNosotrosOver.jpg","botonOfertasOver.jpg","botonContactoOver.jpg","botonCatalogoOver.jpg" ,"botonEventosOver.jpg");
	for(var i=0;i<sources.length;i++)
	{
		images[i]=document.createElement("img");
		images[i].src=navBarImagesDir+sources[i];
	}
}

function setNavBarBehavior()//sets NavBar Behavior | PRE: elements in navBar must be created and in the correct order
{
	try
	{ 
		for(var i=0; i<document.getElementById("navBar").children.length;i++)
		{
			if(document.getElementById("navBar").children[i].tagName=="A")
			{
				if(document.getElementById("navBar").children[i].children[0])
				{
					if(document.getElementById("navBar").children[i].children[0].tagName=="IMG")
					{
						navBarHandler(document.getElementById("navBar").children[i].children[0],i);
					}
				}
			}	
		}
	}catch(error) //fix for browser with no support for element.children
	{
		for(var i=0; i<document.getElementById("navBar").childNodes.length;i++)
		{
			if(document.getElementById("navBar").childNodes[i].tagName=="A")
			{
				for(var j=0;j<document.getElementById("navBar").childNodes[i].childNodes.length;j++)
				{
					if(document.getElementById("navBar").childNodes[i].childNodes[j].tagName=="IMG")
					{
						navBarHandler(document.getElementById("navBar").childNodes[i].childNodes[j],i,j);
					}					
				}
			}	
		}
	}
}
function navBarHandler(image,position,position2)// Sets the correct image when navigating in the specific area
{
	var index=image.src.indexOf("Up.jpg");
	if(image.parentNode.href==document.URL)
	{
		image.src=image.src.substring(0,index)+"Over.jpg";
	}

	var imageName=image.src.substring(0,index)+"Over.jpg";
	if(arguments.length>2)
	{
		image.onmouseover=new Function("x","document.getElementById('navBar').childNodes["+position+"].childNodes["+position2+"].src='"+imageName+"';");
		image.onmouseout=new Function("x","document.getElementById('navBar').childNodes["+position+"].childNodes["+position2+"].src='"+image.src+"';");
	}else
	{
		image.onmouseover=new Function("x","document.getElementById('navBar').children["+position+"].children[0].src='"+imageName+"';");
		image.onmouseout=new Function("x","document.getElementById('navBar').children["+position+"].children[0].src='"+image.src+"';")
	}
}
function nostrosLeftBarHandler() //Defines a special style for the active link. 
{
	var navigationBar=document.getElementById("nosotrosLeftBar");
	var k=0, i=0;
	try
	{
		for(i=0;i<navigationBar.children.length;i++)
		{
			if(navigationBar.children[i].tagName=="LI")
			{
				for(k=0;k<navigationBar.children[i].children.length;k++)
				{
					if(navigationBar.children[i].children[k].tagName=="A")
					{
						if(navigationBar.children[i].children[k].href==document.URL)
						{
							navigationBar.children[i].children[k].style["font-size"]="18px";
							navigationBar.children[i].children[k].style["color"]="#900";
						}
					}
				}
			}
		}
	}catch(error)
	{
		for(var i=0;i<navigationBar.childNodes.length;i++)
		{
			if(navigationBar.childNodes[i].tagName=="LI")
			{
				for(k=0;k<navigationBar.childNodes[i].childNodes.length;k++)
				{
					if(navigationBar.childNodes[i].childNodes[k].tagName=="A")
					{
						if(navigationBar.childNodes[i].childNodes[k].href==document.URL)
						{
							navigationBar.childNodes[i].childNodes[k].style["font-size"]="18px";
							navigationBar.childNodes[i].childNodes[k].style["color"]="#900";
						}
					}
				}
			}
		}
	}
}

function setSize(flag) //Sets a more accurate document size
{
	var availableSize=null;
		try
		{
			if(window.getComputedStyle(document.body,null).height)
			{
				availableSize=parseInt(getComputedStyle(document.body,null).height);
			}
		}catch(error){}		
		try
		{
			if((window.innerHeight&&(availableSize>parseInt(window.innerHeight)&&parseInt(window.innerHeight)!=0))||window.innerHeight&&availableSize==null)
			{				
				availableSize=window.innerHeight;
			}
		}catch(error){}	
		try
		{
			if((document.documentElement.clientHeight&& (availableSize>parseInt(document.documentElement.clientHeight)&document.documentElement.clientHeight!=0))||document.documentElement.clientHeight&&availableSize==null)
			{
				availableSize=document.documentElement.clientHeight
			}
		}catch(error){}
		try
		{
			if((document.body.clientHeight&&(availableSize>parseInt(document.body.clientHeight)&&document.body.clientHeight!=0))||document.body.clientHeight&&availableSize==null)
			{
				availableSize=document.body.clientHeight;
			}
		}catch(error){}
	if(availableSize!=null&&parseInt(availableSize)>0)
	{
		if((availableSize-150)>minHeight)
		{
			document.getElementById("mainPart").style.minHeight=availableSize-150+"px";
		}else
		{
			document.getElementById("mainPart").style.minHeight=minHeight+"px";
		}		
	}else
	{
		document.getElementById("mainPart").style.minHeight=minHeight+"px";
	}
	try
	{
		if(flag=="reset")
		{
			document.getElementById("mainPart").style.height="auto";
		}
	}catch(error){}
}