/************************************************************************************************************
Ajax dynamic content
Copyright (C) November, 2005  DTHMLGoodies.com, Alf Magne Kalleland

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

Dhtmlgoodies.com., hereby disclaims all copyright interest in this script
written by Alf Magne Kalleland.

Alf Magne Kalleland, 2006
Owner of DHTMLgoodies.com


************************************************************************************************************/	

	var slideshow2_noFading = false;
	var slideshow2_timeBetweenSlides = 15000;	// Amount of time between each image(1000 = 1 second)
	var slideshow2_fadingSpeed = 10;	// Speed of fading	(Lower value = faster)
	
	var lastAlt;
	var slideshow2_stats = new Array();
	var timers = new Array(); //collection of timers
	var slideshow2_slideIndex = new Array();	// Index of current image shown
	var slideshow2_slideIndexNext = new Array();	// Index of next image shown
	var slideshow2_slideStartIndex = new Array(); // Index to start off with when no session var available
	var slideshow2_imageDivs = new Array();	// Array of image divs(Created dynamically)
	var slideshow2_currentOpacity = new Array();	// Initial opacity
	var slideshow2_imagesInGallery = new Array();	// Number of images in gallery
	var Opera = navigator.userAgent.indexOf('Opera')>=0?true:false;


function init_banner(){
	
	 slideshow2_noFading = false;
	 slideshow2_timeBetweenSlides = 15000;	// Amount of time between each image(1000 = 1 second)
	 slideshow2_fadingSpeed = 10;	// Speed of fading	(Lower value = faster)
	
	 lastAlt;
	 slideshow2_stats = new Array();
	
	slideshow2_slideIndex = new Array();	// Index of current image shown
	 slideshow2_slideIndexNext = new Array();	// Index of next image shown
	 slideshow2_slideStartIndex = new Array(); // Index to start off with when no session var available
	 slideshow2_imageDivs = new Array();	// Array of image divs(Created dynamically)
	 slideshow2_currentOpacity = new Array();	// Initial opacity
	 slideshow2_imagesInGallery = new Array();	// Number of images in gallery
	 Opera = navigator.userAgent.indexOf('Opera')>=0?true:false;
}









function createParentDivs(imageIndex,divId)
{

	if(imageIndex == slideshow2_imagesInGallery[divId]){	//last image?
		document.getElementById('banner_mask').style.display = 'none';
		showGallery(divId);
	}else{
		var imgObj = document.getElementById(divId + '_' + imageIndex);	
        
		if(Opera)imgObj.style.position = 'static';
		if(!slideshow2_imageDivs[divId])slideshow2_imageDivs[divId] = new Array();
		slideshow2_imageDivs[divId][slideshow2_imageDivs[divId].length] =  imgObj;

		imgObj.style.visibility = 'hidden';	
		imageIndex++;
		createParentDivs(imageIndex,divId);	//recursive loop
	}	
    	
}








function stat(divId,imageIndex)
{
if(divId == 'dgSpace01'){
 
    }

}








