<script language="Javascript">
var time; var tAdRefresh; var AdCount = 0; var LastS; var ThisS;

function showPlayer() {
	Play(<%# intStarter %>);
	top.document.getElementById('divPhoto').childNodes[0].style.display='none';
}

function ChangeImage(fFwd){
    if (fFwd) {
        if (++iimg==imax){
            iimg=0;
        }    
    } else {
        if (iimg==0){
            iimg=imax;
            getobject("layerSelect").selectedIndex = 0;
        }
        iimg--;
    }     
    // Category change when photo change.
    // If has multiple category, category changes.
    if (getobject("layerSelect").options.length >1)
    {
        // When photo load, check which category it should display.
        for (var ind=0; ind<(getobject("layerSelect").options.length); ind++)
        {
            if((ind) < (getobject("layerSelect").options.length-1))
            {
                if ((iimg >= (parseInt(getobject("layerSelect").options[ind].value)+1))&&(iimg < (parseInt(getobject("layerSelect").options[ind+1].value)+1)))
                {
                       getobject("layerSelect").selectedIndex = ind;
                }
             }
             else if(ind == (getobject("layerSelect").options.length -1))
             {
                if (iimg >= (parseInt(getobject("layerSelect").options[ind].value)+1))  
                   getobject("layerSelect").selectedIndex = ind;
             }
        }
    } 
   Update(ImageTable[iimg]);
}


function getobject(obj){
    if (document.getElementById)
        return document.getElementById(obj)
    else if (document.all)
        return document.all[obj]
}

function Play(starter){
    if(starter != -1)
      iimg = starter;
      
    PlayMode = !PlayMode;
    if (PlayMode){
        getobject('ddSpeed').selectedIndex = 2;
        getobject('bntPlay').src = 'http://images.thegolfchannel.com/images/photogallery/89236.gif';
        ChangeImage(true);
    } else {
        getobject('ddSpeed').selectedIndex = 0;
        getobject('bntPlay').src = 'http://images.thegolfchannel.com/images/photogallery/89235.gif';
    }
}

function OnImgLoad(){        
    if (PlayMode)
        time = window.setTimeout('Tick()', getobject('ddSpeed').value);
}

function Tick(){
    if (PlayMode)
        ChangeImage(true);
}

function Update(v){ 
    AdCount++;   
    // Display Ad
    // intAdFrequency = 1 when fldAdFrequency =0 in database, this case trun the Ad off.
    if (<%# intAdFrequency %> != 1 && (AdCount % <%# intAdFrequency %> == 0)){      
        document.getElementById('slideshow').innerHTML = '<iframe style="background-color:#000000;" id=adFrame frameborder=0 marginheight=0 marginwidth=0 scrolling=no width=400 height=300 src="/core.aspx?page=24512&next_url=<%# strAdJavascript %>" onload="javascript:OnImgLoad();"></iframe>'; 
        // play ad take one photo position, photo index go back one to display next photo, otherwise miss one photo.
        iimg--;       
    } else{
        if (window.XMLHttpRequest){
            xmlhttp = new XMLHttpRequest();
        } else if (window.ActiveXObject){
            xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
        }
    	
	    xmlhttp.onreadystatechange = function(){
		    if (xmlhttp.readyState == 4){
			    var maxdim;
			    var height;
			    var width;
			    var url;
    			
			    url = xmlhttp.responseXML.getElementsByTagName('URL')[0].firstChild.nodeValue; 
			       			
		   	    if (xmlhttp.responseXML.getElementsByTagName('Width')[0].firstChild.nodeValue > xmlhttp.responseXML.getElementsByTagName('Height')[0].firstChild.nodeValue) {
				    maxdim = (xmlhttp.responseXML.getElementsByTagName('Width')[0].firstChild.nodeValue > 400) ? 400 : xmlhttp.responseXML.getElementsByTagName('Width')[0].firstChild.nodeValue;
				    width = maxdim;
				    height = (xmlhttp.responseXML.getElementsByTagName('Height')[0].firstChild.nodeValue) / (xmlhttp.responseXML.getElementsByTagName('Width')[0].firstChild.nodeValue / maxdim);
				    if (height > 300) height = 300;
		        } else {
				    maxdim = (xmlhttp.responseXML.getElementsByTagName('Height')[0].firstChild.nodeValue > 300) ? 300 : xmlhttp.responseXML.getElementsByTagName('Height')[0].firstChild.nodeValue;
				    height = maxdim;
				    width = (xmlhttp.responseXML.getElementsByTagName('Width')[0].firstChild.nodeValue) / (xmlhttp.responseXML.getElementsByTagName('Height')[0].firstChild.nodeValue / maxdim);
				    if (width > 400) width = 400;
		        }
    			
		        getobject('slideshow').innerHTML = '<img src="' + url + '" width=' + width + ' height=' + height + ' vspace=0 hspace=0 border=0 onload="javascript:OnImgLoad();">' + 
				    '<img src="http://wwwa.thegolfchannel.com/scripts/t2.aspx?tgcuri=&tgcqry=page%3D-36" width=1 height=1 border=0>';
				    //'<scr' + 'ipt language=Javascript>var tgcuri = \'/core.aspx\'; var tgcqry = \'page=-36\';</scr' + 'ipt>' +
				    //'<scr' + 'ipt language=Javascript src="/scripts/t2.js"></sc' + 'ript><noscript><img src="/scripts/t2.aspx?tgcuri=&tgcqry=page%3D-36" width=1 height=1 border=0></noscript>';
    		    
		   	    getobject('PhotoText').innerHTML = xmlhttp.responseXML.getElementsByTagName('Text')[0].firstChild.nodeValue;
		        		        
		        ThisS = xmlhttp.responseXML.getElementsByTagName('Bid')[0].firstChild.nodeValue + ' '; 
		        
		        if (ThisS != LastS){
		            if ((xmlhttp.responseXML.getElementsByTagName('Kid')[0].firstChild.nodeValue != '0'))
		                getobject('adSpot').innerHTML = '<iframe style="background-color:black;border: 0px;" id=SlideFrame frameborder=0 marginheight=0 marginwidth=0 scrolling=no width=300 height=250 src="/core.aspx?page=24513&next_url='+ xmlhttp.responseXML.getElementsByTagName('Kid')[0].firstChild.nodeValue + '"></iframe>';
		            else 		             		      
		                getobject('adSpot').innerHTML = '<iframe style="background-color:black;border: 0px;" id=SlideFrame frameborder=0 marginheight=0 marginwidth=0 scrolling=no width=300 height=250 src="/core.aspx?page=24513&next_url=24500"></iframe>';			
	            }
	                        	            	            
		        getobject('Img_X').innerHTML = iimg+1;
                getobject('Img_N').innerHTML = imax;
               
		    }	
		}
	    xmlhttp.open('GET', '/scripts/PhotoGallery.aspx?select=' + v, true);
	    xmlhttp.send(null);	
	    LastS = ThisS; 
	}
}

function Prev(){
    ChangeImage(false);
    PlayMode = false;
    getobject("ddSpeed").selectedIndex = 0;
    getobject("bntPlay").src = "http://images.thegolfchannel.com/images/photogallery/89235.gif";
}

function Next(){
    ChangeImage(true);
    PlayMode = false;
    getobject("ddSpeed").selectedIndex = 0;
    getobject("bntPlay").src = "http://images.thegolfchannel.com/images/photogallery/89235.gif";
}

function OnChange(){
   // Change it from play mode to manual mode.
   if (getobject("ddSpeed").selectedIndex == 0){
      PlayMode = false;
      getobject("bntPlay").src = "http://images.thegolfchannel.com/images/photogallery/89235.gif";
   } else{ 
      // Change it from manual mode to paly mode, default speed is normal.
      if(!PlayMode){
        PlayMode=true;
        getobject("bntPlay").src = "http://images.thegolfchannel.com/images/photogallery/89236.gif";
        ChangeImage(true);
      }
      // Change the play mode speed.
      else {
        ChangeImage(true);
        window.clearTimeout(time);
        //time = window.setTimeout('Tick()', getobject('ddSpeed').value);
      }      
   } 
}

function GalleryList(){
//   top.location.href = '/core.aspx?page=24510';
	document.getElementById('slideshow').innerHTML = '<iframe style="background-color:#FFFFFF;" id=listFrame width=400 height=300 src="/core.aspx?page=24510"></iframe>';
	
	PlayMode = false;
    getobject("ddSpeed").selectedIndex = 0;
    getobject("bntPlay").src = "http://images.thegolfchannel.com/images/photogallery/89235.gif";
}

function ChangeCategory(){
  iimg = getobject("layerSelect").value;
  if(!PlayMode){
    getobject("ddSpeed").selectedIndex = 2;
    getobject("bntPlay").src = "http://images.thegolfchannel.com/images/photogallery/89236.gif";
    PlayMode = true;
  }
  ChangeImage(true);
  window.clearTimeout(time);
}

if (document.getElementById||document.all)
	window.onload=showPlayer();
//    window.onload=Play(<%# intStarter %>);
    
</script</>>