//$Id: common-large-v2.js 1501 2008-12-19 21:20:47Z ingvig $
//(c) Siminn.is

/*jquery stuff*/
jQuery.noConflict();
var $j = jQuery;

/*add file type icons*/
$j(document).ready(
			function() {
				$j('a').each(
				  function() {
				    var icons = new Array( 'pdf', 'doc', 'xls', 'txt', 'rtf' );
				    for(var i=0; i < icons.length; i++) {
  				      if (this.href.indexOf('.' + icons[i]) > -1) {
				        $j(this).addClass(icons[i] + '_icon');
				        break;
                                      }				    
				    }
				  }
				);
			 }
		 );

/*prototype starts*/
String.prototype.trim = function() {
// skip leading and trailing whitespace
// and return everything in between
  return this.replace(/^\s*(\b.*\b|)\s*$/, "$1");
}

function addLoadEvent(func) {
	try {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
		window.onload = func;
		} else {
		window.onload = function() {
			if (oldonload) {
			oldonload();
			}
			func();
		}
		}
	} catch (Exception) {
	}
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function styleAbbr() {
var isIE = (document.all) ? true:false;
if( isIE ) {
$$('abbr').each(function(node){
new Insertion.Top(node, '<span class=\"abbr\">');
new Insertion.Bottom(node, '</span>');
});
}
}

function insertAfter(newElement,targetElement) {
  var parent = targetElement.parentNode;
  if (parent.lastChild == targetElement) {
    parent.appendChild(newElement);
  } else {
    parent.insertBefore(newElement,targetElement.nextSibling);
  }
}

function addClass(element,value) {
	Element.addClassName( element, value );
}




function highlightPage() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("navigation")) return false;
  var nav = document.getElementById("navigation");
  var links = nav.getElementsByTagName("a");
  for (var i=0; i<links.length; i++) {
    var linkurl = links[i].getAttribute("href");
    var currenturl = window.location.href;
    if (currenturl.indexOf(linkurl) != -1) {
      links[i].className = "here";
      var linktext = links[i].lastChild.nodeValue.toLowerCase();
      document.body.setAttribute("id",linktext);
    }
  }
}

function siminn_popup(link, window_width, window_height) {
  var theTarget = "_blank"; 
  if ((link.target != null) && (link.target != "")) {
    theTarget = link.target;    
  }

  newWin = window.open(link.href, theTarget, "width="+ window_width +", height="+ window_height);
  newWin.focus(); 
  return false;
}

function contactme(slod)  {
open(slod, "displayWindow", "toolbar=0,location=0, status=0, menubar=0, resizable=0, copyhistory=0, scrollbars=1, width=600,height=620");
}
function kuba(slod)  {
open(slod, "displayWindow", "toolbar=0,location=0, status=0, menubar=0, resizable=0, copyhistory=0, scrollbars=1, width=770,height=650");
}


function setHeight(id){
     single     = id.length <= 1 ? true : false;
     cell     = new Array();

     if (single && document.getElementById( id[0] ) == null) {
     	return;
     }         
    
     id = single ? document.getElementById( id[0] ).childNodes : id;

     for(cellCount=0; cellCount<id.length; cellCount++){
          if(String(id[cellCount].tagName).toLowerCase()=="div" && single)
               cell.push( id[cellCount] );
          else if( !single )
               cell.push( document.getElementById(id[cellCount]) );
     }

     for(checkHeight=0, maxHeight=0; checkHeight<cell.length; checkHeight++) {
          if (cell[checkHeight] != null) {
               maxHeight = cell[checkHeight].offsetHeight>maxHeight ? cell[checkHeight].offsetHeight : maxHeight;
          }
     }

     for(var i=0; i<cell.length; i++) {
          if (cell[i] != null) {
               cell[i].style.height = String(maxHeight)+"px";
          }
     }
}

function changeActionAndSubmit(url,elementID)
{
var form = $( elementID );
   form.action=url;
   form.submit();
}

