function a(){
	alert('hey');
}

(function(){
	
	var ANIMATION_SPEED = 200;
	
	var _pageParams = {};
	var _slider = '';
	
	var nvDetails = [];
	var nvCurrentIndex
	var nvIndexes = [1,2,3];
	
	var Pano = window.Pano = function(){
		
	};
	
	Pano.init = function(params){
		_pageParams = params;
		$('.featurepano_tab').live('click', onPanoTabClick);
		$('.featurepano_overlay').bind('click', hidePano);
		
		if ( $('.newvehicles_details').length > 0 ){
			$('.newvehicles_details').each(function(){
				if ( $(this).find('> li').length > 3){
					$(this).jcarousel({
						wrap: 'circular',
						scroll: 1
						//buttonNextCallback : nvCarouselNextClick,
						//buttonPrevCallback : nvCarouselPrevClick
					});
					nvDetails.push($(this).data('jcarousel'));
				}
			});
			$('.jcarousel-next').live('click', nvCarouselNextClick);
			$('.jcarousel-prev').live('click', nvCarouselPrevClick);
			$('.newvehicle_trims li').live('click', navigateToTrim);
		};
		if ( $('.related_vehicle_slider li').length > 3  ){
			$('.related_vehicle_slider').jcarousel({
				wrap:"circular",
				scroll:1
			});
		};
		
		
		if ( $('.list_slider_container .feature_slider li').length > 0 ) {
			$('.list_slider_container .feature_slider').anythingSlider({
				width:"712px",
				height:"120px",
				delay:"5000",
				autoPlay:false
			});
		};

		if ( $('.tab_list_slider_container .feature_slider li').length > 0  ) {
			$('.tab_list_slider_container .feature_slider').anythingSlider({
				width:"712px",
				height:"100px",
				delay:"5000",
				autoPlay:false
			});
		};

		if ( $('.deals_slider_content .feature_slider li').length > 0 ) {
			$('.deals_slider_content .feature_slider').anythingSlider({
				width:"449px",
				height:"156px",
				delay:"5000"
			});
		};
		

		if ( $('#featurepano_slider li').length > 0) {
			$('#featurepano_slider').anythingSlider({
				width:"920px",
				height:"410px",
				delay:"4000",
				buildNavigation:false
			});
		};

		if ( $('#accessoriespano_slider li').length > 0 ) {
			$('#accessoriespano_slider').anythingSlider({
				width:"658px",
				height:"450px",
				delay:"5000",
				buildNavigation:false,
				autoPlay:true
			});
		};
		
		if ( $('#accessoriespano_slider li').length > 0 ) {
			$('.accessories_slider').anythingSlider({
				width:"680px",
				height:"190px",
				autoPlay : false
			});
		};

		if ( $('#accessoriespano_slider li').length > 0 ) {
			$('.related_vehicle_slider').anythingSlider({
				width:"680px",
				height:"120px",
				autoPlay : true
			});
		};
		
		$('.slide_photo a').click(function(){
			var slide = $(this).attr('href').substring(1);
			$('#accessoriespano_slider').anythingSlider(slide);
			return false;
		});
		
		_slider = $('#featurepano_slider').data('AnythingSlider');
		
		$('#accessoriespano_slider').bind('slide_complete', function(event, slider){	
			$('.accessory_thumbs .slide_photo.selected').removeClass('selected');			
			_target = 	$('a[href="'+'#'+slider.currentPage+'"]').parent();
			$(_target).addClass('selected');
			
			//updateSlideShow(slider.currentPage);
		});
		
		arrangePanoText();
	};
	
	//private
	
	function nvCarouselNextClick(){
		for( var i in nvDetails){
			if ( $(this) != nvDetails[i].buttonNext )
				nvDetails[i].next();
		};
		//return false;
	};
	function nvCarouselPrevClick(){
		for( var i in nvDetails){
			if ( $(this) != nvDetails[i].buttonPrev )
				nvDetails[i].prev();
		};
		//return false;
	};
	
	function navigateToTrim(e){
		var _index = $(this).index() + 1;
		// Change to the trim specific image.
		$('.spec_car_shot img').attr('src',
			$(this).find('a').attr('href'));

		for ( var i in nvDetails )
			nvDetails[i].scroll(_index);
		
		return false;
	};
	
	function updateSlideShow(num){
		$('.accessory_thumbs .accessories_slider').anythingSlider(Math.ceil(num/12));
	};
	
	function hidePano(){
		if ( typeof _slider != "undefined" && _slider.length > 0)
			_slider.updateSlider();
			
		$('.selected_pano_tab').removeClass('selected_pano_tab');
		$('#base_featurepanotabs').animate({top:"378px"},ANIMATION_SPEED)
		$('.featurepano_overlay').animate({opacity:"0"}, ANIMATION_SPEED, function(){
			$(this).css({opacity:'0', display:"none"})
		});
	};
	
	function showPano(){
		if ( typeof _slider != "undefined" && _slider.length > 0)
			_slider.startStop();
		$('#base_featurepanotabs').animate({top:"247px"},ANIMATION_SPEED);
		$('.featurepano_overlay')
			.css({opacity:'0', display:"block"})
			.animate({opacity:"0.5"}, ANIMATION_SPEED);
	};
	
	function onPanoTabClick(e){
		e.preventDefault();
		var _this = $(this);
		//pano is open
		if ( $('.selected_pano_tab').length > 0 ){
			//pano is up, remove it
			if (_this.parent().hasClass('selected_pano_tab')){
				hidePano();
				return;
			};
			var _selected = $('.selected_pano_tab').find('.featurepano_tab_content');
			$('.selected_pano_tab').removeClass('selected_pano_tab');
			_this.parent().addClass('selected_pano_tab');
			_selected.hide();
			$('.selected_pano_tab').find('.featurepano_tab_content').show();
		} else {
			//pano is closed
			$(this).parent().addClass('selected_pano_tab');
			$('.featurepano_tab_content,').show()
			$('.selected_pano_tab').find('.featurepano_tab_content').css('opacity','1');
			showPano();
		};
		$('.featurepano_container').css('z-index', '80');
		$('.selected_pano_tab').parent().css('z-index', "99");
	};
	
	function arrangePanoText(){
		if ( $('.slide_copy').length > 0 ){
			$('.slide_copy').each(function(){
				var _top = (($(this).parents('li.panel').height() - $(this).height()) / 2) - 25;//25 is the height of the tabs in the pano area
				$(this).css('top', _top);
			});
		}
	};
	
})();

