var auto;
var manual;
var ProfileLocation;


function LoadTour()
{
ProfileLocation = "Profiles/" + ProfileGUID + "/";
GetButtons(); 
ChangeText('TitleContent',Title);

// firstChild.nodeValue for auto  player  
auto='<table align="center" cellspacing="0" cellpadding="0" border="0"><tr><td><img src="'+ProfileLocation+'PrevOff.gif" alt="Previous" name="Previous" width="35" height="22" border="0" id="Previous"></td><td><a href="javascript:bPlay();" onMouseOver="document.Stop.src=Stopbtn_over.src" onMouseOut="document.Stop.src=Stopbtn_up.src"><img src="'+ProfileLocation+'StopOn.gif" alt="Stop" name="Stop" width="35" height="22" border="0" id="Stop"></a></td><td> <img  src="'+ProfileLocation+'NextOff.gif" alt="Next" name="Next" width="35" height="22" border="0" id="Next"></td></tr><tr><td colspan=\"3\" align=\"center\">Slide <span id="ilaSlide">1</span>&nbsp;of '+ImageList.length+'</td></tr></table>';

// firstChild.nodeValue for manual  player  
manual='<table align="center" cellspacing="0" cellpadding="0" border="0"><tr><td><a href="javascript:bPrev();"onMouseOver="document.Previous.src=Prevbtn_over.src" onMouseOut="document.Previous.src=Prevbtn_up.src"><img src="'+ProfileLocation+'PrevOn.gif" alt="Previous" name="Previous" width="35" height="22" border="0" id="Previous"></a></td><td><a href="javascript:bPlay();"onMouseOver="document.Play.src=Playbtn_over.src" onMouseOut="document.Play.src=Playbtn_up.src"><img src="'+ProfileLocation+'PlayOn.gif" alt="Play" name="Play" width="35"height="22" border="0" id="Play"></a></td><td><a href="javascript:bNext();"onMouseOver="document.Next.src=Nextbtn_over.src" onMouseOut="document.Next.src=Nextbtn_up.src"><img src="'+ProfileLocation+'NextOn.gif" alt="Next" name="Next" width="35" height="22" border="0" id="Next"></a></td></tr><tr><td colspan=\"3\" align=\"center\">Slide <span id="ilaSlide">1</span>&nbsp;of '+ImageList.length+'</span></td></tr></table>';

ChangeText('ControlBody',GetControlHTML());
	document.getElementById('Options').style.visibility = "hidden";

//ChangeText('DescriptionContent', '<b>'+ImageList[ThisPicture][2]+'<b>');
PlaceAgentInfo();

if(IDX)
	ChangeText('AgentInfoContent', GetContactInfo());

//if(ImageList[ThisPicture][3] != "")
//	ChangeText('DescriptionContent', ' - ' + ImageList[ThisPicture][3], true);

//display autobuttons
//alert(IDX);
if(IDX)
	ChangeText('NavigationIDXContent', auto);
else
	ChangeText('NavigationContent', auto);

//Start Slideshow
setTimeout("slideshowupdate(0,true,0);",1);
}

function GetButtons()
{

if(document.images){ //preload images
Playbtn_up= new Image(35,22)
Playbtn_up.src = ProfileLocation + "PlayOn.gif";

Playbtn_over=new Image(35,22)
Playbtn_over.src=ProfileLocation + "PlayOver.gif";

Nextbtn_over= new Image(35,22)
Nextbtn_over.src=ProfileLocation + "NextOver.gif";

Nextbtn_up=new Image(35,22)
Nextbtn_up.src=ProfileLocation + "NextOn.gif";

Nextbtn_down=new Image(35,22)
Nextbtn_down.src=ProfileLocation + "PlayOff.gif";

Prevbtn_over= new Image(35,22)
Prevbtn_over.src=ProfileLocation + "PrevOver.gif";

Prevbtn_up=new Image(35,22)
Prevbtn_up.src=ProfileLocation + "PrevOn.gif";

Prevbtn_down=new Image(35,22)
Prevbtn_down.src=ProfileLocation + "PrevOff.gif";

Stopbtn_over= new Image(35,22)
Stopbtn_over.src=ProfileLocation + "StopOver.gif"

Stopbtn_up= new Image(35,22)
Stopbtn_up.src=ProfileLocation + "StopOn.gif";

PayNowbtn_up= new Image(75,22)
PayNowbtn_up.src=ProfileLocation + "PlayOn.gif";
}
}

var ThisPicture = 0;
var Play = true;
var NextImage = 1;
var PrevImage = -1;
var nopic = 0;
var Timer = 8500;
var changetime = new Date().getTime()+Timer;
var fadeDuration = 1.5;
var nextSlide = new Image(430,353)
var loaded = false;
browser_version=parseInt(navigator.appVersion);
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie4up  = (is_ie && (is_major >= 4));
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