function alternate_init() {
	if (!document.getElementsByTagName) return;
	tbls = document.getElementsByTagName("table");
	for (ti=0;ti<tbls.length;ti++) {
		thisTbl = tbls[ti];
		if (((' '+thisTbl.className+' ').indexOf("alternate_rows") != -1) && (thisTbl.id)) {
			alternate(thisTbl);
		}
	}
}

function addEvent(elm, evType, fn, useCapture)
{
	Event.observe( elm, evType, fn, useCapture );
} 

function replace(s, t, u) {
  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + u;
  if ( i + t.length < s.length)
    r += replace(s.substring(i + t.length, s.length), t, u);
  return r;
}

function alternate(table) {
	var tableBodies = table.getElementsByTagName("tbody");
	for (var i = 0; i < tableBodies.length; i++) {
		var tableRows = tableBodies[i].getElementsByTagName("tr");
		for (var j = 0; j < tableRows.length; j++) {
			if ( (j % 2) == 0  ) {
				if (tableRows[j].className == 'odd' || !(tableRows[j].className.indexOf('odd') == -1) ) {
					tableRows[j].className = replace(tableRows[j].className, 'odd', 'even');
				} else {
					tableRows[j].className += " even";
				}
			} else {
				if (tableRows[j].className == 'even' || !(tableRows[j].className.indexOf('even') == -1) ) {
					tableRows[j].className = replace(tableRows[j].className, 'even', 'odd');
				}
				tableRows[j].className += " odd";
			} 
		}
	}
}

function onLoadTasks() {
	highlightPage();
	alternate_init();
}
addLoadEvent(onLoadTasks);

//ie flash fix - click to actiavte
(function( Eolas_Fixed,
            win, doc,
            getElementsByTagName,
            outerHTML,
            parentNode,
            tags,
            elmsToRemoveOnload,
            x,
            is_ie,
            y,z,elm,childNode,HTML,dummy,eolasfix)
{
  
  if (win[Eolas_Fixed]) return;
  win[Eolas_Fixed] = 1;

  eolasfix = function ()
  {
    
    while (tags[++x])
    {
       
      y = 0;
      while (elm = doc[getElementsByTagName](tags[x])[y++])
      {
        if (is_ie)
        {
          HTML = '>';
          z = 0;
          
          
          while (childNode = elm.childNodes[z++])
              HTML += childNode[outerHTML];

          
          dummy = doc.createElement('i');
          
          elm[parentNode].insertBefore(dummy, elm);
          
          dummy[outerHTML] = elm[outerHTML].replace(/>/, HTML);
          
          y++;
          elm.style.display = 'none';
          elmsToRemoveOnload[elmsToRemoveOnload.length] = elm;
        }
        else
        {
          elm[outerHTML] = elm[outerHTML];
        }
      }
    }
  };

  is_ie && !eolasfix() && win.attachEvent('onload', function(){
    x=0;
    while(elm = elmsToRemoveOnload[x++])
        elm[parentNode].removeChild(elm);
  });
  
  win.opera && doc.addEventListener('DOMContentLoaded', eolasfix, 0);

})( '__Eolas_Fixed',
    window, document,
    'getElementsByTagName',
    'outerHTML',
    'parentNode',
    ['object','embed','applet'],
    [],
    -1 /*@cc_on,1 @*/
  );
  
  
var cookieNameTextSize = "SiminnR4";
var textSizes = "small;medium;big;huge".split(";");

function setTextSizeCookie(size) {
	eraseCookie(cookieNameTextSize);
	createCookie(cookieNameTextSize, size, 365);
}

function doTextSize(textSizeName, textSizeValue) {
	var bodyElement = document.getElementsByTagName('body')[0];
	bodyElement.style.fontSize = textSizeValue;
	setTextSizeCookie(textSizeName);
	markSelectedTextSize(textSizeName);
}


//font-size monster
function hugeText() { 
	doTextSize("huge", '4em'); 
	try {
		reEqualHeightForRounded();
	} catch (Exception) {
	}
}

function bigText() {
	doTextSize("big", '1em'); 
	try {
		reEqualHeightForRounded();
	} catch (Exception) {
	}
}	
	
function mediumText() {
	doTextSize("medium", '.75em'); 
	try {
		reEqualHeightForRounded();
	} catch (Exception) {
	}
}	
	
