var vid = document.getElementById("videobox");
    function playToggle() {
if(vid.paused==false)
{
vid.pause();

}
else{
vid.play();

}
}

$(document).ready(function(){
    
    $('#map_container').attr({'src':'map/map.php'});});
    var map_loaded = false;
    var vid_trans = false;
    var trans1 = false;
    var trans2 = false;
    var trans3 = false;
    var trans4 = false;
    var trans5 = false;
    var trans6 = false;

    vid.addEventListener("timeupdate", function() {
	
	
	//about us
	if(vid.currentTime >= 20 && trans3 == false) {
	    trans3 = true;
	    $('.video_cta.two').fadeIn(800);
	}
	
	//transition to PPP
	if(vid.currentTime >= 26 && trans4 == false) {
            trans4 = true;
            $('.video_cta.two').animate({
                top: '0%',
                left: $('.video_cta_top.two').css('left'),
                width: $('.video_cta_top.two').css('width')
                },
                2500,
                function() {
                    $('.video_cta_top.two').fadeIn(300);
                    $('.video_cta.two').fadeOut(200);
                }
            );
	}
	
        //transition in methodology
	if(vid.currentTime >= 46 && trans2 == false) {
	    trans1 = true;
	    $('.video_cta.one').fadeIn(800);
	}
	//transition to about us
	if(vid.currentTime >= 52 && trans2 == false) {
                trans2 = true;
                $('.video_cta.one').animate({
                    top: '0%',
                    left: $('.video_cta_top.one').css('left'),
                    width: $('.video_cta_top.one').css('width')
                    },
                    2500,
                    function() {
                        $('.video_cta_top.one').fadeIn(300);
                        $('.video_cta.one').fadeOut(200);
                    }
                );
	}
	 
	if(vid.currentTime >= 73 && trans5 == false) {
	    trans5 = true;
	    $('.video_cta.three').fadeIn(700);
	}
         
        //transition PPP out
	if(vid.currentTime >= 82 && trans6 == false) {
            trans6 = true;
            $('.video_cta.three').animate({
                top: '0%',
                left: $('.video_cta_top.three').css('left'),
                width: $('.video_cta_top.three').css('width')
                },
                2500,
                function() {
                    $('.video_cta_top.three').fadeIn(300);
                    $('.video_cta.three').fadeOut(200);
                }
            );
	 }
	 
	//preload map at 95s mark	
        if(vid.currentTime >= 95 && map_loaded == false) {
		$('#map_container').attr({'src':'map/map.php'});
		map_loaded = true;
	}
	//Transition to map from video
	if(vid.currentTime > 94 && vid_trans == false) {
		
		/*
		$('#map_container').flash({
				swf: 'map/LeadMap2.swf',
				width: '100%',
				height: '662'
		});
		*/

				vid_trans = true;
				//Set cookie
				var exdate=new Date();
				exdate.setDate(exdate.getDate() + 30);
				var c_value=escape("played") + "; expires="+exdate.toUTCString();
				document.cookie= "video=" + c_value;
				
				$('#map_container').show();
				$('#videobox').fadeOut(1200,function(){$('#videobox').css({'height':0})});
				$('#homepage-video').fadeIn();
				$('#homepage-map').fadeOut();
				$('.home #branding').css({'height':'662px'});
				$('#map_counter').fadeIn();
	}
	
	if(vid.currentTime > 100) {
		vid.load();
		vid.pause();
	}
});


    $('#homepage-map').click(function(){
		vid.pause();
		/*
		$('#map_container').flash({
					swf: 'map/LeadMap2.swf',
					width: '100%',
					height: '662'
			});
		*/
		if(map_loaded == false) $('#map_container').attr({'src':'map/map.php'})
		map_loaded = true;
		
		//Set cookie
		var exdate=new Date();
		exdate.setDate(exdate.getDate() + 30);
		var c_value=escape("played") + "; expires="+exdate.toUTCString();
		document.cookie= "video=" + c_value;
		
		$('#map_container').show();
		$('#videobox').fadeOut(1200);
		$('#homepage-video').fadeIn();
		$('#homepage-map').fadeOut();
		$('.home #branding').css({'height':'662px'});
		$('#map_counter').fadeIn();
                $('.video_cta_top').fadeIn();
		return false;	
    });
    
    $('#homepage-video').click(function(){
		$('#videobox').css({'height':'auto'});
		$('#map_counter').fadeOut();
		$('#homepage-video').fadeOut();
		$('#videobox').fadeIn(1500, function(){vid.play();});
		$('#homepage-map').fadeIn();
		$('.home #branding').css({'height':'auto'})
		$('#map_container').hide();
		return false;	
    });
    
    $('.grid').click(function(){
		playToggle()
    });
