Cufon.replace('.metalic', { fontFamily: 'OfficinaSerifC', color: '-linear-gradient(#4e4e4e, #797979)' });
Cufon.replace('.metalic2', { fontFamily: 'OfficinaSerifC' , color: '-linear-gradient(#4e4e4e, #797979)' });
/*Cufon.replace('.quote', {  textShadow: '#000000 1px 1px 2px' });
Cufon.replace('.shadow', {  textShadow: '#000000 1px 1px 2px' });*/
var gal_count = 0;
function lightbox_close() {
	$('#lightbox').hide();
}
function lightbox_open(url, width) {
	$('#lightbox .opacity-plate, #lightbox .lightbox-window, #lightbox .lightbox-close').click(function(e) {	if (e.target == this) lightbox_close();	});
	$('#lightbox .lightbox-window').css('top' , ($(window).scrollTop() + 100) + 'px');
	if (width == undefined) {
		width = 600;
	}
	$('#lightbox .lightbox-window-content').width(width);
	$('#lightbox').show();

	if (url != '')
		$.get(url, function(data) {	$('#lightbox .lightbox-content').html(data); });
	$('#lightbox .opacity-plate').height($(document).height()+100);	
}

function image_open(src) {
	$('#lightbox .lightbox-content').html(
		$('<img>').attr('src', src)
	);
	lightbox_open('');
}

function input_blur(el, text) {
	if ($(el).val() == ''){
		$(el).val(text);
	}
}
function input_focus(el, text) {
	if ($(el).val() == text) {
		$(el).val('');
	}
}

function nextphoto() {
	$.each($('.imggroup'), function (i, item) {
		var act = false;
		if($(item).children('.nav').children('a:last').attr('class') == 'active') {
			$(item).children('.nav').children('a:first').click();
			return;
		}
		$.each($(item).children('.nav').children('a'), function(j, jtem) {
			if ($(jtem).attr('class') == 'active') {
				act = true;
			} else if (act) {
				$(jtem).click();
				act = false;
				return;
			}
		});
	});
	setTimeout(nextphoto,10000);
}

function nextobject() {
	$('#gallery .main').fadeOut( function() {
		var a = $('#gallery .el').get(gal_count);
		var b = $('#gallery .main');
		var tmp;
		tmp =  $(a).attr('photo');
		$(a).attr('photo', $(b).attr('photo') );
		$(b).attr('photo', tmp);
		
		tmp =  $(a).attr('href');
		$(a).attr('href', $(b).attr('href') );
		$(b).attr('href', tmp);
	
		tmp =  $(a).attr('title');
		$(a).attr('title', $(b).attr('title') );
		$(b).attr('title', tmp);
		
		$(a).css('background-image', 'url(/images/photo/60/'+$(a).attr('photo')+')');
		$(b).css('background-image', 'url(/images/photo/290/'+$(b).attr('photo')+')');
		
		$(b).fadeIn();
		gal_count ++;
		gal_count = gal_count % $('#gallery .el').size();
	});
	
	setTimeout(nextobject,10000);
}

function show_hint(el) {
    var offset = $(el).offset();
    $('#hint').children('span').html($(el).attr('title'));
    $('#hint').show().css({
        'top': (offset.top - $('#hint').height() - 15 ) + 'px',
        'left':( offset.left + $(el).width()/2 - $('#hint').width()/2 - 7) + 'px'
    });
}
function hide_hint(el) {
	$('#hint').hide();
}
$(function() {
	$.each($('.metalic'), function(i, item) {
		$(item).append($('<span>').addClass('gr').width($(item).width() ).height(parseInt($(item).css('font-size'))+10).css('background-position','left '+parseInt($(item).css('font-size'))/1.5 + 'px'));	
	});
	$.each($('.metalic2'), function(i, item) {
		$(item).append($('<span>').addClass('gr').width($(item).width() ).height(parseInt($(item).css('font-size'))+10).css('background-position','left '+parseInt($(item).css('font-size'))/1.1 + 'px'));	
	});
	
	$.each($('.imggroup'), function (i, item) {
		var x = $('<div>').addClass('nav');
		$(item).prepend(x);
		if ($(item).children('img').size() > 1)
		$.each($(item).children('img'), function(j, jtem) {
			var a = $('<a>').attr('href', 'javascript://').html((j+1)).appendTo(x).click(function() {
				$(item).children('img').hide();	
				$(jtem).show();
				$(item).children('.nav').children('a.active').removeClass('active');
				$(this).addClass('active');
			});
			if (j > 0) {
				$(jtem).hide();
			} else {
				$(a).addClass('active');
			}
		});
	});
	
	$.each($('#text ol'), function(j , itm) {
		$.each($(itm).children('li'), function(i , item) {
			$(item).prepend($('<span>').addClass('num').html((i+1)));	
		});
	});
	

	
	setTimeout(nextphoto,10000);
	setTimeout(nextobject,10000);
});

