// JavaScript Document

function imgpreload(a,b){if(b instanceof Function){b={all:b}}if(typeof a=="string"){a=[a]}var c=[];var t=a.length;var i=0;for(i;i<t;i++){var d=new Image();d.onload=function(){c.push(this);if(b.each instanceof Function){b.each.call(this)}if(c.length>=t&&b.all instanceof Function){b.all.call(c)}};d.src=a[i]}}if(typeof jQuery!="undefined"){(function($){$.imgpreload=imgpreload;$.fn.imgpreload=function(b){b=$.extend({},$.fn.imgpreload.defaults,(b instanceof Function)?{all:b}:b);this.each(function(){var a=this;imgpreload($(this).attr('src'),function(){if(b.each instanceof Function){b.each.call(a)}})});var c=[];this.each(function(){c.push($(this).attr('src'))});var d=this;imgpreload(c,function(){if(b.all instanceof Function){b.all.call(d)}});return this};$.fn.imgpreload.defaults={each:null,all:null}})(jQuery)}


				$.fn.wait = function(time, type) {
						time = time || 1000;
						type = type || "fx";
						return this.queue(type, function() {
							var self = this;
							setTimeout(function() {
								$(self).dequeue();
							}, time);
						});
					};





			yami_bg = function() {				

				function startAnim() {
				    renova();										  
					setInterval( function(){
						do{
							var novaimagem = anyArray[Math.ceil(Math.random()*(anyArray.length-1))];
						}while( novaimagem == imagem )
						imagem = novaimagem;
						
						$.imgpreload( 'http://www.yami.com.br/full_bg/'+pasta+'/'+imagem,function()
						{
							$('#bg_full').fadeOut("slow", function () {
								$('#bg_full').css({'background' : 'url(http://www.yami.com.br/full_bg/'+pasta+'/'+imagem+') fixed top center no-repeat'});
							$('#bg_full').fadeIn('slow');
							});
						});
						
					}, 45000)

				}

			
			function randOrd(){
				return (Math.round(Math.random())-0.5); 
			}
			
			function renova () {
				
				anyArray = new Array('001.jpg','002.jpg','003.jpg','004.jpg','005.jpg','006.jpg','007.jpg','008.jpg','009.jpg','010.jpg');
			anyArray.sort( randOrd );
			
				imagem = anyArray[0]; 
		
				if (screen.width<=1280)		{
					pasta = "1280";
				} else if (screen.width<=1600)		{
					pasta = "1600";
				} else {
					pasta = "1920";
				}
				
			}
			
			renova();
			$('#bg_full').css({'background' : 'url(http://www.yami.com.br/full_bg/'+pasta+'/'+imagem+') fixed top center no-repeat'});
			
			startAnim();	


		}
