// JavaScript Document
var timer;
var secTime = 8000;
var srcHomePageBackground
var countBackgound = 1;
var numBackground = 0;

$(document).ready(function(){
	$("ul.homeSlider a.bselector").click(bgSelect);		
	  numBackground = $("a.bselector").length;
	  if(numBackground > 1)
		pictureCarrusel();
	/* HPLL Highlight products */	
	$("ul.highlights li").mouseover(function(e){e.preventDefault();$(this).addClass("expanded")});
	$("ul.highlights li").mouseout(function(e){e.preventDefault();$(this).removeClass("expanded")});
	
});

function bgSelect(e){
	e.preventDefault();
	clearTimeout(timer); //kill the automatic turn of the pictres on the carrusel
	$("a.bselector.selected").removeClass("selected");
	$("div.contentText.selected").removeClass("selected");
	$(this).addClass("selected");
	$($(this).attr("href")).addClass("selected");
	$("body").css("background-image", 'url("'+ $($(this).attr("href")).find(".background").attr("src")+'")');
}

/* 
 * pictureCarrusel will enable the automatic turn of the pictures in the background of the page every 8 sec
 * By: Victor Redondo Quiros, 27 July,2010
 */
function pictureCarrusel(){
  imageSource = $("#contentText"+countBackgound).find(".background").attr("src");
  $("body").css("background-image", 'url("'+imageSource+'")');
  $("a.bselector.selected").removeClass("selected");
  $("div.contentText.selected").removeClass("selected");
  $("#contentText"+countBackgound).addClass("selected");
  /*$("div.contentText:eq("+(countBackgound-1)+")").addClass("selected");*/
  $("a.bselector:eq("+(countBackgound-1)+")").addClass("selected");
  if(countBackgound == numBackground)
    countBackgound = 1;
  else
    countBackgound++;  
	timer = setTimeout("pictureCarrusel()",secTime);
} 
