var carousel;
var container;
var container_offset = 0;
var step = 1;
var interval = 10;
var children_total_width = 0;
var init_children_width = 0;
var sets_shown = -1;
var children;
var alarm;
var alarmOn=1;

function initCarousel() {
	if($('.carousel .container'))
		{

			carousel = $('.carousel');
			container = carousel.find('.container');

			container.find('a').each(function(){
				children_total_width = children_total_width + parseInt($(this).width())  + parseInt($(this).css('margin-right'));
			});
			init_children_width = parseInt(children_total_width);
			children = container.find('a');
			children.clone().each(function(){
					container.append($(this).clone());
			});
			runCarousel();
		}
}

function runCarousel() {
	container_offset = container_offset - step;
	container.css({left:container_offset});
	if(parseInt(container_offset) < parseInt(init_children_width) * parseInt(sets_shown)) {
		sets_shown = sets_shown - 1;
		children.clone().each(function(){
			container.width(container.width() + 200);
			container.append($(this).clone());
		});
	}
	alarm = window.setTimeout(runCarousel,interval);
    alarmOn=1;
}

function preInit() {
	if ((jQuery.browser.safari || jQuery.browser.opera) && document.readyState != "complete"){
		alarm = setTimeout(preInit,100);
            alarmOn=1;
	}else{
		initCarousel();
	}
}


$(document).ready(function(){
	preInit();

   $('.carousel').hover(function() {
        if(alarmOn){
            clearTimeout(alarm);
            alarmOn = 0;
        }

        //show titles
        //$('#slideLogoFrameTitle').append('asdf');

    }, function() {
        if(!alarmOn){
            runCarousel();
            alarmOn = 1;
        }

        //hide titles
        //$('#slideLogoFrameTitle').empty();
    });
});


