﻿Type.registerNamespace("Com.Apartments");

jQuery.extend({
  Trace: function(str) 
         { 
            if(jQuery.Timer.time==0)
                jQuery.Timer.start();
                
            $("#Trace").append("Trace: " + str + " " +jQuery.Timer.since() + "<br />" ); 
         }
});

jQuery.extend({
  HandleError: function(str) 
         {      
            $("#Error").append("Error: " + str + " " + str.description + "<br />" ); 
         }
});


jQuery.extend(
{
  Timer: {
              time: 0,
              now: function(){ return (new Date()).getTime(); },
              start: function(){ this.time = this.now(); },
              since: function(){ return this.now()-this.time; }
         }
});

function itemImagesLoaded (domObject){             
	    //alert("Item Images Loaded");  
	    this.CenterMedia();         
	    $("img").filter(".LargeImage").removeClass("Hidden");
    }

 function selectorImagesLoaded($selector){             
		    //note: $selector is $('.imageSection') here and $selector.length == 2 (since we have 2 imageSection classes on the page)             
		    var allLoaded = ""; //build a string of all items within the selector
		    $selector.each(function() {

		        var MediaViewWidth = $("#Media-View-Style").width();
		        var MediaViewHeight = $("#Media-View-Style").height();
		        $("img").filter(".LargeImage").removeClass("Hidden");
		        var media = $("img").filter(".LargeImage");
		        var MediaWidth = media.width();
		        var MediaHeight = media.height();

		        if (MediaWidth > MediaViewWidth) {
		            $("img").filter(".LargeImage").width(MediaViewWidth);
		        }

		        if (MediaHeight > MediaViewHeight) {
		            $("img").filter(".LargeImage").height(MediaViewHeight);
		        }

                //Center media in Media Viewer if Media hight or with is smaller than Media Viewer Size.
		        if ((MediaWidth < MediaViewWidth) || (MediaHeight < MediaViewHeight)) {
		            //CenterMediaLarge(MediaWidth, MediaHeight, MediaViewWidth, MediaViewHeight);
		        	CenterMedia();
				}        
		    })             
	    }
	    function CenterMediaLarge(mediaWidth, mediaHeight, mediaViewWidth, mediaViewHeight) { 
   		    var media = $("img").filter(".LargeImage");
	        var cssPropReset = { position: 'absolute' };
		    var mediaLeftMargin = (mediaViewWidth - mediaWidth)/2;
    	    var mediaTopMargin = (mediaViewHeight - mediaHeight)/2;
            var cssProp = { position: 'absolute' };		    
            
	        cssPropReset.marginTop = 0;
	        cssPropReset.marginLeft = 0;
	        media.css(cssPropReset);

	        if (mediaHeight < mediaViewHeight) {
	            cssProp.marginTop = mediaTopMargin;
	        }
	        
	        if (mediaWidth < mediaViewWidth) {	        
	            cssProp.marginLeft = mediaLeftMargin;
            }
	        media.css(cssProp);
        }		

function CenterMedia(elem) 
    { 
        //jQuery.Trace("Com.Apartments.MediaClickController.CenterMedia");
       // if ($(elem).hasClass("Photo") || $(elem).hasClass("FloorPlan")) {
            var $media = $("img").filter(".LargeImage");
            var cssPropReset = 
			    {
			    position: 'absolute'
			    };
		    cssPropReset.marginTop = 0;
		    cssPropReset.marginLeft = 0;
			cssPropReset.Top = 0;
		    cssPropReset.Left = 0;
		    $media.css(cssPropReset);
            
            // Get Media height and width
            var width = $media.width();
		    var height = $media.height();
		    

		    // Get container height and width
		    //var $container = $("div").filter(".LargeImage");
		    //var parentDivHeight = $container.height();
		    //var parentDivWidth = $container.width();
		    var parentDivHeight = 505;
		    var parentDivWidth = 640;
		        
		    // Calculate top and left margins of the media within the container
            var mediaLeftMargin = (parentDivWidth-width)/2;
	        var mediaTopMargin = (parentDivHeight-height)/2;
	        /*
	        // Snap image to upper left corner of container if larger than 640X480
	        if(mediaLeftMargin < 0) { 
		        mediaLeftMargin = 0; 
		    }
		        
		    if(mediaTopMargin < 0) { 
		        mediaTopMargin = 0; 
		    }
            */

		    var cssProp = 
			    {
			    position: 'absolute'
			    };
		    cssProp.marginTop = mediaTopMargin;
		    cssProp.marginLeft = mediaLeftMargin;

		    $media.css(cssProp);
		//}
    }


