var RESORT_PHOTO_FORM_ID = "resortPhotoFormID";

function setDisplay(bEnable, id)
{   
    newDisplay = "";
    if(bEnable)
    {
        newDisplay = "block";
    }
    else
    {
        newDisplay = "none";
    }
    
    obj = document.getElementById(id);
    obj.style.display = newDisplay;
}

function getCurrentPage(withExtention)
{
    currentUrl = window.document.location.toString();
    currentUrlIndex = currentUrl.lastIndexOf("/");
    urlAnchorIndex = currentUrl.lastIndexOf("#");
    
    endUrlSubString = currentUrl.length;
    if (urlAnchorIndex > -1)
    {
        endUrlSubString = urlAnchorIndex;
    }
    
    currentPage = currentUrl.substring(currentUrlIndex + 1, endUrlSubString);
    
    if (!withExtention)
    {
        dotIndex = currentPage.lastIndexOf(".");
        currentPage = currentPage.substring(0, dotIndex);
    }
    
    return currentPage;
}

function setOpacity(sourceImg, opacity)
{
    sourceImg.style.filter = "alpha(style=0,opacity:" + Math.floor(opacity * 100) + ")"; // IE
    sourceImg.style.KHTMLOpacity = opacity; // Konqueror
    sourceImg.style.MozOpacity = opacity; // Mozilla (old)
    sourceImg.style.opacity = opacity; // Mozilla (new)
}

//http://www.hunlock.com/blogs/The_Ultimate_Ajax_Object
function ajaxObject(url, callbackFunction) 
{
    var that = this;      
    this.updating = false;
    this.abort = function() 
    {
        if (that.updating) 
        {
          that.updating=false;
          that.AJAX.abort();
          that.AJAX=null;
        }
    }
    
    this.update = function(passData, postMethod) 
    { 
        if (that.updating) 
        { 
            return false; 
        }
        
        that.AJAX = null;                          
        if (window.XMLHttpRequest) 
        {              
            that.AJAX = new XMLHttpRequest(); 
            if (that.AJAX.overrideMimeType) 
            {
                that.AJAX.overrideMimeType('text/xml');
            }             
        } 
        else if (window.ActiveXObject) // IE
        { 
            try 
            {
                that.AJAX = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) 
            {
                try 
                {
                    that.AJAX = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                catch (e) 
                {
                    //alert(e);
                }
            }
        }
                                             
        if (that.AJAX==null) 
        {                             
            return false;                               
        } 
        else 
        {
            that.AJAX.onreadystatechange = function() 
            {  
                if (that.AJAX.readyState == 4) 
                {     
                    //Component returned failure code: 0x80040111 
                    //Will some occur
                    try
                    {
                        if (that.AJAX.status == 200 && that.AJAX.statusText == "OK")
                        {       
                          that.updating=false;                
                          that.callback(that.AJAX.responseText, that.AJAX.status, that.AJAX.responseXML);        
                          that.AJAX=null;   
                        }  
                    }  
                    catch(e)
                    {
                        //alert(e);
                    }                                  
                }                                                      
            }                                                        
            
            that.updating = new Date();                              
            
            if (/post/i.test(postMethod)) 
            {
                var uri=urlCall+'?'+that.updating.getTime();
                that.AJAX.open("POST", uri, true);
                that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                that.AJAX.setRequestHeader("Content-Length", passData.length);
                that.AJAX.send(passData);
            } 
            else 
            {
                var uri=urlCall+'?'+passData+'&timestamp='+(that.updating.getTime()); 
                that.AJAX.open("GET", uri, true);                             
                that.AJAX.send(null);                                         
            }    
                      
            return true;                                             
        }                                                                           
    }
    
    var urlCall = url;        
    this.callback = callbackFunction || function () { };
}


function clearVirtualTour()
{
    objDivContainer = document.getElementById("virtualTourDivID");
    objAllMenuItems = objDivContainer.getElementsByTagName("li");
    
    for (i = 0; i < objAllMenuItems.length; i++)
    {
        objCurrentMenuItem = objAllMenuItems[i];
        objCurrentMenuItem.className="";
    }
}

function virtualTourSetMenuBackground(clear, menuID)
{
    if(clear)
    {
        clearVirtualTour();
    }
    
    objSelectedMenuItem = document.getElementById(menuID);
    objSelectedMenuItem.className = "virtualTourSelected";
}

function displayVirtualTour(menuID, moviePath)
{
    virtualTourSetMenuBackground(false, menuID);
    
    var so = new SWFObject("./virtualTour/pano.swf", "pano", "480", "320", "9", "#282828"); 
    so.addVariable("movie", "./virtualTour/pano.swf");
    so.addVariable("xml_file", "./virtualTour/parameters.xml");
    
    so.addVariable("panoName", moviePath);
    
    
    so.addVariable("redirect", window.location);
    so.addParam("allowFullScreen","true");
    so.addParam("allowScriptAccess","sameDomain");
    so.write("flashcontent");
}