function smallText() {
	doTextSize("small", '.7em');
	try {
		reEqualHeightForRounded();
	} catch (Exception) {
	}
}

function markSelectedTextSize(textSize) {
	for(var i=0; i < textSizes.length; i++) {
		var link = document.getElementById( textSizes[i] + 'Link');
		if (link != null) {
			if (link.className != null) {
				link.className = link.className.replace("selectedTextSize", "");
			}
		}
	}
	var link = document.getElementById( textSize + 'Link');
	if (link != null) {
		if (link.className != null) {
			link.className = " selectedTextSize";
		} else {
			link.className += " selectedTextSize";
		}
	}
}

function textResize() {
	var textSize = readCookie(cookieNameTextSize);
	if (textSize != null) {
		eval(textSize + "Text()");
	}
}

addLoadEvent(textResize);

var tabboxesInPage = {};

function addTabbox(id, parameters) {
	if (parameters == null) {
		parameters = { header: "h3",autosize: true };
	}
	var box = new Tabbox(id, parameters);
	eval("tabboxesInPage." + id + "=box;");
	if (window.location.href.indexOf("#") > 0 ) {
		var tabId = window.location.href.substring(window.location.href.indexOf("#") + 1);
		if (tabId.match(/-tab$/) != null) {
			tabId = tabId.substring(0, tabId.lastIndexOf("-tab"));
		}
		box.selectTab(tabId);
	} else {
		if (box.config == null || box.config.select < 0) {  
			box.selectTab(0);
		}
	}
	return box;
}

function selectTab(tabboxId, tabId) {
	if (tabboxesInPage != null && eval("tabboxesInPage." + tabboxId) != null) {
		eval("tabboxesInPage." + tabboxId).selectTab(tabId);
	}
}

/* popup.js */

if (!Array.prototype.push) Array.prototype.push = function() {
    for (var i=0; i<arguments.length; i++) this[this.length] = arguments[i];
    return this.length;
}

Array.prototype.find = function(value, start) {
    start = start || 0;
    for (var i=start; i<this.length; i++)
        if (this[i]==value)
            return i;
    return -1;
}

Array.prototype.has = function(value) {
    return this.find(value)!==-1;
}

try {
	var Popup = Class.create();
	Popup.prototype = {
		initialize: function () {
			_POPUP_FEATURES = 'location=0,statusbar=1,scrollbars=1,menubar=0,width=800,height=640';
		},
	
		// MISC CLEANING-AFTER-MICROSOFT STUFF
		isUndefined : function (v) {
		    var undef;
		    return v===undef;
		},
		
		raw_popup : function (url, target, features, classInstance) {
		    if (classInstance.isUndefined(features)) features = _POPUP_FEATURES;
		    if (classInstance.isUndefined(target  )) target   = '_blank';
		    var theWindow = window.open(url, target, features);
		    theWindow.focus();
		    return theWindow;
		},
		
		link_popup : function (src, features, classInstance) {
		    return this.raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features, classInstance);
		},
		
		event_popup_features : function (features, classInstance) {
		    return function(e) { classInstance.link_popup(e.currentTarget != null ? e.currentTarget : e.srcElement, features, classInstance); e.preventDefault() };
		},	
	
		makePopups : function (elements, features) {
			if (elements != null) {
				for(var i=0; i < elements.length; i++) {
					var customParameters = elements[i].getAttribute("parameters");
					if (customParameters != null) {
						features = customParameters;
					} else {
						if (this.isUndefined(features)) {
							features = this._POPUP_FEATURES;
						}
					}							
					elements[i].observe("click", this.event_popup_features(features, this));
				}
			}			
		}	 
	};
	
	Event.observe(
		window,
		'load', 
		function () {
			var popup = new Popup();
			popup.makePopups($$('a.popup'));
			popup.makePopups($$('a.popup_small'), 'location=0,statusbar=1,scrollbars=1,menubar=0,width=570,height=600');
		},
		false
	);
} catch (Exception) {
}

