﻿/**
 * Finds the product description on the page and converts 
 * it to one of those Javascript drop down things.
 * 
 * Quite a bit of hairy code here, but it seems to work well enough.
 *
 * @author Tim Booker
 * @date 27/09/2007
 */
 
 
var introDiv;
var buttonDiv;
var moreDiv;
var feefoHTML;

function initDropDown()
{
    //debugger;

    var el = document.getElementById( "TextDropDown" );        
  
    var text = el.innerHTML;        
    text = text.replace( /<\/?span>/gi, "" );    
    
    var prIndex = text.indexOf( "</p>" );    
    if( prIndex == -1 )
        prIndex = text.indexOf( "</P>" );
    
    var introText = text.substring( 0, prIndex );
    var moreText = text.substring( text.indexOf( ">", prIndex ) + 1 );
    
    moreText = moreText.replace( /^\s*<pr\s*\/?>/i, "" );   // Strip out first pr only
	
	feefoHTML = escape(introText + moreText);
	
    if( prIndex != -1 )
    {
        introDiv = document.createElement( "DIV" );
    
        introDiv.innerHTML = introText;
                    
        buttonDiv = document.createElement( "DIV" );
        buttonDiv.setAttribute( "ID", "TextDropDownButton" );
        buttonDiv.innerHTML += "<a href=\"#\" onclick=\"showDropDown();return false;\" onfocus=\"showDropDown();return false;\" id=\"TextDropDownMoreButton\">Read More</a>";
        
        moreText += "<p /><a href=\"#\" onclick=\"hideDropDown();return false;\" onfocus=\"hideDropDown();return false;\" id=\"TextDropDownHideButton\">Hide Description</a>";

        moreDiv = document.createElement( "DIV" );
        moreDiv.setAttribute("ID", "TextDropDownMore" );
        moreDiv.style.display = "none";  
        moreDiv.style.paddingTop = "10px";          
        moreDiv.innerHTML = moreText;
        
        el.innerHTML = "";
        el.appendChild( introDiv );
        el.appendChild( buttonDiv );
        el.appendChild( moreDiv );    
    }
}

function showDropDown( e )
{
    buttonDiv.style.display = "none";            
    moreDiv.style.display = "block";        
}

function hideDropDown( e )
{
    buttonDiv.style.display = "block";            
    moreDiv.style.display = "none";        
}

//addEventHandler( window, "load", initDropDown );
initDropDown();
//showDropDown(); // <-- This forces description to show in full automatically.  Can be removed.

