var slideshow;
function slideSize()
{
	var el = this.els[this.i];
	var maxWidth=screen.width-200;
	var maxHeight=screen.height-300;
	var img=el.getElementByClass('slide');
	var w=parseInt(img.getAttribute('pwidth'));
	var h=parseInt(img.getAttribute('pheight'));
	maxWidth=parseInt(maxWidth);
	maxHeight=parseInt(maxHeight);
	if((w>h)&&(w>maxWidth))
	{
		h=((maxWidth*h)/(w));
		w=maxWidth;
		w=parseInt(w);
		h=parseInt(h);
	}
	if(h>maxHeight)
	{
		w=((maxHeight*w)/(h));
		h=maxHeight;
		w=parseInt(w);
		h=parseInt(h);
	}
	if(document.getElementById('slide'))
	{
		var slide=document.getElementById('slide');
		w=parseInt(w);
		h=parseInt(h);
		slide.width=w;
		slide.height=h;
	}
	var winWidth=w+20;
	var winHeight=h+100;
	//move - resize
	var x=(screen.width/2)-(winWidth/2);
	var y=(screen.height/2)-(winHeight/2);
	w+=20;
	if(parseInt(this.el.parentNode.style.width<(w+20)))
	{
		//this.el.parentNode.style.width=w+'px';
	}
	//window.moveTo(x, y);
	//window.resizeTo(winWidth,winHeight);
}
function nextSlide()
{
	 this.i++;
	 if(this.i>=this.els.length)
	 {
	 	this.i=0;
	 }
	 this.loadSlide();
}
function lastSlide()
{
	 this.i--;
	 if(this.i<0)
	 {
	 	this.i=this.els.length-1;
	 }
	 this.loadSlide();
}
function loadSlide( i )
{
	if(i>-1)
	{
		this.i=i-1;
	}
	
	var img=this.el.getElementByClass('slide');
	var cap_el=document.getElementById('caption');
	
	img.src=this.slides[this.i].img.src;
	
	this.img=img;
	
	cap_el.innerHTML='<div style="float:left;margin-right:10px;">('+(this.i+1)+' of '+this.slides.length+')</div> '+this.slides[this.i].caption;
	this.slideSize();
	
	
}
function loadImg( i )
{
	var thumb = this.els[i];
	var thumb_img = thumb.getElementByClass('slide');
	var caption=thumb.getAttribute('title');
	var file=thumb_img.getAttribute('file');
	
	var img=this.el.getElementByClass('slide');
	
	var url=this.base_url+'dbimages/'+file;
	
	if(this.base_url.search(/property_images/)!=-1)
	{
		url=this.base_url+file;
	}
	
	var slide = new Slide(url,caption);
	return slide;
}
function slideShow(el,base_url)
{
	this.name='Slide Show';
	this.el=el;
	this.base_url=base_url;
	this.els=document.getElementsByClass("hslide");
	this.loadSlide = loadSlide;
	this.lastSlide = lastSlide;
	this.nextSlide = nextSlide;
	this.slideSize = slideSize;
	this.loadImg = loadImg;
	this.loading = loading;
	this.i=0;
	
	if(this.els.length==0)
	{
		document.getElementById('load').innerHTML='No Slides Found';
		return;
	}
	//alert(window.innerHeight);
	document.getElementByClass('spec_gal_bg').style.height=winHeight()+'px';
	
	this.slides = new Array();
	
	document.getElementById('load').style.visibility='visible';
	document.getElementById('load').innerHTML='Loading Slide Show<div id="bounc_cont" align="left"><div id="bouncing">&nbsp;</div></div>';
	
	for(var c=0; c<this.els.length; c++)
	{
		this.slides[c]=this.loadImg(c);
	}
	
	this.loadSlide(-1);
	this.loading();
}
function winHeight() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}

var interval=4000;
var toID=0;
var ltoID=0;

function loadAndShow(base_url,num)
{
	loadSlideShow(base_url);
	slideshow.loadSlide(num);
}
function loadSlideShow(base_url)
{
	document.getElementByClass('hspec_gal_bg').className='spec_gal_bg';
	document.getElementByClass('hspec_gal_cont').className='spec_gal_cont';
	if(slideshow==null)
	{
		slideshow=new slideShow(document.getElementById('Slide'),base_url);
	}
}
function hideSlideShow()
{
	document.getElementByClass('spec_gal_bg').className='hspec_gal_bg';
	document.getElementByClass('spec_gal_cont').className='hspec_gal_cont';
}
function play()
{
	document.getElementById('playBtn').className='active_button';
	slideshow.nextSlide();
	toID=window.setTimeout(play,interval);
}
function pause()
{
	document.getElementById('playBtn').className='button';
	clearTimeout(toID);
	toID=0;
}

function loading()
{
	if(slideshow==null)
	{
		slideshow=this;
	}
	if(slideshow.slides[slideshow.slides.length-1].img.complete==true)
	{
		document.getElementById('load').style.visibility='hidden';
		return;
	}
	else if(slideshow.slides[slideshow.i].img.complete==true)
	{
		slideshow.i++;
	}
	var bouncer = document.getElementById('bouncing');
	bouncer.style.width=((slideshow.i/slideshow.slides.length)*100)+'px';
	ltoID=window.setTimeout(this.loading,10);
}

// Slide
function Slide(url,caption)
{
	this.img = new Image;
	this.img.src = url;
	this.caption=caption;
}
