");
//Wrapping ol with div - applying styling
$(".mod-searchBarHistory .select-box .slider_wrapper").prepend("200019001800");
// Creating buttons with years
var containsDateOne = $('.mod-searchBarHistory .select-box ol li a:contains(2011-2012)');
var containsDateTwo = $('.mod-searchBarHistory .select-box ol li a:contains(1998-1999)');
var containsDateThree = $('.mod-searchBarHistory .select-box ol li a:contains(1900-1901)');
$(containsDateOne).addClass("item-2000").attr('id', 'item-2000');
$(containsDateTwo).addClass("item-1900").attr('id', 'item-1900');
$(containsDateThree).addClass("item-1800").attr('id', 'item-1800');
$(function () {
var scrollPane = $(".slider_container");
var scrollContent = $(".scroll-content");
// Slider
$('#slider').slider({
orientation: "vertical",
value: 100,
max: 100,
animate: true,
min: -660,
slide: function (event, ui) {
console.log(ui.value);
console.log(scrollPane.height());
if (scrollContent.height() > scrollPane.height()) {
scrollContent.css("margin-top", (-1 * (scrollPane.height() - ((scrollPane.height() * ui.value) / 100))) + "px");
} else {
scrollContent.css("margin-top", 0);
}
}
});
//slider prototype
function customSlider(sliderObject, content, container) {
this.content = content;
this.handle = $('.ui-slider-handle');
//method for moving slider and content with date range clicks
this.move = function (e, num, heightStep) {
e.preventDefault();
//moving slider content
this.content.animate({
marginTop: heightStep
}, 500);
//moving slider itself - condition for IE7-8 or other modern browsers
if (jQuery.support.leadingWhitespace) {
this.handle.animate({ bottom: num }, 500);
} else {
this.handle.css('bottom', num);
}
}; //method for moving slider with up/down arrows clicks
this.slide = function (e, dir) {
//SLIDER PROPERTIES
//setting up maximum height of the slider content
this.maxHeight = Math.round((scrollContent.height() - scrollPane.height()) / 100) * 100 - 100;
//setting up actual position of the content
this.actualContentPos = Math.round(parseInt(content.css('margin-top')) / 100) * 100;
//checking what will be the next content margin - this number is a base to find out what will be new slider position, so it has to be done before this.newSliderPos definiton
dir ? this.nextContentPos = Math.round((parseInt(content.css('margin-top')) - 100) / 100) * 100 : this.nextContentPos = Math.round((parseInt(content.css('margin-top')) + 100) / 100) * 100;
//setting up the new slider position
this.newSliderPos = Math.round(this.nextContentPos * 100 / this.maxHeight) + 100 + '%';
//if the newSliderPos will be lower than 0, it should be 0; if the newSliderPos will be bigger than 100, it should be 100
parseInt(this.newSliderPos) < 0 ? this.newSliderPos = '0%' : (parseInt(this.newSliderPos) > 100 ? this.newSliderPos = '100%' : void (0));
//slider moving down (dir = true)
if (dir) {
if (this.actualContentPos > -(this.maxHeight)) {
//moving content
this.move(e, this.newSliderPos, (this.actualContentPos - 100));
} else {
//moving content to its maximum height and it stops at fixed position
this.move(e, this.newSliderPos, -(this.maxHeight));
}
//slider moving up (dir = false)
} else {
//slider back at the top, position 0
if (this.actualContentPos >= 0) {
this.move(e, '100%', 0);
} else {
this.move(e, this.newSliderPos, (this.actualContentPos + 100));
}
}
};
}
//new slider object
var dropdownSlider = new customSlider($('#slider'), $(".scroll-content"), $('.slider_container'));
//clicking arrows down and up
$('.cp-scrollDown').click(function (e) {
dropdownSlider.slide(e, 1);
});
$('.cp-scrollUp').click(function (e) {
dropdownSlider.slide(e, 0);
});
//custom location links
$('.cp-buttonHolder-one .cp-button').click(function (e) {
dropdownSlider.move(e, '100%', '0');
//location of the date 2012
});
$('.cp-buttonHolder-two .cp-button').click(function (e) {
dropdownSlider.move(e, '94%', '-180px');
//location of the date 1999
});
$('.cp-buttonHolder-three .cp-button').click(function (e) {
dropdownSlider.move(e, '12%', '-1530px');
//location of the date 1899
});
// $("#dateSelect").live("change", function () {
// $('#refineSearchForm').submit();
// });
$(".select-box .cp-button").click(function () {
$(".cp-button-active").removeClass("cp-button-active");
$(this).addClass("cp-button-active");
});
});
/* On Tab keypress add class to element with focus */
$(document).live('keyup', function (e) {
var currentElement = document.activeElement;
$('.hasFocus').removeClass('hasFocus');
if (e.keyCode == 27) {
$('.show').removeClass('show');
}
if (e.keyCode == 9) {
if ($(currentElement).is(':focus')) {
$(currentElement).addClass('hasFocus');
}
if ($(currentElement).parent().children('ol').length > 0) {
$(currentElement).parent().addClass('show');
var getLength = $(currentElement).parent().children().children('li').length;
var sum = 0;
if (getLength > 5) {
$(currentElement).parent().addClass('oScroll show');
}
}
}
$(document).live('keydown', function (e) {
if (e.keyCode == 9) {
if ($('.show li:last a').is(':focus')) {
$('.show').removeClass('show');
$('.oScroll').removeClass('oScroll');
}
}
});
$('body').click('live', function () {
if ($('.select-box').hasClass('show')) {
$('.select-box').removeClass('show');
}
})
});
$('.selectBox').live("click", function () {
$(this).parent().toggleClass('show');
var getLength = $(this).parent().children().children('li').length;
var sum = 0;
if (getLength > 5) {
$(this).parent().addClass('oScroll');
}
else {
$('.select-box').removeClass('oScroll');
}
});
/* Set widths of dropdowns*/
$('.select-box a').click(function () {
var widthofParent = $(this).innerWidth();
$(this).parent().children('ol').innerWidth(widthofParent - 2);
$(this).parent().children().children('li').innerWidth(widthofParent - 2);
var length, max = 0;
$(this).parent().children().children('li').each(function () {
length = $(this).text().length;
max = length > max ? length : max;
});
if (max > 25) {
$(this).parent().children('ol').css('width','auto')
$(this).parent().children().children('li').css('width', 'auto')
}
});
});