Type.registerNamespace('MySpace.PhotoAlbums.Pages');

MySpace.PhotoAlbums.Pages.photoalbumscommon = function(element) {
	MySpace.PhotoAlbums.Pages.photoalbumscommon.initializeBase(this, [element]);
}

MySpace.PhotoAlbums.Pages.photoalbumscommon.prototype = {
	//vars
	
	//initialize
	initialize: function() {
	    //Setup handlers
	},

	//Dispose vars
	dispose: function() {
	    //dispose elements
	}
};

MySpace.PhotoAlbums.Pages.photoalbumscommon.ValidateAlbumTitle = function(albumTitleClientID) {
   	    var newAlbumTitle =  _proxy_jslib_handle( _proxy_jslib_handle( _proxy_jslib_handle(document, 'getElementById', '', 1, 0)(albumTitleClientID), 'value', '', 0, 0), 'replace', '', 1, 0)(/^\s+|\s+$/g,"");

    	    if (newAlbumTitle.length > 0)
   	        {
    		    return true;
    	    }
    	    else
    	    {
    		    return false;
    		}
}

MySpace.PhotoAlbums.Pages.photoalbumscommon.PreloadImage = function(img) { 
       var newCover = new (Image)();
	   if (img != null)
	   {
	             _proxy_jslib_assign('', newCover, 'src', '=', (  _proxy_jslib_handle(img, 'src', '', 0, 0)));
	            //setTimout is not required. Please don't add, unless really required.
	            //for some reason beyond my understanding, 
	            //img does not return Height but newCover does.
	            //window.setTimeout(MySpace.PhotoAlbums.Pages.photoalbumscommon.PreloadImage, 1000); 
	            return newCover;
	   } 
	   else
	   {
	        return img;
	   }
}

MySpace.PhotoAlbums.Pages.photoalbumscommon.FixNonCustomCover = function(img, dvMargin) {
        var cover = { w: 170, h: 127 };
	
	    //if the image is not completely loaded then preload image
	    //this is most often possible in IE browsers 6,7
	    if(!img.complete)
          img = MySpace.PhotoAlbums.Pages.photoalbumscommon.PreloadImage(img);
            
	   	img.style.cssFloat = "left";
	
	    if (img.width < cover.w || img.width > cover.w)
		{
			img.width = cover.w;
			img.style.width = cover.w;				
		}
	   
		var halfWay = img.height / 2;
		var topOfCover = cover.h / 2; 

        //by this time, image must be completely loaded to make all this work
        //that is the purpose of preloadImage()
        var offset = topOfCover - halfWay;
        
          //This is to make the non custom album cover work as per business rule - 
          //  "the cover should display the central part of the image"
          //offset is rounded by IE, so I am explicitly doing it for all browsers
        if(dvMargin !== undefined)  
            dvMargin.style.marginTop = Math.round(offset) + "px";  
}

MySpace.PhotoAlbums.Pages.photoalbumscommon.FadeMessage = function(theDiv) {		
	var fadeThisFiv = $get(theDiv);
	if (fadeThisFiv !== null)
	{
	  fadeThisFiv.style.width = "100%"; //Hack for IE, to make Opacity Work
      MySpace.PhotoAlbums.Pages.photoalbumscommon.FadeIn(theDiv);
	   _proxy_jslib_handle(null, 'setTimeout', setTimeout, 1, 0)("MySpace.PhotoAlbums.Pages.photoalbumscommon.FadeOut('" + theDiv + "')", 4000);
	}
}


MySpace.PhotoAlbums.Pages.photoalbumscommon.FadeOut = function(theDiv) {	
    var fadeOut=$create(MySpace.UI.Effects.FadeAnimation, {
			    target:$get(theDiv),
			    effect:MySpace.UI.Effects.FadeEffect.FadeOut,
			    duration: 1

 });
 	
	fadeOut.play();
}

MySpace.PhotoAlbums.Pages.photoalbumscommon.FadeIn = function(theDiv) {
		
    var fadeIn=$create(MySpace.UI.Effects.FadeAnimation, {
			target:$get(theDiv),
			effect:MySpace.UI.Effects.FadeEffect.FadeIn,
			duration: 1

 });
		
   fadeIn.play();
  
}

MySpace.PhotoAlbums.Pages.photoalbumscommon.MaxImage = function(img) {
        
		if (img.height > 90) 
		{
			var r = img.width *(90 / img.height);
			img.style.height = 90 + "px";
			img.style.width = r + "px";
		}
		
		if (img.width > 80) 
		{
			var r = img.height *(80 / img.width);
			img.style.width = 80 + "px";
			img.style.height = r + "px";
		}	
		
		var topBoxID = "topEmptyBox" + img.title;
		var bottomBoxID = "bottomEmptyBox" + img.title;
	    
		var neededPadding = 100 - img.height;                	                
		var splitPadding = neededPadding / 2;                                        
	    
		img.vspace = splitPadding;
} 	

