/* PROPERTY PRICE POPUP BINDING CODE */
function list_BindPricePopupToLink(id)
{
    el1 = document.getElementById('pricelink_'+id);
    if (!el1) return;
    
    el2 = document.getElementById('pricextra_'+id);
    if (!el2) return;
        
    el1.onmouseover  = function(e) { document.getElementById('pricextra_'+id).style.display = 'block'; };
    el2.onmouseout   = function(e) { this.style.display = 'none'; };
}            

function details_BindPricePopupToLink(id)
{
    el = document.getElementById('pricelink_'+id);
    if (!el) return;
        
    el.onmouseover  = function(e) { 
        //document.getElementById('pricehide_'+id).style.display = 'none'; 
        //document.getElementById('pricextra_'+id).style.display = 'block'; 
        
        document.getElementById('pricextra_'+id).style.display = 'block'; 
        document.getElementById('pricehide_'+id).style.visibility = 'hidden'; 
        
        
    };    
    el.onmouseout   = function(e) { 
        //document.getElementById('pricextra_'+id).style.display = 'none'; 
        //document.getElementById('pricehide_'+id).style.display = 'block'; 
        
        document.getElementById('pricextra_'+id).style.display = 'none'; 
        document.getElementById('pricehide_'+id).style.visibility = 'visible'; 
    };
}      

/* PROPERTY CONTENT LANGUAGE SWITCHER */
function ContentLangSwitcher()
{                         
    this.isInitialized = false;
    
    this.idSets = new Array();    
    this.elSets = new Object();
}                             

ContentLangSwitcher.prototype.add     = function( arg )
{
    return this.idSets.push( arg );
}

ContentLangSwitcher.prototype.init    = function()
{                             
    if (this.isInitialized) { return; }
          
    var self = this;
    var cnt  = this.idSets.length;                             
    
    for (var i = 0; i < cnt; i++) {                               
        var buttonEL    = document.getElementById( this.idSets[i].buttonELID );        
        (function() {
            var lc           = self.idSets[i].langcode;
            buttonEL.onclick = function() { self.setLang( lc ); }
        })()
        var contentEL   = document.getElementById( this.idSets[i].contentELID );
        this.elSets[ self.idSets[i].langcode ] = { btnEl: buttonEL, cntEl: contentEL };
                
    }
}
                 
ContentLangSwitcher.prototype.setLang = function( lc )
{                                                  
     //alert(this.elSets[lc].cntEl+':'+this.elSets[lc]+':'+lc);
    
     if (this.elSets && this.elSets[lc]) {
        for (i in this.elSets) {
            if (i == lc) { continue; }
            removeCSSClass( this.elSets[i].btnEl, 'SelectedLanguage');
            this.elSets[i].cntEl.style.display = 'none';
        }
        addCSSClass( this.elSets[lc].btnEl, 'SelectedLanguage');
        this.elSets[lc].cntEl.style.display = 'inline';     
     }
}        

/* PROPERTY IMAGE SLIDESHOW FUNCTIONALITY */
/*
 * a slide show object 
 */
function SlideShow(ssID, stID, scID, sooID, sspID, sskID, stbID, playImgURL, pauseImgURL)
{                              
    this.isInitialized  = false;
    this.allLoaded      = false;    

    this.initialStart   = true;
    this.curSlide       = 0; // array key.
    this.lastMoveDir    = 1; // slideshow direction                        
                        
    this.playImgURL     = playImgURL;
    this.pauseImgURL    = pauseImgURL;
    
    this.toHandle       = null;

    this.globName       = 'Slide_'+ssID+'_Show';
    
    this.imgList        = new Array();                     
    this.plc            = new Array(); // Pre Load Cache
    
    this.ssID           = ssID;
    this.stID           = stID; 
    this.scID           = scID;  
    this.sooID          = sooID;
    this.sspID          = sspID;
    this.sskID          = sskID;              
    
    this.stbID          = stbID;    
}
SlideShow.prototype.slShowList  = new Array();

SlideShow.prototype.newImage	= function(arg)
{
    if (document.images) {
        rslt = new Image();
        rslt.src = arg;
        return rslt;
    }
}

