// SHARED
function init() {
	// Menu icons...
	var icons = new Array();
	icons[0] = "journal";
	icons[1] = "home";
	icons[2] = "shows";
	icons[3] = "classes";
	icons[4] = "gallery";
	icons[5] = "about";
	for (i=0; i<6; i++) {
		var icon = "icon_"+icons[i];
		changeOpac("75",icon);
		document.getElementById(icon).onmouseover = new Function("fade_icon('"+icon+"','1')");
		document.getElementById(icon).onmouseout = new Function("fade_icon('"+icon+"','')");
	}
	
	if (document.getElementsByTagName) {
		var anchors = document.getElementsByTagName("a");
		for (var i=0; i<anchors.length; i++) {
			var anchor = anchors[i].getAttribute("href");
			if (anchor) {
				if (anchor.indexOf("clayshapers") == -1) {
					if (anchor.substring(0,4) == "http") anchors[i].target = "_blank";
				}
			}
		}
	}
}

function toggle_div(n) {
	if (document.getElementById(n).style.display=="none") { 
		document.getElementById(n).style.display="";
	} else {
		document.getElementById(n).style.display="none";
	}
}

function view_img(src,title,param) {
	window.open('view_img.php?src='+src,title,param);
}

// PRODUCT GALLERY
function swap_prod_img(a,b,c,d) {
	document.getElementById('primary_img_holder').innerHTML = "					<a href=\"javascript:view_img('images/products/"+b+"','img','width="+c+",height="+d+"')\"><img src=\"phpThumb/phpThumb.php?src=../images/products/"+b+"&amp;w=248&amp;h=248&amp;zc=1\" alt=\""+a+"\" /></a>\n";
}

// JOURNALS
function confirm_post() {
	input_box=confirm("Post this message:\n\""+document.getElementById('blurb').value+"\"");
	if (input_box==true) {
		document.getElementById('cmd').value = "1";
		document.getElementById('comment_post').submit(); 
	} else {
		return false;
	}
}

// EMAIL
function no_spam(user,domain) {
	locationstring="mailto:"+user+"@"+domain;
	window.location=locationstring;
}

// MENU
function fade_icon(id,x) {
	var object = document.getElementById(id).style;
	current = object.opacity * 100;
	if(x && current==75) {
		changeOpac("100",id);
	} else {
		opacity(id, current, 75, 1000);
	}
}
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;
    //determine the direction for the blending, if start and end are the same nothing happens
    if (opacStart > opacEnd) {
			for (i = opacStart; i >= opacEnd; i--) {
				fadeID = setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
				timer++;
			}
		}
		else if (opacStart < opacEnd) {
        for (i = opacStart; i <= opacEnd; i++) {
            fadeID = setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";

	if(object.opacity==0) object.zIndex=-10;
	else object.zIndex=10;
}
