var _messagebox_green           = "FlyOutGreen";
var _messagebox_yellow          = "FlyOutYellow";
var _pointer                    = "FlyOutPointer";

var timerVideo;

var _txt_Search                 = "txtSearch";

var _btn_Search                 = "btnSearch";

function load()
{
    //assign the focus to the search text box
}

function search()
{ 
    //called from 
    alert("Search");
}


//HANDLERS
function body_onload()
{
    load();
}

function txtSearch_onkeydown(e)
{
    if(e.keyCode == 13)
    {
        PreventPostBack();
        var btn = $(_btn_Search);
        btn.click();
    }
}

function txtSearch_onfocus()
{
    var txt = $(_txt_Search)
    
    if (txt.value == "Search the entire store here...")
        txt.value = "";
}

function GetLocation(ctrl)
{
    var ctrl2 = $(ctrl.id);

    try

    {

        //Init object

        var dim = new Object();

 

        //Get Location

        dim.width = parseInt(ctrl2.offsetWidth,10);

        dim.height = parseInt(ctrl2.offsetHeight,10);

        

        offobj = Element.cumulativeOffset(ctrl2);

        dim.top = offobj.top;

        dim.left = offobj.left;       

        return dim;

    }

    catch(err)

    {

       alert('Unable to find control\'s window location.');

    }

    return null;

}

function FlyOut(el,html)
{
     el = $(el.id);
     var dim = GetLocation(el);
    
//    alert("height: " + dim.height + " width: " + dim.width + " top: " + dim.top + " left: " + dim.left);
//    alert(html);

     var style = _messagebox_green;
    
     var div = $('divFlyOut');
     var pointer = $('divFlyOutPointer');
        
     //try to get the parent's message box div
     if (!(div))
         div = window.parent.document.getElementById('divFlyOut');
 
     if (div)
     {
         var divBody = $('divFlyOutBody');
         
         if (!(divBody))
             divBody = window.parent.document.getElementById('divFlyOutBody');
     
         divBody.className = "FlyOutBody";
         divBody.innerHTML = html;
     
         div.className = style;
         pointer.className = _pointer;
         div.style.left = (dim.left + dim.width + 40) + 'px';
         
         var div_dim = GetLocation(div);
         
         div.style.top = ((dim.top + (dim.height / 2)) - (div_dim .height/ 2)) + 'px';
         
         div_dim = GetLocation(div);
         
         pointer.style.left = (div_dim.left - 40) + 'px';
         pointer.style.top = ((div_dim.top + (div_dim.height / 2)) - 20) + 'px';
         
         var tdTopMiddle = $('tdTopMiddle');
         var tdMiddleMiddle = $('tdMiddleMiddle');
         var tdBottomMiddle = $('tdBottomMiddle');  
         
         //var divBody_dim = GetLocation(divBody);     
         
         tdTopMiddle.style.width = "390px";
         tdBottomMiddle.style.width = "390px";
         tdMiddleMiddle.style.width = "390px";     
         
         /*tdTopMiddle.style.width = (div_dim.width - 40);
         tdBottomMiddle.style.width = (div_dim.width - 40);
         tdMiddleMiddle.style.width = (div_dim.width - 40);*/
         
         //tdTopMiddle.style.width = (divBody_dim.width);
         //tdBottomMiddle.style.width = (divBody_dim.width);
         //tdMiddleMiddle.style.width = (divBody_dim.width);         
     }
     else
         alert('FlyOut div not found!');    
}

function Cancel_FlyOut()
{
    var div = $('divFlyOut');
    var pointer = $('divFlyOutPointer');
    div.className = 'hide';
    pointer.className = 'hide';
}

function Video_RollOver(index) 
{
    timerVideo = setTimeout("Video_Tick(" + index +")",500);
}

function Video_RollOut(index)
{
    clearTimeout(timerVideo);
    
    Videos[index].selectedVideoIndex = 0;    
    var img = $("imgYT_" + index);
    img.src = Videos[index].images[Videos[index].selectedVideoIndex];
}

function Video_Tick(index)
{
    var img = $("imgYT_" + index);
    
    if (Videos[index].selectedVideoIndex == (Videos[index].images.length - 1))
        Videos[index].selectedVideoIndex = 0;
    else
        Videos[index].selectedVideoIndex = Videos[index].selectedVideoIndex + 1;
        
    img.src = Videos[index].images[Videos[index].selectedVideoIndex];
    
    //clearTimeOut(timerVideo);
    timerVideo = setTimeout("Video_Tick(" + index +")",500);
}