function InitBoatInfo()
{
    var contentNode = document.getElementById("boat_content");
    var childCount = contentNode.childNodes.length;
    for (var i = 0; i < childCount; ++i)
    {
        child = contentNode.childNodes[i];
        if( child.nodeName.toLowerCase() == "div" )
        {
            child.style.display = "none";
        }
    }
    document.getElementById("floor_plan").style.display = "block";
    document.getElementById("floor_plan_button").className = "on_page";
}

function ShowBoatInfo( id )
{
    var node = document.getElementById(id);
    var contentNode = document.getElementById("boat_content");
    var childCount = contentNode.childNodes.length;
    for (var i = 0; i < childCount; ++i)
    {
        child = contentNode.childNodes[i];
        if( child.nodeName.toLowerCase() == "div" )
        {
            child.style.display = "none";
        }
    }
    node.style.display = "block";
    
    var buttonNode = document.getElementById(id + "_button");
    var ulNode = document.getElementById("boat_buttons");
    var childCount = ulNode.childNodes.length;
    for (var i = 0; i < childCount; ++i)
    {
        child = ulNode.childNodes[i];
        if( child.nodeName.toLowerCase() == "li" )
        {
            child.className = "";
        }
    }
    buttonNode.className = "on_page";
    
    return false;
}

function findTop(obj)
{
    var curTop = 0;
    if (obj.offsetParent)
    {
        do
        {
            curTop += obj.offsetTop;
        }
        while (obj = obj.offsetParent);
    }
    return curTop;
}

function findLeft(obj)
{
    var curLeft = 0;
    if (obj.offsetParent)
    {
        do
        {
            curLeft += obj.offsetLeft;
        }
        while (obj = obj.offsetParent);
    }
    return curLeft;
}

function FindWidth(t)
{
    var node;
    var totalWidth = 0;
    var chilLength = t.childNodes.length;
    for(var i = 0; i < chilLength; ++i)
    {
        node = t.childNodes[i];
        if( node.nodeName.toLowerCase() == "li" )
        {
            totalWidth += node.offsetWidth + 1;
        }
    }
    return totalWidth;
}

function ShowTopNav(t)
{
    var node;
    var found = false;
    var chilLength = t.childNodes.length;
    for(var i = 0; i < chilLength && !found; ++i)
    {
        node = t.childNodes[i];
        if( node.nodeName.toLowerCase() == "ul" )
        {
            var totalWidth = FindWidth(node);
            node.style.width = totalWidth + "px";
            totalWidth = FindWidth(node);
            node.style.width = totalWidth + "px";
            node.style.visibility="visible";
            parLeft = findLeft( t.parentNode );
            parWidth = t.parentNode.offsetWidth;
            curLeft = findLeft( node );
            curWidth = node.offsetWidth;
            if((parLeft + parWidth) < (curLeft + curWidth))
            {
                adjWidth = (curLeft + curWidth) - (parLeft + parWidth) + 1;
                node.style.left = "-" + adjWidth + "px";
            }
            found = true;
        }
    }
}

function ShowSizes(t)
{
    var node;
    var found = false;
    var chilLength = t.childNodes.length;
    for(var i = 0; i < chilLength && !found; ++i)
    {
        node = t.childNodes[i];
        if( node.nodeName.toLowerCase() == "ul" )
        {
            node.style.visibility="visible";
            parTop = findTop( t.parentNode );
            parHeight = t.parentNode.offsetHeight;
            curTop = findTop( node );
            curHeight = node.offsetHeight;
            if((parTop + parHeight) < (curTop + curHeight))
            {
                adjHeight = (curTop + curHeight) - (parTop + parHeight) + 1;
                node.style.top = "-" + adjHeight + "px";
            }
            found = true;
        }
    }
}

function ShowDetails(t)
{
    var node;
    var menuNode;
    var found = false;
    var chilLength = t.childNodes.length;
    for (var i = 0; i < chilLength && !found; ++i)
    {
        node = t.childNodes[i];
        if (node.nodeName.toLowerCase() == "div")
        {
            node.style.visibility="visible";
            node.style.height="";
            if( node.style.top === "" )
            {
                menuNode = t.parentNode.parentNode.parentNode.parentNode;
                parTop = findTop(menuNode);
                curTop = findTop(node);
                if (parTop < curTop)
                {
                    adjHeight = curTop - parTop;
                    maxAdj = node.offsetHeight - t.offsetHeight;
                    if( adjHeight > maxAdj )
                    {
                        adjHeight = maxAdj;
                    }
                    node.style.top = "-" + adjHeight + "px";
                }
            }
            
            
            found = true;
        }
    }
}

function HideTopNav(t)
{
    var node;
    var found = false;
    var chilLength = t.childNodes.length;
    for(var i = 0; i < chilLength && !found; ++i)
    {
        node = t.childNodes[i];
        if( node.nodeName.toLowerCase() == "ul" )
        {
            node.style.visibility="hidden";
            fond = true;
        }
    }
}


