var polderknowledge = {
	contact:function(){
		if(polderknowledge.contact_visible){
		}else{
		}
	},
	contactsend:function(){
	//-- send correct hide the form.
	

		
	},
	contact_visible:false
}
var afspraak ={
	versturen:function(){
		error=false;
		$('naam').className = $('email').className="contact_input";
		$('message').className="contact_message";
		$('afspraak_status').update('');
		if($('datum').value==""){
			$('afspraak_status').update($('afspraak_status').innerHTML + 'U heeft geen datum ingevuld<br />').className="error";
			$('datum').className='contact_message required_field';
			error = true;
		}
		if($('naam').value==""){
			$('afspraak_status').update($('afspraak_status').innerHTML + 'U heeft geen naam ingevuld<br />').className="error";
			$('naam').className='contact_message required_field';
			error = true;
		}
		if($('email').value==""){
			$('afspraak_status').update($('afspraak_status').innerHTML + 'U heeft geent E-mail adres ingevuld<br />').className="error";
			$('email').className='contact_input required_field';	
			error =true;
		}
  		if($('email').value !="" && !pup_stringvalidators.IsValidEmail($('email').value)){
 			$('afspraak_status').update($('afspraak_status').innerHTML + 'U heeft een onjuist E-mailadres ingevuld<br />').className="error";
 			$('email').className='contact_input required_field';
			error =true;
		}

		return !error;
	}

}
var imgPreloader;
var portfolio = {
	scroll:function(p_sId,p_bUp){
		if(!portfolio.scrolling&&!portfolio.sliding){
			if(Prototype.Browser.IE){
				var tmpindex = $('wrapper').style.zIndex;
				$('wrapper').style.zIndex=10000;
				$('wrapper').style.position="relative";
			}
			portfolio.scrolling =true;
			var step = 540;
			var top_wrapper =$('wrapper').offsetTop
			var height_wrapper =$('wrapper').clientHeight
			var top_list=$('portfolio-list-'+portfolio.current_list).offsetTop
			var height_list=$('portfolio-list-'+portfolio.current_list).clientHeight
			if((Math.abs((Math.floor(top_list/step)))>Math.abs((Math.floor(height_list/step)-1))&&p_bUp)){
				portfolio.scrolling=false;
				return false;
			}
			if((Math.abs(Math.floor(top_list/step))<1)&&p_bUp!=true ){
				portfolio.scrolling=false;
				return false;
			}
			if(height_wrapper<height_list){
				if(p_bUp){
					new Effect.Move($('portfolio-list-'+this.current_list), { offset:step ,x: 0, y: -step, mode: 'relative',afterFinish:function(){portfolio.scrolling=false;} });
				}else{
					new Effect.Move($('portfolio-list-'+this.current_list), { offset:step ,x: 0, y: step, mode: 'relative',afterFinish:function(){portfolio.scrolling=false;} });
				}
			}else{
				portfolio.scrolling=false;
				return false;
			}
		}
	},
	slide:function(p_sId,p_iTab){
		var menutabs  = $('portfoilio-menu').getElementsByTagName('a');
		for(i=0;i<menutabs.length;i++){
			if((i+1)==p_iTab){
				menutabs[i].className ="selected";
			}else{
				menutabs[i].className ="";
			}
		}
		$('wrapper').style.height ="540px";
		$('wrapper').style.width ="460px";
		$('wrapper').style.overflow="hidden";
		var post=0;
		if(Prototype.Browser.IE){
			var tmpindex = $('wrapper').style.zIndex;
			$('wrapper').style.zIndex=10000;
			$('wrapper').style.position="relative";
			post =Math.abs($('wrapper_content').offsetLeft)-(((p_iTab-1)*460));
		}else{
			post =$('wrapper').offsetLeft-((p_iTab-1)*460)-$('wrapper_content').offsetLeft;
		}
		portfolio.current_list=p_sId;
		if(!portfolio.scrolling&&!portfolio.sliding&&p_iTab!=portfolio.current_tab){
			portfolio.sliding=true;
			portfolio.current_tab=p_iTab;
			new Effect.Move($('wrapper_content'), { offset:0 ,x: post, y: 0, mode: 'relative',afterFinish:function(){portfolio.sliding=false;}});
		}
		if(Prototype.Browser.IE){
			 $('wrapper').style.zIndex =tmpindex;
		}
	},
	selectproject:function(object,p_sUrl){
		viewport.block.disable('right_column');
		//$$('[class="portfolio-entry"]').each(function(obj) {obj.style.background="url('/images/img_bg_projects.jpg')"});
		var projects = $('wrapper').getElementsByTagName('div');
		
		for(i=0;i<projects.length;i++){
			if(projects[i].className=='portfolio-entry selcted_project'){
				projects[i].className="portfolio-entry";
			}
		}
		object.className="portfolio-entry selcted_project";
		//object.style.background="url('/images/img_bg_projects_selected.jpg')";
		new Ajax.Updater("right_column", 'http://'+document.domain+p_sUrl , {method: "post",parameters:"ajax=true",onComplete:function(t){portfolio.init_gallery();viewport.block.enable_all();}});
	},
	imageselect:function(p_sId){
		if($('large_image').src !=this.src.replace("/thumbs/","/") &&portfolio.fading ==false){
			portfolio.fading=true;
			portfolio.selected_image = this.src.replace("/thumbs/","/");
			var gallery_images = $('thumb_strip').getElementsByTagName('img');
			if(gallery_images.length!=0){
				for(i=0;i<gallery_images.length;i++){
					gallery_images[i].className="";
					gallery_images[i].setStyle({opacity: 0.2});
				}
			}
			this.className="selected";
			this.setStyle({opacity: 1});
			imgPreloader = new Image();
			$('large_image').fade({ duration:0.5, from: 1, to:0.001,afterFinish: function(){$('large_image').src=portfolio.selected_image;imgPreloader.src=portfolio.selected_image;}});
			imgPreloader.onload=function(){
				$('large_image').fade({ duration:0.5, from: 0.001, to:0.99,afterFinish:function(){portfolio.fading=false;}});
			}
			
		}
	},
	thumbslide:function(event){
		
		$('thumb_strip').style.zIndex=10000;
		$('thumb_strip').style.position="relative";
		
		if(this.id=='thumb_scroll_right'){
			new Effect.Move($('thumb_strip_content'), { offset:0 ,x: -426, y: 0, mode: 'relative',afterFinish:function(){portfolio.sliding=false;}});
			portfolio.current_thumbs++;
		}else{
			new Effect.Move($('thumb_strip_content'), { offset:0 ,x: 426, y: 0, mode: 'relative',afterFinish:function(){portfolio.sliding=false;}});
			portfolio.current_thumbs--;
		}
		if((portfolio.current_thumbs+1) ==(Math.ceil($('thumb_strip_content').clientWidth/424))){
			$('thumb_scroll_right').src="/images/btn_arrow_gallery_right_non_active.jpg";
			$('thumb_scroll_right').style.cursor="default";
			Event.stopObserving($('thumb_scroll_right'),'click');
		}else{
				$('thumb_scroll_right').src="/images/btn_arrow_gallery_right.jpg";
				$('thumb_scroll_right').style.cursor="pointer";
				Event.observe($('thumb_scroll_right'),'click',portfolio.thumbslide);
		}
		if(portfolio.current_thumbs==0){
			$('thumb_scroll_left').src="/images/btn_arrow_gallery_left_non_active.jpg";	
			$('thumb_scroll_left').style.cursor="default";
			Event.stopObserving($('thumb_scroll_left'),'click');
		}else{
			$('thumb_scroll_left').src="/images/btn_arrow_gallery_left.jpg";	
			$('thumb_scroll_left').style.cursor="pointer";
			Event.observe($('thumb_scroll_left'),'click',portfolio.thumbslide);
		}
	},
	imagehover:function(event){
		
		var element = event.element();
		if(element.className!="selected"){
		element.fade({ duration:0.3, from: 0.2, to:0.99});
		}
		
	},
	imageblurr:function(event){
		var element = event.element();
		if(element.className!="selected"){
			element.fade({ duration: 0.3, from: 0.99, to: 0.2 });
		}

	
	},
	init_gallery:function(){
		var gallery_images =  $('thumb_strip_content').getElementsByTagName('img');
		if(gallery_images.length!=0){
			for(i=0;i<gallery_images.length;i++){
				Event.observe(gallery_images[i],'mouseover', portfolio.imagehover);
				Event.observe(gallery_images[i],'mouseout', portfolio.imageblurr);
				Event.observe(gallery_images[i],'click', portfolio.imageselect);
			}
			$('thumb_strip_content').style.width =(gallery_images.length * 142)+'px';
			if((gallery_images.length * 142)>426){
				Event.observe($('thumb_scroll_left'),'click',portfolio.thumbslide);
				Event.observe($('thumb_scroll_right'),'click',portfolio.thumbslide);
			}else{
				$('thumb_scroll_right').src="/images/btn_arrow_gallery_right_non_active.jpg";
				$('thumb_scroll_left').style.cursor=$('thumb_scroll_right').style.cursor="default";
			}
		}
		
	},
	scrolling:false,
	sliding:false,
	fading:false,
	current_thumbs:0,
	current_tab:1,
	current_list:"web",
	selected_image:""
}

