/* Fix layout fixes the height of the content 
when the content is smaller than  highlights section on right 
it also fixes navigation alignment for IE*/
		

var heightOfOtherTexts;
	
	function fixLayout(){
		more_margin=0;
		tolerance=0;
		margin_left=0;

		/* Fix navigation 
		There are two things to fix 
		a) In IE the navigation is shown towards right of the parent.
		b) If there is no space at right most navigation should be shifted towards left
		*/
		myEle=document.getElementById('sub_navigation');
                if(myEle){
		            m_parent=myEle.parentNode;
		            requiredSpace=myEle.offsetLeft+myEle.clientWidth-document.getElementById("my_body").offsetLeft;
		            spaceAvailable=document.getElementById("my_body").offsetWidth;
		           if (isIE()){
			        //margin_left=myEle.parentNode.clientWidth;
				//for IE8
					   if(isIE8()){
						  margin_right=myEle.parentNode.clientWidth-50;
					   }
					   else{
			        		margin_left=myEle.parentNode.clientWidth;
					   }

					requiredSpace=requiredSpace-margin_left;
		           }	
		           if(spaceAvailable<requiredSpace){
				      tolerance=15
				      more_margin=requiredSpace-spaceAvailable
		           }
		
		           myEle.style.marginLeft=((-1)*(margin_left+more_margin+tolerance))+'px';
		           myEle.style.display='block';
               }  
		
		/*fix heights of the content div if the height is less than highlight div*/
		fixHeights()
	}

	function isIE(){
		return document.all;
	}
  /*fix heights of the content div if the height is less than highlight div*/
	
	function fixHeights(){
		heightOfOtherTexts=0;
		textsDiv=getTextsDiv(); // get divs whose height needs to be fixed
		highlightsDiv=document.getElementById('highlights');
		
		if(textsDiv){
			diff=highlightsDiv.clientHeight-textsDiv.clientHeight;
			marginPadding=0;
			adjustments=marginPadding+25+heightOfOtherTexts;
			if(!isIE()){
				adjustments+=7	
			}
			if(diff>0){
			 textsDiv.style.height=(textsDiv.clientHeight+diff-adjustments)+"px";
			}
		}
		
	}
	/* returns array of divs whose height needs to be fixed */
	
	function getTextsDiv(){
		
		/* home page and other pages have different structure
		hence we need to know the contenxt */
		mLocation=document.location.href;
		mLocation=mLocation.replace("http://","");
		pos_firstSlash=mLocation.indexOf("/");
		pos_lastSlash=mLocation.lastIndexOf("/");
		mContext=mLocation.substring(pos_firstSlash+1,pos_lastSlash);
		mFilename=mLocation.substring(pos_lastSlash+1);
		pos_query_string = mFilename.lastIndexOf("?");
		if(pos_query_string != -1){			
			mFilename = mFilename.substring(0,pos_query_string);	
		}

		for(i=0;i<10;i++){
			mContext=mContext.replace("/","");
		}
		
		if(mContext==""){ 
			if(mFilename=="" || mFilename=="index.php"){ //if is home page
			 	mContext="home";
				//fixHome(document.getElementById("texts_"+mContext));
				return false
			}
			else
			 mContext=mFilename.replace('.php','');
		}
		
		if(contextDiv=document.getElementById("texts_"+mContext)){
			//alert(contextDiv.childNodes.length)
			for(i=0;i<contextDiv.childNodes.length;i++){
				if(contextDiv.childNodes[i].className=="texts"){
					retDiv=contextDiv.childNodes[i];
					heightOfOtherTexts=heightOfOtherTexts+retDiv.clientHeight+12;
				}

			}
		}
		heightOfOtherTexts=heightOfOtherTexts-retDiv.clientHeight-12;
		return retDiv;
	}
	
	/* Fixes hiome page 
	function fixHome(contextDiv){
		MaxHeight=0;
		cnt=0;
		halfDivs= new Array()
		highlightsDiv=document.getElementById('highlights');
		for(i=0;i<contextDiv.childNodes.length;i++){
			if(contextDiv.childNodes[i].className=="texts"){
				elementsDiv=contextDiv.childNodes[i];
				//elementsDiv.style.height=(highlightsDiv.clientHeight+5)+"px";
				//elementsDiv.style.overflow='hidden'
				for(i=0;i<elementsDiv.childNodes.length;i++){
					curdiv=elementsDiv.childNodes[i];
					if(curdiv.className=="textelement"){
						heightOfOtherTexts=curdiv.clientHeight+12
					}
					if(curdiv.className=="textelement half"){
						if(curdiv.clientHeight>MaxHeight){
							MaxHeight=curdiv.clientHeight;
						}
						halfDivs[cnt]=curdiv;
						cnt++;
				
					}

				}
				
			}

		}
		diff=highlightsDiv.clientHeight-heightOfOtherTexts-MaxHeight;
			adjustments=25;
		if(!isIE()){
			adjustments+=7	
		}

		if(diff>0){
			MaxHeight=MaxHeight+diff-adjustments;
		}
	
		for(i=0;i<halfDivs.length;i++){
			halfDivs[i].style.height=MaxHeight+"px";

		}
	}
	*/


	/*
	// Returns the version of Internet Explorer or a -1
	// (indicating the use of another browser).
	*/
	function getInternetExplorerVersion()
	
	{
	  var rv = -1; // Return value assumes failure.
	  if (navigator.appName == 'Microsoft Internet Explorer')
	  {
		var ua = navigator.userAgent;
		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)
		  rv = parseFloat( RegExp.$1 );
	  }
	  return rv;
	}

	/*
	Checks the version for IE if it is greater thant 8
	*/
	function isIE8()
	{
	  
	  var ver = getInternetExplorerVersion();
	
	  if ( ver > -1 )
	  {
		if ( ver >= 8.0 ) 
		  return true;
		else
		  return false;
	  }
	  
	}
