$fluid = $("body");
var w = $fluid.width();
var h =  w * .6;
var full = 0;
var bheight = $fluid.height();

	var height = $("#footer_bar").height();
	$footer = $('#footer_bar');



function openFooter(){

var height = $("#footer_bar").height();
if(height <= 30){

	$footer.animate({'height':'120px'},500, function(){
			$('#thumbs').show();
			});
			$("#exp").html("X");
}

}


function closeAll(){

	var height = $("#footer_bar").height();
			$footer = $('#footer_bar');


if($('#bio').is(":visible")){

$('#bio').slideToggle();

}

if($('#content').is(":visible")){
$('#content').slideToggle();
}

if (height >= 119){

$footer.animate({'height':'20px'},500, function(){
			$('#thumbs').hide();
			});
			$("#exp").html("+");


}

}
	
	

$("#footer_bar").click(function(){
	var height = $(this).height();
	
		
	
			
			if(height <= 30){
			
			$(this).animate({'height':'120px'},500);
			$("#exp").html("x");
			$('#thumbs').show();
			
			}else if (height >= 119){
			
			
			$footer.animate({'height':'20px'},500, function(){
			$('#thumbs').hide();
			});
			
			
			$('#exp').html("+");
						
			}else{
			
			return false;
			}
		
});

$('#subnav1').click(function(){
	$('#bio').slideToggle();	
});	
	
$('#subnav2').click(function(){
	$('#content').slideToggle();
	pause();
	$('#pause').hide();
});	

$('.closer, .closerb').live('click',function(){
	$(this).parent().slideToggle();	

});

$('.closerb').live('click',function(){
var state = ytplayer.getPlayerState();
if((state== -1)||(state==0)||(state==2)){
		play();

		$footer.animate({'height':'20px'},500, function(){
			$('#thumbs').hide();
			$('#exp').html("+");
			});
			
			
			
		
}

});


	

//top nav finctions
function set_cd(){
var w = $fluid.width();
var h =  w * .6;
   swfobject.embedSWF(enrique,"ytplayer", w, h, "8", null, null, params, atts);
	$('#bioname').html('ENRIQUE RIOS');
	$('#topic').html('BECOMING A COMPANY DRIVER');
	$('#bio').load('bios/enrique.html');
	$('#content').load('pages/company-drivers.html');
	if($('#content').is(":hidden")){
	$('#content').slideToggle();	
	}
	if($('#bio').is(":visible")){
	$('#bio').slideToggle();
	}
	openFooter();
}

function set_oo(){
var w = $fluid.width();
var h =  w * .6;
    swfobject.embedSWF(wilder,"ytplayer", w, h, "8", null, null, params, atts);
	$('#bioname').html('ROBERT &amp; FRANCES WILDER');
	$('#topic').html('BECOMING AN OWNER OPERATOR');
	$('#bio').load('bios/robert.html');
	$('#content').load('pages/owner-operators.html');
	if($('#content').is(":hidden")){
	$('#content').slideToggle();	
	}
	if($('#bio').is(":visible")){
	$('#bio').slideToggle();
	}
	openFooter();	
}

function set_rd(){
var w = $fluid.width();
var h =  w * .6;
	 swfobject.embedSWF(tristan,"ytplayer", w, h, "8", null, null, params, atts);
	$('#bioname').html('TRISTAN NAULT');
	$('#topic').html('BECOMING A REGIONAL DRIVER');
	$('#bio').load('bios/tristan.html');
	$('#content').load('pages/regional-drivers.html');
	if($('#content').is(":hidden")){
	$('#content').slideToggle();	
	}
	if($('#bio').is(":visible")){
	$('#bio').slideToggle();
	}
	openFooter();
}

function set_sd(){
var w = $fluid.width();
var h =  w * .6;
	 swfobject.embedSWF(enrique,"ytplayer", w, h, "8", null, null, params, atts);
	$('#bioname').html('ENRIQUE RIOS');
	$('#topic').html('BECOMING A STUDENT DRIVER');
	$('#bio').load('bios/enrique.html');
	$('#content').load('pages/student-drivers.html');
	if($('#content').is(":hidden")){
	$('#content').slideToggle();	
	}
	if($('#bio').is(":visible")){
	$('#bio').slideToggle();
	}
	openFooter();

}

//THUMBS FUNCTIONS
function set_cd_thumb(){
var w = $fluid.width();
var h =  w * .6;
   swfobject.embedSWF(enrique,"ytplayer", w, h, "8", null, null, params, atts);
	$('#bioname').html('ENRIQUE RIOS');
	$('#topic').html('BECOMING A COMPANY DRIVER');
	$('#bio').load('bios/enrique.html');
	$('#content').load('pages/company-drivers.html');
	
	if($('#bio').is(":hidden")){
	$('#bio').slideToggle();	
	}
	if($('#content').is(":visible")){
	$('#content').slideToggle();
	}
	openFooter();
	
	
}

