var Site = {

	Init: function() {
		Site.Flash();
		Site.ImageRotater();
		Site.TestimonialRotater();
		Site.Editor();
		Site.Reorder();
		Site.SetFocus();
	},

	Flash: function() {
		var obj = new Swiff('/flash/ice.swf', {
		    width:  250, 
		    height: 120, 
		    container: $('flashLeft'),
		    events: {
		        onLoad: function() {		            
		        }
		    }
		});		

		var obj = new Swiff('/flash/ice.swf', {
		    width:  250, 
		    height: 120, 
		    container: $('flashRight'),
		    events: {
		        onLoad: function() {		            
		        }
		    }
		});		

	},
	
	SetFocus: function() {
		if ($('txtUsername')) $('txtUsername').focus();
		if ($('txtCode')) $('txtCode').focus();
		if ($('txaData')) $('txaData').focus();
		if ($('txaQuestion')) $('txaQuestion').focus();
		if ($('txtHeadline')) $('txtHeadline').focus();
		if ($('txtTitle')) $('txtTitle').focus();
		if ($('txtFirstName')) $('txtFirstName').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();
		}
	},	
	
	TestimonialRotater: function() {
		if ($(document.body).getElement('div.testimonialRotater')) {
			$(document.body).getElement('div.testimonialRotater').setStyle('display', 'block');
			
			var scroller = new ContentScroller({slideDuration: 8500, fadeDuration: 500});
			scroller.addSlides($$('div.testimonialRotater div').setStyle('z-index', 3));
			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/' });	
	},
	
	FillingDeliveryAddress: function() {
		$('txtDeliveryFirstName').value = $('txtBillingFirstName').value;
		$('txtDeliveryLastName').value = $('txtBillingLastName').value;
		$('txtDeliveryAddress1').value = $('txtBillingAddress1').value;
		$('txtDeliveryAddress2').value = $('txtBillingAddress2').value;
		$('txtDeliveryTownCity').value = $('txtBillingTownCity').value;
		$('txtDeliveryCounty').value = $('txtBillingCounty').value;
		$('txtDeliveryPostcode').value = $('txtBillingPostcode').value;
		$('sltDeliveryCountryID').value = $('sltBillingCountryID').value;
	}
		
};

window.addEvent('domready', Site.Init);