var Site = {
	init: function(){
		var contentRightHeight = $('#content-left').height() > $('#content-right').height() ? $('#content-left').height() + 3 : $('#content-right').height() + 3;
		$('#content-right').css({
			height:contentRightHeight
		});
		
		$.preloadCssImages();		
		
		Cufon.replace('h2.page-title,.pxl');
		
		if($('#collections-container')){
			Site.cycle({
				item:'.collection',
				container:'#collections-container',
				direction:'left',
				duration:6000,
				speed:500
			});
		}
		
		if($('#view-collection')){
			Site.cycle({
				item:'.watch-collection',
				container:'#watch-collections',
				direction:'right',
				duration:6000,
				speed:500
			});
		}
	},
	
	cycle: function(options){
		var cycleCount = $(options['item']).length;
		if(cycleCount > 1){
			$(options['item'] + ':first').clone().appendTo(options['container']);
			var currentCycle = 0;
			var cycleTimer;
			
			var itemWidth = $(options['item'] + ':first').width();
			var cycleWidth = itemWidth * (cycleCount + 1);
			var startMargin = (options['direction'] == 'left' ? 0 : '-' + (itemWidth * cycleCount) + 'px');
			
			$(options['container']).css({
				width: cycleWidth + 'px',
				marginLeft: startMargin
			});
			$(options['item']).css({
				float:options['direction']
			});
					
			var endCycle = function(){
				currentCycle++;
				if(currentCycle == cycleCount){
					$(options['container']).css({
						marginLeft: startMargin
					});
					currentCycle = 0;
				}
			}
			
			var switchCycle = function(){
				cycleTimer = setTimeout(function(){
					
					if(options['direction'] == 'left'){
						var cycleMargin = parseInt($(options['container']).css('margin-left').replace('px','')) - itemWidth + 'px';
					}else{
						var cycleMargin = parseInt($(options['container']).css('margin-left').replace('px','')) + itemWidth + 'px';
					}

					$(options['container']).animate({
						marginLeft: cycleMargin
					},options['speed'],function(){
						endCycle();
					});
					
					switchCycle();
				},options['duration']);
			}
			switchCycle();
		}
	}
}
$(document).ready(function(){ Site.init(); });