// Find object in HTML DOM
function findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function moveMenuArrow(button, offset) {
	
}

function useSearchField(field) {
	if (field.value == "&lt;zoeken&gt;") {
		findObj(field).value = "";
	} else if (field.value == "") {
		finObj(field).value = "";
	}
}

function hideSubMenu(object) {
	$(object).hide("slide", { direction: "right" });
}



// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// JS FUNCTIONS FOR FORM VALIDATION AND MAIL PROCESSING
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
var attachmentSelected = false;

function attachAttachment() {
	attachmentSelected = true;
}

function callSuccessFunction() {
	// Upload file (if found) when form is validated
	if (attachmentSelected == true) {
		$('#attachment').uploadifyUpload();
		return false;
	} else {
		sendMailFunction(false);
		return false;
	}
}

function signUp() {
	// Send data to mailer script (updater)
	$.post("/api/php/updaters/send_mime_mail.php", $('#formID').serialize(),
	function(data){ 
		if (data == "1") { signUpSuccessFunction(data); } else { mailErrorFunction(data); }
	});
	
	return false;
}

function sendMailFunction(data) {
	// Set data file
	if (data) {
		$('#attachmentHidden').val(data.filePath);
	}
	
	// Send data to mailer script (updater)
	$.post("/api/php/updaters/send_mime_mail.php", $('#formID').serialize(),
	function(data){ 
		if (data == "1") { mailSuccessFunction(data); } else { mailErrorFunction(data); }
	});
	
	return false;
}

function mailSuccessFunction() {
	$.modal("Uw bericht is succesvol verzonden. Indien nodig zal een van onze medewerkers z.s.m. contact met u opnemen.", { 
	containerCss: { fontSize: 13, height: 150,width: 380,backgroundColor: '#fff',color: '#333333',border: '7px solid #ccc',overflow: 'hidden'}, opacity: 85, close: true 
	});	
	
	$('#formID').reset();
}

function signUpSuccessFunction() {
	$.modal("Uw e-mail addres is succesvol geregistreerd. Binnenkort ontvangt u onze nieuwsbrief op het opgegeven e-mail adres", { 
	containerCss: { fontSize: 13, height: 150,width: 380,backgroundColor: '#fff',color: '#333333',border: '7px solid #ccc',overflow: 'hidden'}, opacity: 85, close: true 
	});	
	
	hideSignupForm();
}

function mailErrorFunction(data) {
	$.modal("Er is een fout opgetreden bij het versturen van het contactformulier: " + data, { 
		containerCss: {	fontSize: 13, height: 150,width: 380,backgroundColor: '#fff',color: '#333333',border: '7px solid #ccc',overflow: 'hidden'}, opacity: 85, close: true 
	});	
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// JS FUNCTION TO ANIMATE HIGHLIGHT BANNER ON HOMEPAGE
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
var current 	= 5;
var total		= 0;
var highlights	= new Array();
var timer		= "";

function swapHighlightBanner(int) {

	// IF USER CLICKED ON A TAB
	if (int) {
		current = int;
		clearTimeout(timer);
	} else if (int == 0) {
		current = int;
		clearTimeout(timer);
	} else {
		timer 	= setTimeout("swapHighlightBanner()",5000);
	}
		
	// HIDE DAY / MONTH / TITLE
	$('.label-highlight-blue').hide("slide", { direction: "right" }, 250, function() { 
		$('.label-highlight-blue .day').html(highlights[current]['day']); Cufon.replace('.label-highlight-blue .day');
		$('.label-highlight-blue .month').html(highlights[current]['month']); Cufon.replace('.label-highlight-blue .month');
		$('#hp-highlight-bestel a').attr('href','/voorstelling/'+highlights[current]['alias']+'.html');
	});
		
	$('#hp-highlight-title').hide("slide", { direction: "left" }, 250, function() {
		$('#hp-highlight-bestel').hide("slide", { direction: "left" }, 250);
		$('#hp-highlight-title').html(highlights[current]['title']); Cufon.replace('#hp-highlight-title');
		$('#hp-highlight img').fadeOut('fast', function() {
			
			$('.label-highlight-counter').each( function() { 
				$(this).removeClass('label-highlight-counter-active', 'slow'); 
			});
			$('#counter-'+current).addClass('label-highlight-counter-active', 'slow');
			$('#hp-highlight img').attr('src',highlights[current]['image']); 
			$('#hp-highlight img').delay(750).fadeIn('slow', function() { 
 			    if (highlights[current]['alias'] == "#") {
					$('.label-highlight-blue').show("slide", { direction: "right" }, 100);
					$('#hp-highlight-title').show("slide", { direction: "left" }, 100);
				} else {
					$('.label-highlight-blue').show("slide", { direction: "right" }, 500);
					$('#hp-highlight-title').show("slide", { direction: "left" }, 250, function() { 
						$('#hp-highlight-bestel').show("slide", { direction: "left" }, 250);																			
					});	
				}
			});
		}); 
	});
	
	
	// CUFON NEW VALUES OF LABEL
	Cufon.now();
		
	if (!int) { current++; if (current > total) { current = 0;  } }
		
}
