var cntReady = 0;
var imagesLoaded = 0;
var gotime = 0;

$(document).ready( function() {
	$('.previewImage a').lightBox();

	if(showFlashIntro == true) {
		if(cntReady == 0) {
			init();
		}
		cntReady++;
	}
});

function removeFlash() {
	$('#container').css('display', 'block');
	setTimeout(function() {
		$('#flashContent').remove();
		$('.previewImage a').lightBox();
	}, 1500);
}

function loadPage(target) {
	$.ajax( {
		url : location.href + target,
		type : "POST",
		dataType : "html",
		success : function(data) {
			var containerPos = data.search(/<div id="container">/);
			var bodyEndPos = data.search(/<\/body>/);
			var newHTML = $(data.substr(containerPos, bodyEndPos));

			$('#container').html( newHTML.html() );
			
		}
	});
}

function init() {
	$.ajax( {
		url : location.href + 'script/php/readdir.php',
		type : "GET",
		data : { dir: 'gfx'},
		dataType : "html",
		success : function(data) {
			var _images = data.split(","); 
			
			imagesLoaded = 0;
			gotime = _images.length;
			
			$.each(_images,function(e) {
				var loader = new ImageLoader(this);
				loader.loadEvent = imageIsLoaded();
			    loader.load();
			});
		}
	});
}

function imageIsLoaded(  )
{
     ++imagesLoaded;
	if(imagesLoaded == gotime) {
		begin();
	}
}

function begin() {
	var flashvars = {};
	var params = {};
	params.allowFullScreen = "true";
	params.quality = "best";
	params.scale = "noscale";
	params.wmode = "transparent";
	var attributes = {};
	swfobject.embedSWF("BSKIntro.swf", "flash", "1000", "820", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
}

