// JavaScript Document


/***********************************************
* Extra styling for mac to overwrite pc specific fontsizing..
***********************************************/

var mac_css='assets/templates/satya/css/macstyles.css' // specify Mac css file here
var mactest=navigator.userAgent.indexOf("Mac")!=-1
if(mactest) {
	document.write('<link rel="stylesheet" type="text/css" href="'+ mac_css +'" />')
}




/*
addPrintLink function by Roger Johansson
*/
var addUtilityLinks = {
	init:function(sTargetEl,emailUser) {
		if (!document.getElementById || !document.createTextNode) {return;} // Check for DOM support
		if (!document.getElementById(sTargetEl)) {return;} // Check that the target element actually exists
		
		var oTarget = document.getElementById(sTargetEl);
		if(!oTarget) return;
		
		// get end marker for insertion..
		//var oEnd = document.getElementById('email_address');
		
		/*//////
		PRINT BUTTON 
		///////
		if (window.print) { // Check that the browser supports window.print
			var oPrint = document.createElement('a');
			oPrint.className = 'print_button'; // Give the link a class to allow styling
			oPrint.href = '#'; // Make the link focusable for keyboard users
			oPrint.appendChild(document.createTextNode('Print page'));
			oPrint.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 pList = document.createElement('li');
			pList.appendChild(oPrint);
			//oTarget.insertBefore(pList, oEnd);
			oTarget.appendChild(pList);
		}*/
		
		/*///////
		BOOKMARK BUTTON
		/////////*/
		if((window.sidebar || window.external) && document.getElementsByTagName) {
			// add link
			var oBookmark = document.createElement("a");
			oBookmark.className = 'bookmark_button'; // Give the link a class to allow styling
			oBookmark.href = '#'; // Make the link focusable for keyboard users
			oBookmark.appendChild(document.createTextNode("Bookmark page"));
			
			oBookmark.onclick = function(){
				var title=document.getElementsByTagName("title")[0].text;
				
				if(window.sidebar) window.sidebar.addPanel(title,location.href,"");
				else if(window.external) window.external.AddFavorite(location.href,title);
				
				// optional, but won't fire due to support checks at start of object
				else alert("Please bookmark this site manually using your browser.");
				
				return false; // Return false prevents the browser from following the link and jumping to the top of the page after printing
		   }
			var bList = document.createElement('li');
			bList.appendChild(oBookmark);
			//oTarget.insertBefore(bList, oEnd);
			oTarget.appendChild(bList);
		}
		
		/*//////
		EMAIL BUTTON 
		///////*/
		//if (emailUser && window.location.hostname) { // Check that we have a designated user and domain
		if (emailUser) { // Check that we have a designated user
			// try to fool spambots..
			//var eHost = window.location.hostname;
			var eHost = 'satyacapital.com';
			var oEmail = document.createElement('a');
			oEmail.className = 'email_button'; // Give the link a class
			oEmail.href = 'mailto:'+emailUser+'@'+eHost; // Make the link
			oEmail.appendChild(document.createTextNode('Email us'));
			
			var eList = document.createElement('li');
			eList.appendChild(oEmail);
			//oTarget.insertBefore(pList, oEnd);
			oTarget.appendChild(eList);
		}
		
		

		//oTarget.appendChild(oList);
	},
/*
addEvent function included here for portability. Replace with your own addEvent function if you use one.
*/
/* addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html */
	addEvent:function(obj, type, fn) {
		if (obj.addEventListener)
			obj.addEventListener(type, fn, false);
		else if (obj.attachEvent) {
			obj["e"+type+fn] = fn;
			obj[type+fn] = function() {obj["e"+type+fn](window.event);}
			obj.attachEvent("on"+type, obj[type+fn]);
		}
	}
};
addUtilityLinks.addEvent(window, 'load', function(){addUtilityLinks.init('utils','info');});



// Adds email links via JS
////////////////////////////////////////////////////////////////////////
function insertContact (theName, linkText)
{	
	var theDomain = ('satyacapital' + '.' + 'com');
	
	theAddress = (theName + '&#064' + theDomain);
	if(linkText=='me'){
		linkText = theAddress;
	}
	document.write('<a href="mailto:' + theAddress +'">' + linkText + '<\/a>');
}


/// PRELOAD ROLLOVER ICONS:

/***********************************************
* preload css rollover images
***********************************************/
if (document.images)
{
  icon1= new Image(15,16); 
  icon1.src="assets/templates/satya/images/contact_icon_ro.gif"; 

  icon2= new Image(15,16); 
  icon2.src="assets/templates/satya/images/bookmark_icon_ro.gif"; 
  
  icon3= new Image(15,16); 
  icon3.src="assets/templates/satya/images/print_icon_ro.gif"; 
  
  icon4= new Image(15,16); 
  icon4.src="assets/templates/satya/images/email_icon_ro.gif"; 

}

function addEvent(elm, evType, fn, useCapture){
	if(elm.addEventListener){
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}else if (elm.attachEvent){
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	}else{
		elm['on' + evType] = fn;
	}
}

function findPopUps()
{
	var popups = document.getElementsByTagName("a");
	for (i=0;i<popups.length;i++)
	{
		if (popups[i].rel.indexOf("external")!=-1)
		{
			// attach popup behaviour
			popups[i].target = '_blank';
			//popups[i].onclick = doPopUp;
			// add info to title attribute to alert fact that it's a pop-up window
			popups[i].title = popups[i].title + " [Opens in new window]";
		}
		else if (popups[i].rel.indexOf("home page")!=-1)
		{
			// attach popup behaviour
			popups[i].target = '_top';
		}
	}
}
addEvent(window, 'load', findPopUps, false);


