/*
JavaScript file for AMJ portfolio functions
Mike Smith - www.SomeURL.net - 2010
*/

var tld = 'http://amjgraphic.co.uk/'; //Make sure you end this with a slash
var activeElement = '';

/*
Generic opacity setting
*/
function setElementOpacity(obj, opacity) {
	opacity = (opacity == 100)?99.999:opacity;
	//IE
	obj.style.filter = "alpha(opacity:" + opacity + ")";
	//IE8
	obj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + opacity + ")";
	//Firefox and Mozilla
	obj.style.opacity = opacity/100;
	//Older Safari
	obj.style.KHTMLOpacity = opacity/100;
	//Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	//debug('Set glbOpacity..' + glbOpacity)

}

function mainClick(m)
{
	
	//window.location = "http://www.mozilla.org"; 
	if(m == 'home') { window.location = tld; }
	if(m == 'photography') { window.location = tld + 'gallery/photography/'; }
	if(m == 'graphics') { window.location = tld + 'gallery/graphicdesign/'; }
	if(m == 'illustration') { window.location = tld + 'gallery/illustration/'; }
	if(m == 'cv') { window.location = tld + 'cv/Online CV 2011.pdf'; }
	if(m == 'email') { window.location = 'mailto:contact@amj-graphic.co.uk';}
	if(m == 'contact') {handleContact();}
	if(m == 'about') {handleAbout();}
}

function mainMouseOut(m)
{
	if(m == 'contact') {handleContactMouseOut();}
	if(m == 'about') {handleAboutMouseOut();}
}


function mainMouseOver(m)
{
	if(m == 'contact') {handleContactMouseOver();}
	if(m == 'about') {handleAboutMouseOver();}
}


function debug(m)
{
	//document.getElementById("debug").innerHTML = 'Debug: ' + m;
	//window.document.title = m;
}

function repositionMain()
{
	winW = (document.body.offsetWidth - 1024) / 2;
	
	document.getElementById("main").style.left= winW + "px";
	//winW = document.body.offsetWidth;
	//winH = document.body.offsetHeight;

}

function greenElement(elt, current)
{
	document.getElementById(elt).style.color = "#61E339";
	if(current == 'illustration'){
		document.getElementById('ill').style.color = "#61E339";
		return;
	}if(current == 'graphicdesign'){
		document.getElementById('gfx').style.color = "#61E339";
		return;
	}if(current == 'photography'){
		document.getElementById('photography').style.color = "#61E339";
		return;
	}
}

function unGreenElement(elt, current)
{
	document.getElementById(elt).style.color = "#393939";
	if(current == 'illustration'){
		document.getElementById('ill').style.color = "#61E339";
	}if(current == 'graphicdesign'){
		document.getElementById('gfx').style.color = "#61E339";
	}if(current == 'photography'){
		document.getElementById('photography').style.color = "#61E339";
	}
}

function setActiveElement(arg)
{
	activeElement = arg;
}


/*Lolahack to get around the fading problems without creating classes and what not...*/
var DigFadeIn = false;
var GraphFadeIn = false;
var PhotoFadeIn = false;

function setDigFade(val) { DigFadeIn = val; }	

function setGraphFade(val) { GraphFadeIn = val; }

function setPhotoFade(val) { PhotoFadeIn = val; }	

function fadeDigitalElementIn(elId, opacity, level) {
		if ((document.getElementById(elId)) && (DigFadeIn)) {
			obj = document.getElementById(elId);
			if ((opacity >= 0 && level < 0)|| (opacity <= 100 && level > 0)) {
				setElementOpacity(obj, opacity);
				opacity += level;
				window.setTimeout("fadeDigitalElementIn('"+elId+"',"+opacity+"," + level + ")", 10);
			}
		}
}
function fadeDigitalElementOut(elId, opacity, level) {
		if ((document.getElementById(elId)) && (!DigFadeIn)) {
			obj = document.getElementById(elId);
			if ((opacity >= 0 && level < 0)|| (opacity <= 100 && level > 0)) {
				setElementOpacity(obj, opacity);
				opacity += level;
				window.setTimeout("fadeDigitalElementOut('"+elId+"',"+opacity+"," + level + ")", 10);
			}
		}
}

function fadeGraphicElementIn(elId, opacity, level) {
		if ((document.getElementById(elId)) && (GraphFadeIn)) {
			obj = document.getElementById(elId);
			if ((opacity >= 0 && level < 0)|| (opacity <= 100 && level > 0)) {
				setElementOpacity(obj, opacity);
				opacity += level;
				window.setTimeout("fadeGraphicElementIn('"+elId+"',"+opacity+"," + level + ")", 10);
			}
		}
}
function fadeGraphicElementOut(elId, opacity, level) {
		if ((document.getElementById(elId)) && (!GraphFadeIn)) {
			obj = document.getElementById(elId);
			if ((opacity >= 0 && level < 0)|| (opacity <= 100 && level > 0)) {
				setElementOpacity(obj, opacity);
				opacity += level;
				window.setTimeout("fadeGraphicElementOut('"+elId+"',"+opacity+"," + level + ")", 10);
			}
		}
}


function fadePhotoElementIn(elId, opacity, level) {
		if ((document.getElementById(elId)) && (PhotoFadeIn)) {
			obj = document.getElementById(elId);
			if ((opacity >= 0 && level < 0)|| (opacity <= 100 && level > 0)) {
				setElementOpacity(obj, opacity);
				opacity += level;
				window.setTimeout("fadePhotoElementIn('"+elId+"',"+opacity+"," + level + ")", 10);
			}
		}
}
function fadePhotoElementOut(elId, opacity, level) {
		if ((document.getElementById(elId)) && (!PhotoFadeIn)) {
			obj = document.getElementById(elId);
			if ((opacity >= 0 && level < 0)|| (opacity <= 100 && level > 0)) {
				setElementOpacity(obj, opacity);
				opacity += level;
				window.setTimeout("fadePhotoElementOut('"+elId+"',"+opacity+"," + level + ")", 10);
			}
		}
}

