$(document).ready(function(){
	Irma.init();
});

$(window).resize(function(){
	Irma.resize();
})

var Irma = {
	firstNews: null,
	newsArray: [],
	newsTotal: 0,
	cursor: 0,
	timeout: null,
	timeshow: 10000,
	init: function(){
		
		$(".menuItem").each(function(){
			$(this).css({'width': '160px'});
		});
		$(".menuItemColor").each(function(){
			$(this).css({'width': $(this).parent().width() + 'px'});
		});
		
		$(".menuItemTitle, .menuItemText").mouseover(function(){
			$(this).parent().addClass("menuHover");
		});
		$(".menuItemTitle").click(function(){
			window.location = $(this).find("a").attr("href");
		});
		$(".menuItemTitle, .menuItemText").mouseout(function(){
			$(this).parent().removeClass("menuHover");
		});
		$("#headerRightNewsContentButton").mouseover(function(){
			$(this).css({"background-color":"#F0F0F0"});
		});
		$("#headerRightNewsContentButton").click(function(){
			Irma.showLightbox();
		});
		$("#headerRightNewsContentButton").mouseout(function(){
			$(this).css({"background-color":"#FFF"});
		});
		$("#lbxMainBottomButton").mouseover(function(){
			$(this).css({"background-color":"#FFF"});
		});
		$("#lbxMainBottomButton").click(function(){
			Irma.hideLightbox();
		});
		$("#lbxMainBottomButton").mouseout(function(){
			$(this).css({"background-color":"#f2f0eb"});
		});
		$('#menuItemContainer:firstchild').css({"margin-left":0});
		//Irma.firstNews = $("#lbxMainBottomSelect select").val();
		
		Irma.timeout = setTimeout("Irma.newsFader()",Irma.timeshow);
	},
	resize: function(){
		windowHeight = $(window).height();
		windowWidth = $(window).width();
		documentHeight = $(document).height();
		$("#lbxBkg").css({"height":documentHeight});
		$("#lbx").css({"height":documentHeight});
		$("#lbxMain").css({'top':(windowHeight - 533)/2, 'left':(windowWidth - 484)/2})
	},
	showLightbox: function(url){
		Irma.resize();
		$("#lbxMainContent").html('');
		//$("#lbxMainBottomSelect select").val(Irma.firstNews);
		$("#lbxMainBottomSelect select").val(url);
		$("#lbxMainBottomSelect select").unbind("change");
		$("#lbxMainBottomSelect select").change(function() {
			Irma.loadNews($(this).val());
		});
		$("#lbxMainBottomSelect select").change();
		$("#lbx").fadeIn();
		
	},
	hideLightbox: function(){
		$("#lbx").fadeOut();
	},
	loadNews:function(url){
		
		$("#lbxMain").fadeOut();
		
		$("#lbxMainContent").load(url, function(data){
			$("#lbxMain").fadeIn();
		});
	},
	setNewsArray: function(cursor, id){
		Irma.newsArray[cursor] = id;
	},
	newsFader: function(){
		//alert(Irma.newsTotal);
		var stopForeach = false;
	    $('#headerRightNewsContentText h3 ~ .article-item').each(function(e){
			if(stopForeach == false){

				if($(this).hasClass('on')){
					$(this).fadeOut(function(){
						$(this).removeClass('on');

						if($('#'+Irma.newsArray[Irma.cursor+1]).is('.article-item')){
							$('#'+Irma.newsArray[Irma.cursor+1]).fadeIn(function(){$(this).addClass('on');});
							Irma.cursor++;							
						}else{
							$('#'+Irma.newsArray[0]).fadeIn(function(){$(this).addClass('on');});
							Irma.cursor = 0;
						}
					});
					stopForeach = true;
				}
			}
		});
		
		Irma.timeout = setTimeout("Irma.newsFader()",Irma.timeshow);
	}
}