/*
Created: car-man
Website: http://thebesthtml.com
*/
$(document).ready(function(){
	Cufon.replace('.logo-block p');
	$('.slider-wrap').sliderLn();
});
$(window).load(function(){$('.top-nav li a, .slider-thumb, .slider-main, .content-inner, .content-wrap .unit-img').each(function(){PIE.attach(this)})});
if(jQuery) (function($){
	// slider
	$.fn.sliderLn = function(params){
		var conf = $.extend({
			itemBlock:'.slider-main li',
			itemNav:'.slider-thumb li',
			playDuration:3000,
			fadeTime:200,
			opacityText:0.3
		},params);
		return this.each(function(){
			var c=conf,o=$(this),f=this,t=null,current=0,prev=-1;
			$.extend(f,{
				getItems:function(){return $(c.itemBlock, o)},
				getNavItem:function(){return $(c.itemNav, o)},
				moveItem:function(){
					//document.title='current '+current+'+ prev '+prev;
					if(prev!=current){
						if(current>=f.getItems().size()){current=0}
						var cf=f.getItems().eq(current), pf=f.getItems().eq(prev);
						cf.css({opacity:1});
						f.getNavItem().eq(prev).removeClass('item-active');
						pf.animate({opacity:0}, c.fadeTime,
							function(){cf.css({zIndex:10}); pf.css({zIndex:1});
								prev=current;
								f.getNavItem().eq(current).addClass('item-active');
						});
					}
				},
				autoRestart:function(){
					clearTimeout(t);
					t=setTimeout(function(){
						++current; f.moveItem();
						f.autoRestart();
					},c.playDuration);
				},
				autoPause:function(){clearInterval(t)}
			});
			
			if((c.fadeTime*2)<c.playDuration){
				f.getItems().each(function(i){
					if(i!=0){$(this).css({opacity:0})}else{$(this).css({zIndex:10})}
				}); f.moveItem();
				f.autoRestart();
				f.getNavItem().each(function(i){
					$('a', this).hover(function(){current=i; f.moveItem(); f.autoPause()},
					function(){f.autoRestart()})
				});
				f.getItems().hover(
					function(){f.autoPause()},function(){f.autoRestart()}
				)
			}
		})
	};
})(jQuery);
