if(window.location.href.match(/works\.html/)) {
    var section = 0;
    var page = 0;
    function buildPaginator(page) {
        var html = '';
        if (pages[page] > 1) {
            html += '<a href="#" class="active" onclick="changePage(this, 0);return false;">01</a>';
            for (var i = 1; i < pages[page]; i++) {
                html += '<a href="#" onclick="changePage(this, ' + i + ');return false;">' + (i < 9 ? '0' + (i+1) : (i+1)) + '</a>';
            }
        }
        $('div.projects div.paginator').html(html);
        
        return true;
    }
    function changePage(el, id) {
        var left = 0;
        for(var i=0;i<section;i++) {
            left+=pages[section];
        }
        left+=id;
        $('div.projects div.cont').animate({
            marginLeft:-$('div.projects')[0].offsetWidth*left+'px'
        },500);
        $('div.projects div.paginator a').removeClass('active');
        $(el).addClass('active');
        
        return true;
    }
    
    $(document).ready(function() {
        var a = $('ul.whatwedo ul a');
        var left = 0;
        for (var i = 0; i < a.length; i++) {
            a[i].i = i;
            a[i].left = left;
            left+=pages[i];
        }
        $(a).click(function() {
            $('ul.whatwedo ul a').removeClass('active');
            $(this).addClass('active');
            $('div.projects div.cont').animate({
                marginLeft:-$('div.projects')[0].offsetWidth*this.left+'px'
            },1000);
            section = this.i;
            page = 0;
            buildPaginator(section);
            
            return false;
        });
    });
}
if(window.location.href.match(/contacts\.html/)) {
    $(document).ready(function(){
        $('textarea').focus(function() {
            if(typeof this.init == 'undefined') this.init = this.innerHTML;
            if(this.init == this.innerHTML) this.innerHTML = ''; 
        });
        $('textarea').blur(function() {
            if(this.innerHTML == '') this.innerHTML = this.init; 
        });
    });
}
if (window.location.href.match(/pages\//)) {
    $(document).ready(function() {
        var a = $('div.quick a');
        for (var i = 0; i < a.length; i++) {
            a[i].i = i;
        }
        $(a).click(function() {
            $('div.quick a').removeClass('active');
            $(this).addClass('active');
            $('ul.posts').animate({
                left: -100*this.i-17 + '%'
            }, 750);
            
            return false;
        });
    });
}
if (window.location.href.match(/works\//)) {
    $(document).ready(function(){
        try {
            $(document).keypress(function(e) {
                var c = e.ctrlKey;
                if(c && e.keyCode == 37) {
                    window.location.href = $('li.prev a')[0].href;
                }
                if(c && e.keyCode == 38) {
                    window.location.href = $('li.up a')[0].href;
                }
                if(c && e.keyCode == 39) {
                    window.location.href = $('li.next a')[0].href;
                }
            });
        } 
        catch (e) {
        }
    });
}
function checkContactForm(el) {
    var form = el.parentNode;
    var error = '';
    if(form.type.value == -1) error+=lang[0]+"\n";
    if(form.budget.value == -1) error+=lang[1]+"\n";
    if(!form.name.value) error+=lang[2]+"\n";
    if(!form.company.value) error+=lang[3]+"\n";
    if(!form.mail.value) error+=lang[4]+"\n";
    if(!form.phone.value) error+=lang[5]+"\n";
    if(!form.captcha.value) error+=lang[6]+"\n";
    if(error) alert(error);
    else form.submit();
}

function checkCommentForm(el) {
    var form = el.parentNode;
    var error = '';
    if(!form.mail.value) error+=lang[0]+"\n";
    if(!form.comment.value) error+=lang[1]+"\n";
    if(!form.captcha.value) error+=lang[2]+"\n";
    if(error) alert(error);
    else form.submit();
}