/** * @author IEChernov * @copyright RolfImport * @extends jquery */ jQuery.fn.carsflow = function(startInit,activeInit){ var carsFlow = jQuery(this); var ItemCarsFlow = carsFlow.find('.item'); var igox = []; var activenow = 0; var easynig = 'swing'; var iw = []; var Dy = []; var Recurs = false; var itime = 1000; var iwidth = []; var firsttime = true; var exceptcar = false; var idtime = 0; var select = false; var carSelect = false; var direct = -1; var GlobalWidth = parseInt(carsFlow.width() / 2); jQuery(window).resize(function(){ GlobalWidth = parseInt(carsFlow.width() / 2); }); var imax = ItemCarsFlow.length; var ileft = parseInt(imax / 2); var iright = imax - ileft; ItemCarsFlow.each(function(index){ var width = parseInt(jQuery(this).attr('maxw')); jQuery(this).find('.info').css('left', ((width - 600) / 2)); iwidth[index] = width; jQuery(this).css('width',parseInt(iwidth[index] / 2)); jQuery(this).data('n',index); }); function igo(i,active){ if (Recurs) {easynig = 'linear'; if (direct < 0) {i = i - 1;} if (direct > 0) {i = i + 1;} itime = 0.05; if (Math.abs(direct) > 1) { itime = 0.1; } } else { easynig = 'swing'; itime = 1000; } if (i < 0) { i = imax + i;} if (i >= imax) { i = i - imax;} ItemCarsFlow.stop(); var realJ = 0; var intent = 0; for(j=i-ileft;j=imax) {realJ = j - imax;} igo[realJ] = intent; if ((realJ == i) && active){ iw[realJ]=iwidth[realJ] ; Dy[realJ] = 0; intent += iw[realJ] + 100; } else { Dy[realJ] = 75; iw[realJ]=parseInt(iwidth[realJ] / 2); intent += iw[realJ] + 100; } } var Dx = igo[i] - ((1000-iw[i])/2); carsFlow.find('.info').hide(); if (firsttime) { firsttime = false; ItemCarsFlow.each(function(index){ jQuery(this).css({left:(igo[index] - Dx),width:iw[index],bottom:Dy[index]}); if ((index == i) && active) { jQuery(this).find('.info').fadeIn(50); } if (index == (imax - 1)) { activenow = i; if (Recurs) {igo(activenow,false);} } }); } else{ if (Recurs) { itime = parseInt(Math.abs(parseInt(ItemCarsFlow.eq(i).css('left')) - (igo[i] - Dx)) / itime); } ItemCarsFlow.each(function(index){ if ( Math.abs(parseInt($(this).css('left')) - (igo[index] - Dx)) > 1200) { var newX = igo[index] - Dx; if (newX > 0) {jQuery(this).css({left:newX + 500,width:iw[index],bottom:Dy[index]});} else{ jQuery(this).css({left:newX - 500,width:iw[index],bottom:Dy[index]});} } $(this).animate({left:(igo[index] - Dx),width:iw[index],bottom:Dy[index]},itime,easynig,function(){ if ((index == i) && active) { idtime = setTimeout(function() { select = false; }, 3000); jQuery(this).css('overflow','visible'); jQuery(this).find('.info').fadeIn(50); } if (index == (imax - 1)) { activenow = i; carSelect=false; if (exceptcar) {Recurs = true; exceptcar = false;} if (Recurs) { igo(activenow,false);} } }); }); } } Recurs = false; igo(startInit,activeInit); ItemCarsFlow.click(function(){ if (carSelect) {return false;} clearInterval(idtime); clickI = $(this).data('n'); if ($(this).find('.info').css('display') == 'none') { Recurs = false; select = true; carSelect = true; igo(clickI,true); return false; } }); ItemCarsFlow.mousemove(function() { if (jQuery(this).data('n') == activenow) {return false;} }); $("div.leftcar").click(function(){ direct = 0; i = (activenow - 1); if (i < 0) { i = imax + i;} ItemCarsFlow.eq(i).trigger('click'); }); $("div.rightcar").click(function(){ direct = 0; i = (activenow + 1); if (i >= imax) { i = i - imax;} ItemCarsFlow.eq(i).trigger('click'); }); carsFlow.mouseleave(function(){ $("div.leftcar").hide(); $("div.rightcar").hide(); direct = 0; Recurs = false; }); carsFlow.mousemove(function(event) { GlobalX = GlobalWidth - event.pageX; if ((GlobalX < 125) && (GlobalX > -125)){ $("div.leftcar").hide(); $("div.rightcar").hide(); }else { if (GlobalX < 0){ $("div.leftcar").hide(); $("div.rightcar").show(); }else{ $("div.leftcar").show(); $("div.rightcar").hide(); }} if ((select) || (carSelect)) {return false;} if (GlobalX > 500) { if (direct != -2) { direct = -2; Recurs = true; igo(activenow,false); } direct = -2; } else if (GlobalX >= 350) { if (direct != -1) { direct = -1; Recurs = true; igo(activenow,false); } direct = -1; } else if (GlobalX < -500) { if (direct != 2) { direct = 2; Recurs = true; igo(activenow,false); } direct = 2; } else if (GlobalX <= -350) { if (direct != 1) { direct = 1; Recurs = true; igo(activenow,false); } direct = 1; } else { direct = 0; Recurs = false; } }); };