/*Web Safe Color Palette, By Martin Carlsson, www.webpelican.com*/
/*DOM compatible or Internet Explorer?*/
var ie = (document.all) ? true:false; // IE4+
var dom = ((document.getElementById) && (!ie)) ? true:false; // Mozilla 
var colorWindow;var popDoc;

/*help-function for adding events to elements*/
function setEventById(id, ev, fu, currentDocument) {
	
	if(dom) {
		currentDocument.getElementById(id).addEventListener(ev, fu, false);
	} 
	if(ie) {
		currentDocument.getElementById(id).attachEvent('on' + ev, fu);
	}
} 


/*help-function for adding events to objects*/
function setEventByObject(ob, ev, fu) {

	if(dom) {
		ob.addEventListener(ev, fu, false);
	} 
	if(ie) {
		ob.attachEvent('on' + ev, fu);
	}	
} 


/*Connects an eventhandler to onclick-events*/
for(i=1; i <=216; i++) {
    setEventById("clicked"+i, "click", openColorWindow, window.document);
}

/*Used for opening a color-window of the chosen color.*/
function openColorWindow(e) {
   
   
    if(colorWindow)
    try {
        colorWindow.close();
       
    
    }
    catch(e){}
    colorWindow = window.open("","ColorPopUp", "width=420,height=230, resizable=yes,status=1,scrollbars=yes");
    var targ
    
    if (e.target) 
        targ = e.target
    else if (e.srcElement) 
        targ = e.srcElement
    if (targ.nodeType == 3) // defeat Safari bug
       targ = targ.parentNode
       
    var tname;
    tname=targ.tagName;
    popDoc = colorWindow.document;
   
    popDoc.write("<div id='h' >"+targ.value+"</div>");
    var header = popDoc.getElementById("h");
    header.style.backgroundColor = targ.value;
    colorWindow.document.bgColor = targ.value;
    colorWindow.document.title = targ.value;
    colorWindow.focus();
}

function inspectStyle(elm, doc){
  if (elm.style){
    var str = "";
    for (var i in elm.style){
	  str += i + ": " + elm.style[i] + "\n";
	}
	doc.write(str);
  }
}















