// different menu items
var items = new Array("form", "why", "what", "friends", "facebook", "videos");

// base url
//var url = 'http://localhost/gaia/';
var url = '';

url = 'http://' + document.domain + '/';
//window.alert(path);

// banner interval
var INTERVAL = 6000;



function toggleItems(item){
	// toggle the selected item, hide all others
		
	for(i=0; i<items.length; i++){
		if(item != items[i]){
			$('#'+items[i]+'_toggled_out').hide();
		}else{
			$('#'+item+'_toggled_out').slideToggle(400, function(){
				$('#flashHolder').height($(document).height()+'px');
			});
		}
	}
	toggleArrows(item);
}


function toggleImage(){
	// toggles the i love pigs image in the header, unless the user is using IE6
	
	var toggle = false;
	
	if(navigator.appName != 'Microsoft Internet Explorer'){
		toggle = true;
	}else{
		if(checkVersion() != 6){
			toggle = true;
		}
	}
	
	//window.alert(document.getElementById('i_love_pigs').src);
	
	if(toggle == true){
		if(document.getElementById('i_love_pigs').src == url + 'images/i_love_pigs.png'){
			document.getElementById('i_love_pigs').src = 'images/i_love_pigs_hover.png';
			document.getElementById('i_love_pigs').style.top = '90px';
		}else{
			document.getElementById('i_love_pigs').src = 'images/i_love_pigs.png';
			document.getElementById('i_love_pigs').style.top = '100px';
		}
	}
}

function toggleArrows(item){
	// toggles the arrows of the clicked menuitem 
	
	if(item != 'form'){
		if(document.getElementById('arrow_'+item).src == url + 'images/pijl_small.gif'){
			document.getElementById('arrow_'+item).src = url + 'images/pijl_small_standingup.gif';
		}else{
			document.getElementById('arrow_'+item).src = url + 'images/pijl_small.gif';
		}
	}

	resetOtherArrows(item);	
}

function resetOtherArrows(item){
	// resets all arrows (except the clicked one) to the original arrow
	
	var i = 1;
	if(item == 'form'){
		for(i=1; i<items.length; i++){
			document.getElementById('arrow_'+items[i]).src = url + 'images/pijl_small_standingup.gif';
		}	
	}else{
		for(i=1; i<items.length; i++){
			if(item != items[i] && item != 'form'){
				document.getElementById('arrow_'+items[i]).src = url + 'images/pijl_small_standingup.gif';	
			}
		}	
	}
}

function switchHeader(){
	// switches the header every 6 seconds		
	
	// get language
	var lang = document.getElementById('language').value;
	
	var img = document.getElementById('subheader');
	if(img.src == url + 'images/elke_handtekening_'+ lang + '.gif'){
		img.src = url + 'images/sign_now_'+ lang + '.gif';
		img.style.paddingLeft = '0px';
		if(lang == 'fr'){
			img.style.paddingTop = '0px';
		}else{
			img.style.paddingTop = '8px';
		}
	}else{
		img.src = url + 'images/elke_handtekening_'+ lang + '.gif';
		if(lang == 'fr'){
			img.style.paddingTop = '7px';
		}else{
			img.style.paddingTop = '8px';
		}
	}
}

// set the interval for the switching of header
setInterval("switchHeader()", INTERVAL);

function showPrivacy(lang){
	// show privacy statement, hide disclaimer
	
	$('#privacy_'+ lang).slideToggle(400, function(){
		$('#flashHolder').height($(document).height()+'px');
	});
	$('#disclaimer_'+ lang).hide();
}

function showDisclaimer(lang){
	// and vice versa
	
	$('#disclaimer_'+ lang).slideToggle(400, function(){
		$('#flashHolder').height($(document).height()+'px');
	});
	$('#privacy_'+ lang).hide();
}


function validateSignForm(){
	// validates the 'sign-the petition'-form
	
	var voornaam = document.signform.voornaam.value;
	var naam = document.signform.naam.value;
	
	if(voornaam == '' || naam == '' || voornaam == 'voornaam' || naam == 'naam' || checkMail(document.signform.email.value) == 0){
		document.getElementById('form_error').style.display = 'block';
	}else{
		document.signform.submit();
	}
}

function validateSendToFriendsForm(){
	// validates the 'send-to-a-friend'-form
	
	var voornaam1 = document.send_to_friends_form.first_name1.value;
	var voornaam2 = document.send_to_friends_form.first_name2.value;
	var email1 = document.send_to_friends_form.email1.value;
	var email2 = document.send_to_friends_form.email2.value;
	
	if(voornaam1 == '' || voornaam2 == '' || checkMail(email1) == 0 || checkMail(email2) == 0){
		document.getElementById('send_to_friends_error').style.display = 'block';
	}else{
		document.send_to_friends_form.submit();
	}
}

function checkMail(email){
	// checks for correct email
	
	var pattern = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(pattern.test(email)){         
		return 1; 
    }else{   
		return 0; 
    }

}

// some functions i pulled of the internet
function getInternetExplorerVersion(){
	var rv = -1;
	if(navigator.appName == 'Microsoft Internet Explorer'){
		var ua = navigator.userAgent;
		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null) rv = parseFloat(RegExp.$1);
	}
	
	return rv;
}

function checkVersion(){
	var msg = "You're not using Internet Explorer.";
	var ver = getInternetExplorerVersion();
	if ( ver > -1 ){
		if ( ver == 6.0 ){ 
			msg = "You're using Internet Explorer 6.0. Bah!"
			version = "6";
		}else{
			msg = "You should upgrade your copy of Internet Explorer.";
			version = "";
		}
	}
	
	return version;
}

