$(function() {
    var basedir = '/';
    $('#admin-left #pdf-viewer').gdocsViewer({width: "100%", height: "930px"});
    $('#text #pdf-viewer').gdocsViewer({width: "756px", height: "1050px"});
//    function pulsate() {
//        $('.left-menu-eshop img').animate({width: '50px', height: '50px', top: '0px', right: '50px'}, 500, 'swing').animate({width: '40px', height: '40px', top: '0px', right: '50px'}, 1500, 'swing', pulsate);
//    }
//    pulsate();
    var li_num = $('#content-menu ul > li').length;
    var li_width = Math.round((100 / li_num));
    $('#content-menu ul > li').each(function() {
        $(this).attr('style', 'width: ' + li_width + '%');
    });
    if (li_num * li_width == 100) $('#content-menu ul > li:first-child').attr('style', 'width: ' + (li_width - 2) + '%');
    $('#content-menu li[rel=drop] ol').hover(function() {
        $('#content-menu li[rel=drop] ol').show();
    }, function() {
        $('#content-menu li[rel=drop] ol').hide();
    });        
    $('#content-menu li[rel=drop] a').hover(function() {
        $('#content-menu li[rel=drop] ol').show();
    }, function() {
        $('#content-menu li[rel=drop] ol').hide();
    });
    $('#content-menu li[rel=video] a').click(function() {
        $('#content-video').fixedCenter().css('opacity', '0.9').show();
    });
    $('#content-video span').click(function() {
        $('#content-video').hide();
    });
    $('#content-menu li[rel=video]').append('<li class="eshop-label"><a href="' + basedir + 'eshop/" onclick="window.open(this.href, \'_blank\'); return false;"><img src="' + basedir + 'images/eshop.png" alt="" /></a></li>');
    $('.contacts td:nth-child(1)').css({'width' : '240px', 'font-weight' : 'bold'});
    $('.contacts td:nth-child(2)').css('width', '200px');
    $('.contacts td:nth-child(3)').css('width', '100px');
    $('.contacts td:nth-child(4)').css('width', '100px');
    $('.contacts tr:even td').css('border-bottom', '1px dotted black');
    $('.contacts tr:odd td').css('border-bottom', '1px dotted black');
    jQuery.fn.mailToLink = function() {
        var regEx = /(\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)/;
        return this.filter(function() {
            return $(this).html().match(regEx);
        }).each(function() {
            $(this).html($(this).html().replace(regEx, "<a href=\"mailto:$1\">$1</a>"));
        });
    }
    $('.contacts td:nth-child(2)').mailToLink();
//    var regEx = /(\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)/;
//    $(".contacts td:nth-child(2)").filter(function() {
//        return $(this).html().match(regEx);
//    }).each(function() {
//        $(this).html($(this).html().replace(regEx, "<a href=\"mailto:$1\">$1</a>"));
//    });
	$('#content #text a[class^="nabytek-"]').each(function() {   
		var a_rel = $(this);
		var a_class = a_rel.attr('class');
		a_rel.attr('rel', a_class);
	});	
	$('#content #text a[class=nabytek]').fancybox({'titlePosition' : 'over'});
	$('#content #text a[rel]').fancybox({'titlePosition' : 'over'});	
});	

