var thumbnail_shrink=4
var def_newsl_email_message='Your address here'

window.onload = function()
{
	var address = 'andrew'+'boult'
	address = '@' +address+'er.com'
	address = 'andre'+ 'w'+address
	email_substitute(document.getElementById('footer_email'), address, true)
	email_substitute(document.getElementById('body_email'), address, false)

	var e0=document.getElementById('heading')
	if(e0)
	{
		if(screen.height<768)
		{
			document.body.style.padding='0'
			e0.style.margin='0'

			var e0=document.getElementById('footer')
			e0.style.fontSize='10px'
			e0.style.padding='0'
			var e0=document.getElementById('heading')
			e0.style.height='45px'
			e0.style.backgroundImage='url(skins/andrewboulter_elegant/images/signiture.lofi.png)'
		}
	}

	var e0=document.getElementById('actual_contents')
	if(e0)
	{
		var l0=e0.childNodes
		var image_gallery_pages_div=null
		var video_gallery_pages_div=null
		for(var i0=0;i0<l0.length;++i0)
		{
			var e1=l0[i0]
			switch(e1.className)
			{
				case 'image_gallery_pages':
					image_gallery_pages_div=e1
					break

				case 'video_gallery_pages':
					video_gallery_pages_div=e1
					break

				default:
			}
		}

		if(image_gallery_pages_div)
		{
			apply_shrink_effect(image_gallery_pages_div.childNodes)
		}

		if(video_gallery_pages_div)
		{
			apply_shrink_effect(video_gallery_pages_div.childNodes)
		}
	}

	var e0=document.getElementById('news_subs_email')
	if(e0)
	{
		e0.onfocus=function()
		{
			if(this.value==def_newsl_email_message)
			{
				this.value=''
				e0.style.color=''
			}
		}
		e0.onblur=function()
		{
			if(this.value=='')
			{
				this.style.color='#999'
				this.value=def_newsl_email_message
			}
		}
		e0.onblur()
	}
}

function apply_shrink_effect(nodes)
{
	for(var i0=0;i0<nodes.length;++i0)
	{
		var e1=nodes[i0]
		e1.onmouseout=function()
		{
			var e0=this.childNodes[0]
			e0.style.width=parseInt(e0.style.width)-(thumbnail_shrink*2)+'px'
			e0.style.height=parseInt(e0.style.height)-(thumbnail_shrink*2)+'px'
			e0.style.padding=thumbnail_shrink+'px'
		}
		e1.onmouseover=function()
		{
			var e0=this.childNodes[0]
			e0.style.width=parseInt(e0.style.width)+(thumbnail_shrink*2)+'px'
			e0.style.height=parseInt(e0.style.height)+(thumbnail_shrink*2)+'px'
			e0.style.padding='0px'
		}
		e1.onmouseout()
	}
}

function check_newsletter()
{
	var e0=document.getElementById('news_subs_email')
	if(!e0)
		return true

	var val=e0.value
	var at_pos=val.indexOf('@')
	var last_dot_pos=val.lastIndexOf('.')
	// minimum email: 'a@b.ca'
	if(val == def_newsl_email_message || at_pos < 1 || at_pos > val.length - 5 || last_dot_pos < at_pos || last_dot_pos > val.length - 3)
	{
		alert('Invalid email address, please make sure you enter your address correctly!')

		e0.focus()

		return false
	}

	return true
}

function email_substitute(span, address, keep_text)
{
	if(!span)
		return
	var text = ''
	if(keep_text)
		text = span.innerHTML
	else
		text = address
	span.innerHTML = '<a href="mailto:' + address + '">' + text + '</a>'
}

function view_image_in_window(url, dimensions, image_title)
{
	var features = ''
	var img_height = ''
	var img_width = ''
	if(dimensions != '')
	{
		dimensions = dimensions.split('x')
		img_height = dimensions[1]
		img_width = dimensions[0]
		if(img_height < 100)
			img_height = 100
		if(img_width < 100)
			img_width = 100

		var top  = Math.round((screen.height - img_height) / 2)
		var left = Math.round((screen.width - img_width) / 2)
		features += 'resizable, height=' + img_height + ', width=' + img_width + ', top=' + top + ', left=' + left
	}

	var w = window.open('', '', features)
	if(!w)
		return false

	var known_width = false
	with(w.document)
	{

		//writeln('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">')
		//writeln('<html xmlns="http://www.w3.org/1999/xhtml">')
		writeln('<html>')
		writeln('<head><title>' + image_title + '</title></head>')
		writeln('<body onclick="window.close()" style="height:100%;margin:0;padding:0;cursor:pointer;cursor:hand">')
		writeln('<table style="margin:0;padding:0;height:100%;width:100%" cellpadding="0" cellspacing="0"><tr><td style="vertical-align:middle;text-align:center">')
		writeln('<img alt="' + image_title + '" title="' + image_title + '" src="' + url + '" />')
		writeln('</td></tr></table>')
		writeln('</body>')
		writeln('</html>')
		close()
	}
	return false
}
