(function($){
$.fn.kinMaxShow = function(user_options){
var default_options = {
height:578,
intervalTime:3,
switchTime:1000,
hoverPause:false,
easing:'linear',
imageAlign:'center center',
button:{
switchEvent:'click',
showIndex:false,
normal:{width:'45px',height:'2px',right:'50%',top:'-28px',background:"#fafafa",marginRight:'5px',marginLeft:'5px',float:'left'},
focus:{width:'45px',height:'2px',background:"#ea8125"}
},
callback:function(index,action){}
};
options = jQuery.extend(true,{},default_options,user_options);
var k = {};
k.selector = $(this).selector;
if($(this).length>1){
$.error('kinMaxShow error[More than one selected object]');
return false;
}
k.self = this;
k.index = 0;
k.lindex = 0;
k.size = $(k.self).children('div').size();
k.prename = 'KMSPrefix_' + k.selector.replace(/\W/ig,'') + '_';
k.data = {};
k.fn = {};
k.onload = function(){
$(k.self).css({width:'100%',height:options.height,overflow:'hidden',position:'relative'}).children('div').addClass(k.prename+'image_item').hide();
k.init();
};
k.init = function(){
k.setLayout();
k.setAnimate();
};
k.setLayout = function(){
$(k.self).children('div').wrapAll('
');
$('.'+k.prename+'image_item',k.self).each(function() {
var a = $(this).children('a');
if(a.length){
var image = a.children('img').attr('src');
a.children('img').remove();
a.addClass(k.prename+'coverlink');
}else{
var image = $(this).children('img').attr('src');
$(this).children('img').remove();
}
$(this).css({background:'url('+image+') no-repeat '+options.imageAlign,'z-index':1});
});
$('.'+k.prename+'image_item',k.self).eq(0).css('z-index','2');
if(options.button.normal.display!='none'){
var button_list = '';
for(i=1;i<=k.size;i++){
if(options.button.showIndex){
button_list+=''+i+'';
}else{
button_list+=' ';
}
}
$(k.self).append('');
$('.'+k.prename+'button li',k.self).eq(0).addClass(k.prename+'focus');
//$('.'+k.prename+'button li',k.self).eq(0).animate({"width":"37px"});
}
k.setCSS();
$('.'+k.prename+'image_item:gt(0)',k.self).css('z-index',1).css({opacity:0});
$('.'+k.prename+'image_item',k.self).show();
$(k.self).css({overflow:'visible',visibility:'visible',display:'block'});
};
k.setCSS = function(){
var cssCode = '';
$(k.self).prepend(cssCode);
}
k.setAnimate = function(){
options.callback.call($('.'+k.prename+'image_item:eq('+k.index+')',k.self),k.index,'fadeIn');
var overDelayTimer;
$('.'+k.prename+'button',k.self).delegate('li',options.button.switchEvent,function(){
_this = this;
function setChange(){
k.data.moveTimer=window.clearInterval(k.data.moveTimer);
k.index = $(_this).index();
k.setOpacity();
setTimeout(k.data.moveTimer = setInterval(k.setOpacity,options.intervalTime*1000+options.switchTime),1000);
}
if(options.button.switchEvent=='mouseover'){
overDelayTimer = setTimeout(setChange,200);
}else{
setChange();
}
})
if(options.button.switchEvent=='mouseover'){
$('.'+k.prename+'button',k.self).delegate('li','mouseout',function(){
clearTimeout(overDelayTimer);
})
}
k.index = 1;
k.lindex = 0;
k.data.moveTimer = setInterval(k.setOpacity,options.intervalTime*1000+options.switchTime);
if(options.hoverPause){
$(k.self).hover(function(){
clearInterval(k.data.moveTimer);
},function(){
k.data.moveTimer = setInterval(k.setOpacity,options.intervalTime*1000+options.switchTime);
})
}
};
k.setOpacity = function(){
options.callback.call($('.'+k.prename+'image_item:eq('+(k.lindex)+')',k.self),k.lindex,'fadeOut');
if(options.button.normal.display!='none'){
$('ul.'+k.prename+'button li',k.self).removeClass(k.prename+'focus');
$('ul.'+k.prename+'button li',k.self).eq(k.index).addClass(k.prename+'focus');
//$('ul.'+k.prename+'button li',k.self).css({"width":"22px"});
//$('ul.'+k.prename+'button li',k.self).eq(k.index).animate({"width":"37px"});
}
$('.'+k.prename+'image_item:animated',k.self).stop(true,false);
$('.'+k.prename+'image_item',k.self).css('z-index',1);
$('.'+k.prename+'image_item',k.self).eq(k.index).css({opacity:0,'z-index':2});
$('.'+k.prename+'image_box .'+k.prename+'image_item:not(:eq('+k.index+'))',k.self).animate({opacity:0},options.switchTime,options.easing);
$('.'+k.prename+'image_item',k.self).eq(k.index).animate({opacity:1},options.switchTime,options.easing,function(){
options.callback.call($('.'+k.prename+'image_item:eq('+k.index+')',k.self),k.index,'fadeIn');
k.lindex = k.index;
if(k.index==k.size-1){
k.index=0;
}else{
k.index++;
}
}
);
};
k.run = function(){
k.onload();
};
k.fn.objToCss = function(obj,excArr,excFlag){
excFlag = excFlag?true:false;
var isIE = navigator.userAgent.indexOf("MSIE")!=-1;
var style = '';
if(excFlag){
for (var key in obj){
if($.inArray(key,excArr)!=-1){
pKey = key.replace(/([A-Z])/,KtoLowerCase);
if(pKey=='opacity' && isIE){
style +="filter:alpha(opacity="+(obj[key]*100)+");";
}else{
style +=pKey+":"+obj[key]+";";
}
}
};
}else{
for (var key in obj){
if($.isArray(excArr)){
if($.inArray(key,excArr)==-1){
pKey = key.replace(/([A-Z])/,KtoLowerCase);
if(pKey=='opacity' && isIE){
style +="filter:alpha(opacity="+(obj[key]*100)+");";
}else{
style +=pKey+":"+obj[key]+";";
}
}
}else{
pKey = key.replace(/([A-Z])/,KtoLowerCase);
if(pKey=='opacity' && isIE){
style +="filter:alpha(opacity="+(obj[key]*100)+");";
}else{
style +=pKey+":"+obj[key]+";";
}
}
};
}
function KtoLowerCase(word){
var str='';
str = '-'+word.toLowerCase();
return str;
};
return style;
};
k.run();
}
})(jQuery)