function resize(){
	var w = window.getSize();
	var c = $('content_wrapper').getCoordinates();
	var i = w.y - (c.height+c.top);
	if(i>0){
		$('footer_wrapper').setStyles({"height": i + 'px'});
	}
}

function ext_links(){
	// process 'external' links	
	var t = $$("a[rel=external]");
	t.each(function(lnk, nr){
		lnk.set({'target':'_blank'}).addClass('external');									
	});	
}

function process_offer(){	
	if($('offer').hasClass('hide')){
		var myFx = [];
		$$('#offer div').each(function(el, i){
			//myFx[i] = new Fx.Tween(el);
			el.set('tween', {duration: 400, transition: Fx.Transitions.linear});
			el.addEvent('mouseenter', function(){
				el.tween('height', 204);
			});
			el.addEvent('mouseleave', function(){
				el.tween('height', 20);
			});
		});
	}	
}

function service_effect(){
	$$('#offer li a').each(function(el) {  
		var fx = new Fx.Morph(el,{ duration:300, link:'cancel' });
		el.addEvents({
			'mouseenter': function() { fx.start({ 'padding-left': 10 }); },
			'mouseleave': function() { fx.start({ 'padding-left': 0 }); }
		});
	});	
}

function activate_accordion(){
	var myAccordion = new Fx.Accordion($$('.toggler'), $$('.toggle_container'), {
		onActive: function(toggler, element){
			toggler.addClass('sel');
		},
		onBackground: function(toggler, element){
			toggler.removeClass('sel');
		}													  
	});
	$$('.toggler').each(function(el){
		el.addClass('cursor');
		el.addEvents({
					 'mouseenter': function(){if(!this.hasClass('sel')){this.addClass('hover');}},
					 'mouseleave': function(){this.removeClass('hover');}
		});
	});				
}

window.addEvent('domready', function(){
	resize();
	ext_links();
	process_offer();
	service_effect();
	activate_accordion();
	if($chk($('showcase_slideshow'))){
		new Ss_animation();		
	}
	new Wos_animation();
	
	// add smooth scrolling for internal links
	new SmoothScroll({ duration:500 }, window);
	$('gototop').set('opacity','0').setStyle('display','block');

	var ss = new ScrollSpy({
		min: 150,
		onEnter: function(position,enters) {
			$('gototop').fade('in');
		},
		onLeave: function(position,leaves) {
			$('gototop').fade('out');
		},
		onTick: function(position,state,enters,leaves) {
		},
		container: window
	});
	
});

window.addEvent('resize', function(){resize();});

var Ss_animation = new Class({					 

	Implements: [Events, Options],
	
	options:{},

	initialize: function(){
		this.case_timer;	
		this.cases = $$('#showcase_slideshow div');	
		this.cases.each(function(el, i){
			if(i < this.cases.length-1){
				el.getElement('span').setStyle('right', -290);								 
			}
		}.bind(this));
		this.current_case = this.cases.length;		
		this.case_timer = this.get_previous(); //.delay(2000, this);		
	},
	
	get_previous: function(){		
		var current = this.cases[this.current_case-1];
		var sp = current.getElement('span');
		sp.set('tween', {duration: 'long', transition: 'bounce:out'});
		sp.tween('right', 0).retrieve('tween').chain(function(){
			(function(){					  	
						sp.tween('right', -290).retrieve('tween').chain(function(){
							current.fade('out').retrieve('tween').chain(function(){
								current.clone().setStyles({'visibility':'hidden', 'opacity':.999}).inject($('showcase_slideshow'), 'top');
								current.dispose();			
								this.cases = $$('#showcase_slideshow div');	
								this.case_timer = this.get_previous.delay(500, this);			
							}.bind(this));			
						}.bind(this));
			}.bind(this)).delay(4000);
		 }.bind(this));
	}	
	
});

var Wos_animation = new Class({					 

	Implements: [Events, Options],
	
	options:{},

	initialize: function(){
		this.wos_timer;	
		this.woss = $$('#wos .logos a');	
		this.current_wos = this.woss.length;		
		this.wos_timer = this.get_previous.delay(2000, this);		
	},
	
	get_previous: function(){		
		var current = this.woss[this.current_wos-1];
		current.fade('out').retrieve('tween').chain(function(){
			current.clone().setStyles({'visibility':'hidden', 'opacity':.999}).inject($$('#wos .logos')[0], 'top');
			current.dispose();			
			this.woss = $$('#wos .logos a');	
			this.wos_timer = this.get_previous.delay(4000, this);			
		}.bind(this));		
	}	
	
});