//preload the first image to be used after start 
function blendSlide(dir){
 //Set img tag
 if(document.getElementById('Slide') == null)
 {
					p = '<img id="Slide" name="Slide" height="'+ViewHeight+'" width="'+ViewWidth+'" src="'+ImageList[ThisPicture][1]+'&w='+ViewWidth+'&h='+ViewHeight+'&bg=%23'+ViewBackgroundColor+'">';
					
					if(document.getElementById('ViewContent') != null)
						ChangeText('ViewContent', p);
					else
						ChangeText('ViewBody', '<div id="ViewContent">'+p+'</div>');
}
else
{
	if (document.all&&is_ie5_5up) 
	{
		slide = document.getElementById('Slide').filters["DXImageTransform.Microsoft.Fade"];
		slide.duration=fadeDuration;
		slide.percent=70;
		slide.overlap=0.8;
		slide.apply();

		slideimg = document.getElementById('Slide');
    if (dir == 1) 
    {
      slideimg.src = nextSlide.src + '&w='+ViewWidth+'&h='+ViewHeight+'&bg=%23'+ViewBackgroundColor;
    }
    else
    {
      slideimg.src = ImageList[ThisPicture][1] + '&w='+ViewWidth+'&h='+ViewHeight+'&bg=%23'+ViewBackgroundColor;
    }
		slide.play(); 
 	}
 	else
 	{
		slide = document.getElementById('Slide');
    if (dir == 1) 
    {
      slide.src = nextSlide.src + '&w='+ViewWidth+'&h='+ViewHeight+'&bg=%23'+ViewBackgroundColor;
    }
    else
    {
      slide.src = ImageList[ThisPicture][1] + '&w='+ViewWidth+'&h='+ViewHeight+'&bg=%23'+ViewBackgroundColor;
    }
 	}
}
}
function check_load(){
  var finished = false;
  var finished2 = false;
  try 
  {
		finished = nextSlide.complete;
		finished2 = document.images['Slide'].complete;
  }
  catch(e) {}
  
  if(finished && finished2)
  {
    return true
  }
  else
  {
    return false
  }
}

function load_next(ni){
 nextSlide = null;
 nextSlide = new Image(ViewWidth,ViewHeight);
 nextSlide.src = ImageList[ni][1]+'&w='+ViewWidth+'&h='+ViewHeight+'&bg=%23'+ViewBackgroundColor;
}

function slideshowupdate(direction,override){
	var now = new Date().getTime();
	var len = ImageList.length;
	if(now > changetime)
	{
		if(Play&&!override)
		{
			if(check_load())
			{
				//Change Image number
				ThisPicture=ThisPicture+direction;
				if (ThisPicture >= ImageList.length||ThisPicture < 0) { ThisPicture=0; }
				ChangeText('ilaSlide', (ThisPicture+1)); 

				changetime = new Date().getTime()+Timer;
		  	
  			//display image# for manual show
  			//document.getElementById('Slide').src = ImageList[ThisPicture][1] + '&w='+ViewWidth+'&h='+ViewHeight+'&bg='+ViewBackgroundColor; 
		  	
  			//Caption
  				document.getElementById('Options').style.visibility = "hidden";

  			ChangeText('AgentInfoContent', GetContactInfo()); 
  			PlaceAgentInfo();
  			//ChangeText('DescriptionContent', '<b>'+ImageList[ThisPicture][2]+'</b>'); 
  			//Description (if available)
  			//if(ImageList[ThisPicture][3] != '')
  			//	ChangeText('DescriptionContent', ' - ' + ImageList[ThisPicture][3], true); //display 

//alert(document.getElementById('ViewContent').firstChild.nodeValue);
				if((document.getElementById('ViewContent').innerHTML == ''))
{					ChangeText('ViewContent', '<img id="Slide" name="Slide" height="'+ViewHeight+'" width="'+ViewWidth+'" src="'+ImageList[ThisPicture][1]+'&w='+ViewWidth+'&h='+ViewHeight+'&bg=%23'+ViewBackgroundColor+'">');

}else{		blendSlide(direction)
 	}

				if (ThisPicture+1 <= ImageList.length-1)
				{
				load_next(ThisPicture+1)
				}
				else
				{
				load_next(0);
				}
			}
	  }
	}

	if(override && (ThisPicture+direction) >= 0 && (ThisPicture+direction) < ImageList.length)
	{
 		ThisPicture=ThisPicture+direction;
 		ChangeText('ilaSlide', ThisPicture+1);  //display image# for automatic show
//		document.getElementById('Slide').src = ImageList[ThisPicture][1] + '&w='+ViewWidth+'&h='+ViewHeight+'&bg='+ViewBackgroundColor; //display image# for manual show
	document.getElementById('Options').style.visibility = "hidden";

 		ChangeText('AgentInfoContent', GetContactInfo()); 
 		PlaceAgentInfo();
 		//ChangeText('DescriptionContent', '<b>'+ImageList[ThisPicture][2]+'<b>'); //display image# for manual show
 		//if(ImageList[ThisPicture][3] != '')
  		//ChangeText('DescriptionContent', ' - ' + ImageList[ThisPicture][3], true);

				if((document.getElementById('Slide') != null))
{
					p = '<img id="Slide" name="Slide" height="'+ViewHeight+'" width="'+ViewWidth+'" src="'+ImageList[ThisPicture][1]+'&w='+ViewWidth+'&h='+ViewHeight+'&bg=%23'+ViewBackgroundColor+'">';
					
					if(document.getElementById('ViewContent') != null)
						ChangeText('ViewContent', p);
					else
						ChangeText('ViewBody', '<div id="ViewContent">'+p+'</div>');
}
else
{
		blendSlide(direction)
 	}
 		if (ThisPicture+1 <= ImageList.length-1)
 		{
 			load_next(ThisPicture+1)
 		}
 		else
 		{
 			load_next(0);
		}
	}
	
	if(Play)
	setTimeout("slideshowupdate(1,false,0);",1000);
}