Com.Apartments.MediaFilter = function( mediaControl)
{
    currentClass = this;
    this._MediaController = mediaControl;
    filterButtons = $(".FilterButtons");
}
Com.Apartments.MediaFilter.prototype=
{
    Init: function() 
    {
        //jQuery.Trace("Com.Apartments.MediaFilter.Init");
        filterButtons.each(function () 
                                 {     
                                 if(currentClass._MediaController.NumberInCategory($(this).attr("CategoryTypeId")) > 0)
                                 {
                                    $(this).bind("click",currentClass._MediaController, currentClass._MediaController.FilterCategory).removeClass("nofiltergrey");
                                 }
                                 });
    },
    Dispose: function()
    {
        
        jQuery.Trace("Com.Apartments.MediaFilter.Dispose");
        filterButtons.addClass("nofiltergrey").unbind();
    }
}



Com.Apartments.MediaInformation = function()
{
    this._freeFormCaption;
    this._LargeImageLocation;
    this._StandardCaption;
    var currentClass = this;
}


Com.Apartments.MediaClickController = function(mediaControl)
{
    this._MediaController = mediaControl;
    currentClass = this;  
    mediaToClick = $(".MediaToClick");
    this._defaultMediaMove = 1;
}
Com.Apartments.MediaClickController.prototype =
{
    Init: function() {
        jQuery.Trace("Com.Apartments.MediaClickController.Init");
        mediaToClick.bind("click", this, this.MediaClicked).each(function(x) {
            if (x < currentClass._MediaController._AmountToShow) {
                currentClass.MediaAddSrc(this);
            }
        });

        if ($(".currentDisplayedMedia").size() == 0) {
            this.MediaClick(mediaToClick[0]);
        }
        else {
            this.MediaClick($(".currentDisplayedMedia")[0]);
        }

    },
    MediaClicked: function(event) {
        jQuery.Trace("Com.Apartments.MediaClickController.MediaClicked");
        event.data.MediaClick(this);

    },
    MediaClick: function(elem) {
        jQuery.Trace("Com.Apartments.MediaClickController.MediaClick");
        if ($(elem).hasClass("MediaToClick")) {
            $(".currentDisplayedMedia").removeClass("currentDisplayedMedia");
            $(elem).addClass("currentDisplayedMedia");

            var myNewElem = $(elem);
            for (i = 0; i < 6; i++) {
                this.MediaAddSrc($(myNewElem));
                myNewElem = $(myNewElem).next();
            }
            $(".StandardCaption").text($(elem).attr("StandardCaption"));
            $(".FreeFormCaption").text($(elem).attr("title"));
            $(".MediaLocationIndex").text($(elem).attr("ind"));
            $(".MediaLocationTotal").text($(elem).attr("total"));
            this.SetUpOutput(elem);
        }
    },
    MediaMoveLeft: function(elem) {
        jQuery.Trace("Com.Apartments.MediaClickController.MediaMoveLeft");
        var currentMedia = $(".currentDisplayedMedia");
        if (elem > this._defaultMediaMove) {
            for (m = 0; m < elem; m++) {
                currentMedia = currentMedia.prev();
            }
            var newCurrentMedia = currentMedia;
        }
        else {
            var newCurrentMedia = currentMedia.prev();
        }
        for (i = 0; i < 6; i++) {
            this.MediaAddSrc(currentMedia);
            currentMedia = currentMedia.prev();
        }
        this.MediaClick(newCurrentMedia);
    },
    MediaMoveRight: function(elem) {
        jQuery.Trace("Com.Apartments.MediaClickController.MediaMoveRight");
        var currentMedia = $(".currentDisplayedMedia");
        if (elem > this._defaultMediaMove) {
            for (m = 0; m < elem; m++) {
                currentMedia = currentMedia.next();
            }
            var newCurrentMedia = currentMedia;
        }
        else {
            var newCurrentMedia = currentMedia.next();
        }
        for (i = 0; i < this._MediaController._AmountToShow; i++) {
            this.MediaAddSrc(currentMedia);
            currentMedia = currentMedia.next();
        }
        this.MediaClick(newCurrentMedia);
    },
    SetUpOutput: function(elem) {
        jQuery.Trace("Com.Apartments.MediaClickController.SetUpOutput");

        if ($(elem).hasClass("VirtualTour")) {
            $("div .LargeImage").addClass("Hidden");
            $("div .VirtualTourView").removeClass("Hidden");
            $("div .VideoView").addClass("Hidden");
            $("div .ShareControl").addClass("Media-Hidden");
            $("div .VideoView").html("<div id='VideoView2'></div>");
            this.OutputVirtualTour(elem);
        }
        if ($(elem).hasClass("Photo") || $(elem).hasClass("FloorPlan")) {

            $("div .VirtualTourView").addClass("Hidden");
            $("div .LargeImage").removeClass("Hidden");
            $("div .VideoView").addClass("Hidden");
            $("div .VideoView").html("<div id='VideoView2'></div>");
            $("div .ShareControl").addClass("Media-Hidden");
            $("div .LargeImage").html("");
            $("div .LargeImage").html("<img class='LargeImage' />");

            $("img").filter(".LargeImage").onImagesLoad({
                //itemCallback: itemImagesLoaded,             
                selectorCallback: selectorImagesLoaded
            });
            $("img").filter(".LargeImage").addClass("Hidden");
            $("img").filter(".LargeImage").attr("src", $(elem).attr("LargeImage"));

        }
        if ($(elem).hasClass("Video")) {
            $("div .LargeImage").addClass("Hidden");
            $("div .VirtualTourView").addClass("Hidden");
            $("div .ShareControl").removeClass("Media-Hidden");
            $("div .VideoView").removeClass("Hidden");

            this.OutputVideo(elem);
        }

    },

    MediaAddSrc: function(elem) {

        jQuery.Trace("Com.Apartments.MediaClickController.MediaAddSrc");

        var jelem = $(elem);
        var el = jelem.children("img");
        if (el.size() == 0) {
            jelem.html('<img width="80px" src="' + jelem.attr("SmallImage") + '" height="60px"  class="pointer" />');
        }
        el = jelem.children("img");
        if (el.attr("src") == "") {
            el.attr("src", jelem.attr("SmallImage"));
        }
    },
    OutputVirtualTour: function(elem) {
        jQuery.Trace("Com.Apartments.MediaClickController.OutputVirtualTour");

        try {
            LogVTActivity();
        }
        catch (err) {
            jQuery.HandleError(err);
        }


        var tempElem = $(elem);
        if (tempElem.attr("VirtualHostingType") == "3") {
            window.open(tempElem.attr("ExternalVirtualTourUrl"), '_new');
        }
        else {
            mediaSource = tempElem.attr("VirtualTourUrl");
            degreeLocation = tempElem.attr("DegreeRotation");
            var html = '<div class=\"media-360views-flash\">';
            html += '<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\"370\" height=\"260\">';
            html += '<param name=\"movie\" value=\"' + tempElem.attr("Player") + '\" />';
            html += '<param name=\"quality\" value=\"HIGH\" />';
            html += '<param name=\"flashvars\" value=\"q=7&f=75&au=3&p=' + degreeLocation + '&s=' + mediaSource + '&u=&n=1&u=Padit%20Liene&n=1&c=FFFFFF\" />';
            html += '<param name=\"bgcolor\" value=\"#FFFFFF\" />';
            html += '<embed src=\"' + tempElem.attr("Player") + '\" quality=\"HIGH\" flashvars=\"q=7&f=75&au=3&p=' + degreeLocation + '&s=' + mediaSource + '&u=&n=1&u=Padit%20Liene&n=1&c=FFFFFF\" bgcolor=\"#FFFFFF\" width=\"370\" height=\"260\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />';
            html += '</object></div>';

            $(".VirtualTourView").html(html);
        }
    },
    OutputVideo: function(elem) {
        jQuery.Trace("Com.Apartments.MediaClickController.OutputVideo");

        var tempElem = $(elem);
        if (tempElem.attr("VideoHostingType") == "External") {
            window.open(tempElem.attr("VideoUrl"), '_new');
        }
        else {
            if ($("#aptsflash").size() > 0) {
                is25 = true;
                is50 = true;
                is75 = true;
                document["aptsflash"].numCall($(elem).attr("trackNum"), $(elem).attr("propNum"), $(elem).attr("mediaid"));

                //this produces the HTML that goes into the "Embed this Video" input box
                var str = $(elem).attr("VideoSrc");
                var index1 = str.indexOf('&v=') + 3;
                var index2 = str.indexOf('&u=');
                var v = str.substring(index1, index2);

                //jquery function that allows you to grab any variable from a url
                (function($) { $.url = {}; $.extend($.url, { _params: {}, init: function() { var paramsRaw = ""; try { paramsRaw = (document.location.href.split("?", 2)[1] || "").split("#")[0].split("&") || []; for (var i = 0; i < paramsRaw.length; i++) { var single = paramsRaw[i].split("="); if (single[0]) this._params[single[0]] = unescape(single[1]); } } catch (e) { alert(e); } }, param: function(name) { return this._params[name] || ""; }, paramAll: function() { return this._params; } }); $.url.init(); })(jQuery);

                var property = $.url.param("property");
                
                //set the value of these hidden inputs.  this is the data the ajax function uses in ShareControl.ascx
                $("#propertyLinkInput").val(property);
                $("#videoIndexInput").val(v);

                var valueURL = 'http://www.apartments.com/v/' + $(elem).attr("trackNum") + '-' + $(elem).attr("propnum") + '-' + v;
                var embedHTML = '<object width="640" height="505"><param name="movie" value="' + valueURL + '"></param>';
                embedHTML += '<param name="wmode" value="transparent"></param>';
                embedHTML += '<embed src="' + valueURL + '" type="application/x-shockwave-flash"wmode="transparent" width="320" height="265">';
                embedHTML += '</embed></object>';

                //Insert the HTML into the input
                $("#Share-embed").val(embedHTML);

                //Gets the current URL, adds the mi field to the end of it (that is the var that distinguishes between videos for each property)
                var url = window.location;
                var url = url + "&mi=" + v;
                //Insert the new URL into the "Copy the URL" input
                $("#Share-copy").val(url);


                //Updates the Facebook, Twitter, Digg, and Stumbleupon links to have current URL
                var facebookURL = 'http://www.facebook.com/share.php?u=http://www.apartments.com/avsummary.aspx?page=avsummary%26cmp=facebook%26mtype=video%26property=' + $(elem).attr("trackNum") + '.' + $(elem).attr("propnum") + '%26mi=' + v;
                $("a[class='facebook']").attr('href', facebookURL);

                var twitterURL = 'http://twitter.com/home?status=http://www.apartments.com/avsummary.aspx?page=avsummary%26cmp=twitter%26mtype=video%26property=' + $(elem).attr("trackNum") + '.' + $(elem).attr("propnum") + '%26mi=' + v;
                $("a[class='twitter']").attr('href', twitterURL);

                var diggURL = 'http://digg.com/submit?phase=2&url=http://www.apartments.com/avsummary.aspx?page=avsummary%26cmp=digg%26mtype=video%26property=' + $(elem).attr("trackNum") + '.' + $(elem).attr("propnum") + '%26mi=' + v;
                $("a[class='digg']").attr('href', diggURL);

                /*http: //www.myspace.com/index.cfm?fuseaction=postto&t=Apartments.com%20Video%20One&u=http://www.apartments.com/v/164433-5-1938*/
                var myspaceURL = 'http://www.myspace.com/index.cfm?fuseaction=postto&t=Apartments.com%20Video%20One&u=http://www.apartments.com/avsummary.aspx?page=avsummary%26cmp=stumbleupon%26mtype=video%26property=' + $(elem).attr("trackNum") + '.' + $(elem).attr("propnum") + '%26mi=' + v;
                $("a[class='myspace']").attr('href', myspaceURL);

                return;
            }
            else {

                /*function getFlashVersion(){ 
                // ie 
                try { 
                try { 
    
      var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6'); 
                try { axo.AllowScriptAccess = 'always'; } 
                catch(e) { return '6,0,0'; } 
                } catch(e) {} 
                return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1]; 
                // other browsers 
                } catch(e) { 
                try { 
                if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){ 
                return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1]; 
                } 
                } catch(e) {} 
                } 
                return '0,0,0'; 
                } 
 
var version = getFlashVersion().split(',').shift(); 
                alert (version);
                if(version == 10){
	
var html = '<p style="height: 80px; width: 80px;"><center>You will need Flash Player 10 and above to view this video.<br><a id="BackWincClk" href="http://get.adobe.com/flashplayer" target="_blank">Get Current Flash Player!</a></center>';
 
document.getElementById("VideoView").innerHTML = html;
                }else{ */
                mediaSource = $(elem).attr("VideoSrc").replace("{tracknum}", $(elem).attr("trackNum")).replace("{propnum}", $(elem).attr("propnum")).replace("{videourl}", $(elem).attr("videourl")).replace("es=", "es=" + $(elem).attr("es"));

                var html = '<div class=\"media-video-flash\">';
                html += '<object id="aptsflash" width="640" height="505" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">';
                html += '<param name="movie" value="' + mediaSource + '" />';
                html += '<param name="quality" value="high" />';
                html += '<param name="allowScriptAccess" value="always" />';
                html += '<embed src=\"' + mediaSource + '\" allowScriptAccess=\"always\" name=\"aptsflash\" quality=\"high\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" width=\"640\" height=\"505\"></embed>';
                html += '</object></div>';
                document.getElementById("VideoView").innerHTML = html;

                
                var str = $(elem).attr("VideoSrc");
                var index1 = str.indexOf('&v=') + 3;
                var index2 = str.indexOf('&u=');
                var v = str.substring(index1, index2);

                //jquery function that allows you to grab any variable from a url
                (function($) { $.url = {}; $.extend($.url, { _params: {}, init: function() { var paramsRaw = ""; try { paramsRaw = (document.location.href.split("?", 2)[1] || "").split("#")[0].split("&") || []; for (var i = 0; i < paramsRaw.length; i++) { var single = paramsRaw[i].split("="); if (single[0]) this._params[single[0]] = unescape(single[1]); } } catch (e) { alert(e); } }, param: function(name) { return this._params[name] || ""; }, paramAll: function() { return this._params; } }); $.url.init(); })(jQuery);
                
                var property = $.url.param("property");
                                
                //set the value of these hidden inputs.  this is the data the ajax function uses in ShareControl.ascx
                $("#propertyLinkInput").val(property);
                $("#videoIndexInput").val(v);


                var valueURL = 'http://www.apartments.com/v/' + $(elem).attr("trackNum") + '-' + $(elem).attr("propnum") + '-' + v;
                var embedHTML = '<object width="640" height="505"><param name="movie" value="' + valueURL + '"></param>';
                embedHTML += '<param name="wmode" value="transparent"></param>';
                embedHTML += '<embed src="' + valueURL + '" type="application/x-shockwave-flash"wmode="transparent" width="640" height="505">';
                embedHTML += '</embed></object>';

                //Insert the HTML into the input
                $("#Share-embed").val(embedHTML);

                //Gets the current URl, adds the mi field to the end of it (that is the var that distinguishes between videos for each property)
                var url = window.location;
                var url = url + "&mi=" + v;
                //Insert the new IRL into the "Copy the URL" input
                $("#Share-copy").val(url);

                //Updates the Facebook, Twitter, Digg, and Stumbleupon links to have current URL
                var facebookURL = 'http://www.facebook.com/share.php?u=http://www.apartments.com/avsummary.aspx?page=avsummary%26cmp=facebook%26mtype=video%26property=' + $(elem).attr("trackNum") + '.' + $(elem).attr("propnum") + '%26mi=' + v;
                $("a[class='facebook']").attr('href', facebookURL);

                var twitterURL = 'http://twitter.com/home?status=http://www.apartments.com/avsummary.aspx?page=avsummary%26cmp=twitter%26mtype=video%26property=' + $(elem).attr("trackNum") + '.' + $(elem).attr("propnum") + '%26mi=' + v;
                $("a[class='twitter']").attr('href', twitterURL);

                var diggURL = 'http://digg.com/submit?phase=2&url=http://www.apartments.com/avsummary.aspx?page=avsummary%26cmp=digg%26mtype=video%26property=' + $(elem).attr("trackNum") + '.' + $(elem).attr("propnum") + '%26mi=' + v;
                $("a[class='digg']").attr('href', diggURL);

                var myspaceURL = 'http://www.myspace.com/index.cfm?fuseaction=postto&t=Apartments.com%20Video%20One&u=http://www.apartments.com/avsummary.aspx?page=avsummary%26cmp=stumbleupon%26mtype=video%26property=' + $(elem).attr("trackNum") + '.' + $(elem).attr("propnum") + '%26mi=' + v;
                $("a[class='myspace']").attr('href', myspaceURL);

                //}
            }
        }
    },
    Dispose: function() {
        jQuery.Trace("Com.Apartments.MediaClickController.Dispose");

        mediaToClick.unbind();
    }
}

