var ProjectCover = {

  scrollable	    : [],
  scrollableHor	  : [],
  scrolling	      : [],
  scrollingHor	  : [],
  timerID	        : null,
  extension	      : null,

  scrollText : function (textField) {
  	var scrollKey = textField.replace("projCoverText", "");
  	scrollKey = parseInt(scrollKey);
  	
  	ProjectCover.scrollable[scrollKey] = 1;
  	if (ProjectCover.scrolling[scrollKey] === 0) {
  		ProjectCover.timerID = setInterval("ProjectCover.scrollNow('"+textField+"')", 75);
  	}
  },

  scrollNow : function (textField) {
  	var scrollKey = textField.replace("projCoverText", "");
  	scrollKey = parseInt(scrollKey);
  	
  	textObj = $(textField);
  	curHeight = textObj.offsetHeight;
  
  	if (curHeight <= 128) { return };
    
		if (ProjectCover.scrollable[scrollKey] == 1) {
			ProjectCover.scrolling[scrollKey] = 1;
			curTop = textObj.style.top;
			
			if (curTop.match("pt")) {
				curBrowser = "notIE";
				this.extension = "pt";
				curTop = curTop.replace("pt", "");
			} else {
				curBrowser = "IE";
				this.extension = "px";
				curTop = curTop.replace("px", "");
			}
			curTopInt = parseInt(curTop);
			newTop = curTop - 1;
			if (newTop == -curHeight) { newTop = 158;}
			
			textObj.style.top = newTop+this.extension;
		}
  },


  stopScroll : function(textField) {
  	var scrollKey = textField.replace("projCoverText", "");
  	scrollKey = parseInt(scrollKey);
  	
  	ProjectCover.scrolling[scrollKey] = 0;
  	ProjectCover.scrollable[scrollKey] = 0;
  	if (ProjectCover.timerID != null) { clearInterval(ProjectCover.timerID); }
  	setTimeout("ProjectCover.resetScroll('"+textField+"')", 30);
  },

  resetScroll : function(textField) {
  	var scrollKey = textField.replace("projCoverText", "");
  	scrollKey = parseInt(scrollKey);
  	
  	if (ProjectCover.scrolling[scrollKey] == 0 && ProjectCover.scrollable[scrollKey] == 0) {
  		textObj = $(textField);
  		textObj.style.top = 0+this.extension;
  	}
  },
  
  /**************  Owners Scroll Functions  *********************/

  checkScrollExist : function(scrollKey) {
  	if (  ProjectCover.scrollingHor[scrollKey] == 0 || 
          ProjectCover.scrollingHor[scrollKey] == null || 
          ProjectCover.scrollingHor[scrollKey] == false) {
  		return false;
  	}
  	else return true;
  },

  scrollTextHor : function(textField) {
  	var curScrollField = textField.replace(/[0-9]+/, "");
  	var scrollKey = textField.replace(curScrollField, "");
  	scrollKey = parseInt(scrollKey);
    
  	ProjectCover.scrollableHor[scrollKey] = 1;
  	if (this.checkScrollExist(scrollKey) == false) {
  		ProjectCover.timerID = setInterval("ProjectCover.scrollNowHor('"+textField+"')", 35);
  	}
  },

  scrollNowHor : function (textField) {
  	var curScrollField = textField.replace(/[0-9]+/, "");
  	var scrollKey = textField.replace(curScrollField, "");
  	scrollKey = parseInt(scrollKey);
  	
  	textObj = $(textField);
  	
  	textNObj = $(curScrollField+'N'+scrollKey);
  	curWidth = textNObj.offsetWidth;
  
  	if (curWidth > 150) {
  		if (ProjectCover.scrollableHor[scrollKey] == 1) {
  			ProjectCover.scrollingHor[scrollKey] = 1;
  			curLeft = textObj.style.left;
  			
  			if (curLeft.match("pt")) {
  				curBrowser = "notIE";
  				ProjectCover.extension = "pt";
  				curLeft = curLeft.replace("pt", "");
  			}
  			else {
  				curBrowser = "IE";
  				ProjectCover.extension = "px";
  				curLeft = curLeft.replace("px", "");
  			}
  			curLeftInt = parseInt(curLeft);
  			newLeft = curLeft - 1;
  			
  			if (newLeft == -curWidth) newLeft = 158;
  			
  			textObj.style.left = newLeft+ProjectCover.extension;
  			
  			
  		}
  	}
  },
  
  stopScrollHor : function(textField) {
  	var curScrollField = textField.replace(/[0-9]+/, "");
  	var scrollKey = textField.replace(curScrollField, "");
  	scrollKey = parseInt(scrollKey);
  	
  	ProjectCover.scrollingHor[scrollKey] = 0;
  	ProjectCover.scrollableHor[scrollKey] = 0;
  	if (ProjectCover.timerID != null ) clearInterval(ProjectCover.timerID);
  	setTimeout("ProjectCover.resetScrollHor('"+textField+"')", 30);
  },
  
  resetScrollHor : function(textField) {
  	var curScrollField = textField.replace(/[0-9]+/, "");
  	var scrollKey = textField.replace(curScrollField, "");
  	scrollKey = parseInt(scrollKey);
  	
  	if (ProjectCover.scrollableHor[scrollKey] == 0 && ProjectCover.scrollableHor[scrollKey] == 0) {
  		textObj = $(textField);
  		textObj.style.left = 0+ProjectCover.extension;
  	}
  }

} // ProjectCover

