// Principal Strategy main scripts
//var webroot = "/ps2009/app/webroot/";
var webroot = "/app/webroot/";
//-----------------------------------------------------------------------------------------------------------
//                                                                                  MAIN PAGE SCRIPTS
//-----------------------------------------------------------------------------------------------------------

// Splash blocks for individual sub-brands
function showComm() {
  if ($("#brands_upper_block").css("display") != "none") {
    $("#brands_upper_block").fadeOut(180, function() {$("#active_block").fadeIn(180);});
  }
  
  $("#brands_upper_active").removeClass("brands_active_comm brands_active_perf brands_active_ppl ");
  $("#brands_upper_active").addClass("brands_active_comm");
  killAllBlurbs();
  $("#splash_comm").css({'display':'block'});
  
  // Set the images to the version with drop shadows
  $("img#tabs_comm").attr({src: webroot+"img/brand_tab_comm.jpg"});
  $("img#tabs_perf").attr({src: webroot+"img/brand_tab_perf_s.jpg"});
  $("img#tabs_ppl").attr({src: webroot+"img/brand_tab_ppl_s.jpg"});

}

function showPerf() {
  if ($("#brands_upper_block").css("display") != "none") {
    $("#brands_upper_block").fadeOut(180, function() {$("#active_block").fadeIn(180);});
  }
  $("#brands_upper_active").removeClass("brands_active_comm brands_active_perf brands_active_ppl ");
  $("#brands_upper_active").addClass("brands_active_perf");
  killAllBlurbs();
  $("#splash_perf").css({'display':'block'});
  
  // Set the images to the version with drop shadows
  $("img#tabs_comm").attr({src: webroot+"img/brand_tab_comm_s.jpg"});
  $("img#tabs_perf").attr({src: webroot+"img/brand_tab_perf.jpg"});
  $("img#tabs_ppl").attr({src: webroot+"img/brand_tab_ppl_s.jpg"});

}

function showPpl() {
  if ($("#brands_upper_block").css("display") != "none") {
    $("#brands_upper_block").fadeOut(180, function() {$("#active_block").fadeIn(180);});
  }
  $("#brands_upper_active").removeClass("brands_active_comm brands_active_perf brands_active_ppl ");
  $("#brands_upper_active").addClass("brands_active_ppl");
  killAllBlurbs();
  $("#splash_ppl").css({'display':'block'});
  
  // Set the images to the version with drop shadows
  $("img#tabs_comm").attr({src: webroot+"img/brand_tab_comm_s.jpg"});
  $("img#tabs_perf").attr({src: webroot+"img/brand_tab_perf_s.jpg"});
  $("img#tabs_ppl").attr({src: webroot+"img/brand_tab_ppl.jpg"});

}

function killAllBlurbs() {
  // Hides all the blurbs
  $("#splash_comm").css({'display':'none'});
  $("#splash_perf").css({'display':'none'});
  $("#splash_ppl").css({'display':'none'});
}

function doNada() { 
// What it says on the tin... 
}

function resetSplash() {
  $("#active_block").fadeOut(200, function(){$("#brands_upper_block").fadeIn(200);});
  
  
  // Set the images to versions with no drop shadow
  $("img#tabs_comm").attr({src: webroot+"img/brand_tab_comm.jpg"});
  $("img#tabs_perf").attr({src: webroot+"img/brand_tab_perf.jpg"});
  $("img#tabs_ppl").attr({src: webroot+"img/brand_tab_ppl.jpg"});
}


// The following is for the rotating quotes on the front page

// this array consists of the id attributes of the divs we wish to alternate between
var divs_to_fade = new Array('quote-1', 'quote-2', 'quote-3', 'quote-4');

// the starting index in the above array.  It should be set to the value of the div which doesn't have the CSS Display property set to "none"
var i = 0;

// the number of milliseconds between swaps.  Default is five seconds.
var wait = 5000;

$(document).ready(function() {
	startPage();
});			

// the function that performs the fade
function swapFade() {
  $("#quotes_overlay_c").fadeIn(800, function(){
  
    $( "#" + divs_to_fade[i] ).hide(function(){
      i++;
      if (i == 3) i = 0;
      $( "#" + divs_to_fade[i] ).show(function(){
        $("#quotes_overlay_c").fadeOut(800);
      });
    });
  
  });
  /*
  $( "#" + divs_to_fade[i] ).fadeOut( 800, function(){
		 i++;
	   if (i == 3) i = 0;
	   $( "#" + divs_to_fade[i] ).fadeIn( 800 );
  } );
  */
					
}

// the onload event handler that starts the fading.
function startPage() {
	setInterval( 'swapFade()', wait );
}

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}
// Make something happen when you mouseover each. Let's start with the commercial one
$(document).ready(function(){
   $.preloadImages(
                   webroot+"img/bg_nav_button_a.jpg",
                   webroot+"img/glass_button_light_a.png",
                   webroot+"img/button_learnmore_a.png",
                   webroot+"img/splash_comm.jpg",
                   webroot+"img/splash_perf.jpg",
                   webroot+"img/splash_ppl.jpg",
                   webroot+"img/brand_tab_comm_s.jpg",
                   webroot+"img/brand_tab_perf_s.jpg", 
                   webroot+"img/brand_tab_ppl_s.jpg",
                   webroot+"img/bg_submit_a.png",
                   webroot+"img/bg_submit_on.png"
                   );

   $("#tabs_comm").hoverIntent( showComm, doNada );
   $("#tabs_perf").hoverIntent( showPerf, doNada );
   $("#tabs_ppl").hoverIntent( showPpl, doNada );
   
   $("#home_main_content").hoverIntent(resetSplash, doNada);
   
 });
