var map;


$(function() {


	// Animate links in footer-menu
	$('#footer-menu dd a').hover(function() {
		$(this).stop().animate({ paddingLeft: '20px' }, 300);
	}, function() {
		$(this).stop().animate({ paddingLeft: 0 }, 300);
	});

	// Clear inputs on blur
	$("#footer-menu input").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});


	$('input,textarea').focus(function(){
		$(this).parent().children('span').css('display', 'block');
	}).blur(function(){
		$(this).parent().children('span').css('display', 'none');
	});

	$('#select-branche').change(f = function(){
		e = document.getElementById('select-branche');
		if (!e) return;
		v = e.options[e.selectedIndex].value;

		if (v==0)
			$('h2.result-title').html('Alle branches');
		else
			$('h2.result-title').html(e.options[e.selectedIndex].text);

		$('.portfolio').each(function(){

			show = (v==0 || this.className.indexOf('branche' + v) != -1);
			if (document.getElementById('only-cases').checked){
				if ($(this).children('a').length==0)
					show = false;
			}

			if (show)
				$(this).animate({ opacity: 'show' }, "slow");
			else
				$(this).animate({ opacity: 'hide' }, "slow");
		});

	});

	$('#only-cases').click(f);
	f();

	// Write items when javascript is enabled
	$(".vcard-info").prepend("<a href='javascript:;' class='explain-vcard'>Wat is een vCard?</a>");


	$(".team-list:nth-child(odd)").addClass("margin-right20");

	$(".explain-vcard").click(function() {
		$(".tooltip-vcard").animate({ opacity: 'show' }, "slow")
	});

	$(".close-tooltip").click(function(){
		$(this).parents(".tooltip-vcard").animate({ opacity: 'hide' }, "slow");
	});

	// Open link in new window
	$(".external").attr("target","_blank");

	// Click entire block team-list
	$(".team-list").click(function(){
		window.location=$(this).find("a").attr("href");return false; // href attribute value
	});
	$(".team-list, .portfolio").addClass('selected'); // Add a class on the li
	$(".team-list, .portfolio ").hover(function(){
		$(this).addClass('team-hover'); // Place a extra class when hover
	},function(){
	$(this).removeClass('team-hover'); // Remove a class on mouseout
	});

	$(".portfolio").hover(function(){
		$(this).addClass('folio-hover'); // Place a extra class when hover
	},function(){
		$(this).removeClass('folio-hover'); // Remove a class on mouseout
	});

	$(".client").hover(function(){
		$(this).addClass('client-hover'); // Place a extra class when hover
	},function(){
		$(this).removeClass('client-hover'); // Remove a class on mouseout
	});
	// Write print link when javascript is enabled
  	$('.page-options').prepend('<li class="print"><a href="#print">Print pagina</a></li>');
	$('.page-options li.print a').click(function() {
		window.print();
		return false;
	});

	$("#header ul li:last-child").addClass("last-item");

	// Highlight form
	$('.contactform input, .contactform textarea').focus(function(){
		$(this).parents('p.row').addClass("current-form");
	}).blur(function(){
		$(this).parents('p.row').removeClass("current-form");
	});


    // Show or hide case studies
    $('.delete').click(function(){
		if (this.checked)
			$('.no-case-studie').animate({ opacity: 'hide' }, 'slow');
		else
			$('.no-case-studie').animate({ opacity: 'show' }, 'slow');
	});

	if ($(document).prettyPhoto)
		$("a[rel^='prettyPhoto']").prettyPhoto();

	// Set the scroll to anchor
	anchor.init()

	$('#frm-contact #email').keyup(email_password = function(){
		t = document.getElementById('email');
		if(t && t.form.author_email){
			if (t.value.toLowerCase() == t.form.author_email.value.toLowerCase()){
				// show password field!
				el = document.getElementById('email_password_div');
				if (!el){
					el = document.createElement('p');
					el.style.display = 'none';
					el.id = 'email_password_div';

					label = document.createElement('label');
					//label = 'passwrd';
					label.innerHTML = 'Wachtwoord';
					el.appendChild(label);

					input = document.createElement('input');
					input.name = 'password';
					input.id = 'password';
					input.type = 'password';
					el.appendChild(input);

					em = document.createElement('em');
					em.innerHTML = 'Dit wachtwoord is vereist om met dit e-mailadres te kunnen reageren';
					el.appendChild(em);

					t.parentNode.parentNode.insertBefore(el, document.getElementById('url').parentNode);
				}

				$(el).animate({ opacity: 'show' }, "slow")

			}
			else{
				el = document.getElementById('email_password_div');
				if (el){
					$(el).animate({ opacity: 'hide' }, "slow")
				}
			}
		}
	});

	email_password();

});

anchor = {
	init : function()  {
		$("a.anchorLink").click(function () {
			elementClick = $(this).attr("href")
			destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100 );
		  	return false;
		})
	}
}

function showText(text){
	tmp = text.split(/\|\|\|/);
	$('#teaser cite')[0].innerHTML = tmp[0].replace(/\&apos\;/g, '\'');

	if (tmp[1]){
		// link naar case
		$('#contact-item').html('<dt><a href="' + tmp[1] + '">Bekijk dit project</a></dt><dd>Of ga naar <a href="javascript: document.getElementById(\'c7flow\').next();">het volgende project</a> (' + tmp[2] + ')</dd>');
	}
	else{
		// geen link naar case
		$('#contact-item').html('Of ga naar <a href="javascript: document.getElementById(\'c7flow\').next();">het volgende project</a> (' + tmp[2] + ')');
	}
}

function openURL(url){
	document.location.href=url;
}

function appendNewsletterMsg(clss, msg, msg2){

	$('#frm-newsletter label').attr('id', 'newsletter-' + clss);
	$('#frm-newsletter label').html(msg + '<br />' + msg2);

}



