
var preload1 = new Image();
preload1.src = "img/firstframe.png";
var preload2 = new Image();
preload2.src = "img/endframe.png";

var isIphone = false;

if((navigator.userAgent.match(/iPhone/i))){
	isIphone = true;
}

$(document).ready(function() {
	
	
	function initializeLoading() {
		var loadingCanvas = document.getElementById("loading1");
		if (loadingCanvas && loadingCanvas.getContext) {
			var context = loadingCanvas.getContext('2d');
			if (context) {
				var width = loadingCanvas.width;
				var height = loadingCanvas.height;
				context.globalAlpha = 0.4;
				context.fillStyle = '#f8ec17';
				context.beginPath();
				context.arc(width * .5, height * .5 - .5, 96, 0, Math.PI, true);
				context.fill();
				context.closePath();
				context.fillStyle = '#00a9f6';
				context.beginPath();
				context.arc(width * .5, height * .5 - .5, 96, Math.PI, 0, true);
				context.fill();
				context.closePath();
				context.globalAlpha = 1.0;
			}
		}
	}
	
	function drawLoading() {
		loadingCanvas = document.getElementById("loading2");
		if (loadingCanvas && loadingCanvas.getContext) {
			var context = loadingCanvas.getContext('2d');
			if (context) {
				loadingCanvas.width = loadingCanvas.width;
				width = loadingCanvas.width;
				height = loadingCanvas.height;
				context.fillStyle = '#fff';
				context.beginPath();
				context.arc(width * .5, height * .5 - .5, 48, 0, Math.PI * 2, true);
				context.fill();
				context.closePath();
				context.fillStyle = '#000';
				context.font = "normal 18px AlexandriaBold";
				context.textBaseline = 'middle';
				var loadString = "Loading";
				for (var i = numPeriods % 4; i > 0; i--) {
					loadString += ".";
				}
				context.fillText(loadString, width * .5 - 40, height * .5);
				numPeriods++;
			}
		}
	}

	function rotateLoading() {
		currentRotation += 360;
		$("#loading1").css("-webkit-transform", "rotate(" + currentRotation.toString() + "deg)");
		$("#loading1").css("-moz-transform", "rotate(" + currentRotation.toString() + "deg)");
	}

	function animateLoading() {
		// alert("animate");
		animating = true;
		clearInterval(loaderRotation);
		clearInterval(loaderDraw);
		$("#loading1").css("-webkit-transform", "rotate(0deg)");
		$("#loading1").css("-moz-transform", "rotate(0deg)");
		rotateLoading();
		drawLoading();
		loaderRotation = setInterval(rotateLoading, 2000);
		loaderDraw = setInterval(drawLoading, 1000);
		$("#loadingCircles").animate({scale:'1'}, 500, "easeOutBack");
		$(".loadingBG").css('opacity', '0.4');

	}
	
	function stopLoadingAnim() {
		animating = false;
		clearInterval(loaderRotation);
		clearInterval(loaderDraw);
		$("#loadingCircles").animate({scale:'0'}, 500, "easeInBack");
		$(".loadingBG").css('opacity', '0');
	}
	
	var numPeriods = 0;
	var currentRotation = 0;
	var loaderRotation;
	var loaderDraw;
	
	
	$("#loadingCircles").scale(0);	
	initializeLoading();

	var videoSrcMP4 = ["video/tripta_baseline_3.0.mp4", "video/lnoir_3.0_baseline.mp4", "video/tween_3.0_baseline.mp4", "video/fv_baseline_3.0.mp4"];
	var videoSrcOGG = ["video/Tripta_570.ogv", "video/Lnoir_570.ogv", "video/tween_570.ogv", "video/flashvacancy_570.ogv"];
	var webLinks = ["http://tripta.com","http://lnoir.com","http://tween.as", "http://www.flashvacancy.com"];
		
	var logoForward = document.getElementById("logoForward");
	var logoReverse = document.getElementById("logoReverse");
	
	var prevFeature;
	var activeFeature = $(".featureColumn section")[0];
	
	var video = document.getElementById("featureVideo");
	var currentVideo = 0;
	var videoPaused = false;
	var videoPlaying = false;
	var videoLoading = false;
	var videoLoaded = false;
	var dataLoaded = 0;
	var totalData = 0;
	
	var bgPos1 = 0;
	var bgPos2 = 0;
	
	var fullscreen = false;
	var firstrun = true;
	
	var animating = false;
	
	
	
	var flag =0;
	
	
	function introAnimation() {
		activeFeatureTransIn(activeFeature);
		setTimeout(function() {
				$(".vr").css("height", "100%");
			}, 250);

		setTimeout(function() {
				$("#viewWebsite").animate({"height": "98px"}, 500, "easeOutBack", function() {
					$("#viewWebsite a").animate({"opacity" : "1", "top" : "49px"}, 400, "easeOutBack");
				});
			}, 500);
	}
	
	function introAnimationIphone() {
		
		$("#featureDescription p").html($(".featureActive .content p").html());
		$("#featureDescription p").animate({"left":0, "opacity":"1"},500);
		
		
	
	}
		
	// bubbles
	
	function bounceBubble() {
		var target = $(this);
		var timing = 100;
		var damping = 5;
		var bounce = [0.98, 1.07, 0.9, 1.05, 0.95, 1.02, 0.98, 1];

		setTimeout(function() {
			doBounce($(target).find(".blue")[0], bounce, 0, timing, damping);
		}, 100);
		setTimeout(function() {
			doBounce($(target).find(".yellow")[0], bounce, 0, timing, damping);
		}, 200);
		doBounce($(target).find(".red")[0], bounce, 0, timing, damping);
	}
	
	function doBounce(object, points, iteration, delay, delta) {
		if (iteration < points.length) {
			setTimeout(function() {
				$(object).css("-webkit-transform", "scaleX(" + points[iteration].toString() + ") scaleY(" + points[iteration].toString() + ")");
				$(object).css("-o-transform", "scaleX(" + points[iteration].toString() + ") scaleY(" + points[iteration].toString() + ")");
				$(object).css("-moz-transform", "scaleX(" + points[iteration].toString() + ") scaleY(" + points[iteration].toString() + ")");
			}, delay * iteration);
			doBounce(object, points, iteration + 1, delay + delta, delta);
		}		
	}
	
	// logo
	
	function playLogoForward() {
		replaceFirstFrame();
		// alert(logoForward)
		logoForward.play();
	}

	function playLogoReverse() {
		replaceLastFrame();
		logoReverse.play();
	}
	
	function hideFirstFrame() {
		$("#firstFrame").show();
		$("#logoReverse").fadeOut(200, function() {
			logoReverse.currentTime = 0;
			logoReverse.pause();
		});
	}
		
	function replaceFirstFrame() {
		$("#logoForward").show();
		$("#firstFrame").hide();
	}

	function hideLastFrame() {
		$("#lastFrame").show();
		$("#logoForward").fadeOut(200, function() {
			logoForward.currentTime = 0;
			logoForward.pause();
		});

	}

	function replaceLastFrame() {
		$("#lastFrame").hide();
		$("#logoReverse").show();
	}
			
	function revealLogo() {
		$("#firstFrame").css("-webkit-transform", "scaleX(1) scaleY(1)");
		$("#firstFrame").css("-moz-transform", "scaleX(1) scaleY(1)");
		$("#firstFrame").css("-o-transform", "scaleX(1) scaleY(1)");
		setTimeout(playLogoForward, 1000);
	}
	
	// feature animations
	
	


	function switchFeature(featureIndex) {
		// alert(navigator.userAgent);
		stopVideo();
		currentVideo = featureIndex;
		// removeVideoEventListeners(video);
		$(video).css("opacity", "0");
		var video = $("#featureVideo").get(0); 
	
		var sources = video.getElementsByTagName("source");
		sources[0].src = videoSrcMP4[featureIndex];
		sources[1].src = videoSrcOGG[featureIndex];
		
		var newVideo = $("#videoPlayer video").clone().css("opacity", "0");
		$(newVideo).find("source").eq(0).attr("src", videoSrcMP4[featureIndex]);
		$(newVideo).find("source").eq(1).attr("src", videoSrcOGG[featureIndex]); 
		$("#viewWebsite").find("a").attr("href", webLinks[featureIndex]);
		
		$("#videoPlayer video").replaceWith(newVideo);
		
		video = document.getElementById("featureVideo");
		resetVideoState();
		
		animateLoading();
		prevFeature = activeFeature;
		activeFeature = $(".featureColumn section:eq("+ featureIndex + ")")[0];
		addVideoEventListeners(video);
		activeFeatureTransOut(prevFeature);
		setTimeout(function() {
			activeFeatureTransIn(activeFeature);
			$("#viewWebsite a").attr("href",webLinks[featureIndex]);
			
		}, 750);
		
	}
	
	function switchFeatureIphone(featureIndex) {
		stopVideo();
		currentVideo = featureIndex;
		activeFeature = $(".featureColumn section:eq("+ featureIndex + ")")[0];
		prevFeature = activeFeature;
		activeFeatureTransIniPhone(activeFeature, continueSwitch);
		$(video).attr("height", video.height.toString());
		
		$("#viewWebsite a").attr("href",webLinks[featureIndex]);
		
	}
	
	function continueSwitch() {
		// removeVideoEventListeners(video);
		$(video).css("opacity", "0");
		var video = $("#featureVideo").get(0); 
	
		var sources = video.getElementsByTagName("source");
		sources[0].src = videoSrcMP4[0];
		sources[1].src = videoSrcOGG[0];

		var newVideo = $("#videoPlayer video").clone();
		$("#videoPlayer video").eq(0).animate({"opacity":"0"},2000);
		
		$(newVideo).find("source").eq(0).attr("src", videoSrcMP4[0]);
		$(newVideo).find("source").eq(1).attr("src", videoSrcOGG[0]); 
		$("#videoPlayer video").eq(0).animate({"opacity":"1"},2000);
		
		
		$("#videoPlayer video").replaceWith(newVideo);

		
		video = document.getElementById("featureVideo");
		resetVideoState();
		
		animateLoading();
		
		
		addVideoEventListeners(video);
	}
	function featureClick() {
		
		if(!isIphone){
			
			switchFeature($(".featureColumn section").index($(this)[0]));
		}
		else{
			switchFeatureIphone($(".featureColumn section").index($(this)[0]));
		}
		
	}
	
	function resetVideoState(){
		var videoPaused = false;
		var videoPlaying = false;
		var videoLoading = false;
		var videoLoaded = false;
		var dataLoaded = 0;
		var totalData = 0; 
	}
	
	
	function activeFeatureTransIniPhone(activeFeature, callback) {
			var offset = $(".featureColumn section").index(activeFeature);
			// alert(offset);
			$("#featureDescription p").animate({"left":-30, "opacity":"0"},500);

			for (var i = 0; i < offset; i++) {
				$(".featureColumn").append($(".featureColumn section").eq(i).clone(true).removeClass("featureActive").css("top", 255 + 51 * i));
				
				videoSrcMP4.push(videoSrcMP4.shift());
				videoSrcOGG.push(videoSrcOGG.shift());
				// webLinks.push(webLinks.shift());

			}
			$(".featureColumn section").eq(i).addClass("featureActive");
			$(".featureColumn section").each(function() {
				var pos = $(".featureColumn section").index($(this));
				var finalY = $(this).position().top;
				var originalPos = finalY;
				var speed = 1;
				if (pos == 0) {
					finalY = -51;
				}
				else if (pos <= offset) {
					finalY = 51;
				}
				else {
					finalY -= 51 * offset
				}
								
				$(this).animate({"top": finalY}, (originalPos - finalY) / (.1 + .03 * offset) , "linear", function() {
					if (pos == offset) {
						$(this).animate({"top": 0}, 400, "linear", callback);
					}
					else if ($(this).position().top == 51 || $(this).position().top < 0) {
						$(this).remove();
						videoSrcMP4.splice[videoSrcMP4[i]];
						videoSrcOGG.splice[videoSrcOGG[i]];
						// webLinks.splice[webLinks[i]];
					}
				});
			});

			$("#featureDescription").html($(activeFeature).find(".content").find("p").html());
			$("#featureDescription p").animate({"left":0, "opacity":"1"},500, "linear");
			
		
	}

	function activeFeatureTransIn(featureObject) {
		$(featureObject).find(".background").animate({"width": "50%"}, 500, "easeOutCubic");
		$(featureObject).find(".content").css({"margin-left":"0", "opacity":"0", "left":"-20"}).find("p").css("color", "#fff");
		setTimeout(function() {
			$(featureObject).find(".content").animate({"opacity" : "1", "left" : "0"}, 500, "linear");
		}, 250);
	}
	
	function activeFeatureTransOut(featureObject) {
		$(featureObject).find(".content").animate({"opacity" : "0", "left" : "-20px"}, 500, "linear", resetFeatureContent);
		setTimeout(function() {
			$(featureObject).find(".background").animate({"width": "0px"}, 500, "easeInCubic");
		}, 250);

	}
	
	function resetFeatureContent() {
		$(this).parents(".activeFeature").removeClass("activeFeature");
		$(this).css({"margin-left":"193px", "opacity":"1", "left":"0"}).find("p").css("color", "#000");
		moveViewWebsite();
		
	}
	
	function moveViewWebsite() {
		$("#viewWebsite").animate({"top" : $(activeFeature).position().top.toString() + "px"}, 500, "easeInOutQuad");
		var up = $.inArray(activeFeature, $(".featureColumn section")) < $.inArray(prevFeature, $(".featureColumn section"))
		$("#viewWebsite a").animate({"top" : up ? "66px" : "0px"}, 250, "easeInQuad", function() {
			$("#viewWebsite a").animate({"top" : "49px"}, 400, "easeInOutQuad")
		});
	}
	
	
///////////// code for iphone v/s web browsers
	// var introAnim = introAnimation();
	// // var switchFeatures = switchFeature(featureIndex);
	// 
	// if(isIphone){
	// 	var introAnim = introAnimationIphone();
	// 	// var switchFeatures = switchFeatureIphone(featureIndex);
	// }
/////////////////////

	
	function removeVideoEventListeners(video) {
		video.removeEventListener("timeupdate", updateProgress, false);
		video.removeEventListener("ended", onEnded, false);
		video.removeEventListener("waiting", onWaiting, false);
		video.removeEventListener("ratechange", onWaiting, false);
		video.removeEventListener("pause", onPause, false);
		video.removeEventListener("error", onWaiting, false);
		video.removeEventListener("stalled", onWaiting, false);
		video.removeEventListener("emptied", onWaiting, false);
		video.removeEventListener("progress", onProgress, false);
		video.removeEventListener("playing", onPlaying, false);
		video.removeEventListener("loadedmetadata", onMeta, false);
		video.removeEventListener("canplay", onCanPlay, false);
		
	}
	
	function addVideoEventListeners(video) {
		video.addEventListener("timeupdate", updateProgress, false);
		video.addEventListener("ended", onEnded, false);
		video.addEventListener("waiting", onWaiting, false);
		video.addEventListener("ratechange", onWaiting, false);
		video.addEventListener("pause", onPause, false);
		video.addEventListener("error", onWaiting, false);
		video.addEventListener("stalled", onWaiting, false);
		video.addEventListener("emptied", onWaiting, false);
		video.addEventListener("progress", onProgress, false);
		video.addEventListener("playing", onPlaying, false);
		video.addEventListener("loadedmetadata", onMeta, false);
		video.addEventListener("canplay", onCanPlay, false);

	}
	
	function onLoadStart(){
		
	}
	
	function onLoadedData(e){
	
		
	}
	
	function onPause(e){

			
			// alert("paused");

	}
	
	function onAborted(){
	
	}
	function onSeeking(){
		
	}
	
	
	function onPlaying(){
		stopLoadingAnim();
		
	}
	
	function onProgress(e)
	{
		
	
		
		if((e.loaded / e.total) >= 0.95)
		{
			stopLoadingAnim();
		}

		if(!video.pause)
		{
			changePlayControlToPause()
			playVideo();
		}
	}
	
	function onCanPlay(){
		$("#videoOverlay div").css("opacity", "0");
		$("#videoOverlay canvas").css("-webkit-transform", "scaleX(0) scaleY(0)");
		$("#videoOverlay canvas").css("-moz-transform", "scaleX(0) scaleY(0)");
		$("#videoOverlay canvas").css("-o-transform", "scaleX(0) scaleY(0)");
		if (fullscreen) {
			$("#videoControls").animate({"opacity": "1", "top":"95%"}, 500, "easeOutBack")
		}
		else {
			$("#videoControls").animate({"opacity": "1", "top":"105%"}, 500, "easeOutBack")
		}
		
		if(!videoPaused)
		{
			changePlayControlToPause();
			playVideo();
		}
		
		
	}
	
	function onWaiting(e) {

		animateLoading();
		switch (e.type) {
			case "error" :
		
				break;
			case "stalled" :
					
					animateLoading();
					pauseVideo();
		
				break;
			case "waiting" :
				pauseVideo();
			default:
				break;
		}

	}
	function meta(){
		var height = ($("#videoPlayer video")[0].videoHeight / $("#videoPlayer video")[0].videoWidth)*570;
		// alert(height);
		$(video).attr("height", video.height.toString());
		$("#videoPlayer").css("height", height);
		$(".loadingCanvas").attr("height", video.height.toString()).css("margin-top", (-video.height * .5).toString() + "px");
		initializeLoading();
		if (animating) {
			animateLoading();
		}
		setTimeout(function() {
			$("#videoPlayer video").css("opacity", "1");
			
		}, 1500);
		
	}
	function metaIphone(){
		$(video).attr("height", video.height.toString());
			setTimeout(function() {
				$("#videoPlayer video").css("opacity", "1");

			}, 1500);
		
		
	}
	function onMeta() {
		if(!isIphone){
			
			meta();
		}
		else{
			metaIphone();
		}

	}
	
	
	
	function onEnded() {
		currentVideo = currentVideo == $(".featureColumn section").length - 1 ? 0 : currentVideo + 1;
		
		if(!isIphone){
			switchFeature(currentVideo);
		}
		else{
			switchFeatureIphone(currentVideo);
		}
		
	}
	
	function updateProgress() {
		
		video = document.getElementById("featureVideo");
	
		$("#played").css("width", (100 * (video.currentTime-0) / video.duration).toString() + "%");


	}
	
	function updateLoadingProgress(loaded){
		
		
	}
	
	function changePlayControlToPlay(){
		if($("#play").hasClass("pausebtn")){
			$("#play").removeClass("pausebtn").addClass("playbtn");
		}
	}
	function changePlayControlToPause(){
		if($("#play").hasClass("playbtn")){
			$("#play").removeClass("playbtn").addClass("pausebtn");
		}
	}
	
	
	function stopVideo() {
	
		pauseVideo();
	
	}
	
	function playVideo() {
		
		$("#featureVideo").css("opacity","1");
	
		if(videoPlaying){
			changePlayControlToPause();
		}
				
				video.play();
	
		
	}
	
	function pauseVideo(){
		if(videoPaused){
			changePlayControlToPlay();
			stopLoadingAnim();
		}
		

				video.pause();

	}
	
	// about section animations
	
	function openAbout() {
		var target = $(this)[0];
		$(target).find(".aboutLine").css({"top": "40px", "border-width" : "1px", "height": "2px"});
		////
		//iphone
		////

		$(target).css({"-moz-background-size": "60% auto"});
		$(target).css({"-o-background-size": "60% auto"});
		
		if(!isIphone){
			$(target).css({"-webkit-background-size": "60% auto", "background-position" : "50% 40%"});
			
		}
		else{
			$(target).css({"-webkit-background-size": "60% auto", "background-position" : "50% 25%"});
			
		}
			
		////
		//iphone
		////
		target.fade = setTimeout(function() {
			$(target).find("p").css("opacity", "1");
		}, 250);
		
		
		var vid = $(this).find("video")[0];
		$(this).find("video").animate({"opacity":"1"},200);
			
			vid.currentTime = 0;
			vid.play();
	}

	
	function closeAbout() {
		var target = $(this)[0];
		clearTimeout(target.fade);
		$(target).find("p").css("opacity", "0");
		setTimeout(function() {
			$(target).find(".aboutLine").css({"top": "0px", "border-width" : "2px", "height": "0px"});
			////
			//iphone
			////
			if(!isIphone){
				$(target).css({"-webkit-background-size": "100% auto", "background-position" : "50% 75%"});

			}
			else{
				$(target).css({"-webkit-background-size": "100% auto", "background-position" : "50% 50%"});

			}

			$(target).css({"-moz-background-size": "100% auto"});
			$(target).css({"-o-background-size": "100% auto"});
		}, 250);
	
	
		var vid = $(this).find("video")[0];
		$(this).find("video").animate({"opacity":"0"},200);
		vid.pause();
		
	}
	
	// other
	
	function submitOver() {
		$("#submit").find(".red").css({"border-color" : "#00f"});
	}
	
	function submitOut() {
		$("#submit").find(".red").css({"border-color": "#f00", "left": "-2px"});
		$("#submit").find(".blue").css({"border-color": "#0ff", "left": "2px"});
	}
	
	function moveFooter() {
		bgPos1 += 25;
		bgPos2 -= 25;
		// alert(bgPos1.toString() + "% 0%, " + bgPos2.toString() + "% 0%");
		$("#footerBG").css("background-position", bgPos1.toString() + "px 0px, " + bgPos2.toString() + "px 0px");
	}
	

	// start	
	
	$("#firstFrame").mouseenter(playLogoForward);
	$("#lastFrame").mouseleave(playLogoReverse);
	logoForward.addEventListener('ended', hideLastFrame, false);
	logoReverse.addEventListener('ended', hideFirstFrame, false);
	
	if(!isIphone){
		introAnimation();
	}
	else{
		introAnimationIphone();
	}
	
	setTimeout(revealLogo, 1000);
			
	$(".bubbles").mouseenter(bounceBubble);
	
	// logoForward.addEventListener("canplaythrough", playLogoForward, false);
	// logoForward.load();
	// setTimeout(playLogoForward, 400);	
	
	addVideoEventListeners(video);

	// video.addEventListener("waiting", onWaiting);
	
 	if (!Modernizr.input.placeholder){
      $("#name").val("Name");
      $("#email").val("Email");
    }

	$(".featureColumn section").click(featureClick);
	

	$("#about section").mouseenter(openAbout);
	$("#about section").mouseleave(closeAbout);
	
	
	// validation
	
	$("form input").focus(function() {
		$(this).addClass("invalid");
	});
	
	$("form textarea").focus(function() {
		if ($(this).val() == "Enquiry") {
			$(this).val("");
		}
		$(this).addClass("invalid");
	});
	
	$("form textarea").blur(function() {
		if ($(this).val() == "") {
			$(this).val("Enquiry");
		}
	});
	
	$("form textarea").keyup(function() {
		if ($(this).val().length > 0) {
			$(this).addClass("valid").removeClass("invalid");
		}
		else {
			$(this).removeClass("valid").addClass("invalid");
		}
	});
	
	$("#name").keyup(function() {
		var re = /^[^\d]*$/;
		if (re.test($(this).val())) {
			$(this).addClass("valid").removeClass("invalid");
		}
		else {
			$(this).removeClass("valid").addClass("invalid");
		}
	});
	
	$("form #email").keyup(function() {
		var re = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
		if (re.test($(this).val())) {
			$(this).addClass("valid").removeClass("invalid");
		}
		else {
			$(this).removeClass("valid").addClass("invalid");
		}
	});
	
	$(".go").click(function() {
		// alert("submit");
		var Name = $("#name").val();
		var Email = $("#email").val();
		var Enquiry = $("#enquiry").val();
		var validated = $("#enquiry").hasClass("valid") && $("#name").hasClass("valid") && $("#email").hasClass("valid");
		if(validated)
		{
			
			$.get("mail.php", { name: Name, email: Email, enquiry: Enquiry },
			   function(data){
					if(data == true)
					{
						$("#contactForm .formTitle").html("Thank You.");
						document.contactForm.reset();					
					}
					else{
						$("#contactForm .formTitle").html("Error occured.Please try again.")

					}
			     
			   });
		}
		else
		{
			if($("#name").hasClass("invalid"))
			{
				$("#name").focus();
			}
			else if($("#email").hasClass("invalid"))
			{
				$("#email").focus();
			}
			else if($("#enquiry").hasClass("invalid"))
			{
				$("#enquiry").focus();
			}
		}

	});
	
	$(".go").hover(submitOver, submitOut);
		
	setInterval(moveFooter, 995);
		
	// video controls
	
	$("#fullscreen").click(function() {
		fullscreen = !fullscreen;
		if (fullscreen) {
			$("#videoPlayer").addClass("fullscreen").css("height", "");
			$("body").css("overflow", "hidden");
			$("#videoControls").animate({"opacity": "1", "top":"95%"}, 500, "easeOutBack")
		}
		else {
			$("#videoPlayer").removeClass("fullscreen");
			$("body").css("overflow-y", "auto");
			$("#videoControls").animate({"opacity": "1", "top":"105%"}, 500, "easeOutBack")
		}
		// video.removeEventListener("canplaythrough", playVideo);
		// video.removeEventListener("timeupdate", updateProgress);
		// video.removeEventListener("ended", onEnded);
		// video.removeEventListener("loadedmetadata", );
		// video.pause();
		// var newVideo = $("#videoPlayer video").clone();
		// $(newVideo).find("source").attr("src", videoSrc[currentVideo]);
		// $("#videoPlayer video").replaceWith(newVideo);
		// video = document.getElementById("featureVideo");
		// if (video.readyState >= 4) {
			if (!fullscreen)
				onMeta();
		// 	video.play();
		// }
		// else {
		// 	video.addEventListener("canplaythrough", playVideo);
		// 	if (!fullscreen)
		// 		video.addEventListener("loadedmetadata", onMeta);
		// }
		// video.addEventListener("timeupdate", updateProgress);
		// video.addEventListener("ended", onEnded);
	});
	
	$("#play").click(function(e) {
		// alert(video.paused);

		if (!videoPaused) {
			// videoPaused=true;
			// alert(e.which);
			
			videoPaused=true;
			videoPlaying = false;
			pauseVideo();
		}
		else {
			// videoPaused=false;
			
			videoPaused=false;
			videoPlaying = true;
			playVideo();
		}
		// changePlayControl();
		
		
	});
	
	$("#volume").click(function() {
		video = document.getElementById("featureVideo");
		video.muted = !video.muted;
	});
	
	$("#progress").click(function(e) {
		video.currentTime = video.duration * (e.pageX - $(this).offset().left) / $(this).innerWidth();
	});

	


});
