function fixDiffs()
{
    $('#articles div.item.right').each(function () {
        var $this = $(this);
        var $prev = $this.prev('div.item:first');
        
        if ($this.height() != $prev.height())
        {
            var diff = Math.abs($this.height() - $prev.height());
            
            if ($this.height() > $prev.height())
            {
                $prev.find('p.perex').css('margin-top',5 + diff + 'px');   //5 - default
            }
            else
            {
                $this.find('p.perex').css('margin-top',5 + diff + 'px');   //5 - default
            }
        }//if ($this.height() != $prev.height())
    });
}//fixDiffs

function initToggler()
{
    $('#toggleBtn').click(function () {
        var $this   = $(this);
    
        if ($this.is('.hide'))
        {
            $('#comments').hide();
        
            initContRight();
        
            $this.text('show comments')
            .removeClass('hide').addClass('show');
        }//if ($this.is('.hide'))
        else
        {
            $('#comments').show();
        
            initContRight();
        
            $this.text('hide comments')
            .removeClass('show').addClass('hide');
        }//else
    });
}//initToggler

function initSocialIcons()
{
    $('#other-contacts ul li a').each(function () {
        var $this   = $(this);
        
        var reg     = new RegExp('\.([a-zA-Z0-9]{2,4})$');
        
        var src     = $this.children('img').attr('src');
        var srcHvr  = src.replace(reg,'h.$1');
        
        $this.data('img',src);
        $this.data('imgHover',srcHvr);
    });

    //

    $('#other-contacts ul li a').hover(function () {
        var $this   = $(this);
        
        $this.children('img').attr('src',$this.data('imgHover'));
    },function () {
        var $this   = $(this);
        
        $this.children('img').attr('src',$this.data('img'));
    });
}//initSocialIcons

function initProjects()
{
    $('#projects ul li a').each(function () {
        var $this   = $(this);
        
        var reg     = new RegExp('\.([a-zA-Z0-9]{2,4})$');
        
        var src     = $this.children('img').attr('src');
        var srcHvr  = src.replace(reg,'h.$1');
        
        $this.data('img',src);
        $this.data('imgHover',srcHvr);
    });

    //

    $('#projects ul li a').hover(function () {
        var $this   = $(this);
        
        $this.children('img').attr('src',$this.data('imgHover'));
    },function () {
        var $this   = $(this);
        
        $this.children('img').attr('src',$this.data('img'));
    });
}//initProjects

//

function initContRight()
{
    var crPos       = getAbsPos($('#cont-right').get(0));
    var footPos     = getAbsPos($('#footer').get(0));
    
    var crBottom    = crPos.Top + $('#cont-right').height();
    
    //
    
    if ((crBottom > footPos.Top - 50) && (crBottom < footPos.Top + 30))     //to fit the last magpie
    {
        var pos = getAbsPos($('#cont').get(0));
    
        $('#cont-right').css('height',footPos.Top + 30 + 'px');
    }//if ((crBottom > footPos - 50) && ( ...
    
    //
    
    $('#page').css('min-height',$('#cont-right').height() - $('#footer').height() + 30 + 'px');
    
    //
    
    var lol = setTimeout(setBottomMagpie,1);
}//initContRight

function setBottomMagpie()
{
    var footPos = getAbsPos($('#footer').get(0));
    
    $('#cont-right > div.magpie-bottom').css({
        top: footPos.Top - 42
    }).show();
}//setBottomMagpie

function initLayout()
{
    var height  = $('#logo').height();

    $('#logo').animate({top: '27px'},1000,'easeOutBounce');

    //
    
    $(window).resize(function () {
        initContRight();
    });
}//initLayout

//

function initForms()
{
    $('input[type="text"]').each(function () {
        var $this = $(this);
        
        $this.data('defaultVal',$this.val());
    });
    
    //
    
    $('input[type="text"]').focus(function () {
        var $this = $(this);
    
        if ($this.val() == $this.data('defaultVal'))
        {
            $this.val('');
        }
    });
    
    $('input[type="text"]').blur(function () {
        var $this = $(this);
    
        if ($.trim($this.val()) == '')
        {
            $this.val($this.data('defaultVal'));
        }
    });
}//initForms

//
//
//

function getAbsPos(elem)
{
    var end  = false;
    var prnt = elem;
    var x    = 0;
    var y    = 0;
    
    while (!end)
    {
        if (prnt != null)
        {
            if (prnt.offsetLeft)
            {
                x += prnt.offsetLeft;
            }
            
            if (prnt.offsetTop)
            {
                y  += prnt.offsetTop;
            }
        
            prnt = prnt.offsetParent;
        }
        else
        {
            break;
        }
    }//while
    
    return {Left: x, Top: y};
}//getAbsPos

function AJAXRequest(params,script,callback)
{
    var XMLHttpRequestObject = false;
            
    try
    {
        XMLHttpRequestObject = new ActiveXObject("MSXML2.XMLHTTP");
    }
    catch (e1)
    {
        try
        {
            XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e2)
        {
            XMLHttpRequestObject = false;
        }
    }//catch
    
    if ((!XMLHttpRequestObject) && (window.XMLHttpRequest))
    {
        XMLHttpRequestObject = new XMLHttpRequest();
    }

    if (XMLHttpRequestObject)
    {
        XMLHttpRequestObject.open('POST',script,true);
        XMLHttpRequestObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        
        XMLHttpRequestObject.onreadystatechange = function()
        {
            if ((XMLHttpRequestObject.readyState == 4) && (XMLHttpRequestObject.status == 200))
            {
                if (typeof(callback) == 'function')
                {
                    callback(XMLHttpRequestObject.responseXML);
                } 
            }//if ((XMLHttpRequestObject.readyState == 4) ...
        }
        
        XMLHttpRequestObject.send(params);
    }//if (XMLHttpRequestObject)
}//AJAXRequest

function postValMakeUp(val)
{
    val = String(val);

    val = encodeURIComponent(val);

    return val;
}//postValMakeUp