function HideSizes(t)
{
    var node;
    var found = false;
    var chilLength = t.childNodes.length;
    for(var i = 0; i < chilLength && !found; ++i)
    {
        node = t.childNodes[i];
        if( node.nodeName.toLowerCase() == "ul" )
        {
            node.style.visibility="hidden";
            fond = true;
        }
    }
}

function HideDetails(t)
{
    var node;
    var found = false;
    var chilLength = t.childNodes.length;
    for(var i = 0; i < chilLength && !found; ++i)
    {
        node = t.childNodes[i];
        if( node.nodeName.toLowerCase() == "div" )
        {
            node.style.visibility="hidden";
            found = true;
        }
    }
}

var g_interval = 5;
var g_fade_smooth = 50;
function closeFlash(){StartFadeout('flash_intro')}
function StartFadeout(elName)
{
    var el = document.getElementById(elName);
    var o = 100;
    el.style.opacity = o / 100;
    el.style.filter = 'alpha(opacity='+o+')';
    time_expr = "FadeOut(\""+elName+"\","+o+")";
    setTimeout(time_expr,g_fade_smooth);
}
function FadeOut(elName, o)
{
    var el = document.getElementById(elName);
    if (g_interval <= o)
    {
        o -= g_interval;
        el.style.opacity = o / 100;
        el.style.filter = 'alpha(opacity='+o+')';
        time_expr = "FadeOut(\""+elName+"\","+o+")";
        setTimeout(time_expr,g_fade_smooth);
    }
    else
    {
        el.style.display = 'none';
    }
}

function Preload(imgs)
{
    img=new Image();
    l=imgs.length;
    for(var i=0;i<l;++i)
    {
        img.src=imgs[i][1];
    }
    img.src="/site_media/images/layout/Submit_on.jpg";
}

var CATS = [];
var ONCAT = 1;

function ClickCategory(t)
{
    showNum=t.id.substr(8);
    ONCAT=parseInt(showNum);
    var i = 1;
    cat_box = document.getElementById('cat_box1');
    do
    {
        cat_box.style.display='none';
        ++i;
        cat_box = document.getElementById('cat_box'+i);
    }
    while(cat_box);
    cat_box = document.getElementById('form_box');
    cat_box.style.display='none';
    cat_box = document.getElementById('cat_box'+showNum);
    cat_box.style.display='block';

    var i = 1;
    cat_name = document.getElementById('cat_name1');
    do
    {
        cat_name.className='';
        cat_img=cat_name.getElementsByTagName('img')[0];
        cat_img.src='/site_media/'+IMGS[i-1][0];
        ++i;
        cat_name = document.getElementById('cat_name'+i);
    }
    while(cat_name);
    btn=document.getElementById('submit_button').getElementsByTagName('img')[0];
    btn.src='/site_media/images/layout/list_submit_button.jpg'
    
    cat_name=document.getElementById('cat_name'+showNum);
    cat_name.className='selected_cat';
    cat_img=cat_name.getElementsByTagName('img')[0];
    cat_img.src='/site_media/'+IMGS[showNum-1][1];
    
    return false;
}

function ShowForm()
{
    var i = 1;
    cat_box = document.getElementById('cat_box1');
    if( cat_box)
    {
        do
        {
            cat_box.style.display = 'none';
            ++i;
            cat_box = document.getElementById('cat_box'+i);
        }
        while(cat_box);
    }
    ONCAT=i;
    cat_box = document.getElementById('form_box');
    cat_box.style.display='block';
    
    var i = 1;
    cat_box = document.getElementById('cat_name1');
    if( cat_box )
    {
        do
        {
            cat_box.className = '';
            cat_img=cat_box.getElementsByTagName('img')[0];
            cat_img.src='/site_media/'+IMGS[i-1][0];
            ++i;
            cat_box = document.getElementById('cat_name'+i);
        }
        while(cat_box);
    }
    btn=document.getElementById('submit_button').getElementsByTagName('img')[0];
    btn.src='/site_media/images/layout/Submit_on.jpg'
    
    return false;
}


function ClickItem(t)
{
    if(t.checked===true)
        AddOption(t);
    else
        RemoveOption(t);
}

function ClickSpan(t)
{
    inp = t.parentNode.getElementsByTagName('input')[0];
    if( !inp.disabled )
    {
        if(inp.checked===true)
        {
            inp.checked = false;
            RemoveOption(inp);
        }
        else
        {
            inp.checked = true;
            AddOption(inp);
        }
    }
}

function AddOption(t)
{
    opt_id = t.parentNode.id.substr(7);
    cat_id = t.parentNode.parentNode.parentNode.id.substr(7);
    standard = t.parentNode.className;
    cat_sel_div = document.getElementById('selected_cat_'+cat_id);
    if( cat_sel_div )
    {
        cat_ul = cat_sel_div.getElementsByTagName('ul')[0];
    }
    else
    {
        cat_name = document.getElementById('cat_name'+cat_id);
        cat_img = cat_name.getElementsByTagName('img')[0];
        cat_div = document.createElement('div');
        cat_div.id = 'selected_cat_' + cat_id;
        cat_ul = document.createElement('ul');
        cat_h2 = document.createElement('h2');
        cat_h2.innerHTML = cat_img.alt;
        cat_div.appendChild(cat_h2);
        cat_div.appendChild(cat_ul);
        sel = document.getElementById('add_to_me');
        sel.appendChild(cat_div);
    }
    
    li = document.createElement('li');
    li.id = "select_"+opt_id;
    if( standard === "standard" )
    {
        li.className = "standard";
    }
    li.innerHTML = t.parentNode.getElementsByTagName('span')[0].innerHTML;
    cat_ul.appendChild(li);
}  

function RemoveOption(t)
{
    opt_id = t.parentNode.id.substr(7);
    cat_id = t.parentNode.parentNode.parentNode.id.substr(7);
    cat_sel_div = document.getElementById('selected_cat_'+cat_id);
    
    li = document.getElementById('select_'+opt_id)
    li.parentNode.removeChild(li);
    li = undefined;
    delete li;
    
    has_options = cat_sel_div.getElementsByTagName('li').length;
    if( !has_options )
    {
        cat_sel_div.id = "";
        cat_sel_div.parentNode.removeChild(cat_sel_div);
        cat_sel_div = undefined;
        delete cat_sel_div;
    }
}

var DESC_HOLDER = '';

function OverOption(t)
{
    desc=document.getElementById('desc_box');
    span=t.getElementsByTagName('span')[0];
	opt_div=t.getElementsByTagName('div')[0];
	if( opt_div )
	{
        desc.innerHTML='<h2>'+span.innerHTML+'</h2>';
		desc.innerHTML+=opt_div.innerHTML;
	}
    desc.style.display='block';
}

function OutOption()
{
    desc=document.getElementById('desc_box');
    desc.style.display='none';
}

function MoveMouseBox(event)
{
    var e=event;
    var el=document.getElementById('desc_box');
    var scrollLeft=0;
    var scrollTop=0;
    if(typeof(window.pageYOffset)=='number')
    {
        scrollLeft=window.pageXOffset;
        scrollTop=window.pageYOffset;
    }
    else if(document.body&&(document.body.scrollLeft||document.body.scrollTop))
    {
        scrollLeft=document.body.scrollLeft;
        scrollTop=document.body.scrollTop;
    }
    else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop))
    {
        scrollLeft=document.documentElement.scrollLeft;
        scrollTop=document.documentElement.scrollTop;
    }
    
    var h=el.offsetHeight;
    var wh=0;
    if(window.innerHeight)
    {
        wh=window.innerHeight;
    }
    else
    {
        wh=document.documentElement.clientHeight;
    }
    if((h+e.clientY+16)>wh)
    {
        scrollTop -= (h+e.clientY+16)-wh;
    }
    
    var w=el.offsetWidth;
    var ww=0;
    if(window.innerWidth)
    {
        ww=window.innerWidth;
    }
    else
    {
        ww=document.documentElement.clientWidth;
    }
    if((w+e.clientX+16)>ww)
    {
        scrollLeft -= (w+e.clientX+16)-ww;
    }
    
    el.style.top=(e.clientY+scrollTop+16)+'px';
    el.style.left=(e.clientX+scrollLeft+16)+'px';
}

scrollStep=3

timerLeft=""
timerRight=""

function toLeft(id)
{
  document.getElementById(id).scrollLeft=0;
}

function scrollDivLeft(id)
{
  clearTimeout(timerRight) ;
  document.getElementById(id).scrollLeft+=scrollStep;
  timerRight=setTimeout("scrollDivLeft('"+id+"')",10);
}

function scrollDivRight(id)
{
  clearTimeout(timerLeft);
  document.getElementById(id).scrollLeft-=scrollStep;
  timerLeft=setTimeout("scrollDivRight('"+id+"')",10);
}

function toRight(id)
{
  document.getElementById(id).scrollLeft=document.getElementById(id).scrollWidth
}

function stopMe()
{
  clearTimeout(timerRight) 
  clearTimeout(timerLeft)
}

CAT_SIZE = 70;

function ScrollTo(num)
{
    var cat=document.getElementById('cat_name'+num);
    var div=document.getElementById('cat_chooser');
    var offset_by = (num-1)*CAT_SIZE;
    div.scrollLeft=offset_by;
    ClickCategory(cat);
}

function ScrollPrev()
{
  showNum=ONCAT-1;
  if(showNum>0)
    ScrollTo(showNum);
}

function ScrollNext()
{
  showNum=ONCAT+1;
  el=document.getElementById('cat_name'+showNum);
  if(el)
    ScrollTo(showNum);
  else
    ShowForm();
}

function InitChooser(bound)
{
    var i = 1;
    cat_box = document.getElementById('cat_box1');
    if( cat_box )
    {
        do
        {
            boxes = cat_box.getElementsByTagName('input');
            box_len = boxes.length;
            for(j = 0;j < box_len; ++j)
            {
                if( boxes[j].checked )
                {
                    AddOption( boxes[j] );
                }
            }
            
            ++i;
            cat_box = document.getElementById('cat_box'+i);
        }
        while(cat_box);
    }
    
    if(document.getElementById('cat_box1')&&!bound)
        ScrollTo(1);
    else
        ShowForm();
}