
var BASE_URL = window.location.href.toString().indexOf('localhost') != -1
	? '/nicoswd3.0'
	: '';

var Mcount = 0;
var Matrix;

function nicoswd(lang)
{
	this.lang = lang;
	this.baseURL = BASE_URL;
}


nicoswd.prototype.displayNews = function(url)
{
	window.open(url, 'news', 'width=450,height=300,top=200,left=300').focus();
	return false;
}


nicoswd.prototype.loading_img = function()
{
	var image = document.createElement('img');
	
	with (image)
	{
		title = 'Loading...';
		alt   = 'Loading...';
		src   = this.baseURL + '/graphics/loading.gif';
	}
	
	return image;
}

function highlight(e)
{
	if (!e) e = window.event;
	var input = e.target ? e.target : e.srcElement;
	
	$('#con_' + input.id)[0].className = 'contact_focus';
}


function unhighlight(e)
{
	if (!e) e = window.event;
	var input = e.target ? e.target : e.srcElement;

	$('#con_' + input.id)[0].className = 'contact_form_border';
}


function fetch_nocache_str()
{
	return escape(new Date().toString());
}


String.prototype.UcWords = function()
{
	return this.toLowerCase().replace(/\w+/g, function(s)
	{
		return s.charAt(0).toUpperCase() + s.substr(1);
	});
}


function textMatrix()
{
	var text = ['Search', '.', '.', '.'];
	
	if (typeof text[Mcount] == 'undefined')
	{
		$('input[name=q]')[0].value = '';
		Mcount = 0;
	}
	
	$('input[name=q]')[0].value += text[Mcount++]
	
	Matrix = window.setTimeout('textMatrix()', 1000);
}

$(document).ready(function()
{
	$('#navbar a')
		.css({backgroundPosition: '-20px 35px'})
		.mouseover(function()
		{
			$(this).stop().animate({backgroundPosition: '(-20px 95px)'}, {duration: 500, complete: function()
			{
				$(this).css({color: '#000'});
			}});
		})
		.mouseout(function()
		{
			$(this).stop().animate({backgroundPosition: '(40px 35px)'}, {duration: 200, complete: function()
			{
				$(this).css({backgroundPosition: '-20px 35px', color: '#fff'});
			}})
		})
	
	var query = $('input[name=q]');
	query[0].value = '';
	
	query.focus(function()
	{
		window.clearTimeout(Matrix);
		
		$(this)[0].value = '';
		$(this).css({color: '#000'});

		$('#go').css({visibility: 'visible'}).hide().fadeIn('slow');
	});
	
	query.blur(function()
	{
		if ($.trim(query[0].value) == '')
		{
			$('#go').fadeOut('slow', function()
			{
				$(this).css({visibility: 'hidden'}).show();
				query.css({color: '#CCC'});

				Matrix = window.setTimeout('textMatrix()', 1000);
				Mcount = 0;
			});
		}
	});
	
	textMatrix();
});