/* Javascript developed by www.cciwebs.com */
var bannerimages = new Array();
var faderindex = 0;
var play = true;
var finished = false;
var source_array = new Array();
var movieclicked = false;
$(document).ready(function() {
	// initialize
	$("img.fader").each(function(n)	{
		if(faderindex == n)	{
			$(this).fadeTo('slow', 1.0);
		}	else	{
			$(this).fadeTo('fast', .4);
		}
		is = $(this).attr('src');
		bannerimages[n] = is;
	});
	// click actions
	$("div#videobox").click(function()	{
//alert('finish');
		finish();
		if (!movieclicked)	{
			swfobject.embedSWF("flash/AskAnn2.swf", 
                   "askannmovie", 
                   "266",
                   "240",
                   "9.0.0",
                   "expressinstall.swf", //Express Install
                   false, //FlashVars
                   { wmode: "opaque", bgcolor: "#37405a" }, //Parameters
                   { id: "akmovie" }, //{ "class": "my-css-classname" }, //Attributes
                   false
									 );
			movieclicked = true;
		}
	});
	$("div#homeimages").click(function()	{
		start();
	});
	// force load for final images
	$(window).load(function()	{
		$.each(finalimages, function(i) {
			source_array[i] = new Image();
			source_array[i].src = this;
		});
	});
	// start timer
	$.timer(3000, function (timer) {
		fiold = faderindex;
/*		
		while (faderindex == fiold)	{
			faderindex=Math.floor(Math.random()*6);
		}
*/
		faderindex = ++faderindex % 6;
		if ((faderindex == 0) || !play)	{
			finish();
		}	else	{
			$("img.fader").each(function(n)	{
				if(faderindex == n)	{
					$(this).fadeTo('slow', 1.0);
				}	else	{
					$(this).fadeTo('slow', .4);
				}
			});
		}
	});
	// Form Submit Actions
	$("#contactForm").ajaxForm(function(response)	{
		$("#responsemessage").html(response);
	});
	$("#contactCancel").click(function()	{
		$("#responsemessage").html('');
		msg_first_time = true;
		return true;
	});
});
function finish()	{
	if (!finished)	{
		$("img.fader").each(function(n)	{
			$(this).fadeTo('fast', 0, function()	{
				$(this).attr('src', finalimages[n]);
				$(this).fadeTo(1500, 1);
			});
		});
		finished = true;
	}	
	play = false;
}
function start()	{
	$("img.fader").each(function(n)	{
		$(this).fadeTo('fast', 0, function()	{
			$(this).attr('src', bannerimages[n]);
			if (n == 0)	{
				$(this).fadeTo(1500, 1);
			}	else	{
				$(this).fadeTo('fast', 0.4);
			}
		});
	});
	faderindex = 0;
	finished = false;
	play = true;
}

