var totalSlides = new Array(2);
var currentSlide = new Array(2);
var contentSlides = new Array(2);
/*
var totalSlidesProducts = totalSlidesLearning = 0;
var currentSlideProducts = currentSlideLearning = 1;
var contentSlidesProducts = contentSlidesLearning = "";
*/
///////////////////////

var slidesArray = ['products','learning'];

$(document).ready(function(){

jQuery.each(slidesArray, function(){
 var currentTarget = this; 
 var totalWidth = 0;
 totalSlides[currentTarget] = 0;
 currentSlide[currentTarget] = 1;
 contentSlides[currentTarget] = "";

  $("#slideshow-" + currentTarget + "-previous").click(function(){showPreviousSlide(currentTarget);});
  $("#slideshow-" + currentTarget + "-next").click(function(){showNextSlide(currentTarget);});
  //$("#slideshow-learning-previous").click(function(){showPreviousSlide('learning');});
  //$("#slideshow-learning-next").click(function(){showNextSlide('learning');});
 
  contentSlides[currentTarget] = $(".slideshow-" + currentTarget + "-content");
  contentSlides[currentTarget].each(function(){
	totalWidth += this.clientWidth;
    totalSlides[currentTarget]++;
  });
  $("#slideshow-" + currentTarget + "-holder").width(totalWidth);
  $("#slideshow-" + currentTarget + "-scroller").attr({scrollLeft: 0});
  updateButtons(currentTarget);

});

});


function  showPreviousSlide($target)
{
  currentSlide[$target]--;
  updateContentHolder($target);
  updateButtons($target);
}

function showNextSlide($target)
{
  currentSlide[$target]++;
  updateContentHolder($target);
  updateButtons($target);
}

function updateContentHolder($target)
{
  var scrollAmount = 0;
  contentSlides[$target].each(function(i){
    if(currentSlide[$target] - 1 > i) {
      scrollAmount += this.clientWidth;
    }
  });
  $("#slideshow-" + $target + "-scroller").animate({scrollLeft: scrollAmount}, 500);
}


function updateButtons($target)
{
  if(currentSlide[$target] < totalSlides[$target]) {
	$("#slideshow-" + $target + "-next-inactive").hide();
    $("#slideshow-" + $target + "-next").show();
  } else {
	$("#slideshow-" + $target + "-next-inactive").show();  
    $("#slideshow-" + $target + "-next").hide();
  }
  if(currentSlide[$target] > 1) {
	$("#slideshow-" + $target + "-previous-inactive").hide();  
    $("#slideshow-" + $target + "-previous").show();
  } else {
	$("#slideshow-" + $target + "-previous-inactive").show();    
    $("#slideshow-" + $target + "-previous").hide();
  }
}