function showGallery(divId)
{
	try
	{


		if(slideshow2_slideIndex[divId]==-1)slideshow2_slideIndex[divId]=0; else slideshow2_slideIndex[divId]++;
	// Index of next image to show
		if(slideshow2_slideIndex[divId]==slideshow2_imageDivs[divId].length)slideshow2_slideIndex[divId]=0;
		slideshow2_slideIndexNext[divId] = slideshow2_slideIndex[divId]+1;	// Index of the next next image
		if(slideshow2_slideIndexNext[divId]==slideshow2_imageDivs[divId].length)slideshow2_slideIndexNext[divId] = 0;
//alert('ss_indexNext >>'+slideshow2_slideIndexNext[divId]+'\nss_imgDivLength >>'+slideshow2_imageDivs[divId].length);
		slideshow2_currentOpacity[divId]=100;	// Reset current opacity
	// Displaying image divs
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.visibility = 'visible';
     if(slideshow2_imageDivs[divId][slideshow2_slideIndexNext[divId]] != slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]]){
		if(Opera)slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.display = 'inline';
		if(navigator.userAgent.indexOf('Opera')<0){
			slideshow2_imageDivs[divId][slideshow2_slideIndexNext[divId]].style.visibility = 'visible';
		}
		if(document.all){	// IE rules
			slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.filter = 'alpha(opacity=100)';
           
			slideshow2_imageDivs[divId][slideshow2_slideIndexNext[divId]].style.filter = 'alpha(opacity=1)';
		}else{
			slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.opacity = 0.99;	// Can't use 1 and 0 because of screen flickering in FF
  
			slideshow2_imageDivs[divId][slideshow2_slideIndexNext[divId]].style.opacity = 0.01;
		}
}
       /**/
		var thisImg = slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]];
		var nxtImg = slideshow2_imageDivs[divId][slideshow2_slideIndexNext[divId]];
	//clear <a> tag above current image 
		
       
		if (thisImg.parentNode.tagName=="A" && thisImg.alt !="")
		{//remove <a> node
        
			var thisa = thisImg.parentNode;
            thisa.href = thisImg.alt;
	        thisa.title = thisImg.alt;
	    	thisa.target = "stockResearchPortal";
		}

		//setTimeout('revealImage("'+ divId +'")',slideshow2_timeBetweenSlides);	
      
       if(slideshow2_imagesInGallery[divId] > 1){  
        if(divId != 'masthead')
		{
        	timers[divId] = setTimeout('revealImage("'+ divId +'")',15000);
            start(divId,(slideshow2_slideIndex[divId]));
		}else{
			timers[divId] = setTimeout('revealImage("'+ divId +'")',10000);
			}
        start(divId,(slideshow2_slideIndex[divId]));
   		}//eof if only 1 image in array
	 }
	 catch(ex)
	 {
		//alert(ex.message);
	}
}


