// JavaScript Document

//this enable the drag and drop on stuff
window.addEvent('domready', function(){
var target = $('target');
var fx = new Fx.Styles(target, {duration: 1000, wait: false});
var box = $('box');

target.setStyles({
	'top': '89px',
	'left': '639px'
});


var result = $('result');

var transition = ("Back");

var ease = ("easeIn");
fx.options.transition = Fx.Transitions[transition][ease];

fx.options.duration = 750;	


new Drag.Base(target, {
	
	onComplete: function(){
		fx.start(this.s);
	},
	
	onStart: function(){
		this.s = {
			'left': '639px',
			'top': '89px'
		};
	}
	
});		});


//this create the scroll for anchor links
		window.addEvent("domready", function() {
     new SmoothScroll({duration: 1500, fps:60, transition: Fx.Transitions.backOut}); 
    });

//this hide the top pull part on load
    window.onload = function(){
       mySlide.hide();
    }
	

// Fx.FontPlus control the font size

Fx.FontPlus = new Class({
	initialize: function(elements, sid, gid, gmid, growsize, growmoresize){
		this.growsize = (growsize) ? growsize : 2;
		this.growmoresize = (growmoresize) ? growmoresize : 4;
		
		this.elements = [];
 		elements.each(function(el){
			this.elements.push([el,el.getStyle('font-size').toInt()]);									   
		},this);
		
		$(gmid).onclick = function(){this.growmore()}.bind(this);
		$(gid).onclick = function(){this.grow()}.bind(this);
		$(sid).onclick = function(){this.shrink()}.bind(this);		
	},
	
	growmore: function(){
		this.elements.each(function(el){
			var currentfsize = el[0].getStyle('font-size').toInt();
			if(currentfsize == el[1])
				el[0].effect('font-size',{duration:300,unit:'px'}).custom(el[1],el[1]+this.growmoresize);
			else if(currentfsize == el[1]+this.growsize)
				el[0].effect('font-size',{duration:300,unit:'px'}).custom(el[1]+this.growsize,el[1]+this.growmoresize);			
		},this);							
	},
	
	grow: function(){		
		this.elements.each(function(el){
			var currentfsize = el[0].getStyle('font-size').toInt();
			if(currentfsize == el[1])
				el[0].effect('font-size',{duration:300,unit:'px'}).custom(el[1],el[1]+this.growsize);
			else if(currentfsize == el[1]+this.growmoresize)
				el[0].effect('font-size',{duration:300,unit:'px'}).custom(el[1]+this.growmoresize,el[1]+this.growsize);	
		},this);							
	},
	
	shrink: function(){
		this.elements.each(function(el){
			var currentfsize = el[0].getStyle('font-size').toInt();
			if(currentfsize == el[1]+this.growsize)
				el[0].effect('font-size',{duration:300,unit:'px'}).custom(el[1]+this.growsize, el[1]);
			else if(currentfsize == el[1]+this.growmoresize)
				el[0].effect('font-size',{duration:300,unit:'px'}).custom(el[1]+this.growmoresize, el[1]);
		},this);		
	}						
});


//this for the ajax contact form

window.addEvent('domready', function(){
			$('myForm').addEvent('submit', function(e) {

			new Event(e).stop();
			var log = $('log_res').empty().addClass('ajax-loading');
			this.send({
				update: log,
				onComplete: function() {
					log.removeClass('ajax-loading');
				}
			});
			});		
		});



//this for the footer links
var Site = {
	
	start: function(){
		if ($('kwick')) Site.parseKwicks();
			
		if ($('services')){
			Site.appearText();
			if (!window.ie6) Site.makeShadow();
		}
	},
	
	parseKwicks: function(){
		var kwicks = $$('#kwick .kwick');
		var fx = new Fx.Elements(kwicks, {wait: false, duration: 200, transition: Fx.Transitions.quadOut});
		kwicks.each(function(kwick, i){
			kwick.addEvent('mouseenter', function(e){
				var obj = {};
				obj[i] = {
					'width': [kwick.getStyle('width').toInt(), 114]
				};
				kwicks.each(function(other, j){
					if (other != kwick){
						var w = other.getStyle('width').toInt();
						if (w != 40) obj[j] = {'width': [w, 40]};
					}
				});
				fx.start(obj);
			});
		});
		
		$('kwick').addEvent('mouseleave', function(e){
			var obj = {};
			kwicks.each(function(other, j){
				obj[j] = {'width': [other.getStyle('width').toInt(), 60]};
			});
			fx.start(obj);
		});
	},
	
	appearText: function(){
		var timer = 0;
		var sideblocks = $$('#services li');
		
		var slidefxs = [];
		var colorfxs = [];
		
		sideblocks.each(function(el, i){
			el.setStyle('margin-left', '-0px');
			timer += 150;
			slidefxs[i] = new Fx.Style(el, 'margin-left', {
				duration: 400,
				transition: Fx.Transitions.backOut,
				wait: false,
				onComplete: Site.createOver.pass([el, i])
			});
			slidefxs[i].start.delay(timer, slidefxs[i], 0);

		}, this);
	},
	
	createOver: function(el, i){
		var first = el.getFirst();
		if (!first || first.getTag() != 'a') return;
		var overfxs = new Fx.Styles(first, {'duration': 200, 'wait': false});
		if (first.hasClass('big')){
			var tocolor = '333';
			var fromcolor = 'fff';
		} else {
			var tocolor = 'faec8f';
			var fromcolor = 'ffffff';
		}
		el.mouseouted = true;
		el.addEvent('mouseenter', function(e){
			overfxs.start({
				'color': tocolor,
				'margin-left': 10
			});
		});
		el.addEvent('mouseleave', function(e){
			overfxs.start({
				'color': fromcolor,
				'margin-left': 0
			});
		});
	},
	
	makeShadow: function(){
		new Element('img').injectInside('bottomlink').setStyles({
			'top': '0', 'margin-top': '0px', 'left': '0px', 'z-index': '999999'
		}).setProperties({
			'height': '0', 'width': '0'
		});
	}
	
};



window.addEvent('load', Site.start);