function set_oo_thumb(){
var w = $fluid.width();
var h =  w * .6;
    swfobject.embedSWF(wilder,"ytplayer", w, h, "8", null, null, params, atts);
	$('#bioname').html('ROBERT &amp; FRANCES WILDER');
	$('#topic').html('BECOMING AN OWNER OPERATOR');
	$('#bio').load('bios/robert.html');
	$('#content').load('pages/owner-operators.html');	
	if($('#bio').is(":hidden")){
	$('#bio').slideToggle();	
	}
	if($('#content').is(":visible")){
	$('#content').slideToggle();
	}
	openFooter();
}

function set_rd_thumb(){
var w = $fluid.width();
var h =  w * .6;
	swfobject.embedSWF(tristan,"ytplayer", w, h, "8", null, null, params, atts);
	$('#bioname').html('TRISTAN NAULT');
	$('#topic').html('BECOMING A REGIONAL DRIVER');
	$('#bio').load('bios/tristan.html');
	$('#content').load('pages/regional-drivers.html');
	if($('#bio').is(":hidden")){
	$('#bio').slideToggle();	
	}
	if($('#content').is(":visible")){
	$('#content').slideToggle();
	}
	openFooter();
}
	
$(function() {

		$("#ytplayer").attr('width',$fluid.width());
         var width =   $("#ytplayer").attr('width');
             
        $("#ytplayer").attr('height', width * .6);
        
        // When the window is resized
  
        $(window).resize(function() {
           $("#ytplayer").attr('width', $fluid.width());
           var width =   $("#ytplayer").attr('width');
           $("#ytplayer").attr('height', width * .6);
        });

});

function onYouTubePlayerReady(playerId) {
      ytplayer = document.getElementById("ytplayer");
    }
    
function play() {
  if (ytplayer) {
    ytplayer.playVideo();
  }
}  

function pause() {
  if (ytplayer) {
    ytplayer.pauseVideo();
  }
}


function fullscreen() {
if (full == 0){
  $("#ytplayer").css("z-index", "350").css("margin-top", "0px").attr("height",bheight);
  $("#fullscreen").html("EXIT FULLSCREEN");
  full = 1;
}else{
$("#ytplayer").css("z-index", "0").css("margin-top", "90px").attr("height",h);
$("#fullscreen").html("FULLSCREEN");
full = 0;

}
}  

  

$('#container').live('mousedown',function(){

var state = ytplayer.getPlayerState();
if((state== -1)||(state==0)||(state==2)){
closeAll();

}

if(state==1){
$footer.animate({'height':'120px'},500, function(){
			$('#thumbs').show();
			});
			$("#exp").html("X");
	
}





});




$('#pause').click(function(){
	pause();


$footer.animate({'height':'120px'},500, function(){
			$('#thumbs').show();
			});
			$("#exp").html("X");

    
    
});

$('#play').click(function(){
	play();

	
  
    closeAll();
});






$(document).ready(function(){
 if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ 
  $('body').append('<img src="images/bg.jpg" id="bg">');
        var theWindow        = $(window),
            $bg              = $("#bg"),
            aspectRatio      = $bg.width() / $bg.height();

        function resizeBg() {

                if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
                    $bg
                        .removeClass()
                        .addClass('bgheight');
                } else {
                    $bg
                        .removeClass()
                        .addClass('bgwidth');
                }

        }

        theWindow.resize(function() {
                resizeBg();
        }).trigger("resize");
  }

	//set_cd_thumb();
	 swfobject.embedSWF(enrique,"container", w, h, "8", null, null, params, atts);
	 $('#bioname').html('ENRIQE RIOS');
	$('#topic').html('BECOMING A COMPANY DRIVER');
	$('#bio').load('bios/enrique.html');
	$('#content').load('pages/company-drivers.html');	
	
});

function onYouTubePlayerReady(playerId) {
  ytplayer = document.getElementById("ytplayer");
  ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
}

function onytplayerStateChange(newState) {
//alert(newState);
   if(newState==1)
		{
	$('#pause, #fullscreen').fadeIn();
	$('#play').hide();
	closeAll();
	}
if((newState== -1)||(newState==0)||(newState==2)){
  	 $('#play').fadeIn();
  	 $('#pause, #fullscreen').hide();
  	  openFooter();
  	 
	}
}
$('.navitem').click(function(){
$('.navitem').removeClass('active');
$(this).addClass('active');

});
  
/**
 * jQuery isHovered (http://mktgdept.com/jquery-ishovered)
 * A jQuery plugin to test if an element is currently hovered
 *
 * v0.0.1 - 11 June 2010
 *
 * Copyright (c) 2010 Chad Smith (http://twitter.com/chadsmith)
 * Dual licensed under the MIT and GPL licenses.
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.opensource.org/licenses/gpl-license.php
 *
 * Test if an element is hovered using: $(selector).isHovered() or $.isHovered(selector)
 *
 **/
;(function(b,c){b('*').hover(function(){b(this).data(c,1)},function(){b(this).data(c,0)}).data(c,0);b[c]=function(a){return b(a)[c]()};b.fn[c]=function(a){a=0;b(this).each(function(){a+=b(this).data(c)});return a>0}})(jQuery,'isHovered');