try {
	Event.observe(
		window,
		'load', 
		function () {
			$$('a.mailto').each(
				function(item) {
					var index = item.href.indexOf("#");
					if (index > -1 && index < item.href.length - 2) {
						var email = item.href.substring(index + 1);
						var splitt = email.split(";");
						if (splitt.length > 1) {
							Event.observe(item, "click", function () {
								item.href = "mailto:" + splitt[0] + "@" + splitt[1];
							});
						} else {
							Event.observe(item, "click", function () {
								item.href = "mailto:" + email + "@siminn.is";
							});
						}
					}
				}
			);	
		},
		false
	);	
} catch (Exception) {
}

//$Id: common-large-v2.js 1501 2008-12-19 21:20:47Z ingvig $
//(c) Siminn.is
//Finnur Magnusson - April 2005 - www.siminn.is
//This function generates a flash file url for the selected category. And renders it in a div tag with id=branding
//If the number attribute is -1, a random file is selected from the category directory

function generateFlash (category, number) {
  var prt = location.protocol.indexOf('https')>-1?'https://':'http://';
  var flashFile = prt+'static.siminn.is/siminn/r4/f/'+category+'/';
  if(number >= 0)
    flashFile += number+'.swf';
  else {
    //Fetch file count for the selected category
    switch (category)
{case'c0':fileCount=1;break
case'c1':fileCount=1;break
case'c2':fileCount=1;break
case'c3':fileCount=1;break
case'c4':fileCount=1;break
case'c5':fileCount=1;break
case'c6':fileCount=1;break
case'c7':fileCount=1;break
case'c8':fileCount=1;break
case'c9':fileCount=1;break
case'c10':fileCount=1;break}
    flashFile += Math.floor(Math.random()*fileCount)+'.swf';
  }

var fo;
if(category=='c0'||category=='c6'||category=='c10') {
	fo=new FlashObject(flashFile,"walker","940","280",6,"#ffffff");
	}else{
		fo=new FlashObject(flashFile,"walker","940","120",6,"#ffffff");
		}
fo.write("branding");
}

var FlashObject = function(swf, id, w, h, ver, c) {
            this.swf = swf;
            this.id = id;
            this.width = w;
            this.height = h;
            this.version = ver;
            this.align = "middle";

            this.params = new Object();
            this.variables = new Object();
            this.redirect = "";
            this.sq = document.location.search.split("?")[1] || "";
            this.bypassTxt = "<p>Ert ˛˙ me Macromedia Flash vibÛtina uppsetta fyrir vafrann ˛inn? <a href='?detectflash=false&"+ this.sq +"'>Smelltu hÈr ef ˛˙ er me Flash vibÛt n˙mer "+ this.version +" uppsetta</a>.</p>";

            if (c) this.color = this.addParam('bgcolor', c);
            this.addParam('quality', 'high'); // default to high
            this.doDetect = getQueryParamValue('detectflash');
}
var FOP = FlashObject.prototype;

FOP.addParam = function(name, value) { this.params[name] = value; }
FOP.getParams = function() { return this.params; }
FOP.getParam = function(name) { return this.params[name]; }
FOP.addVariable = function(name, value) { this.variables[name] = value; }
FOP.getVariable = function(name) { return this.variables[name]; }
FOP.getVariables = function() { return this.variables; }

FOP.getParamTags = function() {
    var paramTags = "";
    for (var param in this.getParams()) {
        paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '" />';
    }
    return (paramTags == "") ? false:paramTags;
}

FOP.getHTML = function() {
    var flashHTML = "";
    if (navigator.plugins && navigator.mimeTypes.length) { // netscape plugin architecture
        flashHTML += '<embed type="application/x-shockwave-flash" src="' + this.swf + '" allowScriptAccess="always" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '"';
        for (var param in this.getParams()) {
            flashHTML += ' ' + param + '="' + this.getParam(param) + '"';
        }
        if (this.getVariablePairs()) {
            flashHTML += ' flashVars="' + this.getVariablePairs() + '"';
        }
        flashHTML += '></embed>';
    } else { // PC IE
        flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.width + '" wmode="opaque" height="' + this.height + '" id="' + this.id + '" align="' + this.align + '">';
        flashHTML += '<param name="movie" value="' + this.swf + '" /><param name="allowScriptAccess" value="always" /><param name="wmode" value="opaque" />';
        if (this.getParamTags()) {
            flashHTML += this.getParamTags();
        }

        if (this.getVariablePairs() != null) {
            flashHTML += '<param name="flashVars" value="' + this.getVariablePairs() + '" />';
        }
        flashHTML += '</object>';
    }
    return flashHTML;       
}

