$(document).ready(initHome);
var currSlide = 0;
var numSlides = 2;
var showControl;
function initHome()
{	
	initRP();
	$('#showHolder > div').each(function()
	{
		if( $(this).hasClass('hidden') )
		{
			$(this).removeClass('hidden');
			$(this).fadeOut(1);
		}
	});
	$('#showSelector > .selector:first').addClass('active');
	//setTimeout(function(){slide(0);}, 5000);
	
	
	
	$('#showHolder').bind("mouseleave",function()
	{
		playShow();
	}).bind("mouseenter", function()
	{
		pauseShow();
	}).trigger("mouseleave");
	
	$('#showSelector > #controller > .selector:eq(0)').click(function(){ if(currSlide != 0) slide(0); });
	$('#showSelector > #controller > .selector:eq(1)').click(function(){ if(currSlide != 1) slide(1); });

//setTimeout(constructionMessage, 4000);
}
function playShow()
{
	showControl = setInterval(function(){ slide(); },8000);
	$('#playPause img').attr("src", "assets/images/home/play.gif");
}
function pauseShow()
{
	clearInterval(showControl);
	$('#playPause img').attr("src", "assets/images/home/pause.gif");
}
function initRP()
{	
	$('#imageContainer1').bind('mouseenter', function()
	{
		$('#title').html($('#rpTitle1').val());
		$('#profile').html($('#rpProfile1').val());
		$('#date').html($('#rpDate1').val());
	});
	$('#imageContainer2').bind('mouseenter', function()
	{
		$('#title').html($('#rpTitle2').val());
		$('#profile').html($('#rpProfile2').val());
		$('#date').html($('#rpDate2').val());
	});
	$('#imageContainer3').bind('mouseenter', function()
	{
		$('#title').html($('#rpTitle3').val());
		$('#profile').html($('#rpProfile3').val());
		$('#date').html($('#rpDate3').val());
	});
	$('#imageContainer1, #imageContainer2, #imageContainer3').bind('mouseleave', function()
	{
		$('#title').html($('#rpTitle0').val());
		$('#profile').html($('#rpProfile0').val());
		$('#date').html($('#rpDate0').val());
	});
}


function slide(next)
{
	if(next==null)
		var next = (currSlide>=numSlides-1) ? 0 : currSlide + 1;
	//var int1;
	
	$('#showSelector > #controller > .selector:eq('+currSlide+')').removeClass('active');
	$('#showSelector > #controller > .selector:eq('+next+')').addClass('active');
			
	$('#showHolder > div:not(#showSelector):eq('+ currSlide +')').fadeOut("slow");
	setTimeout(function(){$('#showHolder > div:not(#showSelector):eq('+ next +')').fadeIn("slow");}, 400);
	currSlide = next;
}



var activated=false;

function constructionMessage()
{
	if(!activated)
	{
		createBackdrop();
		document.getElementById('flash_menu').style.visibility='hidden';
		createInfoBox();
		activated=true;
	}
	else
	{
		removeBackdrop();
		removeInfoBox();
		document.getElementById('flash_menu').style.visibility='visible';
		activated=false;
	}
}
function createInfoBox() 
{
	var newdiv2 = document.createElement('div');
	newdiv2.setAttribute('id', 'constructionMessage');
	document.body.appendChild(newdiv2);
	
	var newdiv3 = document.createElement('div');
	newdiv3.setAttribute('id', 'innerMessage');
	newdiv3.innerHTML='<span class="greenHeader block">Under Construction</span>Please pardon our appearance as our website is under construction.  As we pass through our beta phase, we appreciate your understanding and patience. We are working hard to give you the best experience here on aesthetiqdesign.com.  Please report any bugs or errors that you encounter to <a href="mailto:feedback@aesthetiqdesign.com">feedback@aesthetiqdesign.com</a>.  Thank You.';
	
	document.getElementById('constructionMessage').appendChild(newdiv3);
	
}
function removeInfoBox() 
{
	var div = document.getElementById('constructionMessage');
	document.body.removeChild(div);
}
function createBackdrop() 
{
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id', 'backdrop');
	document.body.appendChild(newdiv);
	
	if(window.addEventListener)
	{
		newdiv.addEventListener("click",constructionMessage,false);
	}
	else if (window.attachEvent)
	{
		newdiv.attachEvent("onclick",constructionMessage);
	}
	else
	{
		newdiv.onclick=constructionMessage;
	}
	
}
function removeBackdrop() 
{
	var divID = document.getElementById('backdrop');
	document.body.removeChild(divID);
}