function load_next(ni){  //preload next image
 nextSlide = null;
 nextSlide = new Image(ViewWidth,ViewHeight)
 nextSlide.src = ImageList[ni][1];
}
function bPlay()
{
Play=!Play;

if(document.getElementById("Slide") == null)
{
	p = '<img id="Slide" name="Slide" height="'+ViewHeight+'" width="'+ViewWidth+'" src="'+ImageList[ThisPicture][1]+'&w='+ViewWidth+'&h='+ViewHeight+'&bg=%23'+ViewBackgroundColor+'">';
					
	if(document.getElementById('ViewContent') != null)
		ChangeText('ViewContent', p);
	else
		ChangeText('ViewBody', '<div id="ViewContent">'+p+'</div>');
}

if(Play)
{
	changetime = new Date().getTime()+Timer;
	if(IDX)
		ChangeText('NavigationIDXContent', auto);
	else
		ChangeText('NavigationContent', auto);

 	//ChangeText('NavigationContent', auto); //display autobuttons
 	if(AgentInfo != null) 
 	{
 		document.getElementById('Options').style.visibility = "hidden";

 	  ChangeText('AgentInfoContent', GetContactInfo());
 	  PlaceAgentInfo();
 	  //ChangeText('DescriptionContent', '<b>'+ImageList[ThisPicture][2]+'<b>');
  }
	slideshowupdate(NextImage,false);
}
else
{
	if(IDX)
		ChangeText('NavigationIDXContent', manual);
	else
		ChangeText('NavigationContent', manual);

  //ChangeText('NavigationContent', manual); //display manual buttons
}

ChangeText('ilaSlide', ThisPicture+1);  //display image# for automatic show
//ChangeText('NavigationContent', manual); //display manual buttons
if(IDX)
	document.getElementById('NavigationIDXContent').align = 'center'; //display manual buttons
else
	document.getElementById('NavigationContent').align = 'center'; //display manual buttons
}

function bPrev(){
 if (ThisPicture <= 0){
  ThisPicture=ImageList.length;
		 load_next(ThisPicture-1);
 } else { 
		 load_next(ThisPicture-1) }
 slideshowupdate(PrevImage,true);
}
function bNext(){
 if (ThisPicture >= ImageList.length-1){
  ThisPicture=-1;
 }
 if (ThisPicture+1 <= ImageList.length-1){
  load_next(ThisPicture+1)}
 else{
 	load_next(0);
 }
 slideshowupdate(NextImage,true);
}
var newViewer2 = null;
function show_paynow(page){
if (newViewer2 && !newViewer2.closed)
	newViewer2.close();
newViewer2=window.open(page,'PayNow','width=640,height=480,toolbar=no,scrollbars=no,resizable=yes,status=no,copyhistory=0');
}
var newViewer = null;
function show_info(page){
if (newViewer && !newViewer.closed)
	newViewer.close();
newViewer=window.open(page,'AgentInfo','width=400,height=350,toolbar=no,scrollbars=yes,resizable=yes,status=no,copyhistory=0');
}

function PlaceAgentInfo()
{
 		ChangeText('DescriptionContent', '<p align=\"center\"><b>'+ImageList[ThisPicture][2]+'<b></p>'); //display image# for manual show
 		if(ImageList[ThisPicture][3] != '')
 			ChangeText('DescriptionContent', '<p>' + ImageList[ThisPicture][3] +'</p>', true);
 		else
 		{
// 			document.getElementById('DescriptionContent').align = 'center';
 		}
		//document.getElementById('DescriptionContent').verticalAlign = 'bottom';
}	