FOP.getVariablePairs = function() {
    var variablePairs = new Array();
    for (var name in this.getVariables()) { 
            variablePairs.push(name + "=" + escape(this.getVariable(name))); 
    }
    return (variablePairs.length > 0) ? variablePairs.join("&"):false;
}

FOP.write = function(elementId) {
            if(detectFlash(this.version) || this.doDetect=='false') {
                        if (elementId) {
                                    document.getElementById(elementId).innerHTML = this.getHTML();
                        } else {
                                    document.write(this.getHTML());
                        }
            } else {
                        if (this.redirect != "") {
                                    document.location.replace(this.redirect);
                        } else if (this.altTxt) {
                                    if (elementId) {
                                                document.getElementById(elementId).innerHTML = this.altTxt +""+ this.bypassTxt;
                                    } else {
                                                document.write(this.altTxt +""+ this.bypassTxt);
                                    }
                        }
            }                       
}

 
/* ---- detection functions ---- */
function getFlashVersion() {
            var flashversion = 0;
            if (navigator.plugins && navigator.mimeTypes.length) {
                        var x = navigator.plugins["Shockwave Flash"];
                        if(x && x.description) {
                                    var y = x.description;
                                    flashversion = y.substring(y.indexOf('.')-2, y.indexOf('.')).trim();}}
                                     else {
                        result = false;
                for(var i = 15; i >= 3 && result != true; i--){
                                    execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
                                    flashversion = i;
                        }
            }
            return flashversion;
}

function detectFlash(ver) {           return (getFlashVersion() >= ver) ? true:false; }


// get value of query string param

function getQueryParamValue(param) {

            var q = document.location.search || document.location.href.split("#")[1];
            if (q) {
                        var detectIndex = q.indexOf(param +"=");
                        var endIndex = (q.indexOf("&", detectIndex) > -1) ? q.indexOf("&", detectIndex) : q.length;
                        if (q.length > 1 && detectIndex > -1) {
                                    return q.substring(q.indexOf("=", detectIndex)+1, endIndex);
                        } else {
                                    return "";
                        }
            }
}

 
/* add Array.push if needed */
if(Array.prototype.push == null){
            Array.prototype.push = function(item) { this[this.length] = item; return this.length; }
}