var Project = {
  
  addTo : function(action, url, title, from) {
  	var from = (from) ? from : 'top menu';
  	if (action == "bookmark") {
      this.bookmark(title, url);
  	} else {
  		window.open(VIRAL_ENDPOINT +'action='+action+'&url='+url+'&title='+title+'&from='+from, '_blank');
  	}
  },

  bookmark : function(title, url) {
		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel( title, url, "" );
		} else if( window.external ) { // IE Favorite
			window.external.addFavorite( url, title ); 
    } else { 
			$('toolError').innerHTML = "<p>&nbsp;</p><p>Safari does not support this feature.</p><p>Please hit CMD + D.</p>";
    }
  },
  
  showAppSeal : function(resp) {
    if ( resp == '1') {
      $('proj-tools-appreciate-seal').show();
      $('proj-tools-appreciate-seal').setStyle({display:'block'});
    } else {
      $('proj-tools-appreciate-thanks-seal').show();
      $('proj-tools-appreciate-thanks-seal').setStyle({display:'block'});
    }
  },
  
  appreciate : function (proj_id) {
    var url = '/service/callbacks.php?action=appreciate&type=project&id='+proj_id;
    var html = '<img src="' + url + '" height="0" width="0" style="line-height:0;"/>';
    
    $(document.body).insert( {bottom : html} );
    
    var sticker	    = $('proj-appreciate-sticker');
    sticker.src	    = 'http://behanceserved.com/images/appreciate_thanks.png';
    sticker.title	  = 'Thanks!';
    sticker.alt	    = 'Thanks!';
    
    $$('.proj-tools-appreciate').invoke('hide');
    
    var apprInfo = $('projApps' + proj_id);
    apprInfo.update( parseInt($('projApps' + proj_id).innerHTML) + 1)
    
  },
  
  appreciatePopup : function( proj_id ) {
     var pop_instance = PopUpMgr.add();

     var a = new Ajax.Request('/index.php/project/postAppreciation?proj_id='+proj_id, {
       method : 'get',
       onComplete : function (transport) {
         PopUpMgr.update(pop_instance,transport.responseText);
       }
     });
  },
  
  positionInfo : function() {
    $('proj-info').clonePosition($('proj-info-img'),{
      setWidth  : false,
      setHeight : false,
      offsetTop : $('proj-info-img').getHeight()
    });
   
  },
  
  positionTools : function() {
    $('proj-tools').clonePosition($('proj-tools-img'),{
      setWidth  : false,
      setHeight : false,
      offsetTop : $('proj-tools-img').getHeight()
    });

  },
  
  positionOwners : function() {
    $('projOwnersList').clonePosition($('projOwners'),{
      setWidth  : false,
      setHeight : false,
      offsetTop : $('projOwners').getHeight()
    });

  },
  
  positionBottomTools : function() {
    $('proj-tools-bottom').clonePosition($('proj-tools-bottom-img'),{
      setWidth  : false,
      setHeight : false,
      offsetTop : $('proj-tools-bottom-img').getHeight()
    });

  },
  
  info : function( e ) { 
  
    // Get the x and y coords of the mouse.
    var x = Event.pointerX(e);
    var y = Event.pointerY(e);
  
    // Get the x and y ranges of the element.
    var infoElPos = this.getXYRange('proj-info-img');
    
    // Get the x and y ranges of the info popup
    var popupPos = this.getXYRange('proj-info');
    
    // See if the mouse is over the info Image
  	var overInfo = (  x >= infoElPos.xLeft &&	x <= infoElPos.xRight && 
                      y >= infoElPos.yTop  &&	y <= infoElPos.yBottom );
          
    // See if the mouse is over the info Popup
  	var overPopup = ( x >= popupPos.xLeft && x <= popupPos.xRight && 
                      y >= popupPos.yTop  && y <= popupPos.yBottom );
  
    if( overInfo ) {
    	this.openInfo();
  	} 
    
    if( !overInfo && !overPopup ) {
  		this.closeInfo();
    }
  
  },
  
  tools : function( e ) {
    
    // Get the x and y coords of the mouse.
    var x = Event.pointerX(e);
    var y = Event.pointerY(e);
  
    // Get the x and y ranges of the element.
    var toolsElPos = this.getXYRange('proj-tools-img');
    
    // Get the x and y ranges of the info popup
    var popupPos = this.getXYRange('proj-tools');
    
    // See if the mouse is over the info Image
  	var overTools = (  x >= toolsElPos.xLeft &&	x <= toolsElPos.xRight && 
                      y >= toolsElPos.yTop  &&	y <= toolsElPos.yBottom );
          
    // See if the mouse is over the info Popup
  	var overPopup = ( x >= popupPos.xLeft && x <= popupPos.xRight && 
                      y >= popupPos.yTop  && y <= popupPos.yBottom );
  
    if( overTools ) {
    	this.openTools();
  	} 
    
    if( !overTools && !overPopup ) {
  		this.closeTools();
    }
  },
  
  projOwners : function( e ) {
    
    // Get the x and y coords of the mouse.
    var x = Event.pointerX(e);
    var y = Event.pointerY(e);
  
    // Get the x and y ranges of the element.
    var toolsElPos = this.getXYRange('projOwners');
    
    // Get the x and y ranges of the info popup
    var popupPos = this.getXYRange('projOwnersList');
    
    // See if the mouse is over the info Image
  	var overTools = (  x >= toolsElPos.xLeft &&	x <= toolsElPos.xRight && 
                      y >= toolsElPos.yTop  &&	y <= toolsElPos.yBottom );
          
    // See if the mouse is over the info Popup
  	var overPopup = ( x >= popupPos.xLeft && x <= popupPos.xRight && 
                      y >= popupPos.yTop  && y <= popupPos.yBottom );
  
    if( overTools ) {
    	this.openOwners();
  	} 
    
    if( !overTools && !overPopup ) {
  		this.closeOwners();
    }
  },
  
  bottomTools : function() {
    var el     = $('proj-tools-bottom');
    if (el.getStyle('visibility') == 'visible') {
      this.closeBottomTools();
    } else {
      this.openBottomTools();
    }

  },
  
  getXYRange : function(el) {
    var el	= $(el);
  	var c	  = el.cumulativeOffset();
  
    return infoElPos = {
      xLeft	    : c[0],
      xRight	  : c[0] + el.getWidth(),
      yTop	    : c[1],
      yBottom	  : c[1] + el.getHeight()
    };
  },
  
  openInfo : function() {
    Project.positionInfo();
  	$('proj-info')._showV();
  },
  
  closeInfo : function() {
    $('proj-info')._hideV();
  },
  
  openTools : function() {
  	Project.positionTools();
    $('proj-tools')._showV();
  },
  
  closeTools : function() {
  	$('proj-tools')._hideV();
    $$('proj-tools-bookmarks').invoke('hide');
  },
  
  openOwners : function() {
  	Project.positionOwners();
  	$('projOwnersList').show();
  },
  
  closeOwners : function() {
    $('projOwnersList').hide();
  },
  
  openBottomTools : function() {
  	Project.positionBottomTools();
    $('proj-tools-bottom')._showV();
  },
  
  closeBottomTools : function() {
  	$('proj-tools-bottom')._hideV();
    $$('proj-tools-bookmarks').invoke('hide');
  },
  
  
  getSendPopup : function(proj_id) {
  	var a = new Ajax.Request('/index.php/project/sendToAFriendForm?proj_id='+proj_id, { 
  		method : 'get',
  		onSuccess : function (transport) {
        var pop_instance = PopUpMgr.add();
        PopUpMgr.update(pop_instance, transport.responseText);
  		}
  	});
  },

  send : function() {
    var validation = new ValidationMgr();
    
    validation.add('name','Generic',$H({required:1}));
    validation.add('email','Email',$H({required:1}));
    validation.add('email_list','Generic',$H({required:1}));
    validation.add('auth_failure','Generic');
    
    var validForm = validation.validate();
    
    PopUpMgr.position(PopUpMgr.getInstance('pop'));
    if (!validForm) { return; }
    
    
    
    var params = $H({
      proj_id    : $F('proj_id'),
      name	     : $F('name'),
      email	     : $F('email'),
      email_list : $F('email_list')
    }).toQueryString();
    
    $('send-project-sending').show();
    $('send-project-button').hide();
    
    var a = new Ajax.Request('/index.php/project/sendToAFriend', {
        method	    : 'post',
        parameters	: params,
        onSuccess : function(transport) {
          var json = transport.responseJSON;
          if( json.status == 'success' ) {
            $('shareProjectDIV').update(json.html);
            PopUpMgr.position(PopUpMgr.getInstance('pop'));
          }

          if( json.status == 'fail' ) {
             validation.handleExtendedErrors(json);
             
             $('send-project-sending').hide();
             $('send-project-button').show();
             
             PopUpMgr.position(PopUpMgr.getInstance('pop'));
          }
          
          
        }
    });
  },
  
  reportSpamPrompt : function(proj_id) {
    var pop = PopUpMgr.add('pop');
    var a = new Ajax.Request('/index.php/project/reportSpamPrompt?proj_id='+proj_id, {
      method : 'get',
      onSuccess : function(transport) {
        PopUpMgr.update(pop, transport.responseText);
      }
    });
  },
  
  reportSpam : function( proj_id ) {
    	var reason = '';
    	if ($('reason1') && $('reason1').checked == true) reason = $F('reason1');
    	if ($('reason2') && $('reason2').checked == true) reason = $F('reason2');
    	if ($('reason3') && $('reason3').checked == true) reason = $F('reason3');
      
      var paramStr = $H({
        proj_id  : proj_id,
        reason   : reason,
        comments : $F('spamReason')
      }).toQueryString();
      
      $('reportSpamButton').replace('<div style="color:#fff;">Sending</div>');
      
    	var a = new Ajax.Request('/index.php/project/reportSpam', {
    		method : 'post',
        parameters : paramStr,
    		onComplete : function (transport) {
           PopUpMgr.update(PopUpMgr.getInstance('pop'), transport.responseText);
    		}
    	});
  },
  
  loadViewProject : function() { 
    
    // preload tool dropdown images
    var toolImg = new Image();
    toolImg.src = 'http://behance.vo.llnwd.net/projects/toolsOn.png';
    var infoImg = new Image();
    infoImg.src = 'http://behance.vo.llnwd.net/projects/projectInfoOn.png';
    
    
    if( Prototype.Browser.IE ) {
      var obj = window;
      var ev  = 'load';
    } else {
      var obj = document;
      var ev  = 'dom:loaded';
    }
    
    Event.observe(obj, ev, function(e){ 
     
      //tool image mouseovers
      $('proj-tools-img','proj-info-img').each(function(el) {
        el.observe('mouseover', function(e) {
          el.src = el.src.replace('Off.gif','On.gif');
        });
      });

      //tool image mouseouts
      $('proj-tools-img','proj-info-img').each(function(el) {
        el.observe('mouseout', function(e) {
          el.src = el.src.replace('On.gif','Off.gif');
        });
      });

      // listeners to open and close info menus
      $$('html')[0].observe('mousemove', function( event ) { Project.info( event ); } );
      $$('html')[0].observe('mousemove', function( event ) { Project.tools( event ); } );
      if ($('projOwners')) $$('html')[0].observe('mousemove', function( event ) { Project.projOwners( event ); } );
      
      ViralIcon.init();
      ProjectFish.init();

    }); 
  },
  
  postComment : function( proj_id ) {
    validation = new ValidationMgr();
    validation.add('comment','Generic',$H({required:1}));
    validation.add('add_comment_failure','Generic');
    var validForm = validation.validate();
    
    if (!validForm) { return false; }
    
    var paramStr = $H({
      proj_id : proj_id,
      comment : $F('comment')
    }).toQueryString();
    $('commentError').update();
    
    $('post-comment-button').hide();
    $('post-comment-sending').show();

    var a = new Ajax.Request('/index.php/project/postComment', {
      method : 'post',
      parameters : paramStr,
      onSuccess : function(transport) {
        var json = jsonTransport(transport);
        if( json.status == 'fail' ) {
          validation.handleExtendedErrors(json);
        } 
        
        if (json.status == 'success') {
          $('commentsAjax').update(json.comments);
          $('comment').value = '';
        }
        
        $('post-comment-button').show();
        $('post-comment-sending').hide();
      }
    });
    
    return false;
  },
  
  pageComments : function(proj_id, page) {
    var a = new Ajax.Request('/project/comments', {
      method : 'get',
      parameters : 'proj_id='+proj_id+'&page='+page,
      onComplete : function(transport) {
        $('commentsAjax').update(transport.responseText);
      }
      
    });
  },
  
  deleteCommentPop : function(cmt_id) {
    var pop_instance = PopUpMgr.add();
    var a = new Ajax.Request('/index.php/project/deleteCommentPop', {
      method	    : 'post',
      parameters  : 'comment_id='+cmt_id,
      onSuccess   : function(transport) {
        PopUpMgr.update(pop_instance, transport.responseText); 
      }
    });
  },
  
  deleteComment : function(cmt_id) {
    var pop_instance = PopUpMgr.add();
    var a = new Ajax.Request('/index.php/project/deleteComment', {
      method	    : 'post',
      parameters  : 'comment_id='+cmt_id,
      onSuccess   : function(transport) {
        $('commentsAjax').update(transport.responseText);
        PopUpMgr.removeAll();
      }
    });
  },
  
  shareFeedbackPrompt : function(proj_id) {
    var pop_instance = PopUpMgr.add();
    var a = new Ajax.Request('/index.php/project/shareFeedbackPrompt?proj_id='+proj_id, {
      method	    : 'get',
      onSuccess   : function(transport) {
        PopUpMgr.update(pop_instance, transport.responseText);
      }
    });
  },
  
  updateOtherOwner : function(proj_id,owner_id,page) {
    var page   = (page) ? page : 1;
    var params = $H({});
    
    params.set('proj_id',proj_id);
    params.set('owner_id',owner_id);
    params.set('page',page);
    
    var paramStr = params.toQueryString();
    
    new Ajax.Request('/index.php/project/updateOtherOwner', {
      parameters : paramStr,
      onComplete : function(transport) {
        var myJSON = jsonTransport(transport);
        $('other-owners-inner').update(myJSON.otherOwners);
        $('other-projects').update(myJSON.otherProjects);
        ProjectFish.init();
      }
    });
  },
  
  addOwnersToWatchlistPrompt : function(proj_id) {
    var pop_instance = PopUpMgr.add();
    var a = new Ajax.Request('/index.php/creative/addOwnersToWatchlistPrompt?proj_id='+proj_id, {
      onSuccess : function(transport) {
        PopUpMgr.update(pop_instance, transport.responseText);
      }
    });
  },
  
  addOwnersToWatchlist : function(proj_id) {
    var pop_instance = PopUpMgr.add();
    var a = new Ajax.Request('/index.php/creative/addOwnersToWatchlist', {
      method : 'post',
      parameters : 'proj_id='+proj_id,
      onSuccess : function(transport) {
        PopUpMgr.update(pop_instance, transport.responseText);
      }
    });
  },
  
  addProjectToCollectionPrompt : function(proj_id) {
    var pop_instance = PopUpMgr.add();
    var a = new Ajax.Request('/index.php/creative/addProjectToCollectionPrompt?proj_id='+proj_id, {
      onSuccess : function( transport ) {
        var json = jsonTransport(transport);
        PopUpMgr.update(pop_instance, json.html);
        collections = new DropdownList('collections', $('collections_field'), { 
          onToggle : function() {
            if (collections._selection_items.length == 0) {
              $('collections_text').hide();
            } else {
              $('collections_text').show();
            }
            $('add-new-collection').hide();
            $('collections_selections_wrap').show();
            $('save-collections').show();
            PopUpMgr.position(pop_instance);
          }
        });
        $('collections_selections_wrap').insert({top:$('collections_text')});
        
        eval(json.js);
        
        collections.save = function(proj_id) {
          var validation = new ValidationMgr();
          validation.add('delim_collections','Generic');
          validation.add('save_collections_failure','Generic');
          var validForm = validation.validate();
          
          if (!validForm) { return; }
          
          $('save-collection-buttons').hide();
          $('save-collection-saving').show();
          
          var params = $H({
            proj_id : proj_id,
            delim_collections : collections.getDelimited()
          });
          
          PopUpMgr.position(PopUpMgr.getInstance('pop'));
          
          var a = new Ajax.Request('/index.php/creative/saveProjectCollections', {
            parameters : params.toQueryString(),
            onComplete : function(transport) {
              var json = jsonTransport(transport);
              
              
              
              if (json.valid == 'no') {
                $('save-collection-buttons').show();
                $('save-collection-saving').hide();
                validation.handleExtendedErrors(json);
                PopUpMgr.position(PopUpMgr.getInstance('pop'));
                return;
              }
              
              if (json.valid == 'yes') {
                PopUpMgr.removeAll();
              }
              
            }
          });
        };
        
        collections.openNew = function() {
          $('add-new-collection').show();
          $('collections_selections_wrap').hide();
          $('save-collections').hide();
          $('new_collection_name').focus();
          $('collections_field').value='new'; //override blur
          PopUpMgr.position(pop_instance);
        };
        
        collections.createNew = function() {
          var validation = new ValidationMgr();
          validation.add('new_collection_name','Generic',$H({required:1,border_width:2}));
          validation.add('new_collection_failure','Generic');
          var validForm = validation.validate();
          
          if (!validForm) { return; }
          
          $('create-collection-buttons').hide();
          $('create-collection-creating').show();
          
          var params = $H({new_collection_name:$F('new_collection_name')});
          
          var a = new Ajax.Request('/index.php/creative/createCollection', {
            parameters : params.toQueryString(),
            onComplete : function(transport) {
              var json = jsonTransport(transport);
              
              $('create-collection-buttons').show();
              $('create-collection-creating').hide();
              
              if (json.valid == 'no') {
                validation.handleExtendedErrors(json);
                return;
              }
              
              if (json.valid == 'yes') {
                collections.makeForeignSelection(json.id,$F('new_collection_name'));
                collections.cancelNew();
              }
              
            }
          });
          
        };
        
        collections.cancelNew = function() {
          $('new_collection_name').value = '';
          $('add-new-collection').hide();
          $('collections_selections_wrap').show();
          $('save-collections').show();
          collections.refocusField();
          PopUpMgr.position(pop_instance);
        };
      }
    });
  },
  
  updateOtherProj : function(proj_id, page, owner_id) {
    var params = $H({});
    params.set('proj_id',proj_id);
    params.set('page',page);
    params.set('owner_id',owner_id);
    var paramStr = params.toQueryString();
    var a = new Ajax.Request('/index.php/project/updateOtherProj', {
      parameters : paramStr,
      onComplete : function(transport) {
        var myJSON = jsonTransport(transport);
        $('other-projects').update(myJSON.otherProjects);
        ProjectFish.init();
      }
    });
  }

} // Project

