// JavaScript Document

function sporNedlasting(fil,side) {
	_gaq.push(['_trackEvent', 'Nedlasting', fil,side]);
}

function sporUtgaaendeLink(linktittel,side) {
	_gaq.push(['_trackEvent', 'Utgående link', linktittel,side]);
}


function getViewportHeight() {
	var viewportheight;
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight
	} else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
		// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
		viewportheight = document.documentElement.clientHeight
	} else {
		// older versions of IE
		viewportheight = document.getElementsByTagName('body')[0].clientHeight
	}
 return viewportheight;
}

window.addEvent('domready',function() {
	/*
	var h = getViewportHeight();
	//console.log('h='+h);
	if(h < 700) {
		$('toppbanner').setStyle('display','none');
	}*/
	
	if($('godtattSMS_bestilling')) {
		var linkCopy = $('bestill_link').clone();
		linkCopy.removeClass('bumpbox');
		linkCopy.href = "javascript:void(0);";
		linkCopy.onclick = false;
		linkCopy.addEvent('click',function() {
			alert("Du må hake av boksen over først");								   
		});
		linkCopy.inject($('bestill_link'),'after')
		if($('godtattSMS_bestilling').checked == false) {
			$('bestill_link').setStyle('display','none');
		} else {
			linkCopy.setStyle('display','none');
		}
		
		$('godtattSMS_bestilling').addEvent('click',function() {
			if($('godtattSMS_bestilling').checked == false) {
				$('bestill_link').setStyle('display','none');
				linkCopy.setStyle('display','inline');
			} else {
				$('bestill_link').setStyle('display','inline');
				linkCopy.setStyle('display','none');
			}
															 
		});
		
	}
	
	$$('.labelInside').each(function(el) {
		
		if(el.value.substr(0,1) == "»") {
			el.value = el.value.substr(1);
			el.addClass('labelInaktiv');
			var orgfeltverdi = el.value;
			el.addEvent('focus',function(e) {
				el.removeClass('labelInaktiv');
				if(el.value == orgfeltverdi) {
					el.value = "";
				}
			});
			el.addEvent('blur',function(e) {
				if(el.value == "") {
					el.addClass('labelInaktiv');
					el.value = orgfeltverdi;
				}
				//alert("gikk ut, verdi = " + el.value);
				//el.value = "";							 
			});
		}
	});
	
	$$('#floatmeny a').each(function(el) {
		if(el.href == window.location) {
			el.addClass('active');
		}
		//alert("href test: " + el.href + "\nwindow = " + window.location);							
									
	});
	
	/*$$('ul.faq').each(function(el) {
		el.getChildren().each(function(el2) {
			alert("element er: " + el2.get('tag'));						   
		});
		
		//var svarElement = el.getChildren('ul')[0];
		//alert("høyde = " + svarElement.get('height'));
		//alert("element er: " + el.get('tag'));
		
		/*el.addEvent('click',function() {
			alert("test, svar element høyde = " + this.get('height'));
		}.bind(el.svarElement));*/
	//});

	/*$$('.commentform').each(function(el) {
		el.addEvent('submit',function(e) {
			e.stop();
			//alert("stoppet submit");
			this.set('send', {onComplete: function(response) { 
				//log.removeClass('ajax-loading');
				//log.set('html', response);
				$('comments').set('html',response + $('comments').get('html'));
			}});
			//Send the form.
			this.send();

			
			/*var req = new Request.HTML({
				url:el.action,
				method:'post',
				data: el.toQueryString(),
				onSuccess: function(html, responseElements, responseHTML, responseJavaScript) {
					//alert("action = " + el.action + "html: " + responseHTML);
					//if(responseHTML != 'error') {
						//html.inject($('comments'),'top');
						//$('comments').adopt(html);
						//$('comments').grab(html);
						
						$('comments').set('html',responseHTML + $('comments').get('html'));
						e.target.set('html',"Kommentaren er lagt til");

					//}
				},
				//Our request will most likely succeed, but just in case, we'll add an
				//onFailure method which will let the user know what happened.
				onFailure: function() {
					$('result').set('text', 'The request failed.');
				}
			}).send();*/
			//alert("test");
		//});
	//});
});


