function stylize(doc)
{
	if(!doc)
		doc = document;
	
	doc = $(doc);
	
	
//	$('.emphase',  doc).each(function() 
//	{
//		this.innerHTML = this.innerHTML.replace(/^the (.+)$/i, 'The <em>$1</em>'); 
//	});
	
	doc.find('#works img').each(function()
	{
		var item = $(this);
		
		var src = item.attr('src');
		
		if(src.match(/\/small\//))
		{
			item.addClass('active_img');
			item.parent().addClass('no_opacity').prepend('<img src="' + src.replace('/small/', '/small/inactive/') + '" class="inactive_img"/>');
		}
			
	});
	
	
	if(!touchBrowser)
	{
		doc.find('#works .selector_item').bind('sb.activate', function () {
			$(this).find('img.active_img').show();
			$(this).find('img.inactive_img').hide();
		});

		doc.find('#works .selector_item').bind('sb.deactivate', function () {
			if($(this).is('.active'))
				return;
			
			$(this).find('img.active_img').hide();
			$(this).find('img.inactive_img').show();
		});

		doc.find('#works .selector_item').mouseenter(function()
		{
			$(this).trigger('sb.activate');
		});

		doc.find('#works .selector_item').mouseleave(function()
		{
			$(this).trigger('sb.deactivate');
		});
	}
}

function spinner_anim(holderid, R1, R2, count, stroke_width, colour) {
    var sectorsCount = count || 12,
        color = colour || "#fff",
        width = stroke_width || 15,
        r1 = Math.min(R1, R2) || 35,
        r2 = Math.max(R1, R2) || 60,
        cx = r2 + width,
        cy = r2 + width,
        r = Raphael(holderid, r2 * 2 + width * 2, r2 * 2 + width * 2),
        
        sectors = [],
        opacity = [],
        beta = 2 * Math.PI / sectorsCount,

        pathParams = {stroke: color, "stroke-width": width, "stroke-linecap": "round"};
        Raphael.getColor.reset();
    for (var i = 0; i < sectorsCount; i++) {
        var alpha = beta * i - Math.PI / 2,
            cos = Math.cos(alpha),
            sin = Math.sin(alpha);
        opacity[i] = 1 / sectorsCount * i;
        sectors[i] = r.path([["M", cx + r1 * cos, cy + r1 * sin], ["L", cx + r2 * cos, cy + r2 * sin]]).attr(pathParams);
        if (color == "rainbow") {
            sectors[i].attr("stroke", Raphael.getColor());
        }
    }
    var tick;
    (function ticker() {
        opacity.unshift(opacity.pop());
        for (var i = 0; i < sectorsCount; i++) {
            sectors[i].attr("opacity", opacity[i]);
        }
        r.safari();
        tick = setTimeout(ticker, 1000 / sectorsCount);
    })();
    return function () {
        clearTimeout(tick);
        r.remove();
    };
}

var loader_anim =
{
	show: function()
	{
		this.sp();
		$('#wait').show();
		
		var st = spinner_anim('loader_animation', 14, 15, 30, 4, '#aaa');
		
		var t = this;
		this.sp = function()
		{
			st();
			t.sp = function(){};
		};
	},
	
	sp: function(){},
	
	hide: function()
	{
		this.sp();
		$('#wait').hide();
	}
}

$(function($)
{
	$('#menu a').html('<span class="menu_inactive"></span><span class="menu_active"></span>').addClass('img');
	$('#top a.link, #top a.mail').html('&nbsp;')
	
	stylize();
});