//////////////////////////////////////////
//////////////////////////////////////////
//////////////////////////////////////////
//////////////////////////////////////////
//////////////////////////////////////////
$(document).ready(function() {

//$("#featuresCats,#featuresProds,#slideshow-learning,#slideshow-products").corner("round 6px").parent().corner("round 6px");
$(".featuresButton").corner("round 5px");
//$("#featuresCats").corner("4px");//.parent().css('padding', '2px').corner("round 10px");
//$("#featuresProds").corner("round 8px").parent().css('padding', '2px').corner("round 10px");

//$(".block-hpage-read-more-button").append("... <span style='text-decoration:underline;'>[read more]</span>");
$(".block-hpage-read-more-button").append("... <img src='/sites/all/themes/pexuniverse_new/images/homepage/decor/read-more.png' />");
$(".block-hpage-read-more-button-less").append(" <img src='/sites/all/themes/pexuniverse_new/images/homepage/decor/read-less.png' />");
$(".shop-now-button").append("<img src='/sites/default/files/homepage/decor/shopnow.png' />");
$(".learn-more-button").append("<span><img src='/sites/all/themes/pexuniverse_new/images/homepage/decor/read-more-c-bg.gif' /></span>");

$(".slideshow-products-content > ul > li > .wrapper").hover(function(){$(this).css("border","1px solid #6eb717");},
										 function(){$(this).css("border","1px solid #ffffff");});
$(".featuresButton").hover(function(){$(this).addClass('active');},
						   function(){
						   	var curId = $(this).attr('id');
						    curId = curId.replace("fb_pop", "");
							if(curId != activeProd){$(this).removeClass('active');}  
						  });

$(".catPhoto,.prodPhoto").hover(function(){
											$(this).addClass('greenBorder');
											$(this).parent().addClass('noBottom');
										 },
								function(){
											if($(this).next('div[class~="ListDescription-container"]').css("display") != "block"){
												$(this).removeClass('greenBorder');
												$(this).parent().removeClass('noBottom');
											}	
								});
										  
						  
						  
/*//////move to main script*/
$('.block-hpage-read-more-button').click(function(){
					$(this).hide();
					$(this).next('.block-hp-read-more').show();
					});
					
$('.block-hpage-read-more-button-less').click(function(){
					$(this).parent().hide();
					$(this).parent().prev('.block-hpage-read-more-button').show();
					});
		/**/			

//$(".catPhoto,.catTitle").bind('click',function() {
var descriptionContainerClose = function($blockName,$tofade) { 
					$('.' + $blockName + 'sListDescription-container').each(function(){
						if($tofade){
							$(this).fadeOut(600, function(){
								$(this).prev().removeClass('greenBorder');
								$(this).prev().parent().removeClass('noBottom');
							});
						}
						else{
							$(this).hide();
							$(this).prev().removeClass('greenBorder');
							$(this).prev().parent().removeClass('noBottom');
						}
					});
  };

$(".catPhoto").bind('click',function() {
                    descriptionContainerClose('category');
					$.scrollTo( '#featuresCats', 400);					
					$(this).next('.categorysListDescription-container').show();
					$(this).next().next('.categorysListDescription-container').show();
					$(this).addClass('greenBorder');
					$(this).parent().addClass('noBottom');
					}
				);	

				
	$(".prodPhoto").bind('click',function() {
					descriptionContainerClose('prod');
					$.scrollTo( '#featuresProds', 400);					
					$(this).next('.prodsListDescription-container').show();
					$(this).next().next('.prodsListDescription-container').show();
					$(this).addClass('greenBorder');
					$(this).parent().addClass('noBottom');
					}
				);	

	$('.prodsListDescription-close').bind('click',function(){descriptionContainerClose('prod');});
	$('.categorysListDescription-close').bind('click',function(){descriptionContainerClose('category');});

	/*
	$('.categorysListDescription-close,.prodsListDescription-close').bind('click',function(){
					$(this).parent().parent().hide();
				    $(this).parent().parent().prev().removeClass('greenBorder');
					$(this).parent().parent().prev().parent().removeClass('noBottom');					
				});
    */
				
	var defaultActiveProd = 2;
	$('#fb_pop'+defaultActiveProd).addClass('active');
	$('#popRight_'+defaultActiveProd).show();
	var activeProd = defaultActiveProd;			
    $('div[id*="fb_pop"]').click(
					function() {
						descriptionContainerClose('prod');
						$('#fb_pop'+activeProd).removeClass('active');
						$('#popRight_'+activeProd).hide();
						var curId = $(this).attr('id');
						activeProd = curId.replace("fb_pop", "");
						$('#fb_pop'+activeProd).addClass('active');						
						$('#popRight_'+activeProd).show();	
					}
				);					
	
	var timerContainerCloseCats;
	var timerContainerCloseProds;

	$("#featuresCats").bind('mouseleave', function(){
					timerContainerCloseCats = setTimeout(function(){ descriptionContainerClose('category',1); }, 1500);
	});

	$("#featuresProds").bind('mouseleave', function() {
					timerContainerCloseProds = setTimeout(function(){ descriptionContainerClose('prod',1); }, 1500);
					//if you wish to set default Active product uncomment below and comment above
					/*$('div[id*="popRight_"]').each(function(){$(this).hide();});
					$('div[id*="fb_pop"]').each(function(){$(this).removeClass('active');});
					descriptionContainerClose('prod');
					activeProd = defaultActiveProd;
					$('#popRight_'+defaultActiveProd).show();
					$('#fb_pop'+defaultActiveProd).addClass('active');
					*/
	});
	
	$("#featuresCats").mouseover(function(){
					clearTimeout(timerContainerCloseCats);
    });
	$("#featuresProds").mouseover(function(){
					clearTimeout(timerContainerCloseProds);
    });	
	
});
