
var inlineboxData ={}; 

var setPosition = function(obj){
	$(obj).css('top',130);
	$(obj).css('left',$(document).width()*0.5-$(obj).width()*0.5);
}

function addInlinebox(id,option){
	inlineboxData[id] = option; 
}
function openInlinebox(id){
	if(!inlineboxData[id]) {return;}
	var obj = '#inlinepop';
	$(obj).find('iframe').attr('src','spop/'+id+'/');
	window.scrollTo(0,0);	
	$('.fancy-outer').each(function(idx,obj){
		
		$(obj).css('display','block');
		$(obj).fadeOut(0);
		$(obj).show();
		$(obj).width(inlineboxData[id].width);
		$(obj).height(inlineboxData[id].height);
		setPosition(obj);
		$(obj).fadeIn(500);
		
		var onMouseOver = function(){
			$(obj).find('.fancy-close').css('backgroundPosition','left -45px')
		}
		var onMouseOut = function(){
			$(obj).find('.fancy-close').css('backgroundPosition','left 0px')
		}
		var onClick = function(){
			$(obj).find('iframe').attr('src','spop/blank.html');
		}
		
		$(obj).find('.fancy-close').hover(onMouseOver,onMouseOut);
		$(obj).find('.fancy-close').click(onClick);
	});
}

var currentMlaOffset = 0;
var totalMla = 0;
function showLargeAdv(offset){
	resetMlaTimer();
	openLargeAdv(offset);
}
function openLargeAdv(offset){

	$('#mlb-'+currentMlaOffset).hide();
	$('#mla-'+currentMlaOffset).removeClass('selected');
	
	$('#mlb-'+offset).show();
	$('#mla-'+offset).addClass('selected');
	
	currentMlaOffset = offset;
}
function nextLargeAdv(){
	offset = currentMlaOffset+1;
	if(offset>totalMla){
		offset = 1;
	}
	
	openLargeAdv(offset);
}
var mlaInterval = false;
function resetMlaTimer()
{
	totalMla = $('.mlbItem').length;
	if(mlaInterval!=false)clearInterval(mlaInterval);
	if(totalMla>0) mlaInterval= setInterval(nextLargeAdv,5000);
}

$(document).ready(function(){
	$('#inlinepop').insertAfter('#container');
		
	resetMlaTimer();
	showLargeAdv(1);
	
	window.onresize = function(){
		$('.fancy-outer').each(function(idx,obj){
			setPosition(obj);
		});
	};
});