window.addEvent('resize', resizeMain);
if (window.ie6) window.addEvent('scroll', resizeMain);
var winHeight;

var footerScroll;

function resizeMain(noAnimattion) {
	if (!footerScroll){
		$('footer').setStyles({position: window.ie6 ? 'absolute' : 'fixed', zIndex: 100, width: '100%', left: 0, top: window.getHeight()});
		footerScroll = new Fx.Styles('footer', {wait: false, transition: Fx.Transitions.linear, fps:25, duration:300});
	}
	var fheight = $("footer").getSize().size.y;
	var top = window.getHeight() - fheight;
	if (window.ie6) top += document.documentElement.scrollTop;
	if (noAnimattion == true){
		$('footer').setStyle('top', top);
	} else {
		footerScroll.start({'top': top});
	}
	$('padding').setStyle('height', fheight); 
}

window.addEvent('onLoad', function() {
	$$('#footer-content').setStyles({'margin': '-150px'});
});

var footerContentSlide;
var slidden_out = false;
var footerClose;

function switchContent(e, tmpl){
	if (e) e.preventDefault();
	footerContentSlide.switchContent('pwc.main.views.footer', tmpl);
	if (!slidden_out) footerClose.start({'margin-left': [-1000, -75]});
}

window.addEvent('domready', function() {
	resizeMain();
    
	footerContentSlide = new SlideBox('footer-content', {transition: Fx.Transitions.Quad.easeOut, fps: 25, duration: 400});
	footerContentSlide.addEvent('onSwitchShow', function(){footerScroll.toBottom(); slidden_out = true;})
	
	footerContentSlide.addEvent('onProgress', function(){resizeMain(true)});
	
    var footerScroll = new Fx.Scroll(window, {offset: {'x': 0, 'y': 1000}, wait: false, transition: Fx.Transitions.Quad.easeOut, fps: 25, duration: 400});
	footerClose = new Fx.Styles('slideout', {wait: false, duration: 500, transition: Fx.Transitions.linear});
	
	$('slideout').addEvent('click', function(e){
		new Event(e).stop();
		footerContentSlide.slideOut();
		footerClose.start({'margin-left': [-75, -1000]});
        slidden_out = false;
	});
	
	if($('footer-content').getSize().size.y > 0) {
		if (!slidden_out) footerClose.start({'margin-left': [-1000, -75]});
	} 
	
	// footer actions
	$ES('a[href^=./?]', 'footer-navigation-content').each(function(item){
		item.addEvent('click', switchContent.bindWithEvent(this, item.href.split('?')[1]));	
	});
	
	//$ES('a[rel=external]').each(function(el){ el.target="_blank"});	  	
});