function getNoCols(element){
	var result=0;
	if(element!=null){
		element=$(element);
		if(element.hasClassName("ui-ga")){
			result=1;
			}else if(element.hasClassName("ui-gb")){
				result=2;
				}else if(element.hasClassName("ui-gc")){result=3;}else if(element.hasClassName("ui-gd")){result=4;}}
return result;}
function roundAllAndEqualHeight(cssRule){var elementRounded=roundAll(cssRule);if(elementRounded!=null&&elementRounded.length>1){var parent=elementRounded[0].parentNode;var noOfCols=getNoCols(parent);if(noOfCols>1){for(var i=0;i<elementRounded.length;i+=noOfCols){var idOfElementRounded=new Array();for(var j=0;j<noOfCols&&(i+j)<elementRounded.length;j++){var elementToEqual=elementRounded[i+j].firstChild.firstChild;if(elementToEqual.id==null||elementToEqual.id.length<1){elementToEqual.id="roundAllAndEqualHeight_"+(i+j)+"_"+(new Date()).getTime();}
idOfElementRounded[j]=elementToEqual.id;}
setHeight(idOfElementRounded);}}}}
function roundAll(cssRule){var elementsToRound=$$(cssRule);if(elementsToRound!=null){var col=elementsToRound.length;for(var i=0;i<col;i++){roundElement(elementsToRound[i]);}}
return elementsToRound;}
function roundElement(element){var divContent=document.createElement("div");divContent.className="content";var divRounded=document.createElement("div");divRounded.className="rounded";divRounded.appendChild(divContent);var divT=document.createElement("div");divT.className="t";divContent.appendChild(divT);if(element.childNodes!=null){while(element.childNodes.length>0){divContent.appendChild(element.childNodes[0]);}}
var brClear=document.createElement("br");brClear.className="clear";divContent.appendChild(brClear);var divB=document.createElement("div");divB.className="b";divRounded.appendChild(divB);var divBEmpty=document.createElement("div");divB.appendChild(divBEmpty);element.appendChild(divRounded);}
function reEqualHeightForRounded(){var elementRounded=new Array();var allDivs=document.getElementsByTagName("div");if(allDivs!=null){for(var i=0;i<allDivs.length;i++){if(allDivs[i]!=null){if(allDivs[i].id!=null&&allDivs[i].id.indexOf('roundAllAndEqualHeight_')==0){elementRounded[elementRounded.length]=allDivs[i];allDivs[i].style.height="";}else if(allDivs[i].className!=null&&allDivs[i].className.indexOf('roundAllAndEqualHeight')>-1){elementRounded[elementRounded.length]=allDivs[i];allDivs[i].style.height="";}}}}
if(elementRounded!=null&&elementRounded.length>1){var noOfCols=getNoCols('rounded');if(noOfCols>1){for(var i=0;i<elementRounded.length;i+=noOfCols){var idOfElementRounded=new Array();for(var j=0;j<noOfCols&&(i+j)<elementRounded.length;j++){var elementToEqual=elementRounded[i+j].firstChild.firstChild;if(elementToEqual.id==null||elementToEqual.id.length<1){elementToEqual.id="roundAllAndEqualHeight_"+(i+j)+"_"+(new Date()).getTime();}
idOfElementRounded[j]=elementToEqual.id;}
setHeight(idOfElementRounded);}}}}

	
function roundLegacyInfoElement(element){var node=element.childNodes[0];if(node.nodeName!="P"){var pContent=document.createElement("p");if(element.childNodes.length>1){var firstNonEmptyNodeP=false;for(var i=0;i<element.childNodes.length;i++){if(element.childNodes[i].nodeName!="#text"){firstNonEmptyNodeP=element.childNodes[i].nodeName=="P";break;}}
if(firstNonEmptyNodeP){}else{var msgContainer=document.createElement("div");msgContainer.style.padding="10px 0px"
msgContainer.style.margin="0px";msgContainer.innerHTML=element.innerHTML;while(element.childNodes.length>0){element.removeChild(element.childNodes[0]);}
element.appendChild(msgContainer);}}else{pContent.appendChild(node);element.appendChild(pContent);}}
roundElement($(element));if(element.hasClassName("info-box")){$(element.childNodes[0]).addClassName("info");element.removeClassName("info-box");}else if(element.hasClassName("info-go")){$(element.childNodes[0]).addClassName("successful");element.removeClassName("info-go");}else if(element.hasClassName("info-yellow")){$(element.childNodes[0]).addClassName("warning");element.removeClassName("info-yellow");}else if(element.hasClassName("info-stop")){$(element.childNodes[0]).addClassName("alert");element.removeClassName("info-stop");}else{}}
Event.observe(window,'load',function(){roundAllAndEqualHeight('div#rounded div.ui-u')},false);Event.observe(window,'load',function(){$$('div.info-box').each(roundLegacyInfoElement);$$('div.info-go').each(roundLegacyInfoElement);$$('div.info-yellow').each(roundLegacyInfoElement);$$('div.info-stop').each(roundLegacyInfoElement);},false);