//This method resets the new album information from modal when cancel button is clicked
MySpace.PhotoAlbums.Pages.photoalbumscommon.ResetDropDownList = function() {
    //Resetting of the panel as the user has selected a pre-defined album from drop-down list
    if(typeof(ddlAlbumsClientID) !== "undefined" && ddlAlbumsClientID !== null){
        var ddlAlbums = $get(ddlAlbumsClientID);
        
        if (ddlAlbums !== null){
            ddlAlbums.selectedIndex = 0;
        }
	}
	
	//Reseting new album information fields on modal
	MySpace.PhotoAlbums.Pages.photoalbumscommon.ClearNewAlbum();
}

//This method resets the new album information from modal when album is selected from drop down list
MySpace.PhotoAlbums.Pages.photoalbumscommon.ClearNewAlbum = function() {
        //Resetting of the panel as the user has selected a pre-defined album from drop-down list
        if (typeof(newAlbumNameClientID) !== "undefined" && newAlbumNameClientID !== null)
             _proxy_jslib_assign('', $get(newAlbumNameClientID), 'value', '=', ( ""));
            
        if (typeof(txtLocationClientID) !== "undefined" && txtLocationClientID !== null)
             _proxy_jslib_assign('', $get(txtLocationClientID), 'value', '=', ( ""));
            
        if (typeof(rblAlbumPrivacyClientID) !== "undefined" && rblAlbumPrivacyClientID !== null){
            var radioSpan = $get(rblAlbumPrivacyClientID);
            var privacyRadio =  _proxy_jslib_handle(radioSpan, 'getElementsByTagName', '', 1, 0)("input");
        	privacyRadio[2].checked = true;
        }
            
        if (typeof(copyImageClientID) !== "undefined" && copyImageClientID !== null)    
             _proxy_jslib_assign('', $get(copyImageClientID), 'value', '=', ( MySpaceRes.ViewMorePicsPage.Move));
}

//This function toggles the text on the create/move button based on the action taken
//1. DDL selection causes "move" to appear
//2. Entering text in album title field causes "create" to appear and 
//      previous ddl selection to reset to first generic msg
MySpace.PhotoAlbums.Pages.photoalbumscommon.ChangeMoveCopyCreateText = function() {
        if (typeof(newAlbumNameClientID) !== "undefined" && newAlbumNameClientID !== null){
                var newAlbumName = $get(newAlbumNameClientID);
                var copyImage; 
    
                if (typeof(copyImageClientID) !== "undefined" && copyImageClientID !== null){
                        copyImage = $get(copyImageClientID);
                }
                
	            if ( _proxy_jslib_handle(newAlbumName, 'value', '', 0, 0).length == 0){
	                    if (copyImage !== null)
	                         _proxy_jslib_assign('', copyImage, 'value', '=', ( MySpaceRes.ViewMorePicsPage.Move));
	            }
	            else{
	                    if (copyImage !== null)
	                         _proxy_jslib_assign('', copyImage, 'value', '=', ( MySpaceRes.ViewMorePicsPage.Create));
	                        
                        //reset drop down list as user is creating new album
                        if(typeof(ddlAlbumsClientID) !== "undefined" && ddlAlbumsClientID !== null){
                            var ddlAlbums = $get(ddlAlbumsClientID);
                            if (ddlAlbums !== null){
                                ddlAlbums.selectedIndex = 0;
                            }
                        }    
	            }   
	    }
	    else{
	        Sys.Debug.trace("newAlbumNameClientID is either undefined or null");
	    }
}

//This function checks for album name in drop down list to move photo(s) to. 
//If user has not selected then it will alert user and return false.
MySpace.PhotoAlbums.Pages.photoalbumscommon.NewAlbumCheck = function() {
        var ddlAlbums;
        var newAlbumName;
        
        ddlAlbums = $get(ddlAlbumsClientID);
            
        if(ddlAlbums !== null){    
                newAlbumName =  _proxy_jslib_handle($get(newAlbumNameClientID), 'value', '', 0, 0).trim();
                if (ddlAlbums.selectedIndex === 0 && newAlbumName.length === 0){
		            window.alert(MySpaceRes.ViewMorePicsPage.SelectAlbumToMove);	
      	            return false;
		        }
		        else{				    
		            return true;
		        }
        }
            
		return false;
}

MySpace.PhotoAlbums.Pages.photoalbumscommon.registerClass('MySpace.PhotoAlbums.Pages.photoalbumscommon', Sys.UI.Behavior);

Sys.Application.add_init(setupPage);

var ClientCodeBehind;

function setupPage() {
    if($get("content") !== null)
	    ClientCodeBehind = $create(MySpace.PhotoAlbums.Pages.photoalbumscommon, null, null, null, $get("content"));
}
 ;
_proxy_jslib_flush_write_buffers() ;