window.onload =function(){
		var url = window.document.location;
		url =url +" ";
		//alert(url.replace("http://"+document.domain,"").split('/'))
		var splits =url.replace("http://"+document.domain,"").split('/');
		var segment = splits[2]+"";
		segment.replace(/^\s+/,'').replace(/\s+$/,'');
		if(segment=="huisstijl-drukwerk"){
			portfolio.slide('identity',2);
		}else if(segment =="overige"){

			portfolio.slide('other',3);
		}else if(segment =="technische-realisatie"){
			portfolio.slide('technical',4);
		}
		if($('thumb_strip')){
			portfolio.init_gallery();
		}
	}

var contactform = {
	contactgroei:function(){
		if(!this.open && !this.resizing){
			this.resizing =true;
			this.open = true;
			$('contactform_content').update($('contact_form_form').innerHTML)
			$('contact_img').src ='/images/img_icon_contactform_open.jpg';
			new Effect.Morph("contactform", {style:'width:400px;',queue: 'front'});
			new Effect.Morph("contactform", {style:'height:500px;',queue: 'end',afterFinish:function(){contactform.resizing=false}});
			return false;
		}else if(!this.resizing){
			this.open = false;
			this.resizing=true;
			$('contact_img').src ='/images/img_icon_contactform_closed.jpg';
			new Effect.Morph("contactform", {style:'height:24px;',queue: 'front'});
			new Effect.Morph("contactform", {style:'width:120px;',queue: 'end',afterFinish:function(){contactform.resizing=false}});
		}
	},
	send:function(){
		var error=false;
		$('contact_person').className = $('email_adress').className=$('phone_number').className="contact_input";
		$('message').className="contact_message";
		$('status').update('');
 		if($('contact_person').value==""){
			$('status').update($('status').innerHTML + 'U bent vergeten uw naam in te vullen<br />').className="error";
			$('contact_person').className='contact_input required_field';	
			error =true;
		}
 		if($('email_adress').value==""){
			$('status').update($('status').innerHTML + 'U bent vergeten het E-mailadres adres in te vullen<br />').className="error";
			$('email_adress').className='contact_input required_field';	
			error =true;
		}
  		if($('email_adress').value !="" && !pup_stringvalidators.IsValidEmail($('email_adress').value)){
 			$('status').update($('status').innerHTML + 'U heeft een onjuist E-mailadres ingevuld<br />').className="error";
 			$('email_adress').className='contact_input required_field';
			error =true;
		}
 		
 		if($('phone_number').value==""){
			$('status').update($('status').innerHTML + 'U bent vergeten het telefoonnummer in te vullen<br />').className="error";
			$('phone_number').className='contact_input required_field';	
			error =true;
		}
		if($('message').value==""){
			$('status').update($('status').innerHTML + 'U bent het bericht vergeten in te vullen<br />').className="error";
			$('message').className='contact_message required_field';
			error =true;
		}
		if(error){
			$('status').update("<b>Er is een fout opgetreden :</b><br/>" +$('status').innerHTML);
			return false;
		}
		//-- if no error's then send the form and shrink
		var params = $('contact_form').serialize();
		new Ajax.Request('http://www.polderknowledge.nl/contactformulier', {
			method: 'post',
			parameters:params+"&ajax=true",
			onCreate:function(){$('status').update('<img src="/images/loader_small.gif" alt=""/> Bezig met het versturen van uw bericht.').className='processing';},
			onComplete:function(r) {
				$('status').update('Uw bericht is verzonden.').className='success';
				setTimeout('contactform.contactgroei();',1000);
			}
		});
	},
	resizing:false
}
