var blindDuration = 0.35;
var animating = false;

function cboxToggle(element) {
	if(Effect && element && animating == false) {
		var x = element.getElementsByTagName("div");
		var icon
		var content
		
		// FIND ICON AND CONTENT ELEMENTS IN THE CBOX
		for ( var i in x )
		{
			if(x[i].className == "icon")
				icon = x[i]
			
			if(x[i].className == "content")
				content = x[i]
		}
		
		/*if(content.id){
			var myEffect = new Effect.toggle(content.id, 'blind', { 
				duration: blindDuration, 
				afterFinish: function() { alert("done") },
				transition: Effect.Transitions.sinoida
			});
			animating = true;
		}*/
		
		if(content.id && icon){
			animating = true;
			if(content.style.display == "none"){
				// OPEN
				new Effect.Parallel([
					new Effect.BlindDown(content, { sync: true }), 
					new Effect.Morph(icon, { sync: true, style: 'background:#fde1b7' }) 
				], { 
					duration: blindDuration,
					afterFinish: function() { animating = false}
				});
				
			}
			else
			{
				// CLOSE
				new Effect.Parallel([
					new Effect.BlindUp(content, { sync: true }), 
					new Effect.Morph(icon, { sync: true, style: 'background:#ff9a00' }) 
				], { 
					duration: blindDuration,
					afterFinish: function() { animating = false }
				});
			}
		}
		
		
	}
	return false;
}

function alpha_dash(str,item)
{
	if(str)
	{
		var regex=/^[0-9A-Za-z]+$/; //^[a-zA-z]+$/
		//convert str to alpha_numeric_dash text for the path field
		str = str.toLowerCase();
		str = str.replace(/[^a-zA-Z 0-9]+/g,'');
		str = str.replace(/[\s]+/g,'_');
		if(item = document.getElementById(item))
			item.value = str;
		else
			document.getElementById("path").value = str;
		
	}
}

function show(item)
{
	if(item)
	{
		item = document.getElementById(item);
		if(item)
			item.style.display = 'block';
	}
}

function hide(item)
{
	if(item)
	{
		item = document.getElementById(item);
		if(item)
			item.style.display = 'none';
	}
}

function deselect_checkboxes(item)
{
	if(item)
	{
		//debug = document.getElementById('debug');
		item = document.getElementById(item);
		if(item)
		{
			inputs = item.getElementsByTagName('input');
			for(var i = 0; i < inputs.length; i++)
			{
				input = inputs[i];
				if(input && input.type == "checkbox")
				{
					//debug.innerHTML += input.id;
					input.checked = false;
				}
			}
			
		}
	}
}

function var_dump(obj) {
   if(typeof obj == "object") {
      return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
   } else {
      return "Type: "+typeof(obj)+"\nValue: "+obj;
   }
}

function vconfirm(text,url) {
	if(text && url)
	{
		var r=confirm(text);
		if (r==true)
		{
			// GO TO URL
			window.location = url;
		}
		else
		{
			return false;
		}
	}
}

// JQUERY @ THORBJORG

$(document).ready(function() {
	
	$('#scrolltopbtn').click(function() {
		$('html,body').animate({scrollTop: '0px'}, "slow");
	return false;
  });



	$('#newssignupbtn,#newsletterfrontbtn').click(function() {
		$('#newssignupform').fadeIn(200);
		return false;
	});



	$('#newssignupclose').click(function() {
		$('#newssignupform').fadeOut(400);
		return false;
	});
	
});

