// JavaScript Document
$.noConflict();
var g_arrImgs,
	g_countPreloadedImgs,
	g_numImgs,
	g_currImg,
	g_numBetweenSlides;
(function($) {
	$(document).ready(function() {
		g_arrImgs = new Array ("/_i/1.jpg", "/_i/2.jpg", "/_i/3.jpg", "/_i/4.jpg", "/_i/5.jpg", "/_i/6.jpg");
		g_numImgs = g_arrImgs.length;
		g_countPreloadedImgs=0;
		g_currImg = 0;
		g_numBetweenSlides=4000;
		preloadImages();
		launchInterval();
		if ($('#slide').length) {
			var h = $('#slide').innerHeight();
		} else {
			var h = $('.apDiv4').innerHeight();	
		}
		if ($('apDiv2').height() < h ) {
			$('.apDiv2').height(h);	
		}
		//document.write("<!-- height to go: "+h+" / height done: "+$('.apDiv2').height(h)+"-->");
		$(window).resize(function() {
		});		
	});
	function launchInterval () {
		g_currImg = g_currImg < g_numImgs-1 ? g_currImg+1 : 0;
		setTimeout(setSlide, g_numBetweenSlides);
	}
	function setSlide() {
		$('#slide').fadeOut(function() {
			$('#slideImg').attr('src',g_arrImgs[g_currImg]);
			$('#slide').fadeIn(function() {
				launchInterval();
			});			
		});	
	}
	function preloadImages() {
		if (g_countPreloadedImgs < g_arrImgs.length) {
			var img = $('<img />').attr('src', g_arrImgs[g_countPreloadedImgs]).load(function() {
				g_countPreloadedImgs++;
				preloadImages();	
			});
		}
	}
})(jQuery);
