$(document).ready(function(){

	// vars
	var screenwidth 		= 	$(window).width();
	var screenheight 		= 	$(window).height();
	var texta 				= 	'Type hier wat STATE OF_ voor je kan betekenen. ';
	var textb 				= 	'Type hier je e-mailadres. ';
	var textc 				= 	'Wat zoek je?';
	var textd 				= 	'Geef een reactie op dit bericht.';
	var texte 				= 	'Wat is je naam?';
	var textf 				= 	'Wat is je e-mailadres? (wordt niet getoond op de site)';
	
	// projectscroll
	
	// setIntro();
	$(window).resize(function() {
		setIntro();
		if($.browser.msie == true && $.browser.version < 8){
			setPos();
		}
	});
	
	if($.browser.msie == true && $.browser.version < 8){
		setPos();
	}
	
	setInterval('toonNieuw()', 3000 );
	
	// setup
	setContainer();
	
	$(".bloglijst.inklap h1").click(function(){
		if($(this).parent().hasClass("uitgeklapt")){
			$(this).parent().find('li').hide();
			$(this).parent().find('img.bloguitklappijl').show();
			$(this).parent().find('img.bloginklappijl').hide();
			$(this).parent().removeClass("uitgeklapt");
		} else {
			$(this).parent().find('li').show();
			$(this).parent().find('img.bloguitklappijl').hide();
			$(this).parent().find('img.bloginklappijl').show();
			$(this).parent().addClass("uitgeklapt");
		}
		setContainer();
	});
	
	var checkprev = $("#blogcontrol #blogcontrolleft a").length;
	if(checkprev == 0){
		$("#blogcontrolleft").hide();
	}
	
	var checknext = $("#blogcontrol #blogcontrolright a").length;
	if(checknext == 0){
		$("#blogcontrolright").hide();
	}

	$("#twittertweet .blok_c").tweet({
		username: "stateof_",
		join_text: "auto",
		avatar_size: 0,
		count: 1,
		loading_text: ".."
	});
	
	// intro
	/*
	window.setTimeout(function() {
		$("#introtagline").fadeOut(1000, function(){
			var blokeq = 0;
			toonBlok(blokeq);
		});
	}, 2000);
	*/
	
	// scroll
	
	if($.browser.msie == true && $.browser.version < 9){
	
	} else {
		jQuery(window).bind('scrollstop', function(e){
			var offset = $(document).scrollTop();
			if(offset > 300){ offset = 300 };
			$('body').stop().animate({backgroundPosition: "0px -"+(offset/4)+"px"}, 1500);
		});
	};
	
	// hover
	
	$('.socialicon, .blok.projectomsch, #blok_mail, #contactverzenden, #pijlterug, .portnav, .bloglijst li, .categorie, .blok.wit.link, .blok #zoek, #blogcontrolright, #blogcontrolleft, #reactieform input#blogreactopslaan').hover(function(){
		$(this).addClass("mo");
	}, function(){
		$(this).removeClass("mo");
	});
	
	$('.blogbericht.klik').hover(function(){
		$(this).addClass("mo");
		$(this).find('.reacticon').addClass("mo");
	}, function(){
		$(this).removeClass("mo");
		$(this).find('.reacticon').removeClass("mo");
	});
	
	// blokken

	$(".blok.link, .bloglijst li, .categorie, .reacticon, .blogbericht.klik").click(function(){
		var loc = $(this).find("a").attr("href");
		document.location = loc;
	});

	$(".blok.project").hover(function(){
		var eqt		=	$('.blok.project').index(this);
		$(".blok.projectomsch").eq(eqt).addClass("mo");
	}, function(){
		var eqt		=	$('.blok.project').index(this);
		$(".blok.projectomsch").eq(eqt).removeClass("mo");
	});
	
	// forms
	
	$("form#form_reageer").bind("keypress", function(e) {
		if (e.keyCode == 13) {
			 return false;
		}
	});
	$("form#form_reageer").submit(function() {
		var formfout = 0;
		if ($("textarea#blogreactbericht").val() == textd){
			formfout = 1;
			$("textarea#blogreactbericht").addClass("formerror").fadeTo("slow", 0.80);
		}
		if ($("input#blogreactnaam").val() == texte){
			formfout = 1;
			$("input#blogreactnaam").addClass("formerror").fadeTo("slow", 0.80);
		}
		if($("input#blogreactemail").val() == textf) {
			formfout = 1;
			$("input#blogreactemail").addClass("formerror").fadeTo("slow", 0.80);
		} 
		if(formfout == 0){
			return true;
		} else {
			return false;
		};
    });
	
	$("form#form_reageer input, form#form_reageer textarea").focus(function() {
		$(this).removeClass("formerror").fadeTo("fast", 1).fadeTo("fast", 1);
	});
	
	var part	=	0;
	
	$("input#hidetxt").val(texta);
	$("input#contactinput").val(textb);
	$("textarea#blogreactbericht").val(textd);
	$("input#blogreactnaam").val(texte);
	$("input#blogreactemail").val(textf);
	
	t = setInterval(function(){
		if(part < texta.length){
			part++;
			$('textarea#contacttextarea').val(texta.substr(0,part));
		} else {
			$('textarea#contacttextarea').css("color","#adadad");
			clearInterval(t);
		}
	}, 15 );
	
	$("#contactformemail").click(function(){
		$(this).find('input').focus();
	});
	
	$("#contactformemail input").keyup(function(){
		var inpval = $(this).val().length;
		if(inpval < 16){ $(this).css("font-size","16px"); }
		else if(inpval > 15 && inpval < 26){ $(this).css("font-size","14px"); }
		else if(inpval > 25 && inpval < 36){ $(this).css("font-size","12px"); }
		else if(inpval > 35){ $(this).css("font-size","10px"); }
	});
	
	$("input, textarea").bind('click focus', function() {
		if($(this).attr("id") == "contacttextarea"){
			if($(this).val() == texta){
				$(this).val("");
				$('textarea#contacttextarea').css("color","#222222");
			}
		}
		if($(this).attr("id") == "contactinput"){
			if($(this).val() == textb){
				$(this).val("");
			}
		}
		if($(this).attr("id") == "zoekblog"){
			if($(this).val() == textc){
				$(this).val("");
			}
		}
		if($(this).attr("id") == "blogreactbericht"){
			if($(this).val() == textd){
				$(this).val("");
			}
		}
		if($(this).attr("id") == "blogreactnaam"){
			if($(this).val() == texte){
				$(this).val("");
			}
		}
		if($(this).attr("id") == "blogreactemail"){
			if($(this).val() == textf){
				$(this).val("");
			}
		}
	});
	
	$("input, textarea").blur(function(){
		if($(this).attr("id") == "contacttextarea"){
			if($(this).val() == ""){
				$(this).val(texta);
				$('textarea#contacttextarea').css("color","#adadad");
			}
		}
		if($(this).attr("id") == "contactinput"){
			if($(this).val() == ""){
				$(this).val(textb);
			}
		}
		if($(this).attr("id") == "zoekblog"){
			if($(this).val() == ""){
				$(this).val(textc);
			} else if($(this).val() == textc){
				
			} else {
				$(this).parent().submit();
			}
		}
		if($(this).attr("id") == "blogreactbericht"){
			if($(this).val() == ""){
				$(this).val(textd);
			}
		}
		if($(this).attr("id") == "blogreactnaam"){
			if($(this).val() == ""){
				$(this).val(texte);
			}
		}
		if($(this).attr("id") == "blogreactemail"){
			if($(this).val() == ""){
				$(this).val(textf);
			}
		}
	});
	
	$('#contactverzenden').click(function(){
		$(this).addClass("act");
	});
	
	$("#zoek").click(function(){
		$(this).hide();
		$("#zoekactie").fadeIn(1000).find('input').select();
	});
	
	// portfolio
	$('.portscreen').cycle({ 
		fx:     'fade', 
		easing: 'easeOutCirc', 
		speed:    2000, 
		timeout:  5000,
		pause:   1,
		next:   '.portscreen',
		pager:  '#portscreennav_c',
		pagerAnchorBuilder: function(idx, slide) {
            return '#portscreennav_c div:eq(' + (idx) + ')';
        }
		//after:   onAfter 
	});
	
	// blog
	
	window.setTimeout(function() {
		$(".blok#shownieuws div").fadeIn(2000);
	}, 4000);

	
});