SlideShow.prototype.add 		= function( arg )
{
    return this.imgList.push( arg );
}
SlideShow.prototype.init        = function()
{                                     
    if (this.isInitialized) { return; }
                  
    SlideShow.prototype.slShowList[this.globName] = this;
                  
    this.imgEL      = document.getElementById( this.ssID  );
    this.titleEL    = document.getElementById( this.stID  );
    this.captionEL  = document.getElementById( this.scID  );                    
    this.toolbarEL  = document.getElementById( this.stbID );             
    
    this.playImage  = this.newImage( this.playImgURL );                                                        
    this.pauseImage = this.newImage( this.pauseImgURL );         
          
    var cnt  = this.imgList.length;                             
    var self = this;

    for (var i = 0; i < cnt; i++) {
        this.plc.push( this.newImage( this.imgList[i].imgURL ) );    
    }
        
    // javascript closure. advanced - wooo.
    (function(){                             
        document.getElementById( self.sooID ).onclick = function() {
            self.startShow();            
        }    
        document.getElementById( self.sspID ).onclick = function() {
            self.moveSlide(-1);            
        }    
        document.getElementById( self.sskID ).onclick = function() {
            self.moveSlide(1);            
        }                                    
    })();     
               
    this.isInitialized = true;
}
SlideShow.prototype.startShow   = function()
{                                       
    if (this.toHandle) {
        return;    
    }        
        
    this.setImageSrc(document.getElementById( this.sooID ), this.pauseImgURL);           
    
    var self = this;     
    (function(){                             
        document.getElementById( self.sspID ).style.display = 'none';
        document.getElementById( self.sskID ).style.display = 'none';
    
        document.getElementById( self.sooID ).onclick = function() {                        
            self.stopShow();            
        }
    })();    
        
    if (!this.initialStart) {
        this.moveSlide();
    } else {
        this.initialStart = false;
    }

    this.toHandle   = setInterval('SlideShow.prototype.slShowList["'+this.globName+'"].moveSlide()', 2900);
}                                              
SlideShow.prototype.stopShow    = function()
{            
    clearInterval( this.toHandle );
    this.toHandle    = false;     
        
    this.setImageSrc(document.getElementById( this.sooID ), this.playImgURL);

    var self = this;     
    (function(){                             
        document.getElementById( self.sspID ).style.display = 'inline';
        document.getElementById( self.sskID ).style.display = 'inline';  
    
        document.getElementById( self.sooID ).onclick = function() {
            self.startShow();            
        }
    })();    
}
SlideShow.prototype.moveSlide   = function( move )
{            
    switch (move) {
        case 1:     // next
        case -1:    // previous    
            break;         
        default:   
            move = this.lastMoveDir;            
    }
         
    var nextKey = this.curSlide + move;    
    var lastKey = this.imgList.length - 1;
    
    var beenRoundOnce = false;    

    //alert('this.curSlide = '+this.curSlide);
    //alert('nextKey = '+nextKey);
    //alert('lastKey = '+lastKey);
    
    while (!this.imgList[nextKey] /* && !this.imgLoaded(nextKey) */)  {
        if (lastKey == 0) {
            return;            
        }
        
        if (nextKey < 0) {
            nextKey = lastKey;
        } else if (nextKey > lastKey) {
            nextKey = 0;        
        } else {            
            nextKey += move;    
        } 
        
        if (nextKey == this.curSlide) {
            if (beenRoundOnce) {              
                alert('bad: '+this.imagesPLC.length);
                return;
            }
            beenRoundOnce = true;    
        }
    }    

    //alert(nextKey);

    this.lastMoveDir = move;   
    this.curSlide    = nextKey;
   
//    for (i in this.imgList[nextKey]) {
//        alert( 'nextKey' + i + ':' + this.imgList[nextKey][i] );
//    }
    
    this.imgEL.src              = this.imgList[nextKey].imgURL;
    this.titleEL.innerHTML      = this.imgList[nextKey].imgTitle;
    this.captionEL.innerHTML    = this.imgList[nextKey].imgCaption;            
}
SlideShow.prototype.imgLoaded   = function( key )
{                                   
    if (this.allLoaded) {
        return true;    
    }               
    
    if (key) {
        if (this.plc[key] instanceof Image) {
            return this.plc[key].completed;
        }          
        return false;
    }
    
    var cnt    = this.plc.length;                             
    var gotErr = false;
    for (var i = 0; i < cnt; i++) {
        if (!this.plc[i].completed) {
            gotErr = true;
            break;
        }            
    }
    
    if (gotErr) {
        return false;            
    } else {        
        this.allLoaded = true;
        return true;       
    }    
}
SlideShow.prototype.setImageSrc = function(img, src) 
{
    if (!img || !img.tagName) return;
     
    switch (img.tagName) {
        case 'IMG':
            img.src = src;
            return;
            break;
        case 'SPAN':
        case 'DIV':
            // this works around the IE 'fixpng' hack
            var imgID      = (img.id) ? "id='" + img.id + "' " : "";
            var imgClass   = (img.className) ? "class='" + img.className + "' " : "";
            var imgTitle   = (img.title) ? "title='" + img.title + "' " : "";
            
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
                        + " style=\"" + "width:" + img.style.width + "; height:" + img.style.height + ";"
                        + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                        + "(src=\'" + src + "\', sizingMethod='crop');\"></span>";

            img.outerHTML = strNewHTML;            
            return;
            break;            
    }
}
