(function($){
$.fn.kinmaxshow = function(user_options){
var default_options = {
height:460,
intervaltime:3,
switchtime:1000,
hoverpause:false,
easing:'linear',
imagealign:'center center',
button:{
switchevent:'click',
showindex:false,
normal:{width:'13px',height:'13px',right:'-50%',top:'-30px',background:"url(../images/tacn/lan1.png) no-repeat",marginright:'7px',float:'left'},
focus:{width:'13px',height:'13px',background:"url(../images/tacn/chen.png) no-repeat"}
},
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)