// functions

function onAfter() {
	$('#portscreennav_c .portnav').removeClass("activeSlide");
    $('#portscreennav_c .portnav').eq(this.name).addClass("activeSlide");
}

function setPos(){
	var offl = $("#WRAPPER_CONTENT").offset().left;
	$(".blokwrap.pos").css("left",offl+"px");
}

function setIntro(){
	var cnt = $("#WRAPPER").offset().left+280;
	$("#intro").css("left",cnt+"px");
}
/*
function toonBlok(blokeq){
	window.setTimeout(function() {
		$('#intro .blok').eq(blokeq).animate({
			opacity: 0,
			left: '-=540',
		}, {queue: false, duration: 4000, easing: 'easeOutQuad', complete: function() {
			$(this).hide();
			
		}});
		if(blokeq == 65){
			$('#intro').hide();
		} else {
			blokeq++;
			toonBlok(blokeq);
		}
	}, 50);
}
*/
var nr = 1;
function toonNieuw(){
	$("#nuweblog").find('h1').hide().eq(nr).fadeIn(500);
	if(nr == 2){
		nr = 0;
	} else { nr++; };
}

function setContainer(){
	var zbh = $("body.bodyblog #zijbalk").height();
	var wrh = $("body.bodyblog #WRAPPER_CONTENT").height();

	if(zbh < wrh){
		var toth = wrh;
		$("body.bodyblog #zijbalk").height(toth);
	} else {
		$("body.bodyblog #WRAPPER_CONTENT").height(zbh);
	}
}
