/*  Image preload and swapping code from LuckyFish */
function MM_preloadImages() { //v3.0
  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 MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/*  Image preload and swapping code from LuckyFish */

function Swap(thisImage, sNewSrc){
    MM_swapImage(thisImage.id,'',sNewSrc,1)
}

function PreLoadHome(){
    MM_preloadImages('/images/nav/n1_ovr.jpg',
    '/images/nav/n2_ovr.jpg',
    '/images/nav/n3_ovr.jpg',
    '/images/nav/n4_ovr.jpg',
    'images/hp/whitepapers_on.jpg',
    'images/hp/customersuccess_on.jpg')
}

function PreLoadColumnImages(){
    MM_preloadImages('images/hp/whitepapers_on.jpg',
    'images/hp/customersuccess_on.jpg')
}

function PreLoadNavigatorImages(){
    MM_preloadImages('/images/arrow_left_ovr.jpg','/images/arrow_right_ovr.jpg');
}

function SetAppearence(sMyColumnID, sMyColumnImage, sOtherColumnColID, sOtherColumnImage){
    MM_swapImage(sOtherColumnColID,'',sOtherColumnImage,1);
    MM_swapImage(sMyColumnID,'',sMyColumnImage,1);
}


function ShowPreviousItem(sLayerID){    
    var aItemLayerIDs = [];
    var iCurrentIndex;
    var iPreviousIndex;
    BuildItemIDs(sLayerID, aItemLayerIDs);
    iCurrentIndex = GetCurrentIndex(aItemLayerIDs);
    iPreviousIndex = GetPreviousIndex(iCurrentIndex, aItemLayerIDs);
    if(iCurrentIndex != iPreviousIndex)
        ShowItem(sLayerID+'_'+iPreviousIndex, aItemLayerIDs);
}

function ShowNextItem(sLayerID){    
    var aItemLayerIDs = [];
    var iCurrentIndex;
    var iNextIndex;
    try{
        ClearAutoForward();
    }
    catch(err){
        //ignore
    }
    BuildItemIDs(sLayerID, aItemLayerIDs);
    iCurrentIndex = GetCurrentIndex(aItemLayerIDs);
    iNextIndex = GetNextIndex(iCurrentIndex, aItemLayerIDs);
    if(iCurrentIndex != iNextIndex)
        ShowItem(sLayerID+'_'+iNextIndex, aItemLayerIDs);
}

function GetCurrentIndex(aItemLayerIDs){
    for(k=0;k<aItemLayerIDs.length;k++){    
        if(document.getElementById(aItemLayerIDs[k]).style.visibility == 'visible'){
            return parseInt(aItemLayerIDs[k].split('_')[1]);
        }
    }
}

function ShowItem(sLayerID, aItemLayerIDs){
    for(k=0;k<aItemLayerIDs.length;k++){
       if(aItemLayerIDs[k] != sLayerID){
            document.getElementById(aItemLayerIDs[k]).style.display = 'none';
            setLayerVisibility(aItemLayerIDs[k],'hidden');            
        } 
        if(aItemLayerIDs[k] == sLayerID){
            document.getElementById(aItemLayerIDs[k]).style.display = 'block';
            setLayerVisibility(aItemLayerIDs[k],'visible');
        } 
    }
}

function GetNextIndex(iCurrentIndex, aItemLayerIDs){
    if(aItemLayerIDs.length <= 1){
        return iCurrentIndex
    }
    for(k=0;k<aItemLayerIDs.length;k++){    
        if(aItemLayerIDs[k].split('_')[1] == iCurrentIndex){
            if(k+1 == aItemLayerIDs.length){
                return aItemLayerIDs[0].split('_')[1]            
            }
            return parseInt(aItemLayerIDs[k+1].split('_')[1]);
        }
    }
}

function GetPreviousIndex(iCurrentIndex, aItemLayerIDs){
    if(aItemLayerIDs.length <= 1){
        return iCurrentIndex
    }
    for(k=0;k<aItemLayerIDs.length;k++){    
        if(aItemLayerIDs[k].split('_')[1] == iCurrentIndex){
            if(k == 0){
                return aItemLayerIDs[aItemLayerIDs.length-1].split('_')[1]            
            }
            return parseInt(aItemLayerIDs[k-1].split('_')[1]);
        }
    }
}

function setLayerVisibility(sLayerID, sValue){ 
	if(document.layers){
		document.layers[sLayerID].visibility = sValue;
	}
	else{
		document.getElementById(sLayerID).style.visibility = sValue;				
	}	
}

function SelectColumn(thisColumn) {    
    var aList=oList.split(',');
    for(i=0;i<aList.length;i++){
        if(aList[i] != aList[thisColumn.name-1]){
            document.getElementById(aList[i]).style.display = 'none';
            setLayerVisibility(aList[i],'hidden');
            HideColumnItems(aList[i]);
        } 
        if(aList[i] == aList[thisColumn.name-1]){
            document.getElementById(aList[i]).style.display = 'block';
            setLayerVisibility(aList[i],'visible');
            ShowColumnItems(aList[i]);            
        }
    }
}

function BuildItemIDs(sLayerID, aItemLayerIDs){
    for(j=1;j<document.getElementById(sLayerID).childNodes.length;j++){
        if(document.getElementById(sLayerID).childNodes[j].id != 'undefined' && document.getElementById(sLayerID).childNodes[j].nodeName == "DIV" && document.getElementById(sLayerID).childNodes[j].id !=sLayerID && document.getElementById(sLayerID).childNodes[j].id.indexOf(sLayerID) > -1){
           aItemLayerIDs.push(document.getElementById(sLayerID).childNodes[j].id);
        }
    }
}

function HideColumnItems(sShowLayerID){
    var aItemLayerIDs = [];
    BuildItemIDs(sShowLayerID, aItemLayerIDs);
    for(k=0;k<aItemLayerIDs.length;k++){
        setLayerVisibility(aItemLayerIDs[k],'hidden');
        document.getElementById(aItemLayerIDs[k]).style.display = 'none';
    }
}

function ShowColumnItems(sShowLayerID){  
    var aItemLayerIDs = [];
    BuildItemIDs(sShowLayerID, aItemLayerIDs);
    setLayerVisibility(aItemLayerIDs[0],'visible');
    document.getElementById(aItemLayerIDs[0]).style.display = 'block';
    for(k=1;k<aItemLayerIDs.length;k++){
        setLayerVisibility(aItemLayerIDs[k],'hidden');
        document.getElementById(aItemLayerIDs[k]).style.display = 'none';
    }    
}

function displayHourglass(){
  document.body.style.cursor = 'wait';
  setTimeout('clearHourglass();', 3000);
}

function clearHourglass(){
  document.body.style.cursor = 'default';
}

function ClearThis(me){
    if(me.type == 'text' && me.value == '>Search'){
        me.value = '';
    }
}
function SpawnPop(qURL,sWindowName)
{
 	var sURL = qURL;
 	var sLocation = 'no';
	var sMenubar = 'no';
	var sScrollbars = 'yes';
	var sResizable = 'yes';
	var iTop = 50;
	var iLeft = 50;
		self.focus();
		SpawnPopDefault(sURL, sWindowName, sLocation, sMenubar, sScrollbars, sResizable, iTop, iLeft);
}

function SpawnFlashPopup(sURL, sWindowName, iWidth, iHeight)
{
	var sFeatures, iTop, iLeft;
	
	iTop=(screen.height - iHeight) / 2;
	iLeft=(screen.width - iWidth) / 2;
	
	sFeatures = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no' +
				',resizable=yes,width=' + iWidth + ',height=' + iHeight + 
				',top=' + iTop + ',left=' + iLeft;
		
	m_rWindow = window.open(sURL,sWindowName,sFeatures);
	
	if (window.screen.width==800 && window.screen.height==600)		
		m_rWindow.moveTo(72,0)
	else if (window.screen.width<1280 || window.screen.height<1024)
		m_rWindow.moveTo(30,0)	
}

function SpawnPopDefault(sURL, sWindowName, sLocation, sMenuBar, sScrollbars, sResizable, iTop, iLeft)
{

	var iWidth, iHeight, sFeatures;
	iWidth = 900;
	iHeight = 700;
	sFeatures = 'toolbar=no,location=' + sLocation + 
				',directories=no,status=no,menubar=' + sMenuBar + 
				',scrollbars=' + sScrollbars + 
				',resizable=' + sResizable + 
				',width=' + iWidth + 
				',height=' + iHeight + 
				',top=' + iTop + 'px' + 
				',left=' +iLeft+ 'px';
		
	m_rWindow = window.open(sURL,sWindowName,sFeatures);
	if (window.screen.width==800 && window.screen.height==600)		
		m_rWindow.moveTo(72,0)
	else if (window.screen.width<1280 || window.screen.height<1024)
		m_rWindow.moveTo(30,0)	
}

function closeMe() {
   window.open('','_self','');
   window.close();
}

function AutoForward(){
    try{
        StartAutoForward();
    }
    catch(err){
        //alert(err);
    }
}

function DisplayConfMsg(msg){
    var result = confirm(msg);
    if(result)
        return true;
    else
        return false;
}

/*
Use these methods on pages that implement the content slider "ext" javascript library only.
*/

function SetPageContent(detailTitleCss,
                        detailCss,
                        detailImageCss,
                        selectorCss,
                        detailLeftAdjustment,
                        imagePositionAdjustment) {

    if (typeof (Ext) != 'undefined') {

        Ext.onReady(function() {
            function deselectAll(hoverEls) {
                Ext.each(hoverEls, function(el) {
                    el = Ext.get(el);
                    el.removeClass("active");
                });
            }
            
            var h3El = Ext.DomQuery.selectNode(detailTitleCss);
            var detailEl = Ext.DomQuery.selectNode(detailCss);
            var imageEl = Ext.DomQuery.selectNode(detailImageCss);
            var hoverEls = Ext.DomQuery.select(selectorCss);

            Ext.each(hoverEls, function(el) {
                el = Ext.get(el);
                imageEl = Ext.get(imageEl);
                el.on("click", function() {
                    deselectAll(hoverEls);
                    this.addClass("active");
                    h3El.innerHTML = this.dom.innerHTML;
                    detailEl.style.left = (detailLeftAdjustment * hoverEls.indexOf(this.dom)) + "px";
                    imageEl.stopFx();
                    imageEl.shift({ duration: .3, x: imageEl.up("div").getX() + (imagePositionAdjustment * hoverEls.indexOf(this.dom)) });
                });
            });
        });
    }
}