/* shared js functions */


// function to follow href
function goUrl(url){
	window.location.href = url;
}

// rollovers 
function roll(img,state,alt){
	if (!alt){
		document.getElementById(img).src = state > 0 ? 'images/'+img+'_on.gif' : 'images/'+img+'_off.gif';
	} else {
		document.images[img].src = state > 0 ? 'images/'+img+'_'+alt+'.gif' : 'images/'+img+'_off.gif';
		//document.images[img].src = state > 0 ? 'images/'+img+'_on.gif' : 'images/'+img+'_off.gif';
	}
}

function rollMap(id,state){
	document.getElementById(id).src = state > 0 ? 'images/btn_map_on.gif' : 'images/btn_map_off.gif';
}

// rollover images
var main = new Array('n1_paintings','n1_bio','n1_gallery','n1_press','n1_calendar','n1_contact',
										 'n2_paintings_newwork','n2_paintings_recentwork1','n2_paintings_recentwork2',
										 'btn_arroright','btn_arroleft','btn_viewthumbs','btn_zoom');

// preload rollovers
function preload(imgArr){
	if (document.getElementById('gnav')){
		off = new Array();
		on  = new Array();
		for (i=0;i<imgArr.length;i++){
			off[i] = new Image;
			off[i].src = "images/" + imgArr[i] + "_off.gif";
			on[i] = new Image;
			on[i].src = "images/" + imgArr[i] + "_on.gif";
		}
	}
}
// onload functions
function init(){
	//preload(main);
	displayBrowserMsg();
}
window.onload = init;

// display browser message
function displayBrowserMsg(){
	var agent = navigator.userAgent.toLowerCase();
	if (agent.indexOf("mac") != -1 && agent.indexOf("msie") != -1){
		alert("This site is currently not viewable in older browsers.\nPlease upgrade to Safari or Firefox on the Mac.\nThank you and please come back soon!");
	}
}


// function to open price popup
function openPricePop(){
	var url = '/prices_pop.php';
	var wOpts = 'height=490,width=610,directories=no,location=no,menubar=no,resizable=yes,scrollbars=no,toolbar=no,screenX=80,screenY=80,left=80,top=80';
	var pWin = window.open(url,'priceWin',wOpts);
	if (window.focus) pWin.focus();
}

// function to open price popup
function openPrintsPop(){
	var url = '/prints_pop.php';
	var wOpts = 'height=744,width=612,directories=no,location=no,menubar=no,resizable=yes,scrollbars=no,toolbar=no,screenX=50,screenY=50,left=50,top=50';
	var pWin = window.open(url,'printsWin',wOpts);
	if (window.focus) pWin.focus();
}

// function to open admin from pricing popup
function goLogin(){
	url = "/admin/admin_index.php"
	if (window.opener){
		window.opener.location.href = url;
		window.opener.focus();
	} else {
		window.open(url);
	}
	window.close();
}

function setPaddingForSafari(){
	if (!document.getElementById) return;
	var h2s = document.getElementsByTagName("H2");
	for (var i=0;i<h2s.length;i++) {
		if (h2s[i].getAttribute('class').charAt('gallhead') != -1){
			h2s[i].style.paddingTop = "40px";
		}
	}
	scrollDivToAnchor("gallerySection");
}

// function to prep scroll anchors
function prepScrollTo() {
	if (document.getElementById) {
		var atags = document.getElementsByTagName("A");
		for (var i=0;i<atags.length;i++) {
			var ca = atags[i];
			if (ca.href.indexOf("#") > -1) {
				ca.onclick = function() {
					scrollDivToAnchor(this.href.split("#")[1]);
				}
			}
		}
	}
}
// function to achieve scroll anchors
function scrollDivToAnchor(a) {
	var b = document.getElementById(targBox);
	b.scrollTop = document.getElementById(a).offsetTop - b.offsetTop + 40;
	// alternately, if your elements are not nested within other nodes inside the box,
	// you could use document.getElementById(a).parentNode.scrollTop
	// that way you wouldn't need to specify the id of the scrollable box
}

