// JavaScript Document

var master_email = "info@marvellousmedia.com";


function add_load_event(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


/* generic text mark up tags */
function create_tag(id,c,text,tagtype) {
	var tag = document.createElement(tagtype);
	tag.setAttribute("id",id);
	tag.className = c;
	var tag_text = document.createTextNode(text);
	tag.appendChild(tag_text);
	return tag;
}

function create_link(url,txt,c,id,target) {
	var new_link = document.createElement("a");
	new_link.setAttribute("href",url);
	new_link.setAttribute("id",id);
	new_link.setAttribute("target",target);
	new_link.className = c;
	var anchor_text = document.createTextNode(txt);
	new_link.appendChild(anchor_text);
	return new_link;
}

function write_email() {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("master_email")) return false;
	var email_address = document.getElementById("master_email");
	var email_link = create_link(
		"mailto:" + master_email,
		master_email,
		"",
		""
	);
	email_address.appendChild(email_link);
}

function portfolio_hijack() {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("portfolio")) return false;
	var portfolio = document.getElementById("portfolio");
	var links = portfolio.getElementsByTagName("a");
	var old_links = new Array();
	for (var i=0;i<links.length;i++) {
		old_links.push(links[i]);
	}
	for (var i=0;i<old_links.length;i++) {
		
		//insertAfter(br,links[i]);
		var li = old_links[i].parentNode.parentNode;
		
		if (old_links[i].className == "txt_link") {
			new_class = "view_website";
			h3 = old_links[i].firstChild;
			old_links[i].parentNode.replaceChild(h3,old_links[i]);
			target = "_blank";
		} else {
			new_class = "more_detail";
			target = "_self";
		}
		var dd = create_tag("",new_class,"","dd");
		var a = create_link(old_links[i].href,new_class,"","",target);
		dd.appendChild(a);
		li.appendChild(dd);
	}
	
}
function footer(){
	
	var bookmark = document.getElementById("bookmark_link");
		bookmark.onclick=function(){
			var ul = document.getElementById("bookmark").getElementsByTagName("ul")[0];
			ul.style.display = "block";
			/*this.getElementsByTagName('a')[0].style.backgroundColor="#FFAA13";
			var linktous = document.getElementById("link");
			var email = document.getElementById("email");
			linktous.getElementsByTagName('a')[0].style.backgroundColor="#e6e6e6";
			email.getElementsByTagName('a')[0].style.backgroundColor="#e6e6e6";*/
			var linktous = document.getElementById("link");
			var dl = linktous.getElementsByTagName("dl")[0];
			dl.style.display = "none";
			var email = document.getElementById("email_to_friend");
			//var email_dl = email.getElementsByTagName("dl")[0];
			email.style.display = "none";
			return false;
		}
		
		var linktous = document.getElementById("link_to_us_link");
		
		linktous.onclick = function(){
			var linktous = document.getElementById("link");
			var dl = linktous.getElementsByTagName("dl")[0];
			
			dl.style.display = "block";
			
			var bookmark = document.getElementById("bookmark");
			
			var ul = bookmark.getElementsByTagName("ul")[0];
			ul.style.display = "none";
			var email = document.getElementById("email_to_friend");
			//var email_dl = email.getElementsByTagName("dl")[0];
			email.style.display = "none";
			
			return false;
			
		}
		
		var email = document.getElementById("email_link");
		email.onclick=function(){
			var email = document.getElementById("email_to_friend");
			//var email_dl = email.getElementsByTagName("dl")[0];
			email.style.display = "block";
			var linktous = document.getElementById("link");
			var dl = linktous.getElementsByTagName("dl")[0];
			dl.style.display = "none";
			var bookmark = document.getElementById("bookmark");
			var ul = bookmark.getElementsByTagName("ul")[0];
			ul.style.display = "none";
			return false;
			
		}
		
		var printpage = document.getElementById("print_link");
		printpage.onclick=function(){
			window.print();
			return false;
		}
		
		var myform= document.getElementById("email_to_friend");
		var button = myform.getElementsByTagName("button")[0];
		button.onclick = function(){
			var myform= document.getElementById("email_to_friend");
			 myform.submit();
		}
		
	
}

add_load_event(write_email);
add_load_event(portfolio_hijack);
add_load_event(footer);