FPS Camera Is Flipping

I’ve been working on my own FPS controller and I am working on a flip mechanism (as in parkour). I am trying to get the camera to flip with the player, but I feel like my MouseLook script is messing it up and flipping the camera over once it reaches a certain angle.

var player : Transform;
var lookSensitivity : float = 5.0;//How sensitive the mouse is.
var lookSmoothDamp : float = 0.1;//This is used to smooth out the mouse looking. 
var minXView : float = 80;//The angle that represents how low the camera can look on the x-axis.
var maxXView : float = 80;//The angle that represents how high the camera can look on the y-axis.

@HideInInspector
var currentAimRacio : float = 1;//Our aim ratio's current value. It has to be between 0 and 1.
@HideInInspector
var yRotation : float;//We can set the camera's y rotation to be equal to this float and we can make this float equal to a float returned from a smooth damp function. This allows for the camera to have smooth movement.
@HideInInspector
var xRotation : float;//We can set the camera's x rotation to be equal to this float and we can make this float equal to a float returned from a smooth damp function. This allows for the camera to have smooth movement.
@HideInInspector
var currentYRotation : float;//Our camera's current rotation on the Y axis.
@HideInInspector
var currentXRotation : float;//Our camera's current rotation on the X axis.
@HideInInspector
var yRotationV : float;//Mathf.SmoothDamp needs a variable for its velocity. We just have to supply it, the variable isn't given a default value.
@HideInInspector
var xRotationV : float;//Mathf.SmoothDamp needs a variable for its velocity. We just have to supply it, the variable isn't given a default value.

function Update () 
{
    yRotation += Input.GetAxis("Mouse X") * lookSensitivity;
    xRotation -= Input.GetAxis("Mouse Y") * lookSensitivity;
   
    xRotation = Mathf.Clamp(xRotation, -minXView, maxXView);
   
    currentXRotation = Mathf.SmoothDamp(currentXRotation,xRotation,xRotationV,lookSmoothDamp);
    currentYRotation = Mathf.SmoothDamp(currentYRotation,yRotation,yRotationV,lookSmoothDamp);
   
    transform.rotation = Quaternion.Euler(player.localEulerAngles.x + currentXRotation, currentYRotation, player.localEulerAngles.z);
}

This works upside-down too: http://forum.unity3d.com/threads/smooth-mouse-look-modified-for-the-wiki.262068/

Thanks, however I’m trying do do this in Javascript with my current script. Is there something simple I can do? Like make the movement added onto something. Right now the mouse looking euler angles is based on the player local euler angles. I’m not sure if that why the flipping occurs. I’ll repaste the part of the code that shows where i think the problem is originating from.

transform.rotation = Quaternion.Euler(player.localEulerAngles.x + currentXRotation, currentYRotation, player.localEulerAngles.z);