it/itf/static/js/frontpage.js

155 lines
4.2 KiB
JavaScript
Raw Permalink Normal View History

2011-08-03 10:34:24 +00:00
var slider;
$(function() {
var slideInterval = 0;
slider = new ItfSlider();
$('#arrowLeft').click(function() {
slider.moveRight(230, 150);
});
$('#arrowRight').click(function() {
slider.moveLeft(230, 150);
});
$('#arrowLeft').mouseover(function() {
slider.moveRight(230, 1500);
slideInterval = setInterval(function() {
slider.moveRight(230, 1500);
}, 1500);
});
$('#arrowLeft').mouseout(function() {
clearInterval(slideInterval);
slider.stop();
2011-08-03 10:34:24 +00:00
});
$('#arrowRight').mouseover(function() {
slider.moveLeft(230, 1500);
slideInterval = setInterval(function() {
slider.moveLeft(230, 1500);
}, 1500);
});
$('#arrowRight').mouseout(function() {
clearInterval(slideInterval);
slider.stop();
2011-08-03 10:34:24 +00:00
});
2011-10-25 14:10:52 +00:00
$('#sliderTabs .tab').click(function() {
2011-10-25 13:53:35 +00:00
var link = $(this).find(".moreTab").attr("href");
location.href = link;
});
2011-08-03 10:34:24 +00:00
$('.banner').click(function() {
var link = $(this).attr("data-link");
2011-12-15 16:21:37 +00:00
if ($.trim(link) != '') {
location.href = link;
}
});
$('.buttons').click(function() {
var $t = $(this);
var buttonNo = parseInt($t.attr("id").replace("button", ""));
$('.buttonsSelected').removeClass("buttonsSelected");
$t.addClass("buttonsSelected");
$('.banner').hide();
$('.banner').eq(buttonNo).show();
2011-12-15 16:21:37 +00:00
clearTimeout(frontImageTimeout);
cycleFrontImages = false;
});
2011-08-03 10:34:24 +00:00
});
2011-12-15 16:21:37 +00:00
/* for front images */
var frontImageTimeout;
$(function() {
$('.banner').eq(0).show();
$('#button0').addClass("buttonsSelected");
frontImageTimeout = setTimeout(cycleFrontImage, 5000);
// frontImageInterval = setInterval(cycleFrontImage, 1000);
});
cycleFrontImages = true;
function cycleFrontImage() {
// BOO = $('.buttonsSelected');
var currImage = parseInt($('.buttonsSelected').attr("id").replace("button", ""));
var currBanner = $('.banner').eq(currImage);
if (currImage < ($('.buttons').length - 1)) {
var nextImage = currImage + 1;
} else {
var nextImage = 0;
}
// console.log(nextImage);
$('.banner').hide();
$('.buttonsSelected').removeClass("buttonsSelected");
$('.banner').eq(nextImage).show();
$('#button' + nextImage).addClass("buttonsSelected");
if (cycleFrontImages) frontImageTimeout = setTimeout(cycleFrontImage, 10000);
}
2011-08-03 10:34:24 +00:00
var ItfSlider = function(o) {
var opts = $.extend({
'jq': '#slider',
'ul': '#sliderTabs',
'li': '.tab',
'width': 960,
'liWidth': 230,
'leftArr': '#arrowLeft',
'rightArr': '#arrowRight'
}, o);
this.jq = $(opts.jq);
this.ul = $(opts.ul);
this.lis = this.ul.find(opts.li);
this.leftArr = $(opts.leftArr);
this.rightArr = $(opts.rightArr);
this.width = opts.width;
this.liWidth = opts.liWidth;
this.contentWidth = this.liWidth * this.lis.length;
this.maxLeft = 0 - (this.contentWidth - this.width + 70);
this.getLeft = function() {
return parseInt(this.ul.css("left").replace("px", ""));
};
this.positionArrow = function() {
var arrLeft = (0 - this.getLeft()) + (this.contentWidth - 10);
console.log(arrLeft);
this.rightArr.animate({'left': arrLeft + "px"});
};
this.stop = function() {
this.ul.stop();
};
2011-08-03 10:34:24 +00:00
};
ItfSlider.prototype.moveLeft = function(distance, speed) {
if (typeof(distance) == 'undefined') {
distance = this.liWidth;
}
this.ul.stop();
var left = this.getLeft();
if (left > this.maxLeft) {
var newLeft = left - distance;
if (newLeft < this.maxLeft) { newLeft = this.maxLeft; }
this.ul.animate({"left": newLeft + "px"}, speed);
// this.positionArrow();
}
};
ItfSlider.prototype.moveRight = function(distance, speed) {
if (typeof(distance) == 'undefined') {
distance = this.liWidth;
}
this.ul.stop();
var left = this.getLeft();
if (left <= 0) {
var newLeft = left + distance;
if (newLeft > 0) { newLeft = 0; }
this.ul.animate({'left': newLeft + "px"}, speed);
// this.positionArrow();
}
};
2011-11-01 02:19:06 +00:00