/**
* Initialize and manage a semantic tab box.
*
* This code was created by Jeremy Gillick.
* To learn more, read the blog post: http://blog.mozmonkey.com/2007/semantic-tab-box-v20/
*
* The configuration object names and default values:
* 
*	header   : h3     // The header element used for each tab name.
*	vertical : false  // TRUE if the tabs should be oriented vertically.
*	select   : 0      // The tab index to select initially.
*	autosize : true   // Automatically size the box to the content of the tab.
*
* @param {String} id The ID of the tab box div.
* @param {Object} config The configuration object.
*/
function Tabbox(id, config) { 
	this.init(id, config);
}
Tabbox.prototype = {
	
	tabbox : null,
	tabs : [],
	selected : null,
	
	config : {
		header: "h3",
		vertical: false,
		select : -1,
		padding: 0,
		autosize: true
	},
	
	/**
	* Called from the constructor to start initializing the tabbox.
	*/
	init : function(id, config){
		var obj = this;
		
		/* 
		* Merge configuration with default values
		*/
		if(config){
			var name;
			for(name in config){
				this.config[name] = config[name];
			}
		}
		
		/* 
		* Poll until the tabbox is available
		*/
		
		// Add onload handler
		this.pageLoaded = false;
		if(window.addEventListener){
			window.addEventListener("load", function(){ obj.pageLoaded = true; }, false);
		}
		else if(window.attachEvent){
			window.attachEvent("onload", function(){ obj.pageLoaded = true; });
		}
		
		function poll(){
			var tabbox = document.getElementById(id);
			obj.tabbox = tabbox;
			obj.formatTabbox();
			tabbox.style.display = '';
			return;
		}
		poll();
	},
	
	/**
	* Add CSS classes and find the important elements of the tab box.
	*/
	formatTabbox : function(){
		var obj = this;
	
		// Add classes
		this.tabbox.className += " tabbox";
		
		if(this.config.vertical){
			this.tabbox.className += " verticalTabs";
		}
		else{
			this.tabbox.className += " horzTabs";
		}
	
		// Get tabs
		var divs;
		var tabs = this.tabbox.getElementsByTagName(this.config.header);
		for(var i = 0; i < tabs.length; i++){
			// Tab container
			this.tabs[i] = { id: tabs[i].id, header: tabs[i], container: tabs[i].parentNode }; 
			
			// Tab content
			divs = this.tabs[i].container.getElementsByTagName("div");
			for(var n = 0; n < divs.length; n++){
				if(divs[n].className.match(/(^|\s)tabContent(\s|$)/)){
					this.tabs[i].id = divs[n].id;
					this.tabs[i].content = divs[n];
					break;
				}
			}
			
		}
		
		// Add event handlers
		var anchor;
		for(var i = 0; i < this.tabs.length; i++){
			anchor = this.tabs[i].container.getElementsByTagName("a");
			if(anchor.length > 0){
				anchor = anchor[0];
				
				anchor.tab = this.tabs[i];
				anchor.onfocus = function(evt){
						evt = window.event || evt;
						obj.selectTab(this.tab, evt);
						window.location.href = this.href + "-tab";
						return true;
					}
				anchor.onclick = function(evt){
						evt = window.event || evt;
						obj.selectTab(this.tab, evt);
						window.location.href = this.href + "-tab";
						return true;
					}
			}
		}
		
		
		// Get/Set selection
		this.getSelected();
		if(this.config.select){
			this.selectTab(this.config.select);
		}
		this.adjustFootprint();
	},
	
	/**
	* Select a tab.
	* @param {Tab|Int|String} tab The tab to select, this can either be the Tab object, tab index or the tab's ID.
	* @param {Event} evt The browser event used to call this method.  Passing this will prevent the default event action.
	*/
	selectTab : function(tab, evt){
		
		// Prevent default event action
		if(evt){
			if (evt.preventDefault) {
				evt.preventDefault();
			} 
			else {
				evt.returnValue = false;
			}
		}
		
		// Convert tab number to Tab object
		if(!isNaN(tab)){
			tab = this.tabs[parseInt(tab)];
		}
		
		// Convert tab ID to Tab object
		else if(typeof tab == "string"){
			tab = this.getTabById(tab);
		}
			
		if(!tab){
			return;
		}
		
		// Deselect last tab
		if(this.selected){
			this.selected.container.className = this.selected.container.className.replace(/selected/g, "");
		}
		
		// Select this tab
		tab.container.className += " selected";
		this.selected = tab;
		
		this.adjustFootprint();				
	},
	
	/**
	* Get a Tab object by it's ID
	* @param {String} id The tab ID
	* @return {Object} The Tab object or null
	*/
	getTabById : function(id){
		for(var i = 0; i < this.tabs.length; i++){
			if(this.tabs[i].id == id){
				return this.tabs[i];
			}
		}
		
		return null;
	},
	
	/**
	* Get the selected tab.
	* @return {int} The selected tab index.
	*/
	getSelected : function(){
		for(var i = 0; i < this.tabs.length; i++){
			if(this.tabs[i].container.className.match(/(^|\s)selected(\s|$)/)){
				this.selected = this.tabs[i];
				return i;
				break;
			}
		}
	},
	
	/**
	* Automatically resizes the tab box to fit the content.
	*/
	adjustFootprint : function(){
		if(this.config.autosize == false){
			return;
		}
		
		if(!this.selected){
			return;
		}
		
		// Set height
		var height = this.selected.content.clientHeight + 5;
		if(this.config.vertical == false){
			height += this.selected.header.clientHeight;
		}
		this.tabbox.style.height = height +"px"; 
	}
	
}