var ViralIcon = {
	over : function(evt) {
		var el = Event.element(evt);
		if (Prototype.Browser.IE) $(el).setStyle({opacity:'1',filter:'alpha(opacity=100)'});
		var viralWrap = document.createElement('div');
		viralWrap.className = 'viralWrap';
		viralWrap.id = 'viralWrap';
		document.body.appendChild(viralWrap);
		var viralTxt = document.createElement('div');
		viralTxt.className = 'viralTxt';
		viralTxt.id = 'viralTxt';
		$('viralWrap').appendChild(viralTxt);
		$('viralTxt').update(el.alt);
		$('viralWrap').clonePosition($('viral-icons'), {setHeight: false, offsetTop: -29});
		
	},
	
	out : function(evt) {
		var el = Event.element(evt);
		if (Prototype.Browser.IE) $(el).setStyle({opacity:'.65',filter:'alpha(opacity=65)'});
		if ($('viralWrap')) $('viralWrap').remove();
	},
  
  init : function() {
    if (!$('viral-icons')) { return; }
    $('viral-icons').select('img').each(function(el) {
      if (Prototype.Browser.IE) $(el).setStyle({opacity:'.65',filter:'alpha(opacity=65)'});
      
      ViralIcon.over = ViralIcon.over.bindAsEventListener(ViralIcon);
      Event.observe($(el), 'mouseover', ViralIcon.over);
      ViralIcon.out = ViralIcon.out.bindAsEventListener(ViralIcon);
      Event.observe($(el), 'mouseout', ViralIcon.out);
    });	
  }
} // ViralIcon
ProjectFish = {
  _initialized : false,
  setZoom : function (img, dir, width, height, margin, zIndex, delay) {
    var imgID = img.id;
    var txtID = imgID+'TxtWrap';
    var fishID = imgID+'Fish';
    $(txtID).style.display='block';


    setTimeout(function () {if (img.dir == dir) {
        img.style.width = width;
        img.style.height = height;
        img.style.margin = margin;
        img.style.zIndex = zIndex;
        $(fishID).style.zIndex = zIndex;

        var roundHeight = parseInt(height.replace('px', ''));
        roundHeight = Math.round(roundHeight);

        $(txtID).clonePosition(imgID, { 'setHeight' : false, 'offsetTop' : roundHeight});
        var intWidth = $(imgID).getWidth();

        var txtInID = imgID+'Txt';
        $(txtInID).style.fontSize = (intWidth/125) +'em';
      }
    }, delay);
  },

  larger : function(img, width, height) {
    img.dir = "rtl";
    now = parseInt(img.style.zIndex);
    for (i = now + 1; i <= 10; i++) {
      w = width * (10 + i) / 20 + "px";
      h = height * (10 + i) / 20 + "px";
      m = - i + "px 0 0 " + - width * i / 40 + "px";
      this.setZoom(img, "rtl", w, h, m, i, 30 * (i - now));
    }
  },

  smaller : function(img, width, height) {  
    img.dir = "ltr";
    now = parseInt(img.style.zIndex);
    for (i = now - 1; i >= 0; i--) {
      w = width * (10 + i) / 20 + "px";
      h = height * (10 + i) / 20 + "px";
      m = - i + "px 0 0 " + - width * i / 40 + "px";
      this.setZoom(img, "ltr", w, h, m, i, 30 * (now - i));
    }
    var imgID = img.id;
    var txtID = imgID+'TxtWrap';
    $(txtID).style.display='none';

  },
  
  init : function() {
    if (!$('other-projects') || this._initialized) { return; }
    var fishes;
    if (typeof(correctPNG) == 'undefined') {
      fishes = 'img.fish';
    }
    else {
      fishes = 'span.fish';
      
      // if ie6 and PNGs haven't finished converting
      if ($('other-projects').select('img.fish').length > 0) {
        setTimeout("ProjectFish.init()",100);
        return;
      }
    }
    
    $('other-projects').select(fishes).each(function(el){
      
      
      $(el).setStyle({
        width   : '58px',
        height  : '45px',
        display : 'block',
        zIndex  : 0
      });
      
      var imgID = el.id;
      var txtID = imgID+'TxtWrap';
      $(txtID).style.top = ($(el).cumulativeOffset()[1]+45)+'px';
      Event.observe(el, "mouseout", function(evt){
        ProjectFish.smaller(el, 115, 90);
      });
      Event.observe(el, "mouseover", function(evt){
        
        ProjectFish.larger(el, 115, 90);
      });
    });	
    this._initialized = true;
  }

}
