/*************************************
*    Script : easyCMS_POP v2.0       *
*    Author : Kim Steinhaug          *
*    Url    : www.steinhaug.com      *
*                                    *
*  --   --  --  --  --  --  --  --   *
* Usage :                            *
* swPOP('link','x','y','scrollbar'); *
*                                    *
* link 	    = Dokument url           *
* x    	    = Popup window X value   *
* y    	    = Popup window Y value   *
* scrollbar = 0, no                  *
*             1, yes                 *
**************************************/
function easyCMS_POP(url,Xvalue,Yvalue,scroll) {
	var w = 480, h = 340;if (document.all || document.layers) { w = screen.availWidth;h = screen.availHeight; };
	var popW = Xvalue, popH = Yvalue;var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	if (scroll) { i = open(url, "displayWindow","top="+topPos+",left="+leftPos+",width="+Xvalue+",height="+Yvalue+",status=no,toolbar=1,menubar=no,resize=no,dependent=yes,scrollbars=yes");} else { i = open(url, "displayWindow","top="+topPos+",left="+leftPos+",width="+Xvalue+",height="+Yvalue+",status=1,toolbar=1,menubar=0,resize=no,dependent=yes,scrollbars=no");};
};

function easyCMS_zoom(header,alt,url,Xvalue,Yvalue,scroll) {
	Xvalue = Number(Xvalue) + 20;
	Yvalue = Number(Yvalue) + 60;
	if (scroll) {
        i = open("", "EUindow","top=50,left=50,width="+Xvalue+",height="+Yvalue+",status=no,toolbar=no,menubar=no,resize=no,dependent=yes,scrollbars=yes");
	} else {
        i = open("", "EUindow","top=50,left=50,width="+Xvalue+",height="+Yvalue+",status=no,toolbar=no,menubar=no,resize=no,dependent=yes,scrollbars=no");
	};
    i.focus();
        i.document.open();
        i.document.write('<html>\n')
        i.document.write('<head>\n')
        i.document.write('<title>Easy CMS - ' + alt + '</title>\n')
        i.document.write('<style><!--\n')
        i.document.write('body { \n')
        i.document.write('margin : 0px 0px 0px 0px;\n')
        i.document.write('}\n')
        i.document.write('--></style>\n')
        i.document.write('<\head>\n')
        i.document.write('<body bgcolor="#ffffff" text="#000000">\n')
        i.document.write('<center>\n')
        i.document.write('<div style="font-size:14px; font-weight:bold; font-family:verdana,arial,sans-serif,helvetica;">',header,'</div><a href="javascript:window.close();"><img src="',url,'" border="2" style="border:2px solid white;" alt=""></a>\n')
        i.document.write('<div style="font-size:10px;font-family:verdana;color:#006;">' + alt + '</div>\n')
        i.document.write('<div style="font-size:10px;font-family:verdana;color:#999;">&copy; Easy CMS 2005</div></center>\n')
        i.document.write('</body>\n')
        i.document.write('</html>\n');
        i.document.close();
};

/* Underliggende kode tilhører SwitchMenu */
/* Slett alt under om den ikke brukes     */
/* Fjern kommentarblokk for å aktivere    */

if (document.getElementById){
  document.write('<style type="text/css">\n')
  document.write('.submenu{display: none;}\n')
  document.write('</style>\n')
};
function SwitchMenu(obj){
  if(document.getElementById){
  var el = document.getElementById(obj);
  if(el){ // For ikke å åpne ikke eksisterende menyer!
  var ar = document.getElementById("CMSmenu").getElementsByTagName("ul");
    if(el.style.display != "block"){
      for (var i=0; i<ar.length; i++){
        if (ar[i].className=="submenu")
        ar[i].style.display = "none";
          };
        el.style.display = "block";
        } else {
        el.style.display = "none";
      };
    };
  };
};

function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}
	
var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();
addEvent(window,'unload',EventCache.flush);

/* Steinhaug Webdesign JS library for Easy CMS */
var swlib = { 
  fixhr_id : 'content',
  fixhr_class : 'hr',
  fixhref: function() {
  var elements = document.getElementsByTagName('a');
  var i;
    for ( i=0;i<elements.length;i++ ) {
      var re = new RegExp("#$");
      if (elements[i].getAttribute('href').match(re)) {
        elements[i].setAttribute('href','javascript:;');
      }
    }
  },
  fixhr: function(){
    if (!document.getElementsByTagName) return;
    var hr = document.getElementById(swlib.fixhr_id).getElementsByTagName('hr');
    for (var i=0; i<hr.length; i++) { 
      var newhr = hr[i]; 
      var wrapdiv = document.createElement('div');
      wrapdiv.className = swlib.fixhr_class;  
      newhr.parentNode.replaceChild(wrapdiv, newhr);  
      wrapdiv.appendChild(newhr);  
    } 
  }
};
addEvent(window,'load',swlib.fixhref,false);
// addEvent(window,'load',swlib.fixhr,false);

/* Easy CMS JS-Class for gallery template #03. 
   (c) Steinhaug AS - www.steinhaug.com
   Automatic slideshow with start and stop button */
var swGallerySlideshow = {
  lang_start : 'START',
  lang_stop  : 'STOP',
  url_start  : '/index.php',
  url_next   : '',
  seconds    : 5,
  img_anim   : '<img src="/images/timer-01.gif" width="16" height="16" alt="">',
  img_none   : '<img src="/images/spacer.gif" width="16" height="16" alt="">',
  active     : false,
  getVersion : function() {
    return 'v1.0';
  },
  toggle : function (el){
    if(this.active){
      this.deactivate(el);
    } else {
      this.activate(el);
    }
  },
  timersequence : function () {
    this.seconds = this.seconds - 1;
    if(this.seconds==0){
      clearTimeout(this.timer01);
      document.location.href = this.url_next;
//      alert('Complete');
    } else {
      self.status = this.seconds;
      this.timer01 = setTimeout('swGallerySlideshow.timersequence()',1000);
    }
  },
  activate : function (el) {
    this.active = true;
//    document.getElementById('swGallerySlideshow-button').value = this.lang_stop;
    document.getElementById('swGallerySlideshow-button').innerHTML = this.lang_stop;
    document.getElementById('swGallerySlideshow-anim').innerHTML = this.img_anim;
    this.applyStyleString(document.getElementById('swGallerySlideshow-button'),'background-color: #990000;')
    this.timer01 = setTimeout('swGallerySlideshow.timersequence()',1000);
  },
  deactivate : function (el) {
    this.active = false;
    clearTimeout(this.timer01);
//    document.getElementById('swGallerySlideshow-button').value = this.lang_start;
    document.getElementById('swGallerySlideshow-button').innerHTML = this.lang_start;
    document.getElementById('swGallerySlideshow-anim').innerHTML = this.img_none;
    this.applyStyleString(document.getElementById('swGallerySlideshow-button'),'background-color: #009900;')
//    this.clearInnerHTML(document.getElementById('swGallerySlideshow-anim'));
  },
  clearInnerHTML : function (obj){
    while(obj.firstChild) obj.removeChild(obj.firstChild);
  },
  applyStyleString : function (obj,str) {
    if(document.all && !window.opera) {
      obj.style.setAttribute("cssText",str);
    } else {
      obj.setAttribute("style",str);
    }
  }
}