function MM_preloadImages() {
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function toggleDiv(whichDiv,anchorText)
{
var div = document.getElementById(whichDiv);
var a = document.getElementById(anchorText);
if(div.style.display == 'none')
{
div.style.display = 'block';
a.innerHTML = 'Hide';
return true;
} else {
div.style.display = 'none';
a.innerHTML = 'Show';
return true;
}
}

function windowScrollable(windowName,frameWidth,frameHeight,url, centered){
      fw=window.open(url, windowName,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=no,left=0,top=0,width=" + frameWidth + ",height=" + frameHeight);     
      if(centered==true){
        fw.moveTo((screen.Width-780)/2,(screen.Height-500)/2 );
      }
      fw.focus();
    }

 function windowReference(windowName,url) {
   fw=window.open(url + "&name=" + windowName , windowName,"toolbar=1,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=yes,left=0,top=0,width=850,height=600");     
   fw.moveTo((screen.Width-780)/2,(screen.Height-500)/2 );
   fw.focus();
}
   
function windowFrame(windowName,frameWidth,frameHeight,url) {
  fw=window.open(url,windowName,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,left=0,top=0,width=" + frameWidth + ",height=" + frameHeight);     
  fw.focus();
}

function LaunchCompare(valID)
{
var url = "/comparePop.aspx?ID=" + valID;
mywindow = window.open (url, "Compare","location=0,status=0,scrollbars=1,toolbar=0,menubar=0,width=800,height=600");
mywindow.focus;
}   

/* HOME PAGE ROTATOR STUFF */
var liWhatsNewCurrItem = 0;
function itemShowing_handler(sender, args)
{
    var listItem = document.getElementById("listItem5");
    listItem.setAttribute("class", "homeRotatorRow");
    listItem.setAttribute("className", "homeRotatorRow");
        
    var iIndex = sender.get_currentItem()._index; 
    var curItemNum = args.get_item().get_index() + 2;
    liWhatsNewCurrItem = curItemNum;
    if (curItemNum < 6)
    {
        listItem = document.getElementById("listItem1");
        listItem.setAttribute("class", "homeRotatorRow");
        listItem.setAttribute("className", "homeRotatorRow");
        listItem = document.getElementById("listItem2");
        listItem.setAttribute("class", "homeRotatorRow");
        listItem.setAttribute("className", "homeRotatorRow");
        listItem = document.getElementById("listItem3");
        listItem.setAttribute("class", "homeRotatorRow");
        listItem.setAttribute("className", "homeRotatorRow");
        listItem = document.getElementById("listItem4");
        listItem.setAttribute("class", "homeRotatorRow");
        listItem.setAttribute("className", "homeRotatorRow");
        listItem = document.getElementById("listItem5");
        listItem.setAttribute("class", "homeRotatorRow");
        listItem.setAttribute("className", "homeRotatorRow");
        
        curItemNum = curItemNum + "";
        listItem = document.getElementById("listItem" + curItemNum);
        if (listItem != null)
        {
            listItem.setAttribute("class", "homeRotatorRowSelected");
            listItem.setAttribute("className", "homeRotatorRowSelected");
        }
        
    }
    
    if (args.get_item().get_index() == 3)
    {
        var img = document.getElementById("imgPausePlay");
        img.click();
        liWhatsNewCurrItem = 0;

        //sender.ShowNext(Telerik.Web.UI.RotatorScrollDirection.Left);
    }
}

function OnClientLoad(sender, args) { 
    /* FF hack to get image click event to work */
    /* from here: http://codingforums.com/showthread.php?t=59651 */
    if (navigator.userAgent.indexOf("Firefox")!=-1)
    {
        HTMLElement.prototype.click = function() {
        var evt = this.ownerDocument.createEvent('MouseEvents');
        evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
        this.dispatchEvent(evt);
        }
    } 
    /* end hack */

    if (!sender.autoIntervalID)
    {
        sender.autoIntervalID = window.setInterval(function()
        {
            sender.showNext(Telerik.Web.UI.RotatorScrollDirection.Left);
        }, sender.get_frameDuration());
    }
} 

function startRotator(clickedButton, rotator, direction)
{
    if (!rotator.autoIntervalID)
    {
        refreshButtonsState(clickedButton, rotator);
        rotator.autoIntervalID = window.setInterval(function()
        {
            rotator.showNext(direction);
        }, rotator.get_frameDuration());
    }
}

function PausePlayRotatorSelectLink(rot, liItem)
{
    var li = document.getElementById(liItem);
    var strTemp = li.id;
    strTemp = strTemp.substring(strTemp.length-1);
    var iTemp = parseInt(strTemp);
    setFrame(iTemp, rot)
    if (rot.autoIntervalID)
        {
            window.clearInterval(rot.autoIntervalID);
            rot.autoIntervalID = null;
        }
        
    var listItem = document.getElementById("listItem1");
    listItem.setAttribute("class", "homeRotatorRow");
    listItem.setAttribute("className", "homeRotatorRow");
    listItem = document.getElementById("listItem2");
    listItem.setAttribute("class", "homeRotatorRow");
    listItem.setAttribute("className", "homeRotatorRow");
    listItem = document.getElementById("listItem3");
    listItem.setAttribute("class", "homeRotatorRow");
    listItem.setAttribute("className", "homeRotatorRow");
    listItem = document.getElementById("listItem4");
    listItem.setAttribute("class", "homeRotatorRow");
    listItem.setAttribute("className", "homeRotatorRow");
    listItem = document.getElementById("listItem5");
    listItem.setAttribute("class", "homeRotatorRow");
    listItem.setAttribute("className", "homeRotatorRow");
    
    li.setAttribute("class", "homeRotatorRowSelected");
    li.setAttribute("className", "homeRotatorRowSelected");
        
    var img = document.getElementById("imgPausePlay");   
    img.src = '/images/b_play.gif';

}

function setFrame(frame, rotator) { 
        var item = rotator.get_currentItem(); 
        var index = item._index + 1; 
         
        if (frame == index) {  
            return;  
        } 
 
        if (frame > index) { 
            while (frame > index) { 
                rotator.showNext(Telerik.Web.UI.RotatorScrollDirection.Left); 
                frame--; 
            } 
        } else { 
            while (frame < index) { 
                rotator.showNext(Telerik.Web.UI.RotatorScrollDirection.Right); 
                frame++; 
            } 
        } 
    } 

function PausePlayRotator(rot)
{
    var img = document.getElementById("imgPausePlay");
    var temp = img.src;
    var pos = temp.indexOf("b_pause", 0);
    if (pos >= 0)
    {
        img.src = '/images/b_play.gif';
        //rot.stop();
        if (rot.autoIntervalID)
        {
            window.clearInterval(rot.autoIntervalID);
            rot.autoIntervalID = null;
        }
    }   
    else
    {
        img.src = '/images/b_pause.gif';
        
        if (!rot.autoIntervalID && liWhatsNewCurrItem != 0)
        {
            rot.autoIntervalID = window.setInterval(function()
            {
                rot.showNext(Telerik.Web.UI.RotatorScrollDirection.Left);
            }, rot.get_frameDuration());
        }

    }
    
    if (liWhatsNewCurrItem == 0)
    {
        var listItem = document.getElementById("listItem1");   
        listItem.setAttribute("class", "homeRotatorRowSelected");
        listItem.setAttribute("className", "homeRotatorRowSelected");
        var listItem = document.getElementById("listItem5");   
        listItem.setAttribute("class", "homeRotatorRow");
        listItem.setAttribute("className", "homeRotatorRow");
        rot.showNext(Telerik.Web.UI.RotatorScrollDirection.Left); 
        
        if (!rot.autoIntervalID && liWhatsNewCurrItem != 0)
        {
            rot.autoIntervalID = window.setInterval(function()
            {
                rot.showNext(Telerik.Web.UI.RotatorScrollDirection.Left);
            }, rot.get_frameDuration());
        }

    }
}

function inspect(obj, maxLevels, level)
{
  var str = '', type, msg;

    // Start Input Validations
    // Don't touch, we start iterating at level zero
    if(level == null)  level = 0;

    // At least you want to show the first level
    if(maxLevels == null) maxLevels = 1;
    if(maxLevels < 1)     
        return '<font color="red">Error: Levels number must be > 0</font>';

    // We start with a non null object
    if(obj == null)
    return '<font color="red">Error: Object <b>NULL</b></font>';
    // End Input Validations

    // Each Iteration must be indented
    str += '<ul>';

    // Start iterations for all objects in obj
    for(property in obj)
    {
      try
      {
          // Show "property" and "type property"
          type =  typeof(obj[property]);
          str += '<li>(' + type + ') ' + property + 
                 ( (obj[property]==null)?(': <b>null</b>'):('')) + '</li>';

          // We keep iterating if this property is an Object, non null
          // and we are inside the required number of levels
          if((type == 'object') && (obj[property] != null) && (level+1 < maxLevels))
          str += inspect(obj[property], maxLevels, level+1);
      }
      catch(err)
      {
        // Is there some properties in obj we can't access? Print it red.
        if(typeof(err) == 'string') msg = err;
        else if(err.message)        msg = err.message;
        else if(err.description)    msg = err.description;
        else                        msg = 'Unknown';

        str += '<li><font color="red">(Error) ' + property + ': ' + msg +'</font></li>';
      }
    }

      // Close indent
      str += '</ul>';

    return str;
}

/* end HOME PAGE ROTATOR STUFF */
