google.setOnLoadCallback(function() {
	
	// $('.similar ul li:odd').next().addClass('last');
	$('.similar ul li:nth-child(3n)').addClass('last');
	$('#portf:not(.inner) .portf-item:odd').next().addClass('last');
	$('#portf.inner .portf-item:nth-child(3n)').addClass('last');
	
	$('.portf-info, .kiejtes').css("visibility", "visible").fadeTo(0, 0);
	
	$('.portf-item').each(function (i){
	        $(this).hover(function() {
	            $(this).find('.portf-info').stop().fadeTo(550, 1); }
	                , function() {
	            $(this).find('.portf-info').stop().fadeTo(350, 0);
	        });
	    });
	
		
	
	// slider with one element shown once
	$('#portf-imgs img').wrap('<div class="portf-img-elem"></div>');
	
    var prevButton    = $("#prev-img");
    var nextButton    = $("#next-img");

	var elementTag = $(".portf-img-elem");
	var elementHolder = $("#portf-imgs");

    var elementWidth  = 700;
    var holderPosition  = 0;
    var elementWidthTotal = elementTag.length * elementWidth;

    elementHolder.width(elementWidthTotal);

	if( elementTag.length > 1) {
		hideControl();
	} else {
		prevButton.hide();
		nextButton.hide();
	}
	

    prevButton.click(function() {
        if(holderPosition < 0) {
            holderPosition  = holderPosition + elementWidth;
            elementHolder.animate({
                'left': holderPosition + 'px'
            });
			hideControl();
        }
        return false;
    });

    nextButton.click(function() {
    		if((holderPosition-elementWidth) > -(elementWidthTotal)) {
            holderPosition  = holderPosition - elementWidth;
            elementHolder.animate({
                'left': holderPosition + 'px'
            });
			hideControl();
        }
        return false;
    });

	function hideControl() {
		switch(holderPosition) {
			case 0:
				prevButton.hide();
				nextButton.show();
				break;
			case -(elementWidthTotal - elementWidth):
				nextButton.hide();
				prevButton.show();
				break;
			default:
				prevButton.show();
				nextButton.show();
		}
	}
	
    $('.scroll-to a').click(function() {
        var rel = $(this).attr("rel");
        var goTo = '#' + rel;
        var offset = $(goTo).offset();
        $('html, body').animate({scrollTop: offset.top - 20}, 'slow'); return false;       
    });
	
	$('#intro h2 span').hover(function() {
        $('.kiejtes').stop().fadeTo(550, 1); }
            , function() {
        $('.kiejtes').stop().fadeTo(350, 0);
    });
		
		// var el = $('.role div');
		// 			el.html(el.html().replace(",", "<br />"));


$('.role div').escapeHtml();
});

(function($) {


$.fn.escapeHtml = function() {
	this.each(function() {
		$(this).html(
			$(this).html()
				.replace(/,/g,'<br />')
		);
	});
	return $(this);
}

})(jQuery);