function revealImage(divId)
{
	//try{
		//if(document.getElementById("comp_bnr").innerHTML == ''){
		//clear_banner();
		//}
	//}
	//catch(ex)
	//{
	//	var dog=ex.message ;
	//}

	if(slideshow2_noFading){
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.visibility = 'hidden';
		if(Opera)slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.display = 'none';
		showGallery(divId);
		return;
	}
	slideshow2_currentOpacity[divId]--;
	if(document.all){
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.filter = 'alpha(opacity='+slideshow2_currentOpacity[divId]+')';
		slideshow2_imageDivs[divId][slideshow2_slideIndexNext[divId]].style.filter = 'alpha(opacity='+(100-slideshow2_currentOpacity[divId])+')';
	}else{
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.opacity = Math.max(0.01,slideshow2_currentOpacity[divId]/100);	// Can't use 1 and 0 because of screen flickering in FF
		slideshow2_imageDivs[divId][slideshow2_slideIndexNext[divId]].style.opacity = Math.min(0.99,(1 - (slideshow2_currentOpacity[divId]/100)));
	}
	if(slideshow2_currentOpacity[divId]>0){
		timers[divId] = setTimeout('revealImage("'+ divId +'")',slideshow2_fadingSpeed);
	}else{
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.visibility = 'hidden';	
		if(Opera)slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.display = 'none';		
		showGallery(divId);
	}
   
}
function initImageGallery(divId)
{  

 var slideshow2_galleryContainer = document.getElementById(divId);
 var galleryImgArray = slideshow2_galleryContainer.getElementsByTagName('IMG');

 
 if(galleryImgArray.length != 0){
    slideshow2_imagesInGallery[divId] = galleryImgArray.length;
   
      if(slideshow2_slideIndex[divId] == undefined || slideshow2_slideIndex[divId] == '' || slideshow2_slideIndex[divId] >= slideshow2_imagesInGallery[divId])
      { 
	  
        slideshow2_slideIndexNext[divId] = false;
        var rand_no = Math.floor((slideshow2_imagesInGallery[divId]-1)*Math.random());
		
        //alert('undef or \'\' or over length >>'+slideshow2_slideIndex[divId]+' divId = '+divId+'\nrandom seed = '+rand_no);
        slideshow2_slideIndex[divId] = rand_no;
        
    //alert('undef or \'\' or over length >>'+slideshow2_slideIndex[divId]+' divId = '+divId);
      }else if(slideshow2_imagesInGallery[divId] == 1){ 
      //alert('gal is 1 long >>'+slideshow2_slideIndex[divId]+' divId = '+divId);
      slideshow2_slideIndexNext[divId] = false;
      slideshow2_slideIndex[divId] = -1;
      }else{
      //alert('gal is pre-set >>'+slideshow2_slideIndex[divId]+' divId = '+divId);
      slideshow2_slideIndex[divId] = slideshow2_slideIndex[divId] - 1;
      slideshow2_slideIndexNext[divId] = slideshow2_slideIndex[divId];
      slideshow2_slideIndex[divId];
      }
          
      
      
      
        	//slideshow2_slideIndexNext[divId] = false;
        	
        	for(var no=0;no<galleryImgArray.length;no++){
        		galleryImgArray[no].id = divId + '_' + no;
        	}
        
       // alert(divId);
        	createParentDivs(0,divId);
}//EOF IF NO IMAGES
 
}
function start(divId,imageId)
{
	try{
   		var xmlhttpBanner = GetXmlHttpObject();
	}catch(ex){
		var xmlhttpBanner = parent.GetXmlHttpObject();
	}
   	//xmlhttpBanner.open("GET", "http://192.168.2.2/modules/banner_session.asp?"+divId+"="+imageId , true);//for loval testing
xmlhttpBanner.open("GET", "/modules/banner_session.asp?"+divId+"="+imageId , true);// for live
	xmlhttpBanner.onreadystatechange=function() 
  	{
   		if (xmlhttpBanner.readyState==4 && xmlhttpBanner.status==200) 
   		{
   			
   			// document.getElementById("statusAj").innerHTML = xmlhttp.responseText+'<br>';
   		}
	}
  	xmlhttpBanner.send(null);/**/
}




function addlink(Img)
{
 var thisImg = Img;
       
			if (thisImg.parentNode.tagName=="A")
			{//remove <a> node
        		var thisa = thisImg.parentNode;
                thisa.href = thisImg.alt;
        	    thisa.title = thisImg.alt;
        	    thisa.target = "stockResearchPortal";
        	}
        	if (thisImg.alt !="")
			{
        		var thisa = document.createElement("A");
        		thisa.href = thisImg.alt;
        	    thisa.title = thisImg.alt;
        	    thisa.target = "stockResearchPortal";
        		thisImg.parentNode.appendChild(thisa);
        	    thisa.appendChild(thisImg);
        	}

}




function BannerGo()
{

	
 	initImageGallery('dgSpace01');
 	initImageGallery('dgSpace02');
 	initImageGallery('dgSpace03');  
 	initImageGallery('dgSpace04');  
 	initImageGallery('dgSpace05');
}


function LoadBanner(){
			
			
			//var xmlhttpLoad = GetXmlHttpObject();
			//var url='http://192.168.2.2/comparator_banner.asp';//for local testing
            var url='comparator_banner.asp';//for live
			document.getElementById("IFR_comp_bnr").src = url;
			
 			//xmlhttpLoad.open("GET", url, true);
  			//xmlhttpLoad.onreadystatechange=function() 
  			//{
   			//	if (xmlhttpLoad.readyState==4 && xmlhttpLoad.status==200) 
   			//	{
    		//		document.getElementById("comp_bnr").innerHTML = xmlhttpLoad.responseText;
           //         		BannerGo();
   			//	}

  			//}
  			//xmlhttpLoad.send(null);
			
		}
		
function clear_banner(){

	for (img_div in slideshow2_imageDivs){
		if (img_div!='masthead'){
			clearTimeout(timers[img_div]);
		}
	}
}

