$(function() {
	var zIndexNumber = 1000;
	$('div').each(function() {
		if(!$(this).hasClass('white_content') && !$(this).hasClass('black_overlay') && !$(this).hasClass('TabbedPanels')) {
			$(this).css('zIndex', zIndexNumber);
			zIndexNumber -= 10;
		}
	});
	homepageSlideInt = setInterval('runHPSlideshow()', 4000);
	$('#hp_slideshow_backnext .btn-back').click(function() {
		clearInterval(homepageSlideInt);
		var nextSlide = $('#hp_slideshow_slides li.active').prev();
		if(!$(nextSlide).length) {
			 nextSlide = $('#hp_slideshow_slides li:last');
		}
		$('#hp_slideshow_slides li.active').fadeOut('slow', function() {
			$(this).removeClass('active');
			
			$(nextSlide).fadeIn('slow', function() {
				$('#hp_slideshow_slides li.active').removeClass('active');
				$(this).addClass('active');
				var curIndex = $(this).parent().children().index($(this));
				curIndex++;
				
				$('#hp_slideshow_contols li:nth-child('+curIndex+') a').fadeIn( 
					function() {
						$('#hp_slideshow_contols li a').removeClass('active');
						$('#hp_slideshow_contols li:nth-child('+curIndex+') a').addClass('active');
				});
			});
		});
	});
	$('#hp_slideshow_backnext .btn-next').click(function() {
		clearInterval(homepageSlideInt);
		runHPSlideshow()
	});
	
	$('#hp_slideshow_contols li a').mouseover(function() {
		if($(this).attr('id') == 'control_all_products')
			return false;
		clearInterval(homepageSlideInt);
		$('#hp_slideshow_contols li a.active').removeClass('active');
		var curIndex = $(this).parent().parent().children().index($(this).parent());
		curIndex++;
		if($('#hp_slideshow_slides li.active').length) {
			$('#hp_slideshow_slides li.active').removeClass('active').fadeOut( 
				function() {
					$('#hp_slideshow_slides li').css('display', 'none');
					$('#hp_slideshow_slides li').removeClass('active');
					$('#hp_slideshow_slides li:nth-child('+curIndex+')').addClass('active').fadeIn( 
						function() {
							
							$('#hp_slideshow_contols li:nth-child('+curIndex+') a').addClass('active');
					});
			});
		} else {
			$('#hp_slideshow_slides li').css('display', 'none');
			$('#hp_slideshow_slides li').removeClass('active');
			$('#hp_slideshow_slides li:nth-child('+curIndex+')').addClass('active').fadeIn('slow', function() {
				$('#slideshow_controller li').removeClass('active');
					$('#slideshow_controller li:nth-child('+curIndex+')').addClass('active');
			});
		}
	});
	$('.dropdown').mouseover(function() {
		//set the layer to active
		$('.dropdown-box').each(function() {
			if($(this).hasClass('dd-active') || $(this).hasClass('dd-pending')) {
				$(this).fadeOut('fast', function() {
					$(this).removeClass('dd-active').removeClass('dd-pending').addClass('dd-inactive');
				});
			}
		});
		$('#dropdown_'+$(this).attr('id').replace('dd_', '')).removeClass('dd-pending').removeClass('dd-inactive').css('zIndex', '100').fadeIn('fast', function() {
			
			$(this).addClass('dd-active');
		});
	});
	$('.dropdown').mouseout(function() {
		$('#dropdown_'+$(this).attr('id').replace('dd_', '')).removeClass('dd-active').removeClass('dd-inactive').addClass('dd-pending');
		setTimeout('dropdownMenuHider("'+$(this).attr('id').replace('dd_', '')+'")', 500);
	});
	$('.dropdown-box').mouseover(function() {
		if($(this).hasClass('dd-pending') || $(this).hasClass('dd-active')) {
			$(this).removeClass('dd-pending', 'dd-inative').addClass('dd-active');
		}
	});
	$('.dropdown-box').mouseout(function() {
		$(this).removeClass('dd-active').removeClass('dd-inative').addClass('dd-pending');
		//alert('here');
		setTimeout('dropdownMenuHider("'+$(this).attr('id').replace('dropdown_', '')+'")', 500);
	});
});
function dropdownMenuHider(layerId) {
	if($('#dropdown_'+layerId).hasClass('dd-pending')) {

		$('#dropdown_'+layerId).fadeOut('fast', function() {
			$(this).removeClass('dd-active').removeClass('dd-pending').addClass('dd-inactive');
		});
	} else {
		//setTimeout('dropdownMenuHider("'+layerId+'")', 1000);	
	}
}
function runHPSlideshow() {
	var nextSlide = $('#hp_slideshow_slides li.active').next();
	if(!$(nextSlide).length) {
		 nextSlide = $('#hp_slideshow_slides li:first');
	}
	$('#hp_slideshow_slides li.active').fadeOut('slow', function() {
		
		$(this).removeClass('active');
		
		$(nextSlide).fadeIn('slow', function() {
			$('#hp_slideshow_slides li.active').removeClass('active');
			$(this).addClass('active');
			
			var curIndex = $(this).parent().children().index($(this));
			curIndex++;
			
			$('#hp_slideshow_contols li:nth-child('+curIndex+') a').fadeIn( 
				function() {
					$('#hp_slideshow_contols li a').removeClass('active');
					$('#hp_slideshow_contols li:nth-child('+curIndex+') a').addClass('active');
			});
		});
	});
}
