var images;
/*var i = Math.floor(Math.random() * 8); */
var ii;
var images2;
var okok=1;
var i =9;

$(document).ready(function(){

// PLUGIN WAIT 4 JQUERY by KoLE

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





		if ( window.timer ) {
			clearInterval(timer);
		}
		
		
		$.getJSON("prev.php",
	function(data){
		images = data;
		html = '<a id="urls10" href="'+ images[0]['url'] +'" target="_blank"><img border="0" src="preview/'+ images[0]['img'] +'" id="imgs10" /></a>';
		$("#header_prev_img").html(html);
		
		html = '<a id="urls0" href="'+ images[0]['url'] +'" target="_blank"><img border="0" src="preview/'+ images[0]['img'] +'" id="imgs0" /></a>';
		$("#header_prev_img0").html(html);
		html = '<a id="urls1" href="'+ images[1]['url'] +'" target="_blank"><img border="0" src="preview/'+ images[1]['img'] +'" id="imgs1" /></a>';
		$("#header_prev_img1").html(html);
		html = '<a id="urls2" href="'+ images[2]['url'] +'" target="_blank"><img border="0" src="preview/'+ images[2]['img'] +'" id="imgs2" /></a>';
		$("#header_prev_img2").html(html);
		html = '<a id="urls3" href="'+ images[3]['url'] +'" target="_blank"><img border="0" src="preview/'+ images[3]['img'] +'" id="imgs3" /></a>';
		$("#header_prev_img3").html(html);
		html = '<a id="urls4" href="'+ images[4]['url'] +'" target="_blank"><img border="0" src="preview/'+ images[4]['img'] +'" id="imgs4" /></a>';
		$("#header_prev_img4").html(html);
		html = '<a id="urls5" href="'+ images[5]['url'] +'" target="_blank"><img border="0" src="preview/'+ images[5]['img'] +'" id="imgs5" /></a>';
		$("#header_prev_img5").html(html);
		html = '<a id="urls6" href="'+ images[6]['url'] +'" target="_blank"><img border="0" src="preview/'+ images[6]['img'] +'" id="imgs6" /></a>';
		$("#header_prev_img6").html(html);
		html = '<a id="urls7" href="'+ images[7]['url'] +'" target="_blank"><img border="0" src="preview/'+ images[7]['img'] +'" id="imgs7" /></a>';
		$("#header_prev_img7").html(html);
		html = '<a id="urls8" href="'+ images[8]['url'] +'" target="_blank"><img border="0" src="preview/'+ images[8]['img'] +'" id="imgs8" /></a>';
		$("#header_prev_img8").html(html);

	
	
	
	
	
	});
	
	timer = setInterval(function() {
		getPicture(++i%9);
	}, 4000);
	


  });	




function getPicture(i) {
	

	$("#header_prev_img a").attr("href", document.getElementById("urls"+i).getAttribute("href"));

	$("#header_prev_img img").animate({opacity: 0.0}, "500",function(){	
		$('#header_prev_img img').attr({src: document.getElementById("imgs"+i).getAttribute("src")}).load(function(){
			$('#header_prev_img img').animate({opacity: 1}, "500");                      
		}); 
	});
	
	if(i == 0)
		$("#header_prev_img a").attr("target", "_blank");
	else
		$("#header_prev_img a").attr("target", "_self");
				
}


function getPicture2(i) {


		/*dbGet = function() {$.getJSON("prev.php", function(data){ images = data;});}
		dbGet();*/
}








function seee(i) {
document.getElementById("header_prev_img").style.display="none";
document.getElementById("header_prev_img0").style.display="none";
document.getElementById("header_prev_img1").style.display="none";
document.getElementById("header_prev_img2").style.display="none";
document.getElementById("header_prev_img3").style.display="none";
document.getElementById("header_prev_img4").style.display="none";
document.getElementById("header_prev_img5").style.display="none";
document.getElementById("header_prev_img6").style.display="none";
document.getElementById("header_prev_img7").style.display="none";
document.getElementById("header_prev_img8").style.display="none";
document.getElementById("header_prev_img"+i).style.display="";
}

function dis() {
document.getElementById("header_prev_img").style.display="";
document.getElementById("header_prev_img0").style.display="none";
document.getElementById("header_prev_img1").style.display="none";
document.getElementById("header_prev_img2").style.display="none";
document.getElementById("header_prev_img3").style.display="none";
document.getElementById("header_prev_img4").style.display="none";
document.getElementById("header_prev_img5").style.display="none";
document.getElementById("header_prev_img6").style.display="none";
document.getElementById("header_prev_img7").style.display="none";
document.getElementById("header_prev_img8").style.display="none";
}

function dis1() {
$("#header_prev_img").css ( { opacity:1 } );
$("#header_prev_img0").css ( { opacity:1 } );
$("#header_prev_img1").css ( { opacity:1 } );
$("#header_prev_img2").css ( { opacity:1 } );
$("#header_prev_img3").css ( { opacity:1 } );
$("#header_prev_img4").css ( { opacity:1 } );
$("#header_prev_img5").css ( { opacity:1 } );
$("#header_prev_img6").css ( { opacity:1 } );
$("#header_prev_img7").css ( { opacity:1 } );
$("#header_prev_img8").css ( { opacity:1 } );
}
function seee1() {
$("#header_prev_img").css ( { opacity:0 } );
$("#header_prev_img0").css ( { opacity:0 } );
$("#header_prev_img1").css ( { opacity:0 } );
$("#header_prev_img2").css ( { opacity:0 } );
$("#header_prev_img3").css ( { opacity:0 } );
$("#header_prev_img4").css ( { opacity:0 } );
$("#header_prev_img5").css ( { opacity:0 } );
$("#header_prev_img6").css ( { opacity:0 } );
$("#header_prev_img7").css ( { opacity:0 } );
$("#header_prev_img8").css ( { opacity:0 } );
}



function seeLayer(i) {

if ( window.timer ) {
	clearInterval(timer);
}

//$('#header_prev_img img').attr({src: document.getElementById("imgs"+i).getAttribute("src")});

//seee1();
//seee(i);

//seee1();
//$("#header_prev_img"+i).fadeTo(600,1);
seee(i) ;
}


function xx(i) {
//dis1();
i =9;
//$("#header_prev_img").wait().fadeTo(3000, 0); 
//$("#header_prev_img").wait().fadeOut(5000,1);

timer = setInterval(function() {
		dis();
		getPicture(++i%9);
	}, 4000);


}




