class Admin::PortfolioImagesController < ApplicationController
  layout "admin"
  
  before_filter :authenticate_admin!
  
  def index
    
    @portfolio_images = PortfolioImage.all
  end


  def show
    @portfolio_image = PortfolioImage.find(params[:id])

  end


  def new
    @portfolio_image = PortfolioImage.new
  
  end

  def edit
    @portfolio_image = PortfolioImage.find(params[:id])
  
  end

  def create
  	@portfolio_image = PortfolioImage.new(params[:portfolio_image])
  
    if @portfolio_image.save
       
      if params[:portfolio_id]
        @images = Portfolio.find(params[:portfolio_id]).images
      else  
       @images = PortfolioImage.order("created_at DESC").all
     end
  	else
  		render :action => "new" 
  	end
  end

  def update
  	@portfolio_image = PortfolioImage.find(params[:id])
    
    if @portfolio_image.update_attributes(params[:portfolio_image])
      redirect_to admin_portfolio_images_path
          
  	else
  		render :action => "edit" 
  	end
    
  end
  		


  def destroy
  	@portfolio_image = PortfolioImage.find(params[:id])
	  @portfolio_image.destroy
    
  end
  
	def rotate
		deg = params[:direction] == "right" ? -90 : 90
		
		@portfolio_image = PortfolioImage.find(params[:id])
		@portfolio_image.rotate(deg)
	end



end
