// Check browser based on active stylesheet
// Kate Kalcevich, 2009

function browserCheck() {
	if(document.getElementsByTagName) {
		var styles = new Array();
		styles = document.getElementsByTagName("link");
		for(i=0; i<styles.length; i++) {
			if (styles[i].getAttribute("href") == "mobile.css" && !styles[i].disabled) {
				return "mobile";
			} else {
				return "desktop";
			}
		}
	}
}

// Hide email from spammers
// Kate Kalcevich, 2008

function showEmail() {
	if(document.getElementsByTagName) {
		
		var allHTMLTags = new Array();
		allHTMLTags = document.getElementsByTagName("*");
		for (i=0; i<allHTMLTags.length; i++) {
			if (allHTMLTags[i].className == "at") {	
				allHTMLTags[i].innerHTML = "@"; 
			}
		}
		x = "mailto:kate";
		y = "@clearwebstudio.ca";
		for (j=0; j<allHTMLTags.length; j++) {
			if (allHTMLTags[j].className == "link") {	
				allHTMLTags[j].href = x + y;
			}
		} 
	}
}

// Swap images
// Kate Kalcevich, 2009

if(document.images) {
	imgs = new Array("portfolio/maa.jpg", "portfolio/teak.jpg", "portfolio/onzone.jpg");
	links = new Array("www.ontario.ca/aboriginal", "www.teakboutique.ca", "www.onzone.ca");
	titles = new Array("Ministry of Aboriginal Affairs Website", "Teak Boutique Website", "Premier McGuinty\'s OnZone Website");
}

function imageSwap(itemNum) {
	if(document.getElementById) {
		var browser = browserCheck();
		
		// redirect to portfolio page if viewing recent work on mobile device
		if (browser == "mobile") {
			window.location = "portfolio.php";
		// if viewing on desktop/laptop then load larger image
		} else {
			document.getElementById("imgLarge").src = imgs[itemNum];
			document.getElementById("imgLarge").alt = titles[itemNum];
			document.getElementById("imgTitle").innerHTML = titles[itemNum];
			document.getElementById("imgLink").href = "http://" + links[itemNum];
			document.getElementById("txtLink").href = "http://" + links[itemNum];
			document.getElementById("txtLink").innerHTML = links[itemNum];
			document.getElementById("txtLink").focus();
		}
	}
}


// Dynamic portfolio
// Kate Kalcevich, 2009

function initPortfolio() {
	if(document.getElementById) {
		
		// hide all portfolios from desktop users
		var browser = browserCheck();
		if (browser == "desktop") {
			var allHTMLTags = new Array();
			allHTMLTags = document.getElementsByTagName("*");
			for (i=0; i<allHTMLTags.length; i++) {
				if (allHTMLTags[i].className == "doublecol portfolio") {
					allHTMLTags[i].style.position = "absolute"; 
					allHTMLTags[i].style.top = "-5000px"; 
					allHTMLTags[i].style.left = "-5000px"; 
				}
			}
		}
	}
}

function portfolio(current) {
	if(document.getElementById) {
		var browser = browserCheck();

		// jump to anchor for mobile users
		if (browser == "mobile") {
			return false;
		} else {
			// hide all portfolios
			initPortfolio();
			// show selected portfolio
			document.getElementById(current).style.position = "relative";
			document.getElementById(current).style.top = "0"; 
			document.getElementById(current).style.left = "0"; 
		}
	}
}

// Form Validation
// Kate Kalcevich, 2008

function validate(form) {
	if (form.check.value != "") { 
		alert("\nPlease leave the last form field blank");
		form.check.focus(); 
		return false; 
	}
	if (form.email.value -= "") { 
		alert("\nPlease enter a valid email address");
		form.email.focus(); 
		return false; 
	}
	if (form.email.value != "") { 
		if (str.indexOf('@',0) == -1 ||  str.indexOf('.',0) == -1) { 
			alert("\nPlease enter a valid email address");
			form.email.focus(); 
			return false; 
		} 
		else {
			document.form.submit();
		}
	}
	document.form.submit();
}