/*
    Calls the Flickr A2 service to get photos
*/

// ****************** Declarations  ****************************
var _constFlickrUrl = "http://" + _RESTDomain + "/Flickr/Flickr.ashx";
var proxyUrl = "/NonAcm/Proxy.ashx";
var _isIE = false;
var _script;
var me;
var _xsl = "";
// ************************************************************

//Check the Browser Type
 if (navigator.appVersion.match(/\bMSIE\b/))
{
    _isIE = true;
}

function flickrPhotos()
{
    this.assetId = "";
    this.eventId = "";
    this.outputElmentId = "";
    this.keywords = "";
    this.mode = "all";
    this.sort = "relevance";
    this.currentPage = "1";
    this.perPage = "";
    this.excludedIds = "";
    this.timeout = "30000";
    this.getPhotos = function()
                            {
                                //Get all of the Flickr Photos with the given keywords
                                me = this;
                                var postBodyValue = "";
                                postBodyValue = "<request>";
                                postBodyValue += "<assetId>" + this.assetId + "</assetId>";
                                postBodyValue += "<keywords>" + this.keywords + "</keywords>";
                                postBodyValue += "<mode>" + this.mode + "</mode>";
                                postBodyValue += "<sort>" + this.sort + "</sort>";
                                postBodyValue += "<page>" + this.currentPage + "</page>";
                                postBodyValue += "<perpage>" + this.perPage + "</perpage>";
                                postBodyValue += "<functionName>get</functionName>";
                                postBodyValue += "<destinationUrl>" + _constFlickrUrl + "</destinationUrl>";
                                postBodyValue += "<eventId>" + this.eventId + "</eventId>";
                                postBodyValue += "<excludedIds>" + this.excludedIds + "</excludedIds>";
                                postBodyValue += "<timeout>" + this.timeout + "</timeout>";
                                postBodyValue += "<urlReferer>" + encodeURIComponent(location.href) + "</urlReferer>";
                                postBodyValue += "</request>";
                                
                                this.showWait(true);                  
                                var requestCall = new Ajax.Request(proxyUrl
                                                                    ,
                                                                        {
                                                                            method: "POST",
                                                                            contentType: "text/xml",
                                                                            postBody: postBodyValue,
                                                                            onSuccess: function(req)
                                                                                        {
                                                                                                document.getElementById(me.outputElmentId).innerHTML = req.responseText;
                                                                                                
                                                                                                
                                                                                 },
                                                                                 onFailure: function()
                                                                                        {
                                                                                            alert('Failed');
                                                                                        },
                                                                                 onComplete: function()
                                                                                        {
                                                                                            me.showWait(false);
                                                                                            
                                                                                        }       
                                                                     }
                                                         );
                            };
    this.showWait = function(blnShow)
                    {
                        //Show the progress wait animation that is offset by the output element
                        var assetsList = $(me.outputElmentId);
                        var progressBar = $("divProgressBar");
                        
                        if (progressBar && assetsList)
                        {
                            // Position the progress bar relative to the list
                            // Left is the offset, plus half the width of the table, minus half the width of the image
                            var offset = assetsList.cumulativeOffset();
                            
                            if (blnShow) 
                            {
                                var left = assetsList.offsetLeft + 20;
                                 var top = assetsList.offsetTop; //IE
            
                                //Get the top position of the waiting animation
                                if (!_isIE)
                                {
                                    top = assetsList.top; //FF
                                }
                                
                                        
                                $(progressBar).setStyle
                                (
                                    {
                                        position: "relative", top: top + "px", left: left + "px"
                                    }
                                );
                                
                                progressBar.show();   
                                new Effect.Opacity(assetsList, { from: 1.0, to: 0.3, duration: 0 });
                            }
                            else 
                            {
                                progressBar.hide();    
                                new Effect.Opacity(assetsList, { from: .3, to: 1.0, duration: 0 });
                            }
                        }
    
                    };
}