Com.Apartments.MediaController = function() 
{
   this._currentImage = 0;
   this._LengthToMove =0;
   this._AmountToShow =6;
   this._DivHoldingImages;
   this._MediaClickController;    
   this._MediaFilter;   
   this._PullHtml = new Object();   
   _currentMediaController = this;  
   this._currentStandardCaptionId = 0;
   this._currentStandardCaptionName =0;
   divArrow ="";
   this._defaultMove = 1;
   this._slideMove = 6;
}

Com.Apartments.MediaController.prototype = {
    Init: function(options) 
    {
        jQuery.Trace("Com.Apartments.MediaController.Init");
        divArrow = $("div .Arrow");
 
        var la = divArrow.filter(".LeftArrow");
        for(x=0; x< la.size(); x++)
        {
            this.AddLeftClicked(la[x]);
        }
        
        la = divArrow.filter(".RightArrow");
        for(b=0; b< la.size(); b++)
        {
            this.AddRightClicked(la[b]);
        }
        
        la = divArrow.filter(".SlideRightArrow");
        for(b=0; b< la.size(); b++)
        {
            this.AddSlideRightClicked(la[b]);
        }
        
        la = divArrow.filter(".SlideLeftArrow");
        for(b=0; b< la.size(); b++)
        {
            this.AddSlideLeftClicked(la[b]);
        }
        
        la = $(".mediaButtons");
        for(b=0; b< la.size(); b++)
        {
            $(la[b]).bind("click",this, this.StandardizedCaptionClicked);
        }
        
        this._LengthToMove = $(".MediaToClick").size();
        this._DivHoldingImages = $("div").filter(".thumbgall");
        this._MediaClickController = new Com.Apartments.MediaClickController(this);    
        this._MediaClickController.Init();
        this._MediaFilter = new Com.Apartments.MediaFilter(this);
        this._MediaFilter.Init();
        _currentMediaController = this;
        _currentMediaController.JumpToMedia(options);
        this.UpdateStandardCaption(options.MediaStandardCaptionName);
		this.UpdateCurrentOfTotal(_currentMediaController._currentImage);
	
        options.initFinished();
        
        jQuery.Trace("Com.Apartments.MediaController.InitFinished");

    },
    
    AddRightClicked: function(elem) {
             jQuery.Trace("Com.Apartments.MediaController.AddRightClicked");
      $(elem).bind("click", this, this.RightClicked);
          },
    AddLeftClicked: function(elem) {
           jQuery.Trace("Com.Apartments.MediaController.AddLeftClicked");
      $(elem).bind("click",this, this.LeftClicked);
    },
    RightClicked: function(event) {
                       jQuery.Trace("Com.Apartments.MediaController.RightClicked");
      event.data.MoveRight(1);
                },      
    LeftClicked: function(event) {
                      jQuery.Trace("Com.Apartments.MediaController.LeftClicked");
       event.data.MoveLeft(1);
    },
    AddSlideRightClicked: function(elem) {
           jQuery.Trace("Com.Apartments.MediaController.AddLeftClicked");
      $(elem).bind("click",this, this.SlideRightClicked);
    },
    SlideRightClicked: function(event) {
                       jQuery.Trace("Com.Apartments.MediaController.RightClicked");
      event.data.MoveRight(6);
                },
    AddSlideLeftClicked: function(elem) {
           jQuery.Trace("Com.Apartments.MediaController.AddLeftClicked");
      $(elem).bind("click",this, this.SlideLeftClicked);
    },
    SlideLeftClicked: function(event) {
                       jQuery.Trace("Com.Apartments.MediaController.RightClicked");
      event.data.MoveLeft(6);
                },
    StandardizedCaptionClicked: function(event) {
                    jQuery.Trace("Com.Apartments.MediaController.StandardizedCaptionClicked");
                    _currentMediaController._currentStandardCaptionId = $(this).attr("StandardCaptionId");
                 _currentMediaController._currentStandardCaptionName = $(this).attr("StandardCaptionName");
                 event.data.NewStandardizedCaption(this);
    },
    NewStandardizedCaption: function(elem) 
    {
           jQuery.Trace("Com.Apartments.MediaController.NewStandardizedCaption");
      var el = $(elem);
      
     $("div.mediaButtonsStyle").removeClass("Active-Media");
        el.addClass("Active-Media");
            $("Apartments-Media-Loading").className = "showDiv";   
        $.get("/MediaListSnippet.aspx", { property: el.attr("tracknum") + "." + el.attr("propnum") , msc: el.attr("StandardCaptionId") },this.ReplaceData);              
    },
   ReplaceData: function(data)
    {
       
        jQuery.Trace("Com.Apartments.MediaController.ReplaceData");
         $("Apartments-Media-Loading").className = "hideDiv";
        var myMediaController = _currentMediaController;
        myMediaController._MediaClickController.Dispose();  
        myMediaController._MediaFilter.Dispose();
        myMediaController._currentImage = 0;
        $("#ImageShowing").html(data); 
        
        myMediaController._LengthToMove = $(".MediaToClick").size();
        myMediaController._DivHoldingImages = $("div").filter(".thumbgall");
        myMediaController._MediaClickController = new Com.Apartments.MediaClickController(_currentMediaController);    
        myMediaController._MediaClickController.Init();
        myMediaController.Move();
        myMediaController._MediaFilter.Init();
        myMediaController.UpdateStandardCaption(myMediaController._currentStandardCaptionName);
		//myMediaController.UpdateCurrentOfTotal(myMediaController._currentImage);
		
        //myMediaController._MediaClickController.CenterMedia();
    },
    JumpToMedia: function(options) 
    {   
        jQuery.Trace("Com.Apartments.MediaController.JumpToMedia");
        if(options != null)
        {
            if(options.MediaId != null  && options.MediaType != null)
            {
                var mediaLocation = -1;
                var currentElem; 
                mediaToClick = $(".MediaToClick");
              
                for(b=0; b< mediaToClick.size(); b++)
                {
                    if(options.MediaId == 0 && $(mediaToClick[b]).hasClass(options.MediaType) && mediaLocation == -1)
                    {
                        mediaLocation = b;
                        currentElem =$(mediaToClick[b]);
                    }
                    else if($(mediaToClick[b]).attr("MediaId") == options.MediaId && $(mediaToClick[b]).hasClass(options.MediaType))
                    {
                        mediaLocation =b;
                        currentElem =$(mediaToClick[b]);
                    }
                }
                if(mediaLocation !=-1)
                {
                    this._currentImage = mediaLocation;
                      currentElem.trigger('click');
                    this.Move();
                  return true;
                }
            }
         } 
         return false;
    },
	UpdateCurrentOfTotal: function()
	{
		 elem = this._currentImage
	 $(".MediaLocationIndex").text($(elem).attr("ind"));
		$(".MediaLocationTotal").text($(elem).attr("total")); 
	},
    UpdateStandardCaption: function(newCaption)
    { 
          jQuery.Trace("Com.Apartments.MediaController.UpdateStandardCaption");
      $(".StandardCaption").text(newCaption);    
    },
    Move: function() 
    {
		
        jQuery.Trace("Com.Apartments.MediaController.Move");
        leftLength = this._currentImage * 94 * -1;
        leftLength = leftLength + "px";
        this._DivHoldingImages.animate({left: leftLength},"normal");
        this.UpdateCurrentOfTotal(this._currentImage);
    },
    MoveRight: function(elem) 
    {
      jQuery.Trace("Com.Apartments.MediaController.MoveRight");
      if(this._currentImage < (this._LengthToMove - this._AmountToShow))
        {
          this._MediaClickController.MediaMoveRight(elem);
          this._currentImage = this._currentImage + elem;
          this.Move();
        }
      else
        {
            this._MediaClickController.MediaMoveRight(this._defaultMove);
        }
       
        
    },
    MoveLeft: function(elem) 
     {
        jQuery.Trace("Com.Apartments.MediaController.MoveLeft");
        if(elem > this._currentImage){
            elem = this._currentImage;
        }
        this._MediaClickController.MediaMoveLeft(elem);
        if((this._currentImage - elem) >= 0)
        {
            this._currentImage = this._currentImage - elem;

            this.Move();
        }
        
        
    },
    NumberInCategory: function(categoryName)
    {
           jQuery.Trace("Com.Apartments.MediaController.NumberInCategory");
      if(categoryName == "FloorPlan")
               return $(".MediaToClick").filter(".FloorPlan").size();
        if(categoryName == "Photo")
               return $(".MediaToClick").filter(".Photo").size();
        
        if(categoryName == "VirtualTour")
               return $(".MediaToClick").filter(".VirtualTour").size();
        
        if(categoryName == "Video")
               return $(".MediaToClick").filter(".Video").size();
        
        if(categoryName == "All")
                return $(".MediaToClick").size();
    },
    FilterCategory: function(event)
    {
        jQuery.Trace("Com.Apartments.MediaController.FilterCategory");
        categoryName = $(this).attr("CategoryTypeId") 
        if(categoryName == "FloorPlan")
        {
         event.data._currentImage = event.data.NumberInCategory("Photo");
        }
        if(categoryName == "Photo")
        {
             event.data._currentImage = 0;
        }
        if(categoryName == "VirtualTour")
        {
         event.data._currentImage = event.data.NumberInCategory("Photo") + event.data.NumberInCategory("FloorPlan") + event.data.NumberInCategory("Video");
        }
        if(categoryName == "Video")
        {
           event.data._currentImage = event.data.NumberInCategory("Photo") + event.data.NumberInCategory("FloorPlan");
        }
        if(categoryName == "All")
        {
             event.data._currentImage = 0;
        }
        event.data._MediaClickController.MediaClick($(".MediaToClick")[event.data._currentImage]);
        event.data.Move();   
		
		
    }
}
