﻿// Copyright 2001-2007 2night Entertainment Corp.
// The total or partial reproduction of its contents is prohibited

/*--------------------------------------------------------
 *  QuickPhoto.MyAlbum: Ajax style album management js Class 
 *  manage album and photos
 */ 
Type.registerNamespace("QuickPhotoClient");

QuickPhotoClient.MyAlbum = function()
{
    QuickPhotoClient.MyAlbum.initializeBase(this);
    // private vars 
	this._currentPage=0; 
	this._perPage = 999;
	this._maxPages = 1;
	this._html = "";
	this._current = 0;
	this._boxOn = 0;
	this._onRatateIndex = 0;
	// show pictures per row
	this._repeatColumns = 3; 
	this._album = null;
	this._adminOption = -1;
	this._showExtras = false;
	this._isPublic3On = false;
	this._interval = 2000;
	this._operators  = new Array();
	this._slideFlag = false;
	this._slideTimer = 0;
	this._d = false;
}

QuickPhotoClient.MyAlbum.prototype={
    // public properties 
     set_Interval:function(v){
        this._interval = v;
     },
     get_Interval:function(){
        return this._interval;
     },
    set_SlideFlag:function(v){
       this._slideFlag = v;
    }, 
     get_SlideFlag:function(){
        return this._slideFlag; 
     }, 
    
     set_SlideTimer:function(v){this._slideTimer=v; },
    get_SlideTimer:function(){return this._slideTimer;},   
     get_CurrentPhotoID :function(){
        return this._photos[this._current]; 
     },
     
     get_MaxPages:function(){
        return this._maxPages;
     },
     
     set_MaxPages:function(value){
        this._maxPages = value;
     },
     
     get_PerPage:function()
     {
        return this._perPage;
     },
     
     set_PerPage:function(value){
        this._perPage = value;
     },
     
     get_Current:function(){
        return this._current;
     },
     
     set_Current:function(value){
        this._current = value;
     },
     
     get_CurrentPhoto:function(){
         return this._album.Photos[this._current];
     },
     
     get_BoxOn:function(){
        return this._boxOn ;
     },
     
     set_BoxOn:function(value){
        this._boxOn = value;
     },
     
     set_Album:function(value){
        this._album = value;
       	this.initialize();
     },
     
     get_Album:function(){
        return this._album;
     },
     
     set_Public:function(value){
        this._album.Public = value;
     },
     
     get_IsPublic3On:function(){
        return this._isPublic3On;
     },
     
     set_IsPublic3On:function(value){
        this._isPublic3On = value;
     },
    
      // functions
     initialize : function(){
        this.SetupOperators();
        document.oncontextmenu=this.nr;
        $addHandler(document, "click", this.hideOptions);  
        $addHandler(document, "keypress", this.kp);   
        $addHandler(document, "keydown", this.kd);  
       
       if( $get("shareAlbum")) $get("shareAlbum").href = "Share.aspx?AlbumID=" + this._album.AlbumID;   
        this.PreloadImages();
     },
   
     ShowPhotos : function(){  
        this._html =''; 
        var fa = this._album.Photos.length ;
        var PhotoUrl = "";
        this._current = 0;

        for (i= 0; i<fa; i++) { 
            var photo= this._album.Photos[i]; 
           
            this._html += '<div class="thm1" id="photoParent'+ i+'">';
            
            this._html += '<div class="itemHandle" id="handle'+i+'"></div>';
            this._html += '<div id="photoItem'+i+'" class="photoItem" style="background-image: url('+photo.Url+'a.jpg);" onclick="album.PhotoBox('+i+')">&nbsp;</div>';
            this._html += '<input type="checkbox"  name="chkPhoto" id="chkPhoto'+i+'" value="'+i+'" onclick="CountSelectedPhoto();" class="chk" style="clear:both;margin:1px 2px 1px 3px;padding:0; vertical-align:top;float:left; height:16px;" />';
            this._html += '<span class="caption" style="font:normal 11px/18px arial; margin:0; padding:0;" id="caption'+i+'" onclick="album.select('+i+')">' + photo.Caption + '</span>';
            this._html += '<img id="indicator'+i+'" alt="" src="/images/loading1.gif" class="indicator" height="16px" /><br clear="all" />';
            
            this._html += '<div id="photoOpt'+i+'" class="ContextCombobox" onclick="album.toggleOptions('+i+');">';
            this._html += '<div id="optTitle'+i+'">Opciones</div>';
            this._html += '<ul class="ContextMenuPanel" name="ContextMenuPanel" id="photoOptpanel'+i+'"  >';
            
            for(var t = 1; t< this._operators.length; t++){
                this._html += '<li class="ContextMenuItem" onclick="album.'+ this._operators[t][1]+'('+i+');" >'+ this._operators[t][0]+'</li>';
            }
            
            this._html += '</ul>';
            this._html += '</div>';
            
            this._html += '</div>';
        }
        
        $get('Photos').innerHTML = this._html;
       if(this._album.IsAdmin){ 
        for (i= 0; i < fa ; i++) { 
            // make photo draggable  
           $create(Sys.Preview.UI.DraggableListItem,{handle: $get('handle'+i)}, {}, {}, $get('photoParent'+i));
         }}
         
        this.BindAlbumTitle();
    },

    BindAlbumTitle : function(){
       $get('albumTitle').innerHTML= this._album.Title;
       $get('albumDate').innerHTML = this._album.Created.getDate()+"/"+ (this._album.Created.getMonth()+1)+"/"+this._album.Created.getFullYear();
       if(this._album.PhotosNum == 1){
          $get('albumCount').innerHTML = this._album.PhotosNum + " " +'Foto ';
       }else{
         $get('albumCount').innerHTML = this._album.PhotosNum + " " +'Fotos ';
       }
    },
      
    LoadAlbum : function(albumID,code){
       var aid = 0 ;
       var c = " ";
       if(albumID)
        aid = albumID;
        else
           aid = this._album.AlbumID
           
       if(code)
          c = code    
          
       QuickPhotoWebSite.PhotoWebService.LoadAlbumDeep(aid,code,this.GetAlbumOnComplete,this.OnFailed,this);
    },

    GetAlbumOnComplete: function(result,a){
       a.ShowAlbum(result);
    },
    
    BindToolbar:function(){
         if(this._album.IsAdmin){
           var qs = new Querystring();
           var s = qs.get("Show");
           
           if(s){
               if(s.toLowerCase() == "extras"){
                  $get("extTitle").style.display = 'block';
                  $get("extTitle").innerHTML = "Tarjetas y Calendarios: por favor selecciona una foto";
               }else if( s.toLowerCase() == "download"){
                   $get("extTitle").style.display = 'block';
                  $get("extTitle").innerHTML = "Bajar Fotos: por favor selecciona una foto";
               }else if( s.toLowerCase() == "edit"){
                   $get("extTitle").style.display = 'block';
                  $get("extTitle").innerHTML = "Editar Fotos: por favor selecciona una foto";
               }
           }
       }
    },
    
    ShowAlbum:function(result)
    {
        if(result){
           this._album = result;
        }
        
        this.set_MaxPages(Math.round((this._album.Photos.length/this._perPage)+0.5)-1);
        if((this._album.Photos.length-1) % this._perPage ==0) 
            this._maxPages= this._maxPages-1;

        this.ShowPhotos();
       
       if(this._album.Public == 3 && !this._isPublic3On){
          var publicPanel = $get("publicPanel");
          publicPanel.innerHTML = 'Publicado';
          this.set_IsPublic3On(true);
       }
    },
  
    OnFailed: function(error){},
    
    SetupOperators:function(){     
      if(this._album.IsAdmin){
         Array.add(this._operators, ["Opciones","Null"]);
         Array.add(this._operators, ["Editar Título","EditCaption"]);
         Array.add(this._operators, ["Borrar Foto","DeletePhoto"]);
         Array.add(this._operators, ["Crear Tarjeta","FramePhoto"]);
         Array.add(this._operators, ["Cambiar Portada","ChangeCover"]);
         Array.add(this._operators, ["Editar Foto","EditPhoto"]); 
         if(userstatus && userstatus == 3)      
            Array.add(this._operators, ["Bajar Foto","DownloadPhoto"]); 
      }else if (this._album.Public == 3 && !this._album.IsAdmin  ){
           Array.add(this._operators, ["Opciones","Null"]);
           Array.add(this._operators, ["Crear Tarjeta","FramePhoto"]); 
         if(userstatus && userstatus == 3) //Premium users      
            Array.add(this._operators, ["Bajar Foto","DownloadPhoto"]); 
      }
      
      // menu of album
      if(!this._album.IsAdmin){
         $remove($get("am_upload")); 
          $remove($get("am_share")); 
           $remove($get("am_cart")); 
         $remove($get("am_edit").parentNode);           
      }
  
    },
    
    PhotosBack : function() {
        if (this._currentPage>0) {
            this._currentPage--; 
            this.ShowPhotos(); 
        }
    },

    PhotosNext : function() { 
        if (this._currentPage<this._maxPages) { 
            this._currentPage++;
            this.ShowPhotos();
        } 
    },

    ShowPhoto : function() {
        var MyImage=$get("Image");
        var photo = this._album.Photos[this._current];
        PhotoUrl = photo.Url + 'b.jpg';
        MyImage.style.backgroundImage='url(' + PhotoUrl + ')';
        $get("PhotoCaption").innerHTML = "Foto "+ (this._current + 1)+" de " + this._album.Photos.length + " - " + photo.Caption;
    },

    Preload : function(Num) {
        var f = this._album.Photos[Num];
        var nextImg =new Image();
         nextImg.src= f.Url+'b.jpg';
    },

    PhotoBack : function(slide) {   
        if ( this._current > 0 ) { 
            this._current--; 
        } else { 
            this._current = this._album.Photos.length-1; 
        }
        
       if(!slide) 
        this.ShowPhoto();
        Back = this._current-1; 
   
        if (Back<1) 
            Back= this._album.Photos.length-1;
        this.Preload(Back);
    },

    PhotoNext : function(slide) {
        if (this._current < this._album.Photos.length-1) {
            this._current ++; 
        } else { 
            this._current = 0
        }
   
       if(!slide)
        this.ShowPhoto();
        Next = this._current+1; 
   
        if (Next > this._album.Photos.length-1) 
            Next = 0;
            
        this.Preload(Next);
    },

    kd : function(e) {
        if (document.all) 
            k=parent.event.keyCode; 
        else 
            k=e.keyCode;
        if (k==32 && this._adminOption!=1) { 
            if ( this._boxOn==0) { 
                album.PhotoBox( this._current); 
            } else { 
                album.PhotoNext(); 
            } 
        }
        
        if (k==37 || k==38) { 
            if (this._boxOn==0) { 
                album.PhotosBack(); 
            } else { 
                album.PhotoBack(); 
            } 
        }
        
        if (k==39 || k==40) { 
            if (this._boxOn == 0 ) { 
                album.PhotosNext(); 
            } else { 
                album.PhotoNext(); 
            } 
        }
        
        if (k==27) 
            album.HidePhoto();
    },

    kp : function(e) { 
        if(album.get_BoxOn() == 0 ) 
        {
            return true; 
        }else 
            return false; 
    },

    nr : function() { 
        parent.focus(); 
        return false; 
    },

    PhotoBox : function(Num) {
        this._boxOn = 1;
       stopfloatter(); 
        if (Num == '') 
            Num = 0;
        this._current = Num;
        
        var f = this._album.Photos[Num]; 
        PhotoUrl= f.Url + 'b.jpg'; 

        w = document.documentElement.clientWidth;
        h = document.documentElement.clientHeight;
        o = document.documentElement.scrollTop;
        w2 = document.body.scrollWidth;
        h2 = document.body.scrollHeight;
        
        if (h>h2) 
            h2=h;
    
        MyOverlay=$get('Overlay');
        MyOverlay.style.width=w2+'px';
        MyOverlay.style.height=h2+o+'px';
        MyOverlay.style.left = 0;
        MyOverlay.style.top = 0;
    
        if (window.createPopup) { 
            MyOverlay.style.filter='alpha(opacity=90)' 
        } else {
            MyOverlay.style.opacity='0.9' 
        }
    
        MyOverlay.style.display='block';
   	    var MyLoading=$get("Loading"); 
        MyLoading.style.left=(w-36)/2+'px';
        MyLoading.style.top=(h-36)/2+o+'px';
        MyLoading.style.display='block';
       $get("banner").style.display="none"; 
        var MyImage=new Image();
    
        MyImage.onload=function() {
           // case user closed box before loading finished. 
            if(album.get_BoxOn()==0){return;} 
            l=(w-500)/2;
            t=(h-600)/2+o;
            MyLoading.style.display='none';
            x=(480-MyImage.width)/2;
            var al = album.get_Album();
            var f = al.Photos[album.get_Current()];
          
            album.ChangeBGImage("Image",PhotoUrl);
            $get("PhotoCaption").innerHtml = f.Caption ;
            album.ShowPhoto();
            MyPhoto= $get('Photo');
            MyPhoto.style.left=l+'px';
            MyPhoto.style.top=t+110+'px';
            MyPhoto.style.width='480px';
            MyPhoto.style.display='block';
    
            // Close
            MyClose=$get("Close");
            MyClose.style.left=l+480-4+'px';
            MyClose.style.top=t+116+'px';
            MyClose.style.display='block';
            
            //PreloadNext
            Next = album.get_Current()+1; 
    
            if (Next>al.Photos.length-1) 
                Next=1;
            if (al.Photos.length > 1)
               album.Preload(Next);
        }
    
        MyImage.src = PhotoUrl;
    },
    
    select:function(i){ 
       var p = $get("chkPhoto"+i);
       if(p){
           p.checked = !p.checked; 
       }
       
       CountSelectedPhoto();
    },

    HidePhoto : function() {
        this._boxOn=0;
        clearTimeout();
        album.set_SlideFlag(false);    
       myload(); 
        $get("Photo").style.display='none';
        $get("Loading").style.display='none';
        $get("Close").style.display='none';
        $get("Overlay").style.display='none';
       $get("banner").style.display="block";  
        $get("Nav").innerHTML = '<a class="LinkText" onclick="album.PhotoBack();">Anterior</a> &nbsp; <a class="LinkText"'+
                'onclick="album.PhotoNext();">Siguiente</a>';
    },

    PreloadImages : function() {
        var MyLoading=$get("Loading"); 
        MyLoading=new Image(); 
        MyLoading.src="/images/loading11.gif";
        MyClose=new Image(); 
        MyClose.src="/images/close.gif";
    },
    
    rnd:function(n) {  
        return Math.floor(Math.random() * n) + 1;  
    } , 
  
    ChangeBGImage : function(id,img){
        newImg = "url("+img +")";
        $get(id).style.backgroundImage = newImg;
        $get(id).style.backgroundPosition = "center";
        $get(id).style.backgroundRepeat = "no-repeat";
    },
    
    hideOptions : function(e){  
        var target = e.target;
        var s = target.getAttribute("id");
        var current = -1;
        if(s){
           if(s.startsWith("optTitle"))
             current = s.substring(8);
        }
                
         var dropdowns = $get("Photos").childNodes; 
         for (var i = 0; i < dropdowns.length ; i++) {
           dropdowns[i].removeAttribute("style");  // important
            if(i!=current){
               dropdown = $get("photoOptpanel"+i);
              if(dropdown){ 
               dropdown.style.display = "none";
              } 
           } 
          }
    },
     
    toggleOptions : function(i){
        var optPanel = $get('photoOptpanel'+i);
        var c = $get("photoOpt" + i);
        c.focus();
        if(optPanel.style.display == 'block')
          optPanel.style.display = "none";
        else{
          optPanel.style.display = "block";
          }
    },

    EditCaption : function(i){
        var photo = this._album.Photos[i]; 
           this._current = i;
        $get('caption'+i).innerHTML ='<input type="text" id="txtCaption'+i+'" class="text" onKeyPress="album.captureCaptionInput('+i+',event);"  value="' + photo.Caption +'" />';
         $get('caption'+i).setAttribute("onclick","");
        $get('txtCaption'+i).select(); 
        $get('txtCaption'+i).focus(); 
    },
   
   captureCaptionInput:function(i,evt){
            var key;
         if(window.event)
              key = window.event.keyCode;     //IE
         else
              key = evt.which;     //firefox
    
        if (key == 13)
        {      
           this.SaveCaption(i); 
        }
        if(!$get('txtCaption'+i).getAttribute("onblur"))
           $addHandler($get('txtCaption'+i),"blur",function(evt){album.SaveCaptione(evt);});
   }, 
   
   SaveCaptione:function(evt){
         var index = evt.target.id.substring("txtCaption".length);
        album.SaveCaption(index);  
   },
    
    SaveCaption : function(index){ 
        var caption = $get("txtCaption"+index).value;
        var photo =  this._album.Photos[index]; 
       if(photo.Caption == caption){
        $get('caption'+index).innerHTML = photo.Caption;
          return;
       }
        photo.Caption = caption; 
        var indicator = $get('indicator' + index);
        indicator.style.display = "block";
       $get('caption'+index).setAttribute("onclick","album.select("+index+");"); 
        QuickPhotoWebSite.PhotoWebService.UpdatePhotoCaption(photo.ID,caption,this.EditCaptionOnComplete, this.OnFailed,index);
    },

    EditCaptionOnComplete : function(result,index){
         $get('caption'+index).innerHTML = album.get_Album().Photos[index].Caption;
         var indicator = $get('indicator' + index);
         indicator.style.display = "none";
    },
    
    DeletePhotos : function(){ 
        var chkPhotos = document.getElementsByName('chkPhoto');     
        var count  = 0;  
        
        for(var i = 0; i< chkPhotos.length; i++){
           if(chkPhotos[i].checked){
                        count ++;  
          }
       }  
       
       if(count == 0){ alert("Por favor selecciona una o más fotos.");   return;}
          
      var answer = confirm ("¿Quieres borrar esta foto?")
      if (!answer)
            return;


      for(var i = 0; i< chkPhotos.length; i++){
          if(chkPhotos[i].checked){
             var index = chkPhotos[i].value;
             this._current = index;
             var photo =  this._album.Photos[this._current]; 
             var indicator = $get('indicator' + index);
             indicator.src="/images/loading1.gif"; 
             indicator.style.display = "block";
             QuickPhotoWebSite.PhotoWebService.DeletePhoto(photo.AlbumID,photo.SecurityCode, photo.PhotoID,this.DeletePhotoOnComplete, this.OnFailed,index);
           }
        }
    },
   
    DeletePhoto : function(index){
        var answer = confirm ("¿Quieres borrar esta foto?")
       if (!answer)
            return;
        this._current = index;
        var photo =  this._album.Photos[this._current]; 
        var indicator = $get('indicator' + index);
        indicator.src="/images/loading1.gif"; 
        indicator.style.display = "block";
        QuickPhotoWebSite.PhotoWebService.DeletePhoto(photo.AlbumID,photo.SecurityCode, photo.PhotoID,this.DeletePhotoOnComplete, this.OnFailed,index);
    },

    DeletePhotoOnComplete :function(result,index){
        $get('indicator' + index).src="";
        $get('indicator' + index).style.display = "none";
        var p = $get('photoParent' + index); 
        p.parentNode.removeChild(p);
        var al = album.get_Album()
        al.PhotosNum = al.PhotosNum - 1;
        album.BindAlbumTitle();
        CountSelectedPhoto();
    },
    
    UploadPhoto : function(){
        window.location.href="Upload.aspx?AlbumID=" + this._album.AlbumID ;
    },
    
    Share : function(){
        window.location.href="Share.aspx?AlbumID=" + this._album.AlbumID ;
    },
    
    SharePhotos : function(index){
         var chkPhotos = document.getElementsByName('chkPhoto');     
         var photos = ""
         for(var i = 0; i< chkPhotos.length; i++){
           if(chkPhotos[i].checked){
              var index = chkPhotos[i].value;
              this._current = index;
              photos +=  this._album.Photos[this._current].PhotoID+","; 
           }
        }
        window.location.href="Share.aspx?AlbumID=" + photo.AlbumID + "&SecurityCode=" + this._album.SecurityCode +"&PhotoIDs=" + photos;
    },
       
    FramePhoto : function(index){
        var photo =  this._album.Photos[index]; 
        window.location.href="Extras.aspx?AlbumID=" + photo.AlbumID + "&SecurityCode=" + this._album.SecurityCode +"&PhotoID=" + photo.PhotoID;
    },
    
    EditPhoto : function(index){
        var photo =  this._album.Photos[index]; 
        window.location.href="Edit.aspx?AlbumID=" + photo.AlbumID + "&SecurityCode=" + this._album.SecurityCode +"&PhotoID=" + photo.PhotoID;
    },
    
    DownloadPhoto : function(index){
        var photo =  this._album.Photos[index]; 
        window.location.href="Download.aspx?AlbumID=" + photo.AlbumID + "&SecurityCode=" + this._album.SecurityCode +"&PhotoID=" + photo.PhotoID+"&Caption=" + photo.Caption;
    },

    Edit : function(d,ev){
          showModalPopup(ev); 
        $get('txtNewTitle').value =  this._album.Title;
        $get('txtNewDescription').value = this._album.Description;
       this._d = d; 
        $get(d).value =  $get('albumDate').innerText; 
        HtmlHelper.SetRadioValue('rblPublic',this._album.Public);
    },

    EditAlbum : function(titleBox){
        this._album.Title = $get(titleBox).value;
        this._album.Description = $get("txtNewDescription").value;
        this._album.Public = HtmlHelper.GetRadioValue('rblPublic');
           var t = $get(this._d).value.split("/")
           $get('albumDate').innerText = $get(this._d).value; 
          
        var srv = QuickPhotoWebSite.PhotoWebService;
        srv.UpdateAlbumInfo(this._album.AlbumID,this._album.Title,this._album.Description,this._album.Public,t[2],t[1],t[0],this.EditAlbumOnComplete, this.OnFailed,this);
    },

    EditAlbumOnComplete : function(result,a){
        $get('EditAlbum').style.display="none";
        var al= a.get_Album();
        a.BindAlbumTitle();
        alert("Tu album ha sido editado.") ;
    },
    
    DeleteAlbum : function(){
        var answer = confirm("¿Quieres borrar este album completo?")
        if (answer){
            QuickPhotoWebSite.PhotoWebService.DeleteAlbum(this._album.AlbumID,this.DeleteAlbumOnComplete, this.OnFailed,this);
        }
    },

    DeleteAlbumOnComplete : function(result,a){
        window.location.href="albums.aspx";
    },
    
    ChangeCover : function(index){
        var photo =  this._album.Photos[index]; 
            QuickPhotoWebSite.PhotoWebService.UpdateCover(photo.AlbumID,photo.PhotoID,this.ChangeCoverOnComplete, this.OnFailed,this);
    },

    ChangeCoverOnComplete : function(result,a){
        var al= "Foto de portada guardada.";
        alert(al) ;
    },
    
    XPosition : function(newIndex,oldIndex){
        var photo =  this._album.Photos[oldIndex]; 
        var newPhoto = this._album.Photos[newIndex];

        var srv =QuickPhotoWebSite.PhotoWebService; 
            srv.UpdatePosition(photo.AlbumID,photo.PhotoID,newPhoto.Position, this.XPositionOnComplete, this.OnFailed,this);
    },

    XPositionOnComplete : function(result,a){
    },
    
    Play:function(){
       if(album.get_SlideTimer() >0) 
           clearTimeout(album.get_SlideTimer());  
        album.set_SlideFlag(true);  
        album.PhotoBox(0);
        var slide =  '<input type="button" id="slideback" class="slideback" value="Anterior"></input>';
        slide += '<select class="slidespeed" id="slidespeed" name="Speed" size="1" >'+
                    '<option value="1">1 Segundo</option>'+
                    '<option selected="" value="1.5">2 Segundos</option>'+
                    '<option value="3">3 Segundos</option>'+
                    '<option value="5">5 Segundos</option>'+
                    '<option value="7.5">7 Segundos</option>'+
                    '<option value="10">10 Segundos</option>'+
                    '</select>';
       slide +='<input type="button" id="slidepause" class="slidepause" value="Pause"></input>';
       slide +='<input type="button" id="slideplay"  class="slideplay" value="Play"></input>';
       slide +='<input type="button" id="slideforward"  class="slidenext" value="Siguiente"></input>';
       
       $get("Nav").innerHTML = slide;
       $addHandler($get("slideback"), "click", album.PlayBack);   
       $addHandler($get("slidespeed"), "change", album.setInterval);    
       $addHandler($get("slidepause"), "click", album.Pause);    
       $addHandler($get("slideplay"), "click", album.Resume);    
       $addHandler($get("slideforward"), "click", album.PlayNext);     
        
        album.set_SlideTimer(setTimeout("album.Playit()", album.get_Interval()));
    },
   
    setInterval:function(){
         album.set_SlideFlag(false);   
         
         if(album.get_SlideTimer() >0) 
           clearTimeout(album.get_SlideTimer());  
         
         var o = $get('slidespeed');
         album.set_Interval(o.options[o.selectedIndex].value*1000);
         album.set_SlideFlag(true);  
         album.Playit();
    },
    
    Playit:function(){
      if(album.get_SlideTimer() >0) 
           clearTimeout(album.get_SlideTimer());  
       if(album.get_SlideFlag()){ 
            // wait?   
           album.PhotoNext(1); 
           var MyImage=new Image();     
           var f = album.get_Album().Photos[album.get_Current()]; 
           var PhotoUrl= f.Url + 'b.jpg';             
 
           MyImage.onload=function() {
               // case user closed box before loading finished. 
                if(album.get_BoxOn()==0){clearTimeout(album.get_SlideTimer());  return;} 
              
                album.ShowPhoto();

                album.set_SlideTimer(setTimeout("album.Playit()", album.get_Interval()));
            }
           MyImage.src = PhotoUrl; 
       } 
    },
   
    PlayNext:function(){
         if(album.get_SlideTimer() >0) 
           clearTimeout(album.get_SlideTimer());  
          
         album.PhotoNext(); 
         album.Playit(); 
    } ,
   
   PlayBack:function(){
       if(album.get_SlideTimer() >0) 
           clearTimeout(album.get_SlideTimer());  
       
       album.PhotoBack();
       album.set_SlideTimer(setTimeout("album.Playit()", album.get_Interval()));
   },
    
    Resume:function(){
       album.set_SlideFlag(true);   
         album.set_SlideTimer(setTimeout("album.Playit()", album.get_Interval()));
    },
    
    Pause:function(){
        album.set_SlideFlag(false);  
         if(album.get_SlideTimer() >0) 
           clearTimeout(album.get_SlideTimer());  
    },
    
    Stop:function(){
       album.set_SlideFlag(false);  
          if(album.get_SlideTimer() >0) 
           clearTimeout(album.get_SlideTimer());  
    },

    dispose : function() {
    }
}

