// Developed by Linas Bari
var doCalc,calcFields,errMsg;
function setCalcLang(_errMsg,f1,f2,f3) {
errMsg = _errMsg;calcFields = new Array(f1,f2,f3);}
function showEl(eID){document.getElementById(eID).style.display = "block";}
function hideEl(eID){document.getElementById(eID).style.display = "none";}
function notNumeric(sText){
	var ValidChars = "0123456789", IsNumber=true, Char, numDots = 0;
	for (i = 0; i < sText.length && IsNumber == true; i++) { 
		Char = sText.charAt(i); 
		if (Char == ".") {
			numDots += 1;
			if (numDots>1) IsNumber = false
		}
		else if (ValidChars.indexOf(Char) == -1) IsNumber = false;
	}
	  
	if(IsNumber) IsNumber = parseFloat(sText);
	return !IsNumber;
}
function cgetValue(eID,arrAt,_andShow){
	if (doCalc) {
		var theValue = document.getElementById(eID).value;
		if(notNumeric(theValue)) {
			if (_andShow) alert(errMsg.replace("^^",calcFields[arrAt]));
			doCalc=false;
			setValue("payment","")
		}
		else {
			return theValue;
		}
	}
}
function setValue(eID,v){if(notNumeric(v))v='';document.getElementById(eID).value=v;}
function getValue(eID){return document.getElementById(eID).value;}
function mcalc(andShow){
	var m_interest, m_minterest, m_months, m_years, m_capital;
	doCalc = true;
	m_interest = cgetValue("interest",0,andShow);
	m_years = cgetValue("years",1,andShow);
	m_capital = cgetValue("capital",2,andShow);
	if (doCalc) {
		m_months = m_years * 12;
		m_minterest = m_interest / 1200;
		m_mpay = m_capital * m_minterest / ( 1 - 1/Math.pow(1+m_minterest,m_months));
		setValue("payment",parseInt(m_mpay*100)/100);
		if (andShow) {
			showEl("calcres");
			document.getElementById("payment").focus();
		}
	}
}

function gotoContact(){document.location.href='../../contact.htm#content';}
function gotoShortlist(){document.location.href='../../shortlist';}

////////

var slidePos = 0;
var slideTimer = 0;
function slide(direction)
{
	slideTimer = setInterval('_slide('+direction+')',50);
}

function stopSlide()
{
	clearTimeout(slideTimer);
}

function _slide(direction)
{
	var l = document.getElementById('innerSlide');
	
	if (direction)
	{
		var thumbWidth = 65;
		var sliderWidth = 500;
		
		if ((slideCount*thumbWidth)-sliderWidth> -slidePos )slidePos-=10;		
	}else{
		if(slidePos<0)	slidePos+=10;
	}
	
	
	l.style.left=slidePos+'px';

}
var photoOpacityIn = 0;
var fadeTimer = 0;

function initFade()
{

}

function fadePhoto()
{
		photoOpacityIn=photoOpacityIn+5;	
		photo_in = document.getElementById('propertyDetails__photoSlide__photo');

		if (document.all)
		{
			photo_in.style.filter="alpha(opacity="+photoOpacityIn+")";

		}else{
			photo_in.style.opacity=photoOpacityIn/100;	
		}

		if (photoOpacityIn>=100)
		{
			clearInterval(fadeTimer);
			fadeTimer = 0;
			photoOpacityIn = 0;
		}
		
}
/*
function ShowPhotoLarge(num,photo)
{
	clearInterval(fadeTimer);
	photoOpacityIn = 0;	
	setTimeout('_ShowPhotoLarge('+num+')',1000);
}
*/

var ptimer;

function ShowPhotoLarge(num,photo)
{
	_photoIndex = num;
	clearInterval(fadeTimer);
	photoOpacityIn = 0;	
	
	if (_photos[_photoIndex] != null)
	{
		u=new String(_thumbnailUrl);
		u=u.replace(/\{0\}/g,_photos[_photoIndex].name);
		u=u.replace(/\{1\}/g,'592');
		//document.getElementById('propertyDetails__photoSlide__photoIndex').innerHTML = _photoIndex + 1;
		document.getElementById('propertyDetails__photoSlide__photo').title = _photos[_photoIndex].caption;
		document.getElementById('propertyDetails__photoSlide__photo').alt = _photos[_photoIndex].caption;

		document.getElementById('propertyDetails__photoSlide__photo').src =u;

		if (document.all)
		{
			document.getElementById('propertyDetails__photoSlide__photo').style.filter="alpha(opacity=0)";
		}else{
			document.getElementById('propertyDetails__photoSlide__photo').style.opacity=0;
		}
		
		//document.getElementById('photoCaption').innerHTML = _photos[_photoIndex].caption;
	}
	clearTimeout(ptimer);
	ptimer = setTimeout("makeFade()",1000);
}

function makeFade()
{
	if (!fadeTimer)
	{
		fadeTimer = setInterval('fadePhoto()',20);
	}	
}

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];}}
}
