// When DOM is ready, prepare portfolio
$(document).ready(function()
{
   var rrbAtWork = new RRBAtWork();
   rrbAtWork.prepareElements();
});

var RRBAtWork = function() 
{
   
   prepareElements = function()
   {
      
      // Footer
      //$("#footer").positionFooter(true);
      
      
      // Prepare rollovers
      $('#menu a,#enter,#lastWordFormSubmit').append('<span class="over"></span>');
      $('.over').css({display:'block',opacity:'0'});
         
      $("#menu a,#enter,#lastWordFormSubmit").hover(
         function () {
            $('.over', this).animate({opacity:'1'}, 250);
         }, 
         function () {
            $('.over', this).animate({opacity:'0'}, 500); 
         }
       );

   
      if ($('body').attr('id') == 'home')
      {    
         // Prepare enter button
         $("#enter").click( function(e){
            showMenu();
            return false;
         })         
      }
      
      
      if ($('body').attr('id') == 'sectionLastWord')
      {    
         // Prepare enter button
         $("#lastWordFormSubmit").click( function(e){
               
            var messageVal = $('#formInput textarea').val()
            if (messageVal.length > 0)
            {
               $(this).unbind('click');
               $('#formInput textarea').attr("disabled","disabled");
                     
               $.post("../sendemail.php",
   			      { emailTo: 'lastword@rrbatwork.com ', emailFrom: 'lastword@rrbatwork.com ', subject: 'Message from The Last Word  ', message: messageVal },
   			      function(data){
						   $('#formInput').remove();
                     $('#formConfirm').fadeIn();									
						}
			         );
            }
            return false;
         })         
      }
      
      
      if ($('body').attr('id') == 'sectionAbout')
      {    
         $('#aboutImg').innerfade({
            speed: 1000,
			   timeout: 5000,
			   type: 'sequence',
			   containerheight: '450px'
			});
			
			$('.buylink a').click(function(e){   
			   $('.sellers').css({display:'none', opacity:'0', marginTop:'20px'});
			   $('.sellers', $(this).parent().parent()).css({display:'block'}).animate({opacity:'1', marginTop:'0px'}, {duration:250});
			   
			   var modal = '<div class="modalOverlay"></div>';
			   $('body').append(modal);  
			   $(".modalOverlay").click(function(){ $(".modalOverlay").remove(); $('.sellers').css({display:'none', opacity:'0', marginTop:'20px'}); });
			   
			   return false;
			});
			
			$('.sellersClose').click(function(e)
			{
			   $('.sellers', $(this).parent().parent()).fadeOut();
			   $(".modalOverlay").remove();
			   return false;
			});
			
			// Podcast 
			var flashvars = {src:'../assets/mp3/kevincarroll_rrbatwork_elevateyourgame.mp3'};
         	var params = {wmode:'transparent'};
         	var attributes = {id:"podcastPlayer", name:"podcastPlayer"};
         	window.swfobject.embedSWF("../assets/swf/podcastPlayer.swf", 'podcastplayer', "37", "37", "6.0.0","expressInstall.swf", flashvars, params, attributes);
			
      }
      
      // Embed video
      
      var bodyId = $('body').attr('id');
      var videoSrc = '';
      var imgSrc = $('#mediaPlayer img').attr('src');
      var backgroundBorderColor='0xc2cb20';
      
      if (bodyId == 'sectionInnovation') { videoSrc='../video/james_mclurkin.flv'; backgroundBorderColor='0xc2cb20'; imgSrc = "../assets/img/video-placeholder-james-mclurkin.jpg"; }
      if (bodyId == 'sectionCuriosity')  { videoSrc='../video/maribel_lieberman.flv'; backgroundBorderColor='0xfcaf17'; }
      if (bodyId == 'sectionTeamwork')   { videoSrc='../video/dwayne_johnson.flv'; backgroundBorderColor='0x00bcd8'; }
      if (bodyId == 'sectionResults')    { videoSrc='../video/marc_hacker.flv'; backgroundBorderColor='0xf287b7'; }
      if (bodyId == 'sectionLeadership') { videoSrc='../video/awista_ayub.flv'; backgroundBorderColor='0xab4a9c'; }
      
      var flashvars = {img:imgSrc, video:videoSrc, autoPlay:"false", autoRewind:"true", backgroundBorderColor:backgroundBorderColor};
      var params = {wmode:'transparent'};
      var attributes = {id:"topVideoPlayer", name:"topVideoPlayer"};
      
      
      if (videoSrc != '')
      {
         var playerVersion = window.swfobject.getFlashPlayerVersion(); // returns a JavaScript object
		 var output = "You have Flash player " + playerVersion.major + "." + playerVersion.minor + "." + playerVersion.release + " installed";
		 //alert(output);
         window.swfobject.embedSWF("../assets/swf/videoPlayer.swf", 'topVideoPlaceholder', "488", "388", "9.0.0","expressInstall.swf", flashvars, params, attributes);
      }
      
      
      if (bodyId == 'sectionInnovation') {
      
      if ( $('#secondVideoPlaceholder').length > 0 )
      {  
         if (bodyId == 'sectionInnovation') { videoSrc='../video/carlos_rodriguez.flv'; backgroundBorderColor='0xc2cb20'; imgSrc = "../assets/img/video-placeholder-carlos-rodriguez.jpg"; }
         flashvars = {img:imgSrc, video:videoSrc, autoPlay:"false", autoRewind:"true", backgroundBorderColor:backgroundBorderColor};
         params = {wmode:'transparent'};
         attributes = {id:"secondVideoPlayer", name:"secondVideoPlayer"};
         window.swfobject.embedSWF("../assets/swf/videoPlayer.swf", 'secondVideoPlaceholder', "488", "388", "9.0.0","expressInstall.swf", flashvars, params, attributes);
      }
      
      if ( $('#thirdVideoPlaceholder').length > 0 )
      {  
         if (bodyId == 'sectionInnovation') { videoSrc='../video/tom_kelly.flv'; backgroundBorderColor='0xc2cb20'; imgSrc = "../assets/img/video-placeholder-innovation.jpg"; }
         flashvars = {img:imgSrc, video:videoSrc, autoPlay:"false", autoRewind:"true", backgroundBorderColor:backgroundBorderColor};
         params = {wmode:'transparent'};
         attributes = {id:"thirdVideoPlayer", name:"thirdVideoPlayer"};
         window.swfobject.embedSWF("../assets/swf/videoPlayer.swf", 'thirdVideoPlaceholder', "488", "388", "9.0.0","expressInstall.swf", flashvars, params, attributes);
      }
      }
      
      
   };
   this.prepareElements = prepareElements;
   
   showMenu = function()
   {
      $('#quote').css({display:'none'});      

      $('#menu').fadeIn();
      
      $('#menu a').each( function(i){
         
         $(this).css({opacity:'0', marginTop:'20px'}).animate({opacity:'1', marginTop:'0px'}, {duration:500, preDelay:i*150});
      });
      
      $('#submenu').fadeIn();
      $('#submenu a').each( function(i){
         
         $(this).css({opacity:'0'}).animate({opacity:'1'}, {duration:1000, preDelay:(i*200) + 1200});
      });
      
      
   }
   this.showMenu = showMenu;
   
   
                  
} // End RRBAtWork
      






