-//
-//  FlipMultipleViews.swift
-//  The Report
-//
-//  Created by jibeex on 1/18/16.
-//  Copyright © 2016 Captain Dash. All rights reserved.
-//
 
 import UIKit
 

        }
    }
    
    private func rotateToSideAtIndex(radial:CGFloat, index:Int, duration:Double, infinitely:Bool){
        
        self.multipleLayerView?.displayLayerAtIndex(index)
        UIView.animateWithDuration(duration, delay: 0, options: UIViewAnimationOptions.CurveLinear, animations: { () -> Void in
            self.layer.transform = CATransform3DRotate(self.layer.transform, radial, 0, 1, 0)
            }) { (complete) -> Void in
                if infinitely{
                    if self.activated{
                        self.rotateToSideAtIndex(CGFloat(M_PI), index: index + 1, duration: self.durationForOneTurnOver, infinitely: true)
                    }
                    else{
                        self.rotateToSideAtIndex(CGFloat(M_PI_2), index: 0, duration: self.durationForOneTurnOver/2, infinitely: false)

                    }
                }
                
                
        }
        
    }

    func startAnimation(){
        if !activated{
            activated = true
            rotateToSideAtIndex(0, duration: durationForOneTurnOver/2, goingIn: false, delay: 0.1)
        }
    }
    
