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 = document.getElementById(albumTitleClientID).value.replace(/^\s+|\s+$/g,"");

    	    if (newAlbumTitle.length > 0)
   	        {
   	            var modalCreate = $get('modalCreateAlbum');
   	            var modalOptions = $get('modalAlbumOptions');
   	            
   	            if (modalCreate != null)
   		            return hideModal('modalCreateAlbum');
   		        if(modalOptions != null)
   		            return hideModal('modalAlbumOptions');    
    		    return true;
    	    }
    	    else
    	    {
    		    return false;
    		}
}

MySpace.PhotoAlbums.Pages.photoalbumscommon.PreloadImage = function(img)
{ 
       var newCover = new Image();
	   if (img != null)
	   {
	            newCover.src = img.src;
	            //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.registerClass('MySpace.PhotoAlbums.Pages.photoalbumscommon', Sys.UI.Behavior);

Sys.Application.add_init(setupPage);

var ClientCodeBehind;

function setupPage(){
	ClientCodeBehind = $create(MySpace.PhotoAlbums.Pages.photoalbumscommon, null, null, null, $get("content"));
}

