

var SGtmr = new Array();
var scrollHeaderItems = function(sel){
	x = $(sel + ':eq(0)').width() * -1;
	$(sel + ':eq(0)').animate({marginLeft:x + 'px'},{queue:false, duration:600, easing:"easeOutQuad", complete:function(){
		$(sel + ':eq(0)').css('margin-left','0px').appendTo($(sel).parent());
		$(sel + ':eq(0)').css('margin-left','0px');
		if(SGtmr[sel])
			clearTimeout(SGtmr[sel]);
		SGtmr[sel] = setTimeout('scrollHeaderItems("'+sel+'")',8000);
	}});
}

var scroll_position = function(selector){
	if (selector == 'auto') {
		var scroll_position = -225;
	} else {
		var scroll_position = parseInt(selector)-225;
	}
	return scroll_position;
}

$(document).ready(function(){

	scrollHeaderItems("#footer #logos div.scroll .logo");
	
	$('#left').height(Math.ceil($('#left').height()/225)*225);

	$('.article.image').each(function(){
		t = $(this).find('img');
		$(this).css('background-image','url('+ t.attr('src') +')');
		t.remove();
	});
	$('.article.overlay').each(function(){
		$(this).find('.content').addClass('background');
		$($(this).find('h2')).prependTo($(this).find('.content'));
		$('<div class="arrow"></div>').appendTo($(this).find('.content'));
		t = $(this).find('img');
		$(this).css('background-image','url('+ t.attr('src') +')');
		t.remove();
		$(this).hover(
		  function() {
			$(this).find('.content').css('background','#1a3133');
			$(this).find('.content').removeClass('background');
		  },
		  function() {
			$(this).find('.content').css('background','');
			$(this).find('.content').addClass('background');
		  }
		).click(function(){
			window.open($(this).find('a').not('a[name]').eq(0).attr('href'), 'new_window', '');
		});
	});
	$('#left-column .article,.article.small,.article.medium').each(function(){
		article_height = Math.ceil($(this).height()/224);
		$(this).height(article_height*224+article_height-1);
		if ($(this).is('.image')) {
			$(this).find('.content').hide();
		}
	});
	$('.article.large').each(function(){
		article_height = Math.ceil($(this).height()/449);
		$(this).height(article_height*449+article_height-1);
		if ($(this).is('.image')) {
			$(this).find('.content').hide();
		}
	});

	$('.down').click(function(e){
		e.preventDefault();
		var scrollpos = scroll_position($('#content').css('marginTop'));
		$('#content').animate({marginTop: scrollpos},{queue:false, duration:700, easing:"easeOutQuad"}); 
	});
	$('.up').click(function(e){
		e.preventDefault();
		$('#content').animate({marginTop: 0},{queue:false, duration:800, easing:"easeOutQuart"});
	});

});


