
var sliderCreated = false;

function startSpinner() {
	return document.getElementById('bucore_modelFinder_numberOfResults_spinner').innerHTML='<img src="/typo3conf/ext/bucore/templates/modelFinder/images/loading_small.gif"/>';
}

function restoreModelFinder() {
	createSlider();  									//enable slider
	jQuery('#tx-bucore-modelFinder-navigation li').addClass( 'enabled' );	//enable all tabs
	jQuery('#slider .scroll').trigger( 'stop' );	//switch to last step
	jQuery('#slider .scroll').trigger( 'goto', 4 );	//switch to last step
	jQuery('#slider .scroll').trigger( 'start' );	//switch to last step
}

function createSlider() {

	if (jQuery('#slider .scrollContainer > div').text() != '' ) {
		var linkMenu = jQuery('#tx-bucore-modelFinder-navigation').html();
		jQuery('#tx-bucore-modelFinder-navigation').empty();
		jQuery('#tx-bucore-modelFinder-navigation').append(linkMenu);

		var $panels = jQuery('#slider .scrollContainer > div');
		var $container = jQuery('#slider .scrollContainer');
		var $scroll = jQuery('#slider .scroll');

		// if false, we'll float all the panels left and fix the width
		// of the container
		var horizontal = true;

		// float the panels left if we're going horizontal
		if (horizontal) {

			// calculate a new width for the container (so it holds all panels)
			$container.css('width', $panels[0].offsetWidth * $panels.length);
		}


		// collect the scroll object, at the same time apply the hidden overflow
		// to remove the default scrollbars that will appear
//		var $scroll = jQuery('#slider .scroll').css('overflow', 'hidden');

		// apply our left + right buttons
//		$scroll.before('<img class="scrollButtons left" src="images/scroll_left.png" />').after('<img class="scrollButtons right" src="images/scroll_right.png" />');


/*
		// handle nav selection
		function selectNav(){
			jQuery(this).parents('ul:first').find('a').removeClass('selected').end().end().addClass('selected');
		}


		jQuery('#tx-bucore-modelFinder-navigation').find('a').click(selectNav);
*/

		function handleBeforeScroll(e, elem, $pane, $items, pos){
			 /**
			 * 'this' is the triggered element
			 * e is the event object
			 * elem is the element we'll be scrolling to
			 * $pane is the element being scrolled
			 * $items is the items collection at this moment
			 * pos is the position of elem in the collection
			 * if it returns false, the event will be ignored
			 */
			 //remove all active-classes
			jQuery('#tx-bucore-modelFinder-navigation li').removeClass('active');


			//console.dir(e);

		}

		function handleAfterScroll(e, elem, $pane, $items, pos){
			 /**
			 * 'this' is the triggered element
			 * e is the event object
			 * elem is the element we'll be scrolling to
			 * $pane is the element being scrolled
			 * $items is the items collection at this moment
			 * pos is the position of elem in the collection
			 * if it returns false, the event will be ignored
			 */
			 //id of panel we arrived right now is the class of the li that is "resposible"
			 jQuery('#tx-bucore-modelFinder-navigation li.' + e.id).addClass('active');

			 // set scroll div height fixed to "450px"
			 jQuery('.tx-bucore-modelFinder .scroll').css('height','450px');

			 //console.log($pane);
			 //console.log($items.lenght);


			//special actions on some panels
			switch (e.id) {
				//panel0: no prev/next-Button
				case 'panel0':
					jQuery('#tx-bucore-modelFinder-switch div').hide();
					break;

				//last panel (actually panel4): no heigth, no next, special xAjax-Action
				case 'panel4':
					jQuery('#bucore_modelFinder_showNumberOfResults').empty();

					jQuery('#tx-bucore-modelFinder-switch div.next').hide();

					// set scroll div height fixed to "100%"
					jQuery('.tx-bucore-modelFinder .scroll').css('height','100%');

					modelFinder_modelFinderFormSubmitted(xajax.getFormValues('bucore_modelFinder'));
					break;

				default:
					jQuery('#tx-bucore-modelFinder-switch div').show();
			}



			 //last panel (actually panel4): no heigth, no next, special xAjax-Action

		}

		//set mouseOver for the LIs (we do not have As and ther is no css "hover" for LIS in IE<=6
		jQuery('#tx-bucore-modelFinder-navigation li').hover(
					function () {jQuery(this).addClass('jq_hover');},
					function () {jQuery(this).removeClass('jq_hover');}
				);

/*
		if (window.location.hash) {
			trigger({
				id: window.location.hash.substr(1)
			});
		}
		else {
			jQuery('#tx-bucore-modelFinder-navigation a:first').click();
		}
*/

		// offset is used to move to *exactly* the right place, since I'm using
		// padding on my example, I need to subtract the amount of padding to
		// the offset.  Try removing this to get a good idea of the effect
		var offset = parseInt((horizontal ? $container.css('paddingTop') : $container.css('paddingLeft')) ||
		 0) *
		 -1;



		var scrollOptions = {
			target: $scroll, // the element that has the overflow

			// can be a selector which will be relative to the target
			items: $panels,

			navigation: '#tx-bucore-modelFinder-navigation li',

			// selectors are NOT relative to document, i.e. make sure they're unique
			//prev: '#tx-bucore-modelFinder-switch .prev',
			//next: '#tx-bucore-modelFinder-switch .next',

			// allow the scroll effect to run both directions
			axis: 'xy',

			onBefore: handleBeforeScroll, //fired before scrolling starts
			onAfter: handleAfterScroll, // fired after scrolling ready


			offset: offset,

			// duration of the sliding effect
			duration: 500,

			// easing - can be used with the easing plugin:
			// http://gsgd.co.uk/sandbox/jquery/easing/
			easing: 'swing'
		};

		// apply serialScroll to the slider - we chose this plugin because it
		// supports// the indexed next and previous scroll along with hooking
		// in to our navigation.
		jQuery('#slider').serialScroll(scrollOptions);

		// now apply localScroll to hook any other arbitrary links to trigger
		// the effect
		jQuery.localScroll(scrollOptions);

		// finally, if the URL has a hash, move the slider in to position,
		// setting the duration to 1 because I don't want it to scroll in the
		// very first page load.  We don't always need this, but it ensures
		// the positioning is absolutely spot on when the pages loads.
		scrollOptions.duration = 1;
		jQuery.localScroll.hash(scrollOptions);

		jQuery('#slider').serialScroll(scrollOptions);






	}
}

jQuery(document).ready(function() {
	//createSlider();

});

