/* script for fucking info */
function initShowHide()
{
	if (document.getElementById && document.getElementsByTagName && document.createTextNode)
	{
		hide();
		var toggle = document.getElementById('mainNav');
		var as = toggle.getElementsByTagName('a');
		for (var i = 0; i < as.length; i++)
		{
			as[i].onclick = function()
			{
				show(this);
				this.className = 'active';
				return false;
			}
		}
		var close = document.getElementById('closeButton');
		close.onclick = function()
		{
			hide();
		}
		var close2 = document.getElementById('closeButton2');
		close2.onclick = function()
		{
			window.location.search = '';
		}
	}
}

function show(s)
{
	hide();
	var id = s.href.match(/#(\w.+)/)[1];
	document.getElementById('result').style.display = 'none';
	document.getElementById('info').style.display = 'block';
	document.getElementById(id).style.display = 'block';
}

function hide()
{
	var links = document.getElementById('mainNav').getElementsByTagName('a');
	for (var x = 0; x < links.length; x++)
	{
		links[x].className = '';
	}
	var info = document.getElementById('info').getElementsByTagName('div');
	for (var i = 0; i < info.length; i++)
	{
		info[i].style.display = 'none';
	}
	document.getElementById('info').style.display = 'none';
}

function closeCall()
{
	document.getElementById('callForEntries').style.display = 'none';
	return false;
}

/* script for fucking photos */
function initFuckPhoto()
{
	if (document.getElementById && document.getElementsByTagName)
	{
		// set the max value to the total number of photos you want to show
		var max = 43;
		var newPhoto;
		var now = new Date();
		//var increment = now.getDate();
		var increment = Math.round(Math.random()*max);
		var photo = document.getElementById('photo');
		
		if (increment > max)
		{
			increment = increment - (max + 1);
			if ((increment > max) || (increment < 1))
			{
				increment = max;
			}
		}
		
		/* this way link */
		var nextLink = document.getElementById('photoNav').getElementsByTagName('a')[0];
		nextLink.onclick = function()
		{
			if (increment < max)
			{
				increment = increment+1;
			}
			else
			{
				increment = 1
			}
			loadPhoto();
			return false;
		}
		
		/* that way link */
		var prevLink = document.getElementById('photoNav').getElementsByTagName('a')[1];
		prevLink.onclick = function()
		{
			if (increment > 1)
			{
				increment = increment - 1;
			}
			else
			{
				increment = max;
			}
			loadPhoto();
			return false;
		}
		
		function loadPhoto()
		{
			if (photo.getElementsByTagName('img').length > 0)
			{
				photo.removeChild(photo.getElementsByTagName('img')[0]);
				newPhoto = document.createElement('img');
				newPhoto.src = 'Images/fuck_'+increment+'.gif';
				photo.appendChild(newPhoto);
			}
			photo.style.display = 'block';
			photo.style.textAlign = 'center';
		}
		loadPhoto();
	}
}

/* Submission Form Validation */
function checkSubmission()
	{
		var form = document.getElementById('submitPhotos');
		
		if (form.name.value == 'NAME')
		{
			alert('Hey, enter your name.');
			form.name.focus();
			return false;
		}
		
		if (form.email.value == 'EMAIL')
		{
			alert('Hey, enter your name.');
			form.email.focus();
			return false;
		}
		
		if (form.location.value == 'LOCATION')
		{
			alert('Hey, enter your location.');
			form.location.focus();
			return false;
		}
		
		if (form.fuckFile.value == '')
		{
			alert('Be sure to select a file to upload.');
			return false;
		}
	}


/* comment popup launcher */
function initLinkFunctions()
{
	if (document.getElementById && document.getElementsByTagName)
	{
		var links = document.getElementsByTagName('a');
		
		for (var a = 0; a < links.length; a++)
		{
			// external links
			if (links[a].className == 'external')
			{
				links[a].onclick = function()
				{
					window.open(this.href);
					return false;
				}
			}
			
			// comments
			if (links[a].className == 'commentLink')
			{
				links[a].onclick = function()
				{
					newWindow(this.href,'comments','500','600','yes','');
					return false;
				}
			}
			
		}
	}
}			

function newWindow(mypage,myname,w,h,scroll,pos)
{
	if (pos == "random")
	{
		LeftPosition = (screen.width)?Math.floor(Math.random()*(screen.width-w)) :100;
		TopPosition = (screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	
	if (pos == "center")
	{
		LeftPosition = (screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;
	}
	
	else if ((pos != "center" && pos != "random") || pos == null)
	{
		LeftPosition = 25; TopPosition = 25;
	}

	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=yes,menubar=yes,toolbar=no,resizable=yes';

	win = window.open(mypage,myname,settings);
	if (win.focus)
	{
		win.focus();
	}

}

function initUpdateOrder()
{
	var items = document.getElementsByTagName('input');
	for (var i = 0; i < items.length; i++)
	{
		if (items[i].getAttribute('type') == 'checkbox')
		{
			items[i].onclick = function()
			{
				updateTotal();
			}
		}
		if (items[i].getAttribute('type') == 'text')
		{
			if ((items[i].value == '') || (items[i].value == '0'))
			{
				items[i].value = 1;
			}
			items[i].onblur = function()
			{
				updateTotal();
			}
		}
		if (items[i].getAttribute('type') == 'reset')
		{
			items[i].onclick = function()
			{
				updateTotal();
				document.getElementById('total').innerHTML = '0.00';
				document.getElementById('shippingUS').checked = true;
			}
		}
		if (items[i].className == 'agreement')
		{
			items[i].onclick = function()
			{
				var el = document.getElementById('stickerDownloads');
				if (el.style.display == 'block')
				{
					el.style.display = 'none';
				}
				else
				{
					el.style.display = 'block'
				}					
			}
		}
		if (items[i].getAttribute('type') == 'radio')
		{
			document.getElementById('shippingUS').checked = true;
			items[i].onclick = function()
			{
				updateTotal();
			}
		}
	}
}

function updateTotal()
{
	var order_total = 0;
	var el = document.getElementById('total');
	
	if (document.getElementById('fuckitBox').checked != false)
	{
		order_total += (parseFloat(document.orderForm.fuckitQty.value) * (document.orderForm.fuckitBox.value));
	}
	
	if (document.getElementById('fuckBookBox').checked != false)
	{
		order_total += (parseFloat(document.orderForm.fuckBookQty.value) * (document.orderForm.fuckBookBox.value));
	}
	
	if (document.getElementById('fuckStickersBox').checked != false)
	{
		order_total += (parseFloat(document.orderForm.fuckStickersQty.value) * (document.orderForm.fuckStickersBox.value));
	}
	
	if (document.getElementById('shippingInt').checked != false)
	{
		order_total += (parseFloat(document.getElementById('shippingInt').value) * 1);
	}
	
	if (document.getElementById('shippingUS').checked != false)
	{
		order_total += (parseFloat(document.getElementById('shippingUS').value) * 1);
	}
	
	var new_total = order_total.toFixed(2);
	el.innerHTML = String(new_total);
}

function checkOrder()
{
	var form = document.getElementById("orderForm");
	
	if ((form.fuckitBox.checked != true) && (form.fuckBookBox.checked != true) && (form.fuckStickersBox.checked != true))
	{
		alert('Hey! Select an item to buy before checking out.');
		return false;
	}
}

/* function to add events */
function addEvent(obj, evType, fn)
{ 
	if (obj.addEventListener)
	{ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	}
	else if (obj.attachEvent)
	{ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	}
	else
	{ 
		//alert('Your browser is old and outdated.\nIt will not work with this site.\nPlease consider upgrading to Mozilla FireFox');
		//window.location.href='http://www.mozilla.com';
		return false;
	} 
}

addEvent(window, 'load', initShowHide);
addEvent(window, 'load', initFuckPhoto);
addEvent(window, 'load', initLinkFunctions);
addEvent(window, 'load', initUpdateOrder);


