var currentURL = '';
var smoothMoveIntervalId = 0;
var currentSign = 0;
var moveDiv = null;
var hideDiv = null;
var searchPre = 'http://mobile.search.aol.com/iphone/search.htm?query=';
var searchPost = '&invocationType=bottomsearchbox.iphonehoroscopes';
function scroll()
{
	window.scrollTo(0,1);
}

function smoothMoveRight()
{
	var left = moveDiv.offsetLeft;
	if (left == 0)
	{
		hideDiv.style.visibility = 'hidden';
		hideDiv.style.display = 'none';
		
		clearTimeout(smoothMoveIntervalId);
	}
	else
	{
		moveDiv.style.left = left - 40 + 'px';
	}
}

function smoothMoveLeft()
{
	var left = moveDiv.offsetLeft

	if (left == 0)
	{
		hideDiv.style.visibility = 'hidden';
		hideDiv.style.display = 'none';

		clearTimeout(smoothMoveIntervalId);
	}
	else
	{
		moveDiv.style.left = left + 40 + 'px';
	}
}

function show(show, hide1, hide2, direction)
{

	// Direction
	// 0: Left
	// 1: Right
	// 2: Up
	// 3: Down
	// Up and Down Are No Yet Implemented
	
	var showdiv = document.getElementById(show);
	var hide1 = document.getElementById(hide1);
	var hide2 = document.getElementById(hide2);
	
	
	showdiv.style.zIndex = "100";
	
	hide1.style.zIndex = "10";
	hide2.style.zIndex = "0";
	
	moveDiv = showdiv;
	hideDiv = hide1;
	window.scrollTo(0,1);
			
	if (direction == 0)
	{
		showdiv.style.left = '-320px';	
		showdiv.style.visibility = 'visible';
		showdiv.style.display = 'block';
		smoothMoveIntervalId = setInterval (smoothMoveLeft, 1);
	}
	
	if (direction == 1)
	{
		showdiv.style.left = '320px';
		showdiv.style.visibility = 'visible';
		showdiv.style.display = 'block';
		smoothMoveIntervalId = setInterval (smoothMoveRight, 1);
	}
	
	
}

function changeSignDetail()
{
	show('main','signDetail','matchDetail',0);
	swapSignDetails('signdetailtoday','signdetailyesterday','signdetailtomorrow','todaytab','yesterdaytab','tomorrowtab');	
}

function submitform(form)
{
	if (document.forms[form].onsubmit())
	{
		document.forms[form].submit();
		document.forms[form].reset();
	}
}

function validate(formName)
{
	if (formName.websearchinput.value != '')
	{ 
		formName.websearchinput = '';
		return true;
	}
	else
	{
		return false;
	}
}

function getSignDetail(id)
{
	currentSign = id;
	swapSignDetails('signdetailtoday','signdetailyesterday','todaytab','yesterdaytab');
	SignInfo.getSignInfoById(id, function(detail) {
		for (var i=0; i < detail.length; i++)
		{
			var signDetail = detail[i];	
			if (signDetail.day == 'today')
			{
				dwr.util.setValue('signdetailtoday', signDetail.signContent);
				
			}
			if (signDetail.day == 'yesterday')
			{
				dwr.util.setValue('signdetailyesterday', signDetail.signContent);
			}
			if (signDetail.day == 'tommorrow')
			{
				dwr.util.setValue('signdetailtomorrow', signDetail.signContent);
			}
			
			currentURL = signDetail.signCurrentURL;
			dwr.util.setValue('signtitle', signDetail.name);
			dwr.util.setValue('signdates', signDetail.signHeader);
			dwr.util.setValue('signauthor', signDetail.publisher);
			var link = document.getElementById('signDetailShareButton');
			link.href = 'mailto:?subject=Horoscopes%20by%20AOL&body=' + currentURL;
		}
		show('signDetail','main','matchDetail',1); 
	}
	);
	
	
}

/*function swapSignDetails(show, hide1, hide2, showtab, hide1tab, hide2tab)
{
	var showDiv = document.getElementById(show);
	var hide1Div = document.getElementById(hide1);
	var hide2Div = document.getElementById(hide2);
	var showtabDiv = document.getElementById(showtab);
	var hide1tabDiv = document.getElementById(hide1tab);
	var hide2tabDiv = document.getElementById(hide2tab);
	
	showDiv.style.visibility = 'visible';
	showDiv.style.display = 'block';
	hide1Div.style.visibility = 'hidden';
	hide1Div.style.display = 'none';
	hide2Div.style.visibility = 'hidden';
	hide2Div.style.display = 'none';
	showtabDiv.className = showtabDiv.className.replace('Inactive','Active');
	hide1tabDiv.className = hide1tabDiv.className.replace('Active','Inactive');
	hide2tabDiv.className = hide2tabDiv.className.replace('Active','Inactive');
}*/

function swapSignDetails(show, hide1, showtab, hide1tab)
{
	var showDiv = document.getElementById(show);
	var hide1Div = document.getElementById(hide1);
	var showtabDiv = document.getElementById(showtab);
	var hide1tabDiv = document.getElementById(hide1tab);
	
	showDiv.style.visibility = 'visible';
	showDiv.style.display = 'block';
	hide1Div.style.visibility = 'hidden';
	hide1Div.style.display = 'none';
	showtabDiv.className = showtabDiv.className.replace('Inactive','Active');
	hide1tabDiv.className = hide1tabDiv.className.replace('Active','Inactive');
}

function getLoveMatch(formName,showThis,hide1,hide2)
{
	var form = document.forms[formName];
	var yourSign = form.elements['yoursign'].value;
	var theirSign = form.elements['theirsign'].value;
	var loveMatch = yourSign + ':' + theirSign;
	var button = dwr.util.byId(formName);
	button.focus();
	SignInfo.getLoveMatch(loveMatch, function(lm) {
		dwr.util.setValue('matchsubtitle', lm.headline, { escapeHtml:false });
		dwr.util.setValue('matchdetail', lm.content);
		var hide1Elem = dwr.util.byId(hide1);
		scroll();
		if (hide1Elem.id != 'matchDetail')
		{
			show(showThis, hide1, hide2,1);
		}
	}
	);
}