QuickPhotoClient.MyAlbum.registerClass('QuickPhotoClient.MyAlbum', Sys.Component);

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();


function test(a,newIndex,oldIndex){
album.XPosition(newIndex,oldIndex);
}

function $remove(el){
   el.parentNode.removeChild(el);
}

// setup events handlers 
var album = false;

$addHandler(window, "load", function(){
      if(typeof(albumData)!="undefined"){
          album = new QuickPhotoClient.MyAlbum();
          var a = Sys.Serialization.JavaScriptSerializer.deserialize(albumData);    
          
          var t = created.split("-")
          a.Created = new Date();
          a.Created.setYear(t[0]);
          a.Created.setMonth(t[1]-1);
          a.Created.setDate(t[2]);
          
          album.set_Album(a);
          album.ShowAlbum();
          if(a.IsAdmin){
             var dropCueTemplate = $create(QuickPhotoClient.Template, {}, {}, {}, $get("dropCueTemplate"));
             var emptyTemplate = $create(QuickPhotoClient.Template, {}, {}, {}, $get("emptyTemplate"));
             var photoDrag = $create(QuickPhotoClient.DragDropList, {
                                        dragDataType: "HTML",
                                        acceptedDataTypes: ["HTML"],
                                        dragMode: Sys.Preview.UI.DragMode.Move,
                                        direction: Sys.Preview.UI.RepeatDirection.Horiztion,
                                        dropCueTemplate:dropCueTemplate,
                                        emptyTemplate: emptyTemplate
                              }, {}, {}, $get("Photos"));
          
            photoDrag.set_Callback("test");
         } 
       
         $addHandler($get("Close"),"click",album.HidePhoto);
         $addHandler($get("Loading"),"click",album.HidePhoto);
         $addHandler($get("Overlay"),"click",album.HidePhoto);  
         $addHandler($get("slideshow"),"click",album.Play);
    }
});