//jQuery.extend(
//	jQuery.expr[ ":" ], 
//	{ reallyvisible : function (a) { return !(jQuery(a).is(':hidden') || jQuery(a).parents(':hidden').length); }}
//);

var MD = function() {
	
	// "private" функции и переменные
	
	var emailTestRegexp = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	
	var validateForm = function($required_all, $required_either_all) {
		if (!$required_all)
			$required_all = $('.required:visible');
		if (!$required_either_all)
			$required_either_all = $('.required_either:visible');
		$required_all.removeClass('error');
		$required_either_all.removeClass('error');
		$required_all.each(function() {
			var $required = $(this);
			$required.find('input, select, textarea').each(function() {
				if (!$.trim($(this).val()))
					$required.addClass('error');
			});
		});
		// требуется заполнение хотя бы одного из полей с классом "required_either"
		var required_either_error = false;
		if ($required_either_all.length) {
			required_either_error = true;
			$required_either_all.find('input, select, textarea').each(function() {
				if ($.trim($(this).val())) {
					required_either_error = false;
					return false; // аналог break
				}
			});
			if (required_either_error)
				$required_either_all.addClass('error');
		}
		$('.email input:visible').each(function() {
			var $this = $(this);
			if ($.trim($this.val()) && emailTestRegexp.test($.trim($this.val())) == false)
				$this.parent().addClass('error');
		});
		/*$('.width input:visible').each(function() {
			var $this = $(this);
			if ($.trim($this.val()) && parseFloat($.trim($this.val())) > 35.5)
				$this.parent().addClass('error width_error');
		});*/
		return showFormErrors();
	};
	
	var validateFormFields = function($required_all) {
		if (!$required_all)
			$required_all = $('.required');
		$required_all.each(function() {
			var $required = $(this);
			$required.find('input, select, textarea').blur(function() {
				var $this = $(this);
				if (!$.trim($this.val()))
					$required.addClass('error');
				else
					$required.removeClass('error');
				showFormErrors();
			});
		});
		$('.email input').blur(function() {
			var $this = $(this);
			if ($.trim($this.val())) {
				if (emailTestRegexp.test($.trim($this.val())) == false)
					$this.parent().addClass('error');
				else
					$this.parent().removeClass('error');
			}
			showFormErrors();
		});
		/*$('.width input').blur(function() {
			var $this = $(this);
			if ($.trim($this.val())) {
				if (parseFloat($.trim($this.val())) > 39.5)
					$this.parent().addClass('error width_error');
				else
					$this.parent().removeClass('error width_error');
			}
			showFormErrors();
		});*/
	};
	
	var showFormErrors = function() {
		$('p.form_error').remove();
		if ($('.field.error').length) {
			//var $error_message = $('#error_message');
			var p = $('<p/>')
				.addClass('error form_error')
				.html('Please fill out the form completely. The missing fields are shown in red. Click SUBMIT when finished.');
			p.insertBefore('form, form input[type=submit]');
			/*if ($('.field.width_error').length) {
				p.append('<br />Maximum width to 39.5" wide.');
			}*/
			return false;
		}
		return true;
	};
	
	var lightBoxParams = {
		imageBtnClose: '/assets/img/lightbox/lightbox-btn-close2.gif',
		imageBtnPrev: '/assets/img/lightbox/lightbox-btn-prev2.gif',
		imageBtnNext: '/assets/img/lightbox/lightbox-btn-next2.gif',
		imageLoading: '/assets/img/lightbox/lightbox-ico-loading.gif',
		imageBlank: '/assets/img/lightbox/lightbox-blank.gif',
		txtImage: 'Image',
		txtOf: 'of'
//		fixedNavigation: true
	};
	
	var more_texts = {
		show: 'Read more',	
		hide: 'Hide'	
	};
	
	return {
		
		// "public" функции и переменные
		
		init: function() {
			$('.read_more').each(function() {
				$more = $(this);
				$more
					.hide()
					.after(
						$('<div />', { 'class' : 'more_link' })
							.append($('<p />')
								.append($('<span />', { 'class' : 'dashed' })
									.html(more_texts.show)
								)
								.click(function() {
									$this = $(this);
									$this.toggleClass('active');
									$span = $this.find('span');
									if ($this.hasClass('active'))
										$span.html(more_texts.hide);
									else
										$span.html(more_texts.show);
									$more.slideToggle();
								})								
							)
					);
			});
			$('#header_message .close').click(function() {
				cookie.set('header_message_closed', 1);
				$(this).parent().fadeOut();
			});
			return this;
		},
		lightBox: function(selector) {
			$(selector).lightBox(lightBoxParams);
			return this;
		},
		lightBoxforContainer: function(selector) {
			$(selector).each(
				function() {
					$(this).find('a').lightBox(lightBoxParams);
				}
			);
			return this;
		},
		quickQuote: function() {
			$('[name=quantity]').keyup(function() {
				var id = $(this).parent().find('[name=id]').val();
//				if ($(this).parent().find('[name=door]').val() != null) // Мы на странице описания двери, добавляем с установленными frame, hardware и prehung 
//					shop.setQuantityChecked(this, id);
//				else
				shop.setQuantity(this, id);
			});
			$('.up').click(function() {
				var id = $(this).parent().parent().find('[name=id]').val();
//				if ($(this).parent().parent().find('[name=door]').val() != null) // Мы на странице описания двери, добавляем с установленными frame, hardware и prehung
//					shop.addProduct({id: id, add: 1, frame:true, hardware:true, prehung:true});
//				else
				shop.addProduct({id: id, add: 1});
				var quantity = $(this).parent().parent().find('[name=quantity]');
				quantity.val(parseInt(quantity.val()) + 1);
			});
			$('.down').click(function() {
				var id = $(this).parent().parent().find('[name=id]').val();
//				if ($(this).parent().parent().find('[name=door]').val() != null) // Мы на странице описания двери, добавляем с установленными frame, hardware и prehung
//					shop.addProduct({id: id, add: -1, frame:true, hardware:true, prehung:true});
//				else
				shop.addProduct({id: id, add: -1});
				var quantity = $(this).parent().parent().find('[name=quantity]');
				var val = parseInt(quantity.val()) - 1;
				quantity.val(val > 0 ? val : 0);
			});
			$('.delete').click(function() {
				var tr = $(this).parent().parent();
				var id = tr.find('[name=id]').val();
				if (confirm('Are you sure you want to remove this door?')) {
					shop.addProduct({id: id, add: 0, set: true});
					var quantity = tr.find('[name=quantity]');
					quantity.val(0);
					tr.remove();
				}
				
				var quantity = $(this).parent().parent().find('[name=quantity]');
				quantity.val(parseInt(quantity.val()) - 1);
			});
			$('tr.door_row :checkbox').change(function() {
				var regexp = /([^\d]+)(\d+)/;
				var result = regexp.exec(this.id);
				var name = result[1];
				var id = result[2];
				var parms = {};
				parms['id'] = id;
				parms[name] = this.checked;
				shop.addProduct(parms);
			});
			$('#quick_quote_shipping').change(function() {
				// set shipping cost
				var order = cookie.get('order');
				if (order) {
					var products = order.split(';'); //формат order -> id,quantity,frame,hardware,prehung;id,quantity,frame,hardware,prehung;...
					shop.setCosts(products);
				}
			});
			return this;
		},
		door: function() {
			$('.up').click(function() {
				var id = $(this).parent().parent().find('[name=id]').val();
//				shop.addProduct({id: id, add: 1, frame:true, hardware:true, prehung:true});
				var quantity = $(this).parent().parent().find('[name=quantity]');
				quantity.val(parseInt(quantity.val()) + 1);
			});
			$('.down').click(function() {
				var id = $(this).parent().parent().find('[name=id]').val();
//				shop.addProduct({id: id, add: -1, frame:true, hardware:true, prehung:true});
				var quantity = $(this).parent().parent().find('[name=quantity]');
				var val = parseInt(quantity.val()) - 1;
				quantity.val(val > 0 ? val : 0);
			});
			$('#add').click(function() {
				var id = $(this).parent().find('[name=id]').val();
				var quantity = parseInt($(this).parent().find('[name=quantity]').val());
				shop.addProduct({id: id, add: quantity, set: true, frame: true, hardware: true, prehung: true});
				$('#quantity').html(quantity);
				/*$('#add_quote').slideUp();
				$('#buttons').slideDown();*/
				$('#add_quote').fadeOut(500, function() {
					$('#buttons').fadeIn(500);
				});
					
				return false;
			});
			/*$('#continue').click(function() {
				$('#quantity_title').html('In Cart');
				$('#add').html('Change q-ty');
				$('#buttons').slideUp();
				$('#add_quote').slideDown();
				$('#buttons').fadeOut(500, function() {
					$('#add_quote').fadeIn(500);
				});
				return false;
			});*/
			return this;
		},
		interiorDoorOrdering: function() {
			
			var showDoorsErrors = function() {
				var no_errors = true;
				$('p.door_error').remove();
				var p_error = $('<p/>')
					.addClass('error door_error')
					.html('Please provide complete information about your door specifications. The missing fields are shown in red. Click SUBMIT when finished.');

				$('#doors .door_over:has(table.modified)').each(function() {
					$this = $(this);
					if ($this.find('.required.error').length) {
						var cur_p_error = p_error.clone();
						cur_p_error.insertBefore($this);
						no_errors = false;
					}
					if ($this.find('.required.error_width').length) {
						cur_p_error.append('<br />Maximum width to 39.5" wide.');
					}
				});
				if (!no_errors)
//					$('<p/>')
//					.addClass('error door_error')
//					.html('Please provide complete information about your door specifications. The missing fields are shown in red. Click SUBMIT when finished.')
					p_error.clone().insertBefore('form input[type=submit]');
				return no_errors;
				
			};
			
			$('#field_doors_ordering_country select').change(function() {
				var states_select = $('#field_doors_ordering_state select'); 
				states_select.html('');
				var states = countries_states[$(this).val()];
				if (states) {
					for (var key in states) {
						var option = $('<option/>').val(key).html(states[key]);
						option.appendTo(states_select);
					}
				}
			});
			$('[id^=door] input, [id^=door] select').live('change', function() {
				var index = -1;
				var regexp = /\[(\d+)\]/;
				var matches = regexp.exec($(this).attr('name'));
					
				if (matches != null && matches.length > 1)
					var index = matches[1];
				
				$('#door' + index).addClass('modified');
				$('#modified' + index).val('1');
			});
			$('input.name').live('focus', function() {
				if ($.trim($(this).val()) == 'Door Name')
					$(this).val('');
			});
			$('input.name').live('blur', function() {
				var $this = $(this);
				if (!$.trim($this.val()))
					$this.val('Door Name');
			});
			$('[id^=model]').live('change', function() {
				var index = $(this).attr('id').replace('model', ''); 
				var colors_select = $('#color' + index); 
				colors_select.html('<option/>');
				var colors = models_colors[$(this).val()];
				if (colors) {
					for (var key in colors) {
						var option = $('<option/>').val(key).html(colors[key]);
						option.appendTo(colors_select);
					}
				}
			});
			$('[id^=color]').live('change', function() {
				var index = $(this).attr('id').replace('color', ''); 
				var color_hidden = $('#color_hidden' + index);
				color_hidden.val($('option:selected', this).html());
			});
			$('[id^=thickness]').live('change', function() {
				var index = $(this).attr('id').replace('thickness', ''); 
				var thickness_hidden = $('#thickness_hidden' + index);
				thickness_hidden.val($('option:selected', this).html());
			});
			$('select.custom').live('change', function() {
				if ($(this).val() == 'custom')
					$('#custom_' + $(this).attr('id')).css('display', 'block');
				else
					$('#custom_' + $(this).attr('id')).css('display', 'none');
			});
			$('[name*=type]').live('change', function() {
				var regexp = /(\d+)/;
				var index = regexp.exec($(this).attr('name'))[0];
				switch($(this).val()) {
					case 'swing':
						$('#hardware' + index + ', #prehung' + index + ', #opening_left' + index +
							', #opening_right' + index).css('display', 'block');
						$('#fix' + index).css('display', 'none');
						if($('#hardware' + index + ' input').is(':checked')) {
							$('#privacy' + index).css('display', 'block');
							$('#items_hardware' + index).css('display', 'table-row');
						}
						else
							$('#privacy' + index + ', #items_hardware' + index).css('display', 'none');
						break;
					case 'double':
						$('#prehung' + index + ', #hardware' + index).css('display', 'block');
						$('#opening_left' + index + ', #opening_right' + index).css('display', 'none');
						if($('#hardware' + index + ' input').is(':checked')) {
							$('#privacy' + index + ', #fix' + index).css('display', 'block');
							$('#items_hardware' + index).css('display', 'table-row');
						}
						else
							$('#privacy' + index + ', #fix' + index + ', #items_hardware' + index).css('display', 'none');
						break;
					case 'pocket':
					case 'sliding':
						$('#hardware' + index + ', #privacy' + index + ', #prehung' + index + ', #fix' + index +
							', #opening_left' + index + ', #opening_right' + index +
							', #items_hardware' + index).css('display', 'none');
						break;
				}
			});
			$('[name*=opening]').live('change', function() {
				var regexp = /(\d+)/;
				var index = regexp.exec($(this).attr('name'))[0];
				switch($(this).val()) {
					case 'left':
						$('#opening_left' + index + ' img').attr('src', '/assets/img/p_swing_L_on.gif');
						$('#opening_right' + index + ' img').attr('src', '/assets/img/p_swing_R_off.gif');
						break;
					case 'right':
						$('#opening_right' + index + ' img').attr('src', '/assets/img/p_swing_R_on.gif');
						$('#opening_left' + index + ' img').attr('src', '/assets/img/p_swing_L_off.gif');
						break;
				}
			});
			$('[id^=hardware] input').live('click', function() {
				var index = $(this).parent().attr('id').replace('hardware', ''); 
				$('#items_hardware' + index + ', #privacy' + index).toggle();
				if ($('#door' + index + ' [name*=type]:checked').val() == 'double' && $(this).is(':checked'))
					$('#fix' + index).css('display', 'block');
				else
					$('#fix' + index).css('display', 'none');
			});
			$('[id^=delete]').live('click', function() {
					var index = $(this).attr('id').replace('delete', ''); 
					if (confirm('Are you sure you want to remove this door?'))
						$('#door_over' + index).remove();
				});
			if ($.browser.msie) {
				$('[name*=type], [name*=opening]').live('click', function () {
						this.blur();
						this.focus();
				});
			}
			$('#add_door').click(function() {
				var index = $('#index').val();
				var new_door = $($('#sample').html().replace(/#index#/g, index).replace(/#/g, ''));
				new_door.appendTo($('#doors'));
				$('#index').val(parseInt(index)+1);
			});
			
			var $form_required_all = $('#form .required');
			var $doors_required_all = $('#doors .modified .required');
			
			validateFormFields($form_required_all);
			
			// validate doors fields
			$('#doors .modified .required input, #doors .modified .required select').live('blur', function() {
				var $this = $(this);
				$required = $this.parent();
				if ($this.is(':visible') && $.trim($this.val()).replace('Door Name', '') == '')
					$required.addClass('error');
				else if ($required.hasClass('width') && parseFloat($this.val()) > 39.5)
					$required.addClass('error error_width');
				else
					$required.removeClass('error error_width');
				showDoorsErrors();
			});
			
			$('form').submit(function() {
				validateForm($form_required_all);
				/*$form_required_all.removeClass('error');
				$form_required_all.each(function() {
					var $required = $(this);
					$required.find('input, select, textarea').each(function() {
						var val = $(this).val();
						if (val == '' || val == null)
							$required.addClass('error');
					});
				});
				$('.email input').each(function() {
					var $this = $(this);
					if ($this.val() && emailTestRegexp.test($this.val()) == false)
						$this.parent().addClass('error');
				});*/
				
				$('#doors .modified .required')
					.removeClass('error')
					.each(function() {
						var $required = $(this);
						$required.find('input, select').each(function() {
							var $this = $(this);
							if ($this.is(':visible') && $.trim($this.val()).replace('Door Name', '') == '')
								$required.addClass('error');
							else if ($required.hasClass('width') && parseFloat($this.val()) > 39.5)
								$required.addClass('error error_width');
						});
					});
				
				var result1 = showFormErrors();
				var result2 = showDoorsErrors();
				return result1 && result2;
			});
			
			return this;
		},
		otherDoorOrdering: function() {
			$('#field_doors_ordering_country select').change(function() {
				var states_select = $('#field_doors_ordering_state select'); 
				states_select.html('');
				var states = countries_states[$(this).val()];
				if (states) {
					for (var key in states) {
						var option = $('<option/>').val(key).html(states[key]);
						option.appendTo(states_select);
					}
				}
			});
			$('#configuration').change(function() {
				$('#transom_field, #left_sidelight_field, #right_sidelight_field').css('display', 'none');
				if ($(this).val().indexOf('Transom') > 0)
					$('#transom_field').css('display', 'block');
				if ($(this).val().indexOf('Left Sidelight') > 0 || $(this).val().indexOf('2 Sidelights') > 0)
					$('#left_sidelight_field').css('display', 'block');
				if ($(this).val().indexOf('Right Sidelight') > 0 || $(this).val().indexOf('2 Sidelights') > 0)
					$('#right_sidelight_field').css('display', 'block');
			});
			$('#casing').change(function() {
					$('#jamb_field').css('display', 'none');
					if ($(this).val() == 'For Door Replacement')
						$('#jamb_field').css('display', 'block');
				});
			validateFormFields();
			$('form').submit(function() {
				return validateForm();
			});
			return this;
		},
		doorsResult: function() {
			$('#show_schedule').click(function() {
				MD.showWindow('schedule', 'Door Schedule', $('#print_header').html() + $('#schedule').html());
				return false;
			});
			$('#show_estimate').click(function() {
				MD.showWindow('estimate', 'Estimate', $('#print_header').html() + $('#estimate').html());
				return false;
			});
			return this;
		},
		showWindow: function(id, title, html) {
			win1 = window.open('', id, 'toolbar=0,scrollbars=1,location=0,width=800,height=380');
//			if (win1.document.body.childElementCount == 0) {
				win1.document.close();
				win1.document.open();
				win1.document.writeln('<html><head><title>' + title + '</title>' + 
				'<style>' +
					'body {font-family:Arial,Tahoma,Verdana,san-serif; font-size:14px;}' +
					'.quick_quote table {border-collapse: collapse;border: 0;padding: 0;margin: 0;margin-top: 30px;}' +
					'.quick_quote td {padding: 5px 10px;font-size: 14px;border: 1px solid #000;}' +
					'.quick_quote thead td {font-size: 14px;font-weight:bold;background-color: #dfdfdf;}' +
					'.quick_quote tfoot td {background-color: #dfdfdf;font-weight: bold;padding: 7px 10px 3px;}' +
					'.quick_quote tfoot td.clear {background: none;border: none;}'+
					'.quick_quote tfoot td.total p {color: #c4152a;font-size: 14px;font-weight: normal;position: relative;top: -3px;}' +
					'.quick_quote tfoot td.total p span {font-size: 20px;font-weight: bold;}' +
					'.right {text-align: right !important;}' +
					'.print {text-align: center;}' +
					'a {background: url(/assets/img/print-btn.gif) no-repeat left center;padding-left:15px;text-align: center;}' +
					'@media print { a { display: none; } }' +
				'</style>' + 
				'</head><body>');
				win1.document.writeln(html);
				win1.document.writeln('<div class="print"><a href="#" onclick="window.print(); return false;">Print</a></div></body></html>');
				if ($.browser.msie)
					win1.location.reload(true);
				if (window.focus)
					win1.focus();
				win1.print();
		},
		payment: function() {
			var paymentShipValues = {}; // для сохранения состояния полей ship... до нажатия "same as bill"
			$('#field_payment_bill_country select, #field_payment_ship_country select').change(function() {
				var name_part = /payment\[(.+?)_country\]/.exec($(this).attr('name'))[1]; 
				var states_select = $('#field_payment_' + name_part + '_state select'); 
				states_select.html('');
				var states = countries_states[$(this).val()];
				if (states) {
					for (var key in states) {
						var option = $('<option/>').val(key).html(states[key]);
						option.appendTo(states_select);
					}
				}
			});
			var $copy = $('#payment_copy1, #payment_copy2');
			$copy.click(function() {
				var thisIsChecked = $(this).is(':checked');
				$copy.attr('checked', thisIsChecked);
				if (thisIsChecked) {
					$('[id^=payment_bill_]').each(function() {
						var $this = $(this);
						var id = $this.attr('id').replace('payment_bill_', '');
						paymentShipValues[id] = $('#payment_ship_' + id).val();
						$('#payment_ship_' + id).val($this.val());
					});
					$('div[id^=field_payment_bill_] select').each(function() {
						var $this = $(this);
						var id = $this.parent().attr('id').replace('field_payment_bill_', '');
						var $shipSelect = $('#field_payment_ship_' + id + ' select');
						paymentShipValues[id + 'html'] = $shipSelect.html();
						paymentShipValues[id + 'selectedIndex'] = $shipSelect.attr('selectedIndex');
						$shipSelect.html($this.html()).attr('selectedIndex', $this.attr('selectedIndex'));
					});
				}
				else {
					$('[id^=payment_ship_]').each(function() {
						var $this = $(this);
						var id = $this.attr('id').replace('payment_ship_', '');
						$(this).val(paymentShipValues[id]);
					});
					$('div[id^=field_payment_ship_] select').each(function() {
						var $this = $(this);
						var id = $this.parent().attr('id').replace('field_payment_ship_', '');
						$this.html(paymentShipValues[id + 'html']).attr('selectedIndex', paymentShipValues[id + 'selectedIndex']);
					});
				}
			});
			validateFormFields();
			$('form').submit(function(e) {
				return validateForm();
			});
			return this;
		},
		forms: function() {
			validateFormFields();
			$('form').submit(function() {
				return validateForm();
			});
			return this;
		},
		formsGA: function(form_type) {
			// Пишем в Google Analytics события при заполнении посетителем формы
			var currentPage = jQuery.url.attr("path");
			$(':input').blur(function () {
				if($(this).val().length > 0){
					_gaq.push(["_trackEvent", "Form " + form_type + ": " + currentPage, "input_exit", $(this).attr('name')]);
					//pageTracker._trackEvent("Form " + form_type + ": " + currentPage, "input_exit", $(this).attr('name'));
				}
			});
			return this;
		},
		coverflow: function() {
			//$('#demo-frame div.wrapper').parent().append(html).end().remove();
			$sliderCtrl = $('#slider');
			$coverflowCtrl = $('#coverflow');
			$coverflowImages = $coverflowCtrl.find('img');
			$sliderVertical= $("#slider-vertical");
			var defaultItem = Math.floor($coverflowImages.length / 2);
			//Initialize CoverFlow
			$coverflowCtrl.coverflow({
				item: defaultItem,
				duration:1200,
				select: function(event, sky) {
					skipTo(sky.value);
				}
			});
			//Initialize Horizontal Slider
			$sliderCtrl.slider({
				min: 0,
				max: $('#coverflow > *').length-1,
				value: defaultItem,
				slide: function(event, ui) {
					$coverflowCtrl.coverflow('select', ui.value, true);
					$('.coverflowItem').removeClass('ui-selected');
					$('.coverflowItem:eq(' + (ui.value) +')').addClass('ui-selected');
				}
			});
			//Skip to an item in the CoverFlow
			function skipTo($itemNumber) {
				$sliderCtrl.slider( "option", "value", $itemNumber);
				$coverflowCtrl.coverflow('select', $itemNumber, true);
				$('.coverflowItem').removeClass('ui-selected');
				$('.coverflowItem:eq(' + ($itemNumber) +')').addClass('ui-selected');
			}
			//Skip all controls to the current default item
			skipTo(defaultItem);
			//Assign click event for coverflow images
			$('body').delegate('.coverflowItem','click', function() {
				skipTo($(this).data('itemlink'));
			});

			//Handle keyboard events (note: keydown is used rather than
			//keypress as Chrome/Webkit has known issues using the latter)
			$(document).keydown(function(e){
				$current = $sliderCtrl.slider('value');
				switch(e.keyCode){
					case 37:
						if($current > 0){
							$current--;
							skipTo($current);
						}
						break;
					case 39:
						if($current < $('#coverflow > *').length-1){
							$current++;
							skipTo($current);
						}
						break;
				}
			});
			
			$coverflowCtrl.mousewheel(function(event, delta){
				var speed = 1;
				var sliderVal = $sliderCtrl.slider("value");
				var coverflowItem = 0;
				var cflowlength = $('#coverflow > *').length-1;
				//check the deltas to find out if the user
				//has scrolled up or down
				if(delta > 0 && sliderVal > 0){
					sliderVal -=1;
				}
				else {
					if(delta < 0 && sliderVal < cflowlength){
						sliderVal +=1;
					}
				}
				coverflowItem = Math.floor(sliderVal);
				skipTo(coverflowItem);
				//stop any default behaviour
				event.preventDefault();
			});			
			return this;
		}
	};
}();