var HtmlIncluder = Class.create();
HtmlIncluder.prototype = {
	initialize: function () {
	},
	 
	include: function( parameters ) {
		try {
			if (parameters.callback != null) {
				this.includeCustomCallback(parameters.url, parameters.callback);
			} else {
				this.includeDefaultCallback(parameters.url, parameters.mustContain, parameters.elementIdToReplaceInnerHTML);
			}
		} catch (Exception) {
		}
	}, 
	 
	includeDefaultCallback: function( url, mustContain, elementIdToReplaceInnerHTML ) {
		var defaultCallBackCode = 
			  " {"
			+ " 	if (response != undefined) { "
			+ " 		if (response != null) { "			
			+ " 			if (response.html.indexOf('" + mustContain + "') > -1) { "
			+ " 				document.getElementById('" + elementIdToReplaceInnerHTML + "').innerHTML = response.html; "
			+ " 				return; "
			+ " 			} "
			+ " 		} "
			+ " 	} "
			+ " 	document.getElementById('" + elementIdToReplaceInnerHTML + "').innerHTML = '';  "
			+ " }";
		try {
		
			var callbackName = "htmlIncluderCallback_" + url.replace(/[^a-zA-Z0-9]/g, '_') + "_" + elementIdToReplaceInnerHTML;
			var scriptCallback = document.createElement('script');
			scriptCallback.type = 'text/javascript';
			scriptCallback.innerHTML = " function " + callbackName + "(response) " + defaultCallBackCode;
			var head = document.getElementsByTagName('head')[0];
			head.appendChild( scriptCallback );
			
			var scriptFetcher = document.createElement('script');
			scriptFetcher.type = 'text/javascript';
			scriptFetcher.src = "https://thjonustuvefur.siminn.is/tilkynningar/servlet/SiminnHtml2Json?callback=" + callbackName + "&url=" + url;
			head.appendChild( scriptFetcher );
		} catch (Exception) {
			try {
				var head = document.getElementsByTagName('head')[0];
				var scriptFetcher = document.createElement('script');
				scriptFetcher.type = 'text/javascript';
				scriptFetcher.src = "https://thjonustuvefur.siminn.is/tilkynningar/servlet/SiminnHtml2Json?callback=( function(response) " + defaultCallBackCode + ")&url=" + url;
				head.appendChild( scriptFetcher );
			} catch (Exception) {
			}
		}		
	}, 
	includeCustomCallback: function( url, callbackName ) {
		try {
			var head = document.getElementsByTagName('head')[0];
			
			var scriptFetcher = document.createElement('script');
			scriptFetcher.type = 'text/javascript';
			scriptFetcher.src = "https://thjonustuvefur.siminn.is/tilkynningar/servlet/SiminnHtml2Json?callback=" + callbackName + "&url=" + url;
			head.appendChild( scriptFetcher );
		} catch (Exception) {
		}			
	}
	
};

function clearDefault(el) {if (el.defaultValue==el.value) el.value = ""}