



	$(document).ready(function(){
		
		$(window).bind('resize', function() { 
		    if (resizeTimer) clearTimeout(resizeTimer); 
		    resizeTimer = setTimeout(setFlags, 10);
		});
		setFlags(true)
	});
	
	var resizeTimer = null;
	
	$(".promonews").cycle();
	
	$(".promonews").bind("click", function(){
		document.location = $(this).find("a:visible:first").attr("href");
	})
	
	function setFlags(initset){
		var offset = $(window).width()%80;
		$("#companylogos").css("left", 320+offset+"px");
		$("#contentwrapper .cw2").css("background-position", 240+offset+"px 0");
		if(initset){
			$("#contentwrapper").css("background-repeat", "repeat-x");
			$("#companylogos").css("top", "0");
		} 
		$("#contentwrapper").css("background-position", 1200+offset+"px 0");
		
		$(".promonews").css("width", $(window).width());
		
	}

	
	group1 = [3,5,8,12,13];
	group2 = [1,2,7,9,11];
	group3 = [4,6,10,14,15];
	
	
	groups = [group1,group2,group3]
	
	currentindex = null;
	
	
	// test background-attribute selection
	bgpostest = $(".c1").css("background-position")
	iebgpos = false;
	if(typeof bgpostest != "string"){
		iebgpos = true;
	}
	
	
	function globalAnimate(){
		if(currentindex == null){
			animateGroup(groups[0]);
			currentindex = 0;
			var longwait = setTimeout(globalAnimate, 3625);
		} else {
			$.each(groups[currentindex], function(index, value){
				animateFlag(value)
			})
			if(currentindex == 2){
				currentindex = 0
			} else {
				++currentindex;
			}
			var secondHalf = function(){animateGroup(groups[currentindex])}
			var wait = setTimeout(secondHalf, 2625)
			var longwait = setTimeout(globalAnimate, 5625);
		}
	}
	var initpause = setTimeout(globalAnimate, 2500);
	
	
	function animateGroup(group, flagnum){
		if(typeof(flagnum) == "undefined"){flagnum=0}
		animateFlag(group[flagnum])
		if(flagnum != 4){
			var doNext = function(){animateGroup(group, ++flagnum);}
			var wait = setTimeout(doNext, 125);
		}
	}
	
	function animateFlag(slidenum){
		var slidenum = slidenum;
		
		
		if(iebgpos){
			$('.c'+slidenum).animate({
					left: '+=40',
					width: '1px',
					"background-position-x": (80*-slidenum)+40+'px'
				}, 175, 'easeInCubic', function(){
					$(this).toggleClass("logo").animate({
							left: '-=40',
							width: '80px',
							"background-position-x": (80*-(slidenum-1))+'px'
					}, 350, 'easeOutCubic')
				});
		} else {
				$('.c'+slidenum).animate({
							left: '+=40',
							width: '1px',
							backgroundPosition: (80*-slidenum)+40+'px  0'
						}, 175, 'easeInCubic', function(){
							$(this).toggleClass("logo").animate({
									left: '-=40',
									width: '80px',
									backgroundPosition: (80*-(slidenum-1))+'px  0'
							}, 350, 'easeOutCubic')
						});
		}
	
	}
