try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

window.addEvent('domready', function() {

	function sifr_init () {
	if(typeof sIFR == "function"){
	
	// This is the preferred "named argument" syntax
		//sIFR.replaceElement(named({sSelector:"body h1", sFlashSrc:"vandenkeere.swf", sColor:"#000000", sLinkColor:"#000000", sBgColor:"#FFFFFF", sHoverColor:"#CCCCCC", nPaddingTop:20, nPaddingBottom:20, sFlashVars:"textalign=center&offsetTop=6"}));
	
	// This is the older, ordered syntax
		//sIFR.replaceElement("h5#pullquote", "vandenkeere.swf", "#000000", "#000000", "#FFFFFF", "#FFFFFF", 0, 0, 0, 0);
		//sIFR.replaceElement("h2", "tradegothic.swf", "#000000", null, null, null, 0, 0, 0, 0);
		//sIFR.replaceElement("h4.subhead", "tradegothic.swf", "#660000", null, null, null, 0, 0, 0, 0);
		//sIFR.replaceElement("h3.sidebox","tradegothic.swf","#000000", "#000000", "#DCDCDC", "#DCDCDC", 0, 0, 0, 0, null);
			if(typeof skin == 'undefined') {return false}
			var color1, color2, color3;
		
			
		
			if(skin=='white-theme') {
				color1 = '#ffffff';
				color2 = '#363636';
				color3 = '#636363';
			}
			
			if(skin=='black-theme') {
				color1 = '#959595';
				color2 = '#bbbbbb';
				color3 = '#717b8b'
			}
		
			sIFR.replaceElement(named({sSelector:".thumb_txt", sFlashSrc:"flash/francophil_sans_bold.swf", sColor:color1,  sWmode:"transparent"}));
			sIFR.replaceElement(named({sSelector:".h2_txt", sFlashSrc:"flash/francophil_sans_bold.swf", sColor:color1,  sWmode:"transparent"}));
			sIFR.replaceElement(named({sSelector:"h3", sFlashSrc:"flash/francophil_sans.swf", sColor:color2, nPaddingBottom:4,  sWmode:"transparent"}));
			sIFR.replaceElement(named({sSelector:"h4", sFlashSrc:"flash/francophil_sans.swf", sColor:color3, nPaddingBottom:5,   sWmode:"transparent"}));
		
		
		}
	
	}


	 Fx.Scroll2 = new Class({
	  
		 'Extends': Fx.Scroll,
	  
		 'styleString': Element.getComputedStyle,
		 'styleNumber': function(element, style) {
			 return this.styleString(element, style).toInt() || 0;
		 },
		 'borderBox': function(element) {
			 return this.styleString(element, '-moz-box-sizing') == 'border-box';
		 },
		 'topBorder': function(element) {
			 return this.styleNumber(element, 'border-top-width');
		 },
		'leftBorder': function(element) {
			 return this.styleNumber(element, 'border-left-width');
		 },
		 'isBody': function(element) {
			 return (/^(?:body|html)$/i).test(element.tagName);
		 }, 
		 'toElement': function(el) {
			 var offset   = {x: 0, y: 0};
			 var element  = $(el);
			
			 if (this.isBody(element)) {
				 return offset;
			 }
			 var scroll = element.getScrolls();
				   
			 while (element && !this.isBody(element)){
				 offset.x += element.offsetLeft;
				 offset.y += element.offsetTop;
				
				 if (Browser.Engine.gecko){
					 if (!this.borderBox(element)){
						 offset.x += this.leftBorder(element);
						 offset.y += this.topBorder(element);
					 }
					 var parent = element.parentNode;
					 if (parent && this.styleString(parent, 'overflow') != 'visible'){
						 offset.x += this.leftBorder(parent);
						 offset.y += this.topBorder(parent);
					 }
				 } else if (Browser.Engine.trident || Browser.Engine.webkit){
					 offset.x += this.leftBorder(element);
					 offset.y += this.topBorder(element);
				 }
	  
				 element = element.offsetParent;
				 if (Browser.Engine.trident) {
					 while (element && !element.currentStyle.hasLayout) {
						 element = element.offsetParent;
					 }
				 }
			 }
			 if (Browser.Engine.gecko && !this.borderBox(element)){
				 offset.x -= this.leftBorder(element);
				 offset.y -= this.topBorder(element);
			 }
			
			 var relative = this.element;
			 var relativePosition = (relative && (relative = $(relative))) ? relative.getPosition() : {x: 0, y: 0};
			 var position = {x: offset.x - scroll.x, y: offset.y - scroll.y};
			
			 return this.start(position.x - relativePosition.x, position.y - relativePosition.y);
		 }
	 });
	 
	 
	 
 
    
	 function navigation () {
		
		function next_nav () {
			var next_nav = document.createElement('a');
			next_nav.setAttribute('href','#');
			next_nav.className = 'next_nav';
			var span = document.createElement('span');
			//span.set('opacity',0);
			next_nav.appendChild(span);
			return next_nav;
		}
		
		function prev_nav () {
			var prev_nav = document.createElement('a');
			prev_nav.setAttribute('href','#');
			prev_nav.className = 'prev_nav';
			var span = document.createElement('span');
			//span.set('opacity',0);
			prev_nav.appendChild(span);
			return prev_nav;
		}
		
		
		
		var wrapper_inner = $('wrapper_inner');
		
		
		function glow (state1,state2) {
			if(typeof skin == 'undefined') {return false}
			if(skin=='black-theme') {
				var glow_span = $('glow');
				if(!glow_span) {
					glow_span = document.createElement('span');
					glow_span.setAttribute('id','glow');
					var active = document.createElement('strong');
					var hover = document.createElement('span');
					glow_span.appendChild(active);
					glow_span.appendChild(hover);
					wrapper_inner.appendChild(glow_span);
					
				}
				
				var active = glow_span.getElementsByTagName('strong')[0];
				var hover = glow_span.getElementsByTagName('span')[0];
				
				
				
				
				if(state1) {
					active.className = state1+'_glow';
					
				} 
				if(state2) {
					hover.className = state2+'_glow';
					
				} 
			}
			
		}
		
		
		
		
		glow('portfolio_lk',null);
		
		
		
		list_next = next_nav();
		list_next.setAttribute('id','list_next');
		items_next = next_nav();
		items_next.setAttribute('id','items_next');
		
		list_prev = prev_nav();
		list_prev.setAttribute('id','list_prev');
		items_prev = prev_nav();
		items_prev.setAttribute('id','items_prev');
		
		var goTop = document.createElement('a');
		goTop.setAttribute('href','#portfolio_list');
		$('top_off').appendChild(goTop);
		
		
		wrapper_inner.appendChild(list_next);
		wrapper_inner.appendChild(list_prev);
		wrapper_inner.appendChild(items_next);
		wrapper_inner.appendChild(items_prev);
		
		
		var allow_scroll = true;
		var main_lks = $$('#main_menu a');
		var logo = $$('#logo a')[0];
		
		var navFx = new Fx.Scroll2($('content'), 
			{
				wait: true, 
				wheelStops: false,
				duration: 750,
				transition: Fx.Transitions.Quad.easeInOut,
				onStart: function () {
					allow_scroll = false;
				},
				onComplete: function () {
					allow_scroll = true;
					
				}
			}
		)
		navFx.set(0,0);
		for(i=0; i<main_lks.length; i++) {
			main_lks[i].onclick = function () {
				if(allow_scroll) {
					var target = this.href.substr(this.href.indexOf('#')+1);
					if(target=='portfolio') {
						toggleListNav (true);
						toggleItemsNav(false);
						if(this.getAttribute('id')=='selected') {
							portfolioFx.toTop();	
						} else {
							var selected = $('selected');
							if(selected) {selected.removeAttribute('id');}
							this.setAttribute('id','selected');
							portfolioFx.set(0,0);
						}
					} else {
						toggleListNav (false);
						toggleItemsNav(false);
					}
					var selected = $('selected');
					if(selected) {selected.removeAttribute('id');}
					this.setAttribute('id','selected');
					navFx.toElement(target);
					glow(this.className,null);
					
				}
				return false;
			}
			main_lks[i].onmouseover = function () {
				if(this.getAttribute('id')!='selected') {
					glow(null,this.className);
				}
			}
			main_lks[i].onmouseout = function () {
					glow(null,' ');
			}
		}
		
		logo.onclick = function () {
			if(allow_scroll) {
				var target = this.href.substr(this.href.indexOf('#')+1);
				toggleListNav (true);
				toggleItemsNav(false);
				
				if($$('.portfolio_lk')[0].getAttribute('id')=='selected') {
					portfolioFx.toTop();	
				} else {
					var selected = $('selected');
					if(selected) {selected.removeAttribute('id')}
					$$('.portfolio_lk')[0].setAttribute('id','selected');
					portfolioFx.set(0,0);
				}
				navFx.toElement(target);
				glow('portfolio_lk',null);
			}
			return false;
		}
		
		var request_quote = $('request_quote');
		if(request_quote) {
			request_quote.onclick = function () {
				if(allow_scroll) {
					var selected = $('selected');
					if(selected) {selected.removeAttribute('id');}
					var contact_lk = $$('.contact_lk');
					if(contact_lk.length) {
						$$('.contact_lk')[0].setAttribute('id','selected');
						var target = this.href.substr(this.href.indexOf('#')+1);
						navFx.toElement(target);
					}
					glow('contact_lk',null);
				}
				return false;
			}
		}
		
		
		var your_project = $('your_project');
		if(your_project) {
			your_project.onclick = function () {
				if(allow_scroll) {
					var selected = $('selected');
					if(selected) {selected.removeAttribute('id');}
					var price_list_lk = $$('.price_list_lk');
					if(price_list_lk.length) {
						$$('.price_list_lk')[0].setAttribute('id','selected');
						var target = this.href.substr(this.href.indexOf('#')+1);
						navFx.toElement(target);
					}
					glow('price_list_lk',null);
				}
				return false;
			}
		}
		
		
		function initGoTop () {
			goTop.set('opacity',0);
			goTop.addEvent('mouseover',function (event) {
				event.stop();
				goTop.set('tween',{duration: 500});
				this.tween('opacity',0,1);
				
			});
			
			goTop.addEvent('mouseout',function (event) {
				event.stop();
				this.tween('opacity',1,0);
				
			});
			
			
			goTop.addEvent('click',function (event) {
				event.stop();
				if(allow_scroll) {
					toggleListNav (true);
					toggleItemsNav(false);
					portfolioFx.toTop();
				}
				
			});
		}
		
		
		
		function initListNav () { 
			list_next.getElement('span').set('opacity',0);
			list_prev.getElement('span').set('opacity',0);
			list_next.addEvent('mouseover',function (event) {
				event.stop();
				this.getElement('span').set('tween',{duration: 500});
				this.getElement('span').tween('opacity',0,1);
				
			});
			
			list_next.addEvent('mouseout',function (event) {
				event.stop();
				this.getElement('span').tween('opacity',1,0);
				
			});
			
			list_prev.addEvent('mouseover',function (event) {
				event.stop();
				this.getElement('span').set('tween',{duration: 500});
				this.getElement('span').tween('opacity',0,1);
				
			});
			
			list_prev.addEvent('mouseout',function (event) {
				event.stop();
				this.getElement('span').tween('opacity',1,0);
				
			});
		}
		
		
		
		function initItemsNav () {
			items_next.getElement('span').set('opacity',0);
			items_prev.getElement('span').set('opacity',0);
			items_next.addEvent('mouseover',function (event) {
				event.stop();
				this.getElement('span').set('tween',{duration: 500});
				this.getElement('span').tween('opacity',0,1);
				
			});
			
			items_next.addEvent('mouseout',function (event) {
				event.stop();
				this.getElement('span').tween('opacity',1,0);
				
			});
			
			items_prev.addEvent('mouseover',function (event) {
				event.stop();
				this.getElement('span').set('tween',{duration: 500});
				this.getElement('span').tween('opacity',0,1);
				
			});
			
			items_prev.addEvent('mouseout',function (event) {
				event.stop();
				this.getElement('span').tween('opacity',1,0);
				
			});
		
		}
		
		
		
		
		
		
		var portfolio_items_inner = $('portfolio_items_inner');
		var portfolio_item = $$('.portfolio_item');
		function toggleItemsNav (mode) {
			if(mode==true) {
				if(portfolio_item.length>1) {
					wrapper_inner.addClass('portfolioItems');
					initGoTop();
					initItemsNav.delay(10);
					glow()
				}
			} else {
					wrapper_inner.removeClass('portfolioItems');
			}
		}
		
		portfolio_items_inner.style.width = portfolio_item.length * 850 + 'px';

		
		var portfolioFx = new Fx.Scroll2($('portfolio'), 
			{
				wait: true,
				wheelStops: false,
				duration: 750,
				transition: Fx.Transitions.Quad.easeInOut,
				onStart: function () {
					allow_scroll = false;
					
					
				},
				onComplete: function () {
					allow_scroll = true;
					
					
				}
			}
		)
		
		portfolioFx.set(0,0);
		
		var portfolioItemsFx = new Fx.Scroll2($('portfolioItems'), 
			{
				wait: true, 
				wheelStops: false,
				duration: 750,
				transition: Fx.Transitions.Quad.easeInOut,
				onStart: function () {
					allow_scroll = false;
					
					
				},
				onComplete: function () {
					allow_scroll = true;
					
				}
			}
		)
		
		portfolioItemsFx.set(0,0);
		
		
		
		
		
		var current_item = 0;
		if(portfolio_item.length>1) {
			items_prev.onclick = function () {
				if(allow_scroll&&current_item>0) {
					current_item--;
					portfolioItemsFx.toElement(portfolio_item[current_item]);
				}
				return false;
			}
			
			items_next.onclick = function () {
				if(allow_scroll&&current_item<portfolio_item.length-1) {
					current_item++;
					portfolioItemsFx.toElement(portfolio_item[current_item]);
				}
				return false;
			}
		}
		
		
		
		
		
		var portfolio_li = $$('#portfolio_list li');
		
		function toggleListNav (mode) {
			if(mode==true) {
				if(portfolio_li.length>6) {
					wrapper_inner.addClass('portfolio_list');
					initListNav.delay(10);
					
				}
			} else {
					wrapper_inner.removeClass('portfolio_list');
			}
		}
		toggleListNav (true);
		
		var portfolioListFx = new Fx.Scroll2($('portfolio_list'), 
			{
				wait: true, 
				wheelStops: false,
				duration: 750,
				transition: Fx.Transitions.Quad.easeInOut,
				onStart: function () {
					allow_scroll = false;
					
				},
				onComplete: function () {
					allow_scroll = true;
					
				}
			}
		)
		
		
		
		var current_list = 0;
		if(portfolio_li.length>6) {
			list_prev.onclick = function () {
				if(allow_scroll&&current_list>0) {
					current_list-=6;
					portfolioListFx.toElement(portfolio_li[current_list]);
				}
				return false;
			}
			list_next.onclick = function () {
				if(allow_scroll&&current_list<portfolio_li.length-6) {
					current_list+=6;
					portfolioListFx.toElement(portfolio_li[current_list]);
				}
				return false;
			}
		}
		
		
		
		
		portfolio_li_left = 276;
		portfolio_li_top = 247;
		var group = 6;
		var row = 0;
	    var col2 = 0;
		var col = col2 * group/2 - 1;
		var portolio_ul = $$('#portfolio_list ul')[0];
		portolio_ul.style.width = Math.ceil(portfolio_li.length/6) * 3 * portfolio_li_left + 'px'; 
		for(i=0; i<portfolio_li.length; i++) {
				col++;
				if(i%3==0&&i>=3) {row++;  col = col2*3;}
				if(i%6==0&&i>=6) { col2++; col = col2 * 3;}
				if(i%6==0&&i>=6) {row=0; }
				portfolio_li[i].style.left = col * portfolio_li_left + 'px';
			    portfolio_li[i].style.top = row* portfolio_li_top + 'px';
				portfolio_li[i].style.visibility = 'visible';
				
				if(portfolio_li[i].getElementsByTagName('a')[0].getAttribute('id')!='your_project') {
					var target_img = portfolio_li[i].getElement('img');
					target_img.parentNode.style.backgroundImage = 'url('+target_img.getAttribute('src')+')';
					target_img.set('opacity',0);
					

					
					portfolio_li[i].getElement('a').onclick = function () {
						
						
						if(allow_scroll&&this.id!='your_project') {
							toggleListNav(false);
							toggleItemsNav(true);
							var target = this.href.substr(this.href.indexOf('#')+1);
							
							
							
							
							
							
							for(x=0; x<portfolio_item.length; x++) {
								if(portfolio_item[x].getAttribute('id')==target) {
									target = 826*x;
									current_item = x;
								}
							}
							
							
							
							
							
							portfolioItemsFx.set(target,0);
							portfolioFx.start(0,498);
							
							
							
							
							
						}
						
						return false;
						
				 }
				 
				 
				 portfolio_li[i].getElementsByTagName('a')[0].addEvent('mouseover',function (event) {
					event.stop();
					this.getElement('img').set('tween',{duration: 500});
					this.getElement('img').tween('opacity',1);
					
				});
				 
				 
				  portfolio_li[i].getElementsByTagName('a')[0].addEvent('mouseout',function (event) {
					 event.stop();																		 
					 this.getElement('img').tween('opacity',0);
				 });
				  
					
					
					
			}
		}
		
		portfolioListFx.set(0,0);
		
		
		function projectGallery (project) {
			var medium_gallery = project.getElement('a[class=medium_gallery]');
			
			medium_gallery.rel = 'milkbox['+ project.getAttribute('id') + ']';
			var portfolio_gallery_thumbs = project.getElement('.portfolio_gallery_thumbs');
			portfolio_gallery_thumbs  = portfolio_gallery_thumbs.getElements('a'); 
			for(y=0; y<portfolio_gallery_thumbs.length; y++) {
				portfolio_gallery_thumbs[y].onclick = function () {return false}
				if(y>0) {
					var clone = medium_gallery.clone();
					clone.style.display = 'none';
					clone.href = portfolio_gallery_thumbs[y].rel;
					clone.getElement('img').src = portfolio_gallery_thumbs[y].href; 
					medium_gallery.parentNode.appendChild(clone);
					
				}
				
				
				portfolio_gallery_thumbs[y].onmouseover = (function (yy) {
					return function () {
						var fotos = project.getElements('.medium_gallery');
						for(i=0; i<fotos.length; i++) {
							fotos[i].style.display = 'none';
						}
						fotos[yy].style.display = 'block';	
						
					}
				})(y);
				
				
			}
			
		}
		
		
		for(i=0; i<portfolio_item.length; i++) {
			projectGallery(portfolio_item[i]);
		}
		
		
		
	}
	
	
	function replaceSelects () {
		var select_input = $$('.select_input');
		if(!select_input.length) {return false}
		
		function replaceSelect (target) {
			var old_select = target.getElement('select');
			var old_select_options = old_select.getElementsByTagName('option');
			old_select.value = old_select_options[0].value;  
			var ul = document.createElement('ul');
			ul.className = 'select';
			var first_li = document.createElement('li');
			first_li.className = 'first';
			var first_lk = document.createElement('a');
			first_lk.setAttribute('href','#');
			first_lk.innerHTML = old_select_options[0].innerHTML;
			
			first_li.appendChild(first_lk);
			ul.appendChild(first_li);
			
			for(x=0; x<old_select_options.length; x++) {
				var li = document.createElement('li');
				var lk = document.createElement('a');
				lk.setAttribute('href','#');
				lk.innerHTML = old_select_options[x].innerHTML;
				if(x==0) {lk.className='active_option'}
				li.appendChild(lk);
				ul.appendChild(li);
			}
			
			target.appendChild(ul);
			
			function toggle_select (mode) {
				if(mode==true) {
					ul.className = 'select select_open';
				} else {
					ul.className = 'select';
					
				}
			}
			
			first_lk = target.getElement('a');
			first_lk.addEvent('click',
				function(event){
					event.stop();
					toggle_select(true);
					document.addEvent('click',
						function (event) {
							event.stopPropagation();
							toggle_select (false);
						}
					);
				}
			 )
			
			var lks = target.getElements('a');
			for(i=1; i<lks.length; i++) {
				lks[i].onclick = (function (ii) {
						return function () {
							active_option = target.getElement('a[class=active_option]');
							active_option.className = '';
							lks[ii].className = 'active_option';
							first_lk.set('text', lks[ii].innerHTML);
							old_select.value = old_select_options[ii-1].value;
							return false;
							
						}
					})(i);
			}
			
		}
		
		for(i=0; i<select_input.length; i++) {
			replaceSelect(select_input[i]);
		}
	}
	
	
	if($('contactForm')) {
		
		var form = $('contactForm');
		
		
		form.set('send', {
			method: "post",
			onSuccess: function(response) {
				switch (response){
					case "email":
						$('response').innerHTML = "<span class='negative'>Invalid mail</span>";
						$('email').focus();
					break;
			
					case "subject":
						$('response').innerHTML = "<span class='negative'>Invalid subject</span>";
						$('subject').focus();
					break;
			
					case "name":
						$('response').innerHTML = "<span class='negative'>Invalid name</span>";
						$('name').focus();
					break;
			
					case "message":
						$('response').innerHTML = "<span class='negative'>Invalid message</span>";
						$('message').focus();
					break;
			
					case "success":
						$('response').innerHTML = "<span class='positive'>Mail sent</span>";
						$('email').value = '';
						$('subject').value = '';
						$('name').value = '';
						$('message').value = '';
					break;
			
					default:
						$('response').innerHTML = "<span class='negative'>Unknown error</span>";
					break;
				}
			},
			onFailure: function () {
				$('response').innerHTML = "<span class='negative'>Unknown error</span>";
			}
		});
		
		form.addEvent('submit', function(e) {
			new Event(e).stop();
			form.send();
		});
		
	}
	
	
     
	
	navigation();
	
	sifr_init();
	replaceSelects ();
	milkbox = new Milkbox();

});


