var Site = {

	Init: function() {
		Site.ImageRotater();
		Site.HomeRotater();
		Site.Editor();
		Site.Reorder();
		Site.SetFocus();
		Site.SiteTips();
	},

	SetFocus: function() {
		if ($('txtUsername')) $('txtUsername').focus();
		if ($('txtCode')) $('txtCode').focus();
		if ($('txaData')) $('txaData').focus();
		if ($('txtHeadline')) $('txtHeadline').focus();
		if ($('txtTitle')) $('txtTitle').focus();			
	}, 

	ImageRotater: function() {
		if ($(document.body).getElement('div.imageRotater')) {
			var scroller = new ContentScroller({slideDuration: 4500, fadeDuration: 500});
			scroller.addSlides($$('div.imageRotater img').setStyle('z-index', 1));
			scroller.start();
		}
	},	

	HomeRotater: function() {
		if ($(document.body).getElement('div.homeRotater')) {
			var scroller = new ContentScroller({slideDuration: 5000, fadeDuration: 300});
			scroller.addSlides($$('div.homeRotater img').setStyle('z-index', 1));
			scroller.start();
		}
	},	

	ChangeImage: function (element, image, title) {
		if ($(element)) {
			$(element).src = image;
			$(element).title = title;		
		}
	},
	
	Reorder: function() {
		if ($('itemList')) {
			var sortableLists = new Sortables($('itemList'), {
				clone: true,
				handle: '.handle', 
				revert: {
					duration: 50
				},
				opacity: .1,
				onStart: function(el){
					el.highlight('#F3F865');	
				},
				onSort: function(el) {
				},
				onComplete: function(el) {
					$('hdnPostionIDs').value = this.serialize(0); 
				}
			}).attach();
		}
	},
	
	Editor: function() {
		var textarea = '';

		if ($('txaDescription')) textarea = 'txaDescription';
		if ($('txaContent')) textarea = 'txaContent';
		if ($('txaArticle')) textarea = 'txaArticle';
		
		if (textarea != '') var editor = new Editor($(textarea), { url: '/images/editor/' });
		
		if ($('frmMember')) {
			var edtServices = new Editor($('txaServices'), { url: '/images/editor/' });
			var edtMessage = new Editor($('txaMessage'), { url: '/images/editor/' });
		}
			
	},
	
	SiteTips: function() {
		$$('img.tipz').each(function(element, index) { 
			var content = element.get('title').split('::'); 
			element.store('tip:title', content[0]); 
			element.store('tip:text', content[1]);
		});
		
		var tipz = new Tips('.tipz', { 
			className: 'tipz', 
			fixed: true, 
			hideDelay: 50, 
			showDelay: 50 
		}); 
	}	
		
};

window.addEvent('domready', Site.Init);