// AdLib Module by HAYA

if( !$Ad.module ) $Ad.module = {};

$Ad.module.top_picture = {

css_id: '#top_picture',
width : 720,
height: 360,

php_module: $Ad.generateByPHP.url.site+'/modules/pic_list/pic_list.php',

dir: '',
putting: false,

init: function(){
	if( !$Ad.module.top_picture.dir ) return;
	var md = $Ad.module.top_picture;
	var el = $(md.css_id);
	el.css('width' , md.width );
	el.css('height', md.height);
	var running = false;
	$.getJSON(
		$Ad.module.top_picture.php_module,
		{ dir: $Ad.module.top_picture.dir , output:'json' },
		function( json ){
			$Ad.Img.preload( json, {
				onComplete: function(){
					var s  = '';
					$.each(json,function(i,v){
						s+='<img class="'+v['class']+'" src="'+v.src+'" width="'+md.width+'" height="'+md.height+'" border="0" />';
					});
					$( md.css_id ).html(s);
					$( md.css_id ).cycle({
						fx:'fade', speed:2500 ,timeout:7500, next: md.css_id , random:1, startingSlide:0, autostopCount:20,
						after: function(){
							if( !running ){
								running = true; $(  md.css_id+'-block').css('background','#fff');
							}
						}
					});
				}
			}, null, 60*1000 );
		}
	);
	el = $( md.css_id+'-toggle' );
	el.html('↑↑↑');
	el.toggle( md.close, md.open );
},
close: function(){
	var cs = $Ad.module.top_picture.css_id;
	$( cs ).slideUp(1000, function(){
		$( cs+'-toggle').html('↓↓↓');
		$( cs ).cycle('pause');
	});
},
open: function(){
	var cs = $Ad.module.top_picture.css_id;
	$( cs ).slideDown(1000,function(){
		$( cs+'-toggle').html('↑↑↑');
		$( cs ).cycle('resume');
	});
}

}

$(function(){ $Ad.module.top_picture.init(); });
