var scrollingDown = true;
var scroller = null;

document.addEvent("domready", function(){

	var changer = new kamContentChanger('mainBannersInner',{ 
		cellsElement:'mainBannersInner',
		contentCellSelector:".mainBanner",
		autoChange:true,
		changeInterval:animationSettings.transitionDelay,
		changeDuration:animationSettings.transitionPeriod
	});
	
	kamUi.setInitialiseOptions({
		kamVideoModal:{
			width:640,
			height:430,
			disablePageScrolling: false
		}
    });
	kamUi.initialise();
	
	var itemsList = document.getElement("li.boxAdTwitter div.inner ul");
	if( itemsList ){

		var listHeight = itemsList.getSize().y;
		var totalHeight = 0;
		var itemListItems = itemsList.getElements("li");
		itemListItems.each( function(elm,index){
			totalHeight += elm.getSize().y;
		});
		
		if( totalHeight > listHeight ){
			scroller = new Fx.Morph(itemListItems[0], {
				duration: itemListItems.length*1800,
				transition: Fx.Transitions.linear,
				onComplete: function(){
					if( scrollingDown ){
						this.start({'margin-top': [(listHeight-totalHeight), 0]});
						scrollingDown = false;
					}
					else{
						this.start({'margin-top': [0, (listHeight-totalHeight)]});
						scrollingDown = true;
					}
				}
			});
			
			scroller.start({'margin-top': [0, (listHeight-totalHeight)]});
			
			itemsList.addEvent("mouseover",function(evt){
				scroller.pause();										
			});
			
			itemsList.addEvent("mouseleave",function(evt){
				scroller.resume();										
			});
		}
	}
	
	// fix legend bug in webkit
	if( Browser.chrome || Browser.safari ){
		document.getElements("legend").each(function(elm,index){
			elm.setStyle("margin-left","0");
		});
	}
	
	overrideSfForms();
});

function overrideSfForms(){
	document.getElements('form').each( function(form){
		var formAction = form.get('action');
		if ( formAction.indexOf('salesforce') > 0 ){
			new Element('input', {
				type: 'hidden',
				name: 'kamSfFormAction',
				value: formAction
			}).inject(form);
			
			var uri = new URI(window.location);
			form.set('action', uri.toAbsolute());
		}
	});
};
