/**
**/
var CCGallery = new Object();
CCGallery = {
    thumbContainer:Object,
    thumbHref:Object,
    opacitycount:0,
    cctimeout:null,
    next:Object,
    previous:Object,
    oXmlHttp:Object,
    pic:Object,
    gNav:Object,
    path:'',
    init:function(){
        if(!document.property_id) document.property_id = arguments[0];
        this.path = 'images_property/';
        this.loading = document.getElementById('CCGalleryLoading');
        this.thumbContainer =  document.getElementById('CCThumbNav');
        this.pic = document.getElementById('CCMainPic');
        this.next = document.getElementById('CCGalleryNext');
        this.previous = document.getElementById('CCGalleryPrevious');
        this.thumbHref = this.thumbContainer.getElementsByTagName('A');
        for(var i=0;i<this.thumbHref.length;i++){
            this.thumbHref[i].onmouseover = function(){CCGallery.showThumb(this)};
            this.thumbHref[i].onmouseout = function(){CCGallery.hideThumb(this)};
            this.thumbHref[i].onclick = function(){CCGallery.showImage(this)};
        }
        if(this.next && i<10) this.next.style.display = 'none';
        if(this.next) this.next.onclick = function(){CCGallery.nextImages(this)};
        if(this.previous) this.previous.onclick = function(){CCGallery.previousImages(this)};
        if(document.getElementById('CCGalleryNav') && this.thumbHref[0].firstChild.nodeValue==01)
            document.getElementById('CCGalleryNav').getElementsByTagName('A')[0].style.display = 'none';
        this.showImage();
    },
    showThumb:function(obj){
        if(!/^\d{2,10}$/.test(obj.firstChild.nodeValue)) return;
        var im = obj.firstChild.nextSibling;
        if(typeof im.filters!='undefined') im.style.display = 'block';
        im.style.left = obj.offsetLeft-(im.width/2)+(obj.offsetWidth/2)-2+'px';
        im.style.top = -im.height-4+'px';
        im.style.display = 'block';    
        if(typeof im.filters!='undefined'){ 
        im.filters.alpha.opacity = 0;
        } else if(typeof im.style.opacity!='undefined'){ 
        im.style.opacity = .0;
        }
        this.fadeIn(im);
    },
    fadeIn:function(im){
        if(typeof im.style.opacity=='undefined' && typeof im.filters=='undefined') return;
        if(typeof im.style.opacity=='undefined'?im.filters.alpha.opacity<100:im.style.opacity<1){
        var opv = typeof im.style.opacity=='undefined'?this.opacitycount*1.5:(this.opacitycount/80);
        typeof im.style.opacity=='undefined'?
        im.filters.alpha.opacity=opv:
        im.style.opacity= opv;
        fn = function() { CCGallery.fadeIn(im); }            
        this.cctimeout = setTimeout(fn,10);
        this.opacitycount++;
        } else {
        clearTimeout(this.cctimeout);
        }
    },
    hideThumb:function(obj){
        obj.firstChild.nextSibling.style.display = 'none';
        this.opacitycount=0;
        clearTimeout(this.cctimeout);
    },
    showImage:function(obj){
        if(document.getElementById("CCGalleryCaption"))
        document.getElementById('CCGallery').removeChild(document.getElementById("CCGalleryCaption"));
        document.getElementById('CCGalleryLoading').style.display='block';
        if(document.getElementById('CCMainPic'))
            document.getElementById('CCGallery').removeChild(document.getElementById('CCMainPic'));
        if(typeof obj=='undefined'){
            if(this.thumbContainer.getElementsByTagName('A')[0]){
                obj = this.thumbContainer.getElementsByTagName('A')[0];
            } else {
            return;
            }
        }
        var img = document.createElement('IMG');
        img.src = 'images_property/'+obj.name;
        if(window.opera) img.src+="?"+Math.random();
        img.setAttribute('id','CCMainPic');
        img.onload = function(){document.getElementById('CCGalleryLoading').style.display='none';};
        document.getElementById('CCGallery').appendChild(img);
        if(document.all && !window.opera) ccinterval = setTimeout(function(){CCGallery.iefix()},100);
        this.caption(obj);
    },
    iefix:function(){
        clearTimeout(ccinterval);
        var sr = document.getElementById('CCMainPic').src;
        document.getElementById('CCMainPic').src = sr;
    },
    nextImages:function(){
        this.next.onclick = null;
        var oXmlHttp = this.createXMLHttp();
        var s,bits='';
        oXmlHttp.open("post",'ccgallery/getimages.php',true);
          oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        oXmlHttp.onreadystatechange = function(){
          if(oXmlHttp.readyState==4) {
          s =oXmlHttp.responseText;
          s = s.split("|");
          if(s.length==1) return;
          var num = s.length-1;
          for(var i=0;i<=s.length;i++){
          if(!s[i]) break;
          var imageinfo = s[i].split("*");
          var oCCNav = document.getElementById('CCThumbNav');
          if(!oCCNav.getElementsByTagName('IMG')[i]){ break;}
          oCCNav.getElementsByTagName('A')[i].name = imageinfo[0];
          oCCNav.getElementsByTagName('IMG')[i].src = 'images_property/thumbs/'+imageinfo[0];
          oCCNav.getElementsByTagName('IMG')[i].setAttribute('title',imageinfo[1]);
          oCCNav.getElementsByTagName('IMG')[i].width = imageinfo[2];
          oCCNav.getElementsByTagName('IMG')[i].height = imageinfo[3];
          oCCNav.getElementsByTagName('A')[(i)].firstChild.nodeValue= parseInt(oCCNav.getElementsByTagName('A')[(i)].firstChild.nodeValue.replace(/^[0]{1}/,''))+10;
          }
          
          if(i<10){
          while(i<10){
          oCCNav.getElementsByTagName('A')[(i)].firstChild.nodeValue='';
          oCCNav.getElementsByTagName('A')[(i)].className = 'null';
          i++;
          document.getElementById('CCGalleryNav').getElementsByTagName('A')[1].style.display = 'none';
          }
          }
          document.getElementById('CCGalleryNav').getElementsByTagName('A')[0].style.display = 'block';
          CCGallery.init();
          CCGallery.showImage();
       }
       }
    oXmlHttp.send("property_id="+document.property_id+"&offset="+ parseInt(this.thumbContainer.getElementsByTagName('A')[0].firstChild.nodeValue.replace(/^[0]{1}/,'')));

    },
    previousImages:function(){
        this.previous.onclick = null;
        var oXmlHttp = this.createXMLHttp();
        var s,bits='';
        oXmlHttp.open("post",'ccgallery/getimages.php',true);
          oXmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        oXmlHttp.onreadystatechange = function(){
          if(oXmlHttp.readyState==4) {
          s =oXmlHttp.responseText;
          s = s.split("|");
          if(s.length!=11) return;
          var num = s.length-1;
          var oCCNav = document.getElementById('CCThumbNav');
          var n = parseInt(oCCNav.getElementsByTagName('A')[0].firstChild.nodeValue.replace(/^[0]{1}/,''));
          for(var i=0;i<=s.length;i++){
          if(!s[i]) break;
          var imageinfo = s[i].split("*");
          if(!oCCNav.getElementsByTagName('IMG')[i]){ break;}
          oCCNav.getElementsByTagName('A')[i].name = imageinfo[0];
          oCCNav.getElementsByTagName('IMG')[i].src = 'images_property/'+imageinfo[0];
          oCCNav.getElementsByTagName('IMG')[i].setAttribute('title',imageinfo[1]);
          oCCNav.getElementsByTagName('IMG')[i].width = imageinfo[2];
          oCCNav.getElementsByTagName('IMG')[i].height = imageinfo[3];
          var l = parseInt(n-10+i);l=l+"";
          if(l==1) document.getElementById('CCGalleryNav').getElementsByTagName('A')[0].style.display = 'none';
          oCCNav.getElementsByTagName('A')[(i)].firstChild.nodeValue= l.replace(/^\d{1}$/g,"0"+l);
          }
          document.getElementById('CCGalleryNav').getElementsByTagName('A')[1].style.display = 'block';
          
          CCGallery.init();
          CCGallery.showImage();
       }
       }
    oXmlHttp.send("property_id="+document.property_id+"&offset="+(parseInt(this.thumbContainer.getElementsByTagName('A')[0].firstChild.nodeValue.replace(/^[0]{1}/,''))-11));

    },
    caption:function(){
        var obj = arguments[0];
        if(obj.firstChild.nextSibling.getAttribute('TITLE')!=""){
        var el = document.createElement('DIV');
        el.setAttribute("id","CCGalleryCaption");
        el.innerHTML = obj.firstChild.nextSibling.getAttribute('TITLE');
        document.getElementById('CCGallery').appendChild(el);
        }
        
    },
    createXMLHttp:function(){
        if(typeof XMLHttpRequest != "undefined"){
            return new XMLHttpRequest();
        } else {
        var aVersions = ["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];
        for(var i=0;i<aVersions.length;i++){
        try {
            var oXmlHttp = new ActiveXObject(aVersions[i]);
            return oXmlHttp;
        } catch(oError){
        
        }
        }
        }
    }
}

