var img = new Array;

img[0] = '001.jpg';
img[1] = '002.jpg';
img[2] = '003.jpg';
img[3] = '004.jpg';
img[4] = '005.jpg';
img[5] = '006.jpg';

var txt = new Array;
txt[0] = '<span style="display:inline-block;padding-right:70px;font-size:smaller">Compressive Proactive</span><br />Marketing';
txt[1] = '<span style="display:inline-block">Virtual Tours<br />Floor Plans</span>';
txt[2] = '<span style="display:inline-block;padding-right:70px;padding-top:00px">Accompanied</span>Viewings';
txt[3] = 'Because<br /><span style="display:inline-block;padding-right:50px">You\'re Important</span>';
txt[4] = '<span style="display:inline-block;padding-right:150px">Weekly News</span><br /><span style="display:inline-block;padding-right:100px">Paper Advertising</span>';
txt[5] = '<span style="display:inline-block;padding-right:70px">Buying, Renting,<br />Selling or Letting</span>';
txt[6] = '<span style="display:inline-block;padding-right:70px;padding-top:00px">Free Rental</span> Guarantee';
txt[7] = 'Free<br /><span style="display:inline-block;padding-right:50px">Legal Cover</span>';
txt[8] = '<span style="display:inline-block;padding-right:150px">RICS Surveys</span><br /><span style="display:inline-block;padding-right:100px">Arranged</span>';
txt[9] = '<span style="display:inline-block;padding-right:70px">Letting &amp;<br />Full Management</span>';

var intImage = 2;
var img1;
var img2;
var image;
var altImage;
var intPreLoad;

var intText = 2;
var txt1;
var txt2;
var text;
var altText;


function callPreLoad(oImg) {
    clearInterval(intPreLoad);
    var x = 0;
    for (x == 0; x < img.length; x++) {
        preLoad(img[x]);
    }
}

function preLoad(oImg) {
    pic1 = new Image(64,64);
    pic1.src = "slides/" + oImg;
}

function window_onload() {
    txt1 = document.getElementById('divText1');
    txt2 = document.getElementById('divText2');
    txt1.innerHTML = txt[0];
    txt2.innerHTML = txt[1];
    text = txt2;
    altText = txt1;
    initText();

    img1 = document.getElementById('divGallery');
    img2 = document.getElementById('divGallery2');
    img1.style.backgroundImage = 'url(slides/' + img[0] + ')';
    img2.style.backgroundImage = 'url(slides/' + img[1] + ')';
    image = img2;
    altImage = img1;
    initImage();

    intPreLoad = setInterval('callPreLoad()', 2000);
}

function initImage() {
    setOpacity(0);
    image.style.visibility = 'visible';
    altImage.style.visibility = 'visible';
    fadeIn(0);
}

function initText() {
    setTextOpacity(0);
    text.style.visibility = 'visible';
    altText.style.visibility = 'visible';
    fadeTextIn(0);
}

function setOpacity(opacity) {
    opacity = (opacity == 100) ? 99.999 : opacity;

    image.style.filter = "alpha(opacity:" + opacity + ")";
    image.style.KHTMLOpacity = opacity / 100;
    image.style.MozOpacity = opacity / 100;
    image.style.opacity = opacity / 100;
}

function setTextOpacity(opacity) {
    opacity = (opacity == 100) ? 99.999 : opacity;

    text.style.filter = "alpha(opacity:" + opacity + ")";
    text.style.KHTMLOpacity = opacity / 100;
    text.style.MozOpacity = opacity / 100;
    text.style.opacity = opacity / 100;

    altText.style.filter = "alpha(opacity:" + (100-opacity) + ")";
    altText.style.KHTMLOpacity = 1-(opacity / 100);
    altText.style.MozOpacity = 1-(opacity / 100);
    altText.style.opacity = 1-(opacity / 100);
}

function fadeIn(opacity) {
    if (opacity <= 100) {
        setOpacity(opacity);
        opacity += 2;
        window.setTimeout("fadeIn(" + opacity + ")", 100);
    } else {
        if (image.id == 'divGallery') {
            image = img2;
            altImage = img1;
            setOpacity(0);
            image.style.backgroundImage = 'url(slides/' + img[intImage] + ')';
            intImage += 1;
            if (intImage == img.length) {
                intImage=0
                }
            img1.style.zIndex = 1;
            img2.style.zIndex = 2;
            window.setTimeout("fadeIn(0)", 5000);
        } else {
            image = img1;
            altImage = img2;
            setOpacity(0);
            image.style.backgroundImage = 'url(slides/' + img[intImage] + ')';
            intImage += 1;
            if (intImage == img.length) {
                intImage = 0
            }
            img1.style.zIndex = 2;
            img2.style.zIndex = 1;
            window.setTimeout("fadeIn(0)", 5000);
        }
    }
}

function fadeTextIn(opacity) {
    if (opacity <= 100) {
        setTextOpacity(opacity);
        opacity += 3;
        window.setTimeout("fadeTextIn(" + opacity + ")", 100);
    } else {
        if (text.id == 'divText1') {
            text = txt2;
            altText = txt1;
            setTextOpacity(0);
            text.innerHTML = txt[intText];
            intText += 1;
            if (intText == txt.length) {
                intText=0
                }
            window.setTimeout("fadeTextIn(0)", 5100);
        } else {
            text = txt1;
            altText = txt2;
            setTextOpacity(0);
            text.innerHTML = txt[intText];
            intText += 1;
            if (intText == txt.length) {
                intText = 0
            }
            window.setTimeout("fadeTextIn(0)", 5100);
        }
    }
}

//gallery

            var dScroll;
            var count=0;
            var maxcount=0;
            var intC=-1;
            var step;
            function scrollPics(dX){
                clearInterval(intC);
                count=0;
                maxcount=dX/2;
                if (maxcount<0){maxcount=maxcount*-1}
                if (dX<0){
                    step=-4;
                }else{
                    step=4;
                }
                intC=setInterval('scroller()', 40);
            }

            function scroller(){
                if(!dScroll){dScroll=document.getElementById('divScroller')}
                var x=dScroll.scrollLeft + step;
                if (x<0){
                    x=0;
                    clearInterval(intC);
                }
                if (x>=(dScroll.scrollWidth-dScroll.offsetWidth+17)){
                    dScroll.scrollLeft=dScroll.scrollWidth;
                    clearInterval(intC);
                }else{
                    dScroll.scrollLeft=x;
                }
                count += 1;
                if (count >= maxcount){clearInterval(intC);}
            }

            function showImage(oSrc){
                document.getElementById('imgImage').setAttribute('src', oSrc.getAttribute('src').replace('thumbs/', ''));
                document.getElementById('pImage').style.display='block';
                //window.scroll(0, document.getElementById('divScrollerHolder').offsetTop);
            }
