// Карусель
$.fn.carousel3d = function(items, iw, ih){
var enabled = true,
pos = active + Math.floor(items.length / 2),
speed = 0
var me = $(this)
.mouseenter(function(){ enabled = true })
.mouseleave(function(){ enabled = false })
.mousemove(function(e){ speed = (e.pageX - win.width() / 2) / win.width() })
$.each(items, function(i, v){
var ii = i
$('<img/>')
.width(iw)
.height(ih)
.attr('src', pixelUri)
.css('background', 'url(' + (v) + ') center center no-repeat')
.css('background-size', v.logo ? 'contain' : 'cover')
.appendTo(me)
.wrap('<div/>')
.mouseenter(function(){
enabled = false
var parent = $(this).parent()
this.lastZIndex = parent.css('z-index')
this.lastOpacity = parent.css('opacity')
parent
.css('z-index', 1000)
.css('opacity', 1)
})
.mouseleave(function(){
$(this).parent()
.css('z-index', this.lastZIndex)
.css('opacity', this.lastOpacity)
enabled = true
})
.click(function(){
alert(ii);
})
})
var rx = me.width() / 2 - iw
var ry = me.height() / 2 - ih
var ox = me.offset().left
var oy = me.offset().top
var px = win.width() / 2
var py = oy + ry + ih
function step(dispos) {
var ns;
if(typeof dispos == 'undefined'){
dispos = 0
ns = parseInt(1200 - Math.abs(speed * 260))
} else {
ns = 800
}
if(!enabled && dispos == 0) {
setTimeout(function(){step()}, ns)
return
}
pos += dispos == 0 ? (speed >= 0 ? 1 : -1) : dispos
if(pos < 0) pos += items.length
else if(pos >= items.length) pos -= items.length
me.children().each(function(k, v){
var a = (pos + k) / items.length * 2 * Math.PI
var i = $(v)
var op = (1 + Math.sin(a)) / 2
i
.stop()
.css('z-index', 10 + parseInt((1 + Math.sin(a)) * items.length * 2))
if(typeof $.browser.msi != 'undefined')
i
.animate({
left: parseInt(px + rx*Math.cos(a) - i.width() / 2),
top: parseInt(py + ry*Math.sin(a) - i.height() / 2),
opacity: op > .3 ? op : 0
}, ns, 'linear')
else if(typeof $.browser.opera == 'undefined')
i
.transition({
left: parseInt(px + rx*Math.cos(a) - i.width() / 2),
top: parseInt(py + ry*Math.sin(a) - i.height() / 2),
opacity: op > .3 ? op : 0
}, ns, 'linear', function(){
// i.css('visibility', op > .3 ? 'visible' : 'hidden')
})
else
i
.transition({
left: parseInt(px + rx*Math.cos(a) - i.width() / 2),
top: parseInt(py + ry*Math.sin(a) - i.height() / 2)
}, ns, 'linear', function(){
// i.css('visibility', op > .3 ? 'visible' : 'hidden')
})
})
setTimeout(function(){step()}, ns)
}
next = step
step()
}