//	Smaw.Custom v 1.0
//	Makes use of Smaw.Common.js
//
if ( typeof Smaw == 'undefined' ) { self.Smaw = {}; }

Smaw.Custom = {
	
	fadeIn: function(o) {
		if (!document.getElementById || !document.getElementById(o)) return false;
		subject = document.getElementById(o)
		var temp = parseFloat(subject.style.opacity);
		if (temp < 1) {
			newval = temp + 0.1;
			subject.style.opacity = newval;
			setTimeout( function() { Smaw.Custom.fadeIn(o) }, 66);
		} else {
			subject.style.opacity = 1;	
		}
	},
	folioShowHide: function(anchor) {
		if ( anchor.href.indexOf("#") >= 0 ) { //Check for anchorness
			anchor.destination = anchor.href.substring(anchor.href.indexOf("#")+1);
			if (document.getElementById(anchor.destination)) {
				// Switch images
				thisItem = document.getElementById(anchor.destination);
				parentList = thisItem.parentNode;
				var items = parentList.getElementsByTagName("li");
				for(var i=0; i<items.length; i++){
					Smaw.Common.addCssClass(items[i],"hide");
				}
				Smaw.Common.removeCssClass(thisItem,"hide");
				// Update tab
				var tabs = anchor.parentNode.parentNode.getElementsByTagName("li");
				for(var j=0; j<tabs.length; j++){
					Smaw.Common.removeCssClass(tabs[j],"current");
				}
				Smaw.Common.addCssClass(anchor.parentNode,"current");
			}
		}
	},
	folioPager: function() {
		if (!document.getElementById("screenshotsList")) {return;}
		var lists = document.getElementById("screenshotsList");
		var linkPrefix = "folioEg-";
		var target=lists;
			var shots = target.getElementsByTagName("li");
			if(shots.length>1) {
				shotPager = document.createElement("ol");
				shotPager.className = "imageNavigation";
				for(var j=0; j<shots.length; j++){
					shots[j].id = linkPrefix+"-"+j;
					if(j>0){
						Smaw.Common.addCssClass(shots[j],"hide");
					}
					shotPagerItem = document.createElement("li");
					if(j==0){
						Smaw.Common.addCssClass(shotPagerItem,"first");
						Smaw.Common.addCssClass(shotPagerItem,"current");
					}
				shotPagerLink = document.createElement("a");
					shotPagerLink.href = "#"+linkPrefix+"-"+j;
					shotPagerLinkImage = document.createElement("img");
					shotPagerLinkImage.src = "http://www.bensmawfield.com/wp-content/themes/default/images/0" + (j+1) + ".gif";
					
					
					
					
					shotPagerLink.appendChild(shotPagerLinkImage);
					shotPagerLink.onclick = function() {					
						Smaw.Custom.folioShowHide(this);
						return false;
					}
					shotPagerItem.appendChild(shotPagerLink);
					shotPager.appendChild(shotPagerItem);
				}
				Smaw.Common.insertAfter(shotPager,lists);
			}
		
	},
	printLink: function() {
			if (!document.getElementById || !document.createTextNode) {return;} // Check for DOM support
			if (!document.getElementById("printDiv")) {return;} // Check that the target element actually exists
			if (!window.print) {return;} // Make sure the browser supports window.print
			var oTarget = document.getElementById("printDiv");
			var oLink = document.createElement('a');
		   	oLink.href = '#'; // Make the link focusable for keyboard users
		  	oLink.appendChild(document.createTextNode("Print a full version of my CV"));
		  	oLink.onclick = function() {window.print(); return false;} // Return false prevents the browser from following the link and jumping to the top of the page after printing
		  	var oPara = document.createElement('p');
		  	oPara.id = 'print';
		  	oPara.appendChild(oLink);
		  	oTarget.appendChild(oPara);
	
	},
	DOMLoaded: function() {
		Smaw.Custom.printLink();
		Smaw.Common.addEvent(window, 'load', addHasJSCSS);
		Smaw.Custom.folioPager();
		
	}
		
}/* /Smaw.Custom */

// SETUP EVENTS HERE
if (Smaw.Common) {
	Smaw.Common.domReady(Smaw.Custom.DOMLoaded);
//	Smaw.Common.addEvent(window, 'load', Smaw.Common.dynamicInputText);
	//Smaw.Common.addEvent(window, 'load', Smaw.Common.getNewWindowLinks);
}

/* Load JS CSS
-----------------------------------*/
//if ( typeof theSiteAssetRoot != 'undefined' ) { 
//	document.write('<link href="http://www.bensmawfield.com/wp-content/themes/default/hasJS.css" media="screen" type="text/css" rel="stylesheet" />');
//}

/* Attach styles for has Javascript 
--------------------------------------------------------------------*/

function addHasJSCSS() {
	var cssNode = document.createElement('link');
	cssNode.setAttribute('rel', 'stylesheet');
	cssNode.setAttribute('type', 'text/css');
	cssNode.setAttribute('href', 'http://www.bensmawfield.com/wp-content/themes/default/hasJS.css');
	document.getElementsByTagName('head')[0].appendChild(cssNode); 
}
	
	