
$(function() {
		
	/**
	 * Flex Content Cycle
	 */
	$(".flex_content_cycle .content_section")
		.each(function(index, element) {
			$(this).siblings(".navigation_next").addClass("navigation_next" + index);
			$(this).siblings(".navigation_previous").addClass("navigation_previous" + index);
			
			$(this).cycle({ 
			    fx:     'scrollHorz', 
			    speed:	 400, 
			    timeout: 10000, 
			    next:   '.navigation_next' + index, 
			    prev:   '.navigation_previous' + index,
			    random:	1,
			    cleartypeNoBg: true,
			    pause:	1
			});

	});
	
	
	/**
	 * Flex Content Swap
	 * Flex Rightcontent Cycle
	 */
	function content_swap(selector) {

		$(selector).each(function(index, elem) {
			var selectorPrefix = selector;
			
			// give unique ID for easy (and unique) selection
			$(this).addClass('content_section' + index);
			
			$(this).siblings('.pager')
				.addClass('pager' + index);
			
			$(this).cycle({
				fx:		'fade',
				speed:	1000,
				//20100525 Deactivated for large images
				//next:	selectorPrefix + '.content_section' + index,
				pager:	selectorPrefix + ' ~ .pager' + index,
				pagerEvent: 'mouseover',
				random:	0,
				fit:	1,
				cleartypeNoBg: true,
				timeout: $('.content_section').size() == 1 ? 5000 : 0
			});
			
			// calculate the width of children, to set the absolut width of parent
			// for centering the children
			var width = 0;
			$(selectorPrefix + ' ~ .pager' + index + " > *").each(function() {
				width += $(this).outerWidth(true);
			});
			if (width > 0) {
				if ($.browser.msie && $.browser.version == 6) {
					width += 10;
				}
				$(selectorPrefix + ' ~ .pager' + index).css("width", width);
			}
			
		});
		// show first at startup
		$(selector).show();
	};
	
	content_swap(".flex_rightcontent_cycle .content_section");
	
	$('.flex_content_swap').find('.content_section').each(function() {

		if ($(this).children().size() > 1 ) {
			//content_swap($(this));
			content_swap("#" + $(this).parent().parent().attr('id') +" .flex_content_swap .content_section");
		} else {
			$(this).find(":first-child").show();
			$(this).find(".pager").remove();
			
			//$(".flex_content_swap .content_section :first-child").show();
			//$(".flex_content_swap .pager").remove();
		}
	});

});
