jQuery(function($) {

	var flashvars = {};
	var params = {};
	var attributes = {};

	swfobject.embedSWF("/swf/bak_logo.swf", "flash-logo", "380", "90", "9.0.0","", flashvars, params, attributes);
	
	$('#scroller li').slider();
	$('#home-content div').homeslider();
});


// home scroller
(function($) { 
	$.fn.homeslider = function(options) { 
			var defaults = {
				speed: 			5000,
				fadeSpeed: 		1500,
				activeItem:		0,
				itemCount:		0,
				top: 			0,
				TO:				''
			};	
			
			var options = $.extend(defaults, options);
			var jQueryMatchedObj = this;
			options.itemCount = jQueryMatchedObj.length;
						
			function start() {
				window.clearTimeout(options.TO);
				options.TO = window.setTimeout(function() { animate() }, options.speed);
			}

			function animate() {
				if(options.itemCount > 1) {
					nTop = options.top - $(jQueryMatchedObj[options.activeItem]).height();
					$(jQueryMatchedObj[options.activeItem]).animate(
						{ top: '-450px' },
						options.fadeSpeed
					);
					
					if(options.activeItem+1 < options.itemCount) {
						$(jQueryMatchedObj[options.activeItem+1]).animate(
							{ top: 0 },
							options.fadeSpeed,
							endAnimation
						);
					} else { 
						$(jQueryMatchedObj[0]).animate(
							{ top: 0 },
							options.fadeSpeed,
							endAnimation
						);
					}
				}
			}
			
			function endAnimation() {
				$(jQueryMatchedObj[options.activeItem]).css({top: '450px'});

				if(options.activeItem+1 < options.itemCount) {
					options.activeItem++;
				} else {
					options.activeItem = 0;
				}
				start();
			}
			
			start(jQueryMatchedObj);
		}
})(jQuery);

// home subscroller
(function($) {
		$.fn.slider = function(options) { 
			var defaults = {
				speed: 			5000,
				fadeSpeed: 		1500,
				zerotop:		0,
				top: 			0,
				startTop:		0,
				TO:				'',
				
				activeLi:		0,
				liCount:		0,
				
				StarScrollTop:	0,
				maxCount:		0
			};

			var options = $.extend(defaults, options);
			var jQueryMatchedObj = this;
			options.liCount = jQueryMatchedObj.length;
	//		options.activeLi = options.liCount;
			options.StartScrollTop = 0 - $('#scroller').outerHeight() + ((350 - $(jQueryMatchedObj[0]).outerHeight() )/2) ;
			options.zerotop = options.StartScrollTop;
		
			$('#scroller li').clone().appendTo('#scroller');
			$('#scroller li:lt('+options.liCount+')').clone().appendTo('#scroller');	
			$('#scroller').css({top: options.StartScrollTop});
			
			
			
			function start() {
				window.clearTimeout(options.TO);
				options.TO = window.setTimeout(function() { animate() }, options.speed);
			}

			function animate() {
				if(options.liCount > 1) {
					active = options.activeLi;
					next =  options.activeLi+1;
					myHeight =  $('#scroller li:eq('+active+')').outerHeight() 
					myOffset = ((350 - $('#scroller li:eq('+active+')').outerHeight() )/2);
					zeroTop = options.zerotop - myOffset - myHeight;
						
					nTop = zeroTop + ((350 - $('#scroller li:eq('+next+')').outerHeight() )/2);
					options.zerotop = nTop;
					
					$("#scroller").animate(
						{ top: nTop },
						options.fadeSpeed,
						endAnimation
					);
				}
			}

			function endAnimation() {
				if(options.activeLi +1 < options.liCount) {
					options.activeLi++;				
					start();
				} else {
					options.activeLi = 0;
					options.zerotop = options.StartScrollTop;
					$("#scroller").css({ top: options.StartScrollTop });
					start();
				}
			}

			start(jQueryMatchedObj);
		}
})(jQuery);
