// JavaScript Document
$(document).ready(function(){
	var getUrlVars = function(){
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++) {
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
		return vars;
	};
	(function(){
		var div = $('<div></div>');
		var setcookie = function(){
			$.cookie("refer", "t", {path:'/', expires:30});
		};
		var setposition = function(element){
			$(element).css('left', ($(window).width() - 730) / 2);
			$(element).css('top', ($(window).height() - 324) / 2);
		};
		var setsize = function(element){
			$(element).width($(window).width());
			var h = Math.max(document.body.clientHeight , document.body.scrollHeight );  
			h = Math.max(h , document.documentElement.scrollHeight );  
			h = Math.max(h , document.documentElement.clientHeight );
			$(element).height(h);
		};
		$(window).resize(function(){
			setposition('#modal');
			setsize(div);
		});
		$('#stay').click(function(){
			setcookie();
			$('#modal').css('display', 'none');
			div.css('display', 'none');
		});
		$('#gootherdomain').click(function(){
			setcookie();
			location.href = 'http://www.ib-tokyo.jp/?from=nagoya';
		});
		var ck = $.cookie("refer");
		if (getUrlVars()['from'] === 'tokyo'){
			setcookie();
		}
		else if (ck === 't'){
		}
		else {
			$('#modal').css('display', 'block');
			$('#modal').css('z-index', 10001);
			div.css('z-index', 10000);
			div.attr('class', 'modalbg');
			setposition('#modal');
			$('body').prepend(div);
			setsize(div);
			div.css('opacity', 0.8);
	
		}
	})();
	(function(){
		var div = $('#headnews .base .newscontents');
		var marquee = function(){
			$(div).css('left', '540px');
			var left = div.width();
			$(div).animate({'left':'-' + left + 'px'}, 15000, "linear", function(){
				marquee();
			});
		};
		marquee();
	})();
});

