// Favola Basic js

// Add class when JS is enabled
if(document.getElementById){
	var html = document.getElementsByTagName("html")[0];
	html.className = 'js';
}

// DOM ready
$(document).ready(function(){
	labelToInput();
	slider();
	$.geekGaTrackPage('UA-11516233-1', 'vaekstogviden.dk');
});

function slider(){
	$('#slidersub').after('<ul></ul>').cycle({
		fx: 'scrollHorz',
		timeout: 8000,
		pager:  '#slider ul',
		pagerAnchorBuilder: function(idx) { 
			return '<li></li>'; 
		}
	});
}

function labelToInput(){
	$("label.labelToInput[for]").each(function(i){
		var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
		var newVal = this.innerHTML.replace(regexp,"");
		if($("#"+this.htmlFor).is("input") || $("#"+this.htmlFor).is("textarea")){
			if(	($("#"+this.htmlFor).val() == "") || ($("#"+this.htmlFor).val() == newVal)	){
				$("#"+this.htmlFor).attr("value",newVal);
				$("#"+this.htmlFor).focus(function(){if(this.value == newVal) this.value = "";});
				$("#"+this.htmlFor).blur(function(){if(this.value == "") this.value = newVal;});
			}
		} else if($("#"+this.htmlFor).is("select")){
			var orgOptions = $("#"+this.htmlFor).html();
			$("#"+this.htmlFor).html("")
			strSelected = ' selected="selected"';
			if(orgOptions.indexOf("selected=") > -1) strSelected = "";
			newOptions = "<option"+strSelected+">"+newVal+"</option>"+orgOptions;
			$("#"+this.htmlFor).html(newOptions)
		}
		$(this).hide();
	})
	cleanForms();
}

function cleanForms(){
	$("form:has(label.mdValueToInput)").submit(function(){
		$("label.mdValueToInput[for]").each(function(){
			var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
			var newVal = this.innerHTML.replace(regexp,"");
			if($("#"+this.htmlFor).attr("value") == newVal){
				$("#"+this.htmlFor).attr("value","");
			}
		})
	})
}

function newsletter(){
	$('#frontendform').submit(function(){
		Inscribe();
	})
}

/* geekGa.js v1.2 */
(function($){var pageTracker;$.geekGaTrackPage=function(account_id,domain_name){var host=(("https:"==document.location.protocol)?"https://ssl.":"http://www.");var src=host+'google-analytics.com/ga.js';$.ajax({type:'GET',url:src,success:function(){pageTracker=_gat._getTracker(account_id);domain_name=domain_name||'';if(domain_name!='')
{pageTracker._setDomainName(domain_name);}
pageTracker._trackPageview();},error:function(){throw"Unable to load ga.js; _gat has not been defined.";},dataType:'script',cache:true});};$.geekGaTrackEvent=function(category,action,label,value){if(typeof pageTracker!=undefined){pageTracker._trackEvent(category,action,label,value);}else{throw"Unable to track event; pageTracker has not been defined";}};})(jQuery);
