

function hideFormText() {
	var _inputs = document.getElementsByTagName('input');
	var _txt = document.getElementsByTagName('textarea');
	var _value = [];
	
	if (_inputs) {
		for(var i=0; i<_inputs.length; i++) {
			if (_inputs[i].type == 'text' || _inputs[i].type == 'password') {
				
				_inputs[i].index = i;
				_value[i] = _inputs[i].value;
				
				_inputs[i].onfocus = function(){
					if (this.value == _value[this.index])
						this.value = '';
				}
				_inputs[i].onblur = function(){
					if (this.value == '')
						this.value = _value[this.index];
				}
			}
		}
	}
	if (_txt) {
		for(var i=0; i<_txt.length; i++) {
			_txt[i].index = i;
			_value['txt'+i] = _txt[i].value;
			
			_txt[i].onfocus = function(){
				if (this.value == _value['txt'+this.index])
					this.value = '';
			}
			_txt[i].onblur = function(){
				if (this.value == '')
					this.value = _value['txt'+this.index];
			}
		}
	}
}
if (window.addEventListener)
	window.addEventListener("load", hideFormText, false);
else if (window.attachEvent)
	window.attachEvent("onload", hideFormText);
	
	
var _id = 'login';
function updateAfterAjax() {
	
	jQuery('.lightbox a.nospam').nospam({
      replaceText: true, 
      filterLevel: 'normal'
    });

}

jQuery(document).ready(function() {
	
	/* Spam protect survey */
	if(jQuery('#survey_form').length != 0) {
		var form_el = jQuery('#survey_form');
		if(form_el.attr('action') == 'nospam') {
			//form_el.attr('action', survey_uri_form);
		}
	}
	
	/* Lik høyde kolonner */
	$('.modules-divider').each(function(){
			var currentTallest = 0;
			$(this).contents().find(".cont").each(function(i){
				if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
			});
			//if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
			// for ie6, set height since min-height isn't supported
			if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
			$(this).contents().find(".cont").css({'min-height': currentTallest}); 
	});
	
	/* Configure NyroModal plugin */
	
	$.nyroModalSettings({
		debug: false,
		closeButton: null,
		endShowContent: updateAfterAjax
	});

	/* Animate the drop-links on frontpage 
	
	var frontpageBoxes = jQuery('.ani_up');
	if(jQuery.browser.opera == false) {
		frontpageBoxes = jQuery('.ani_down, .ani_up');
	}
	
	frontpageBoxes.each( function(i) { 
		jQuery(this).data('orgPosY', jQuery(this).offset().top);
		jQuery(this).data('targetPosY', jQuery(this).offset().top - $(this).find(".drop-link").height());
		jQuery(this).data('animate', false);
	});

	frontpageBoxes.hover(
		function () {
			if(!jQuery(this).data('animate')) {
				var target = $(this).find(".drop-link").height();
				jQuery(this).stop();
				jQuery(this).animate({'top': '-='+target+'px'}, 500 );
				jQuery(this).data('animate', true);
			}
		}, function () {
			jQuery(this).data('animate', false);
			var target = -$(this).find(".drop-link").height();
			jQuery(this).stop();
			jQuery(this).animate({'top': '-='+target+'px'}, 10);
		}
	);

	function done() {
		
		jQuery(this).css('top', jQuery(this).data('orgPosY')+'px');
	}
	
	function done2() {
		jQuery(this).stop();
		//css('top', jQuery(this).data('targetPosY')+'px');
	}
	*/
	/* Tabs */
	
	var tabContainers = jQuery('div.tab');
	var tabs = jQuery('.tabset a');
	
	tabs.each( function(i) { 
	  jQuery(this).click(function() { 
		tabContainers.hide().filter(this.hash).show();
		var parent = jQuery(this).get(0);
		jQuery(parent).siblings().removeClass("active");
		jQuery(parent).addClass("active tab");
		return false;
	  }); 
	 });
	tabs.eq(0).click();
	
	/* Kundereferanse tabs */
	
	var refContainers = jQuery('.reftab'); 
	var refTabs = jQuery('.reftabs a');
	
	refTabs.each( function(i) { 
	  jQuery(this).click(function() { 
		refContainers.hide().filter(this.hash).show();
		return false;
	  }); 
	 });
	refTabs.eq(0).click();
	
	/* Animasjon galleri  */
	
	var art_thumbs = jQuery('#gallery li a');
	art_thumbs.each( function(i) { 
		jQuery(this).click(function() {
			var largePath = jQuery(this).attr("href");
			//console.log(jQuery(this));
			//console.log(largePath);
			var lightboxPath = jQuery(this).attr("rel");
			var caption = jQuery(this).attr("title");
			jQuery(".main-img a img").attr({ src: largePath});

			jQuery(".main-img a").attr({ href: lightboxPath});
			
			if(caption == "") {
				jQuery(".main-img .text").hide();
			} else {
				jQuery(".main-img .text").html(caption).show();
			}
			
			return false;
		}); 
	});
	art_thumbs.eq(0).click();
	jQuery('.box-bottom').infiniteCarousel();

});


