﻿// JScript File

//Variable declaration

//sniffBrowser()
var index_of_submenu_node; 

//launchShowroom()
var childClicked = false;  

//initializeSlideShow()
var array_index;
var num_images = 0;
var array_image_strings = new Array( num_images );
var array_images = new Array();
var image_index;

//playSlideshow()
var img_slideshow;
var slideshow_fade = 3;
var slideshow_timer;
var slideshow_pause = 5000;
var slideshow_paused = false;

//Initialization
sniffBrowser();


//Functions

//Slideshow functions

function initializeSlideshow()
{
    num_images = document.getElementById( "img_slideshow" ).parentNode.id;

    for( array_index = 0; array_index < num_images; array_index++ )
    {
        if( array_index < 10 )
        {
            array_image_strings[ array_index ] = "images/slideshow/0" + array_index + ".jpg";
        }
        else
        {
            array_image_strings[ array_index ] = "images/slideshow/" + array_index + ".jpg";
        }
    }

    for( array_index = 0; array_index < num_images; array_index++ )
    {
        array_images[ array_index ] = new Image();
        array_images[ array_index ].src = array_image_strings[ array_index ];
    }

    //image_index = Math.floor( Math.random() * num_images );
    image_index = 0;

    document.getElementById( "img_slideshow" ).src = array_images[ image_index ].src;
    
    image_index = num_images;
    
    playSlideshow();
}

function playSlideshow()
{
    if( slideshow_paused == false )
    {
        img_slideshow = document.getElementById( "img_slideshow" ); //I don't know why, but it won't work without reassigning this variable

        //image_index = Math.floor( Math.random() * num_images );
        if( image_index < num_images - 1 )
        {
            image_index = image_index + 1;
        }
        else
        {
            image_index = 0;
        }

        if( document.all )
        {
            img_slideshow.style.filter = "blendTrans(duration=2)";
            img_slideshow.style.filter = "blendTrans(duration=slideshow_fade)";
            img_slideshow.filters.blendTrans.Apply();
        }
        
        img_slideshow.src = array_images[ image_index ].src;
        
        if( document.all )
        {
            img_slideshow.filters.blendTrans.Play();
        }
    }
    
    slideshow_timer = setTimeout( 'playSlideshow()', slideshow_pause );
}

function pauseSlideshow()
{
    slideshow_paused = true;
}

function unpauseSlideshow()
{
    slideshow_paused = false;
}

//Navbar functions

function hilite(e)
{
    e.style.background = color_hilite;
}
function unlite(e)
{
    e.style.background = "none";
}

function launchShowroom(e)
{
    if( childClicked == true ) 
    {
        return;
    }
    else
    {
        window.location = "showroom.aspx?type_id=" + e.id;
        childClicked = true;
    }
}

function launchCatalog( manufacturer_id )
{
    document.location = "catalog.aspx?id=" + manufacturer_id;
}

function showRootMenu(e)
{
    hilite(e);
    document.getElementById(e.id + "-menu").style.display = "block";
}
function hideRootMenu(e)
{
    unlite(e);
    document.getElementById(e.id + "-menu").style.display = "none";
}

function showSubMenu(e)
{
    hilite(e);
    e.childNodes[index_of_submenu_node].style.display = "block";
}
function hideSubMenu(e)
{
    unlite(e);
    e.childNodes[index_of_submenu_node].style.display = "none";
}

//Browser detection

function sniffBrowser()
{
    index_of_submenu_node = 3;

    if( navigator.appName.indexOf("Microsoft") != -1 )
    {
        index_of_submenu_node = 1;
        document.writeln("<link rel='stylesheet' type='text/css' href='kf-msie.css' />");
    }
    
    if( navigator.appName.indexOf("Opera") != -1 )
    {
        document.writeln("<link rel='stylesheet' type='text/css' href='kf-opera.css' />");
    }
}