// JavaScript Document
/*
jcarousellite.js
jCarouselLite Created by Ganeshji Marwaha, Enhanced by Karl Swedberg
http://github.com/kswedberg/jquery-carousel-lite
Carousel stops on hover, starts on mouse out
To stop, start Carousel
$(document).trigger('pauseCarousel');
$(document).trigger('resumeCarousel');
*/

$(function() {
    $("#carouselWrapper").jCarouselLite({
        btnNext: "#targetSpotlight .next",
        btnPrev: "#targetSpotlight .prev",
		auto: 800,
		speed: 400,
		circular: true,
		visible:5,
		scroll:1
    });
});

jQuery(document).ready(function() {
	$('#targetSpotlight .next').click(function () {	
		$(document).trigger('pauseCarousel');
	});	
	$('#targetSpotlight .prev').click(function () {	
		$(document).trigger('pauseCarousel');
	});		
	$('#targetSpotlight .rollover').mousemove(function () {	
		$(document).trigger('pauseCarousel');
	});		
	
	$('#targetSpotlight .rollover').mouseleave(function () {	
		//$(".carousel").css("left","0px");														 
		$(document).trigger('resumeCarousel');
	});	
	

	
	$('.rollover').css("display","none");
	$('#targetSpotlight').append('<div class="rolloverWrapper"></div>');
	$('#targetSpotlight .rollover').appendTo('#targetSpotlight .rolloverWrapper');

/*----to set shadow corners-------*/	
	modernize(); 
	setShadowCorners();	

	var currItem;
	var listItems;
	var indexItem;
	var currRollover;

$('#targetSpotlight a.hotspot').mouseenter(function () {	
	popout(this);
});	


$('#targetSpotlight a.hotspot').attr('href','javascript:void(0)');
$('#targetSpotlight').find("li").attr("tabindex", 0 );
$('#targetSpotlight .rollover').attr("tabindex", 0 );

$('#targetSpotlight').find("li").focus(function(){
	$(document).trigger('pauseCarousel');
});	

$('#targetSpotlight .rollover').find('a').blur(function(){

	$('.rollover').hide();
	$('#targetSpotlight .rolloverWrapper').hide();
	$('#targetSpotlight .rolloverWrapper').css( { "top": -9999 + "px" } );
	
	currItem.focus();
						   
});


$('#targetSpotlight a.hotspot').focus(function(){
	$(this).keypress(function(event){
		if(event.keyCode==13){ // ENTER key
			popout(this);			
			currRollover.focus();
		}
    });	
});	



function popout(x){  

	$('.rollover').hide();//hide any open rollover
	
	currItem = $(x).parent().parent().parent(); //current LI
	listItems = $(x).parent().parent().parent().parent().children();  //collection of LI
	indexItem = $(listItems).index(currItem);
	var currIndex   = indexItem % spotlightNumProducts ;
	currRollover = $('#targetSpotlight .rolloverWrapper .rollover').eq(currIndex) ;
	var leftPos = currItem.offset().left - $('#targetSpotlight').offset().left - 30;
	var maxLeftPos = 660; 
	if( leftPos > maxLeftPos ) { leftPos = maxLeftPos; }
	if( leftPos < 0 ) { leftPos = 0; }
	
	$('#targetSpotlight .rolloverWrapper').css( { "left": (leftPos) + "px", "top":-20 + "px" } );
	currRollover.show();
	$('#targetSpotlight .rolloverWrapper').fadeIn(200);
}
	


$('.rollover').mouseleave(function () {		
	$(this).hide();
	$('#targetSpotlight .rolloverWrapper').hide();
	$('#targetSpotlight .rolloverWrapper').css( { "top": -9999 + "px" } );
});




}); 
/*
 * Adds classes to #targetSpotlight element based on availability of advanced CSS features.
 * This is essentially a drastically-reduced subset of Modernizr (http://modernizr.com).
 *
 * Copyright (c) 2009 Faruk Ates - http://farukat.es/
 * Licensed under the MIT license.
 * http://modernizr.com/license/
 *
 * Currently tests for the following CSS properties:
 * 		- border-radius
 * 		- box-shadow
 *		- (IE only) filter
 * @method modernize
 */
	function modernize() {
		var tester = document.createElement("div"),
			style = tester.style,
			tests = {},
			classes = [],
			feature;
	
		function uppercase(prop) {
			return prop.charAt(0).toUpperCase() + prop.substr(1);
		}
	
		function contains( str, substr ) {
			return str.indexOf( substr ) !== -1;
		}
			
		function test_props( props, callback ) {
			for ( var i in props ) {
				if ( style[ props[i] ] !== undefined && ( !callback || callback( props[i] ) ) ) {
					return true;
				}
			}
		}
	
		function test_props_all( prop, callback ) {
			var uc_prop = uppercase(prop),
			props = [
				prop,
				'webkit' + uc_prop,
				'Moz' + uc_prop,
				'moz' + uc_prop,
				'o' + uc_prop,
				'ms' + uc_prop
			];
	
			return !!test_props( props, callback );
		}
	
		tests['borderRadius'] = function () {
			return test_props_all('borderRadius');
		};
		
		tests['boxShadow'] = function () {
			return test_props_all('boxShadow');
		};
		
		tests['ieFilter'] = function () {
			return $.browser.msie && test_props(['filter']);
		};
		
		for (feature in tests) {
			if (tests.hasOwnProperty(feature)) {
				classes.push(!tests[feature]() ? "no" + uppercase(feature) : feature);
			}
		}
		
		$('#targetSpotlight').addClass(classes.join(' '));
		
		// Teardown
		style.cssText = '';
		tester = null;
	}
/* 
* Optionally adds rounded corner elements if border-radius is unavailable,
* and a wrapper for IE if box-shadow is unavailable.
*/
	
function setShadowCorners() {
	var	hasFilterNoShadow = $('#targetSpotlight').hasClass("ieFilter") && $('#targetSpotlight').hasClass("noBoxShadow");
	var	noBorderRadius = $('#targetSpotlight').hasClass("noBorderRadius");				
	if (noBorderRadius) {
		addRoundedCorners();
	}
	if (hasFilterNoShadow) {
		addIEDropShadow();
	}
	function addRoundedCorners() {
			$('<div class="corners"><div class="tl"/><div class="tr"/><div class="bl"/><div class="br"/></div>')
			.appendTo('#targetSpotlight .rollover');
	}
	function addIEDropShadow() {
		$('#targetSpotlight .rolloverWrapper').append('<div class="ieShadow"/>');
	}	
}
		
