$(document).ready(function() {

    //Opera overflow hack
    if ($.browser.opera) {
        $("body, html").css({'position':'absolute', 'overflowX':'auto', 'overflowY':'auto'});
        $('body').addClass('opra');
    }


    //Top menu add class
    $('.tm li:last').addClass('last');
    $('.tm a').click(function() {
        $('.tm').find('a.active').removeClass('active');
        $(this).addClass('active');

    });

    //Fast navigation
    $('.fn a').click(function() {
        $('.fn').find('a.akt').removeClass('akt');
        $(this).addClass('akt');
    });

    //Sub menu navigation
    $('.sbm .active').parent().addClass('lak');
    $('.sbm a').click(function() {
        $('.sbm').find('a.active').removeClass('active').parent().removeClass('lak');
        $(this).addClass('active').parent().addClass('lak');
    });

    //Table style
    $('.rb table').each(function() {
        $(this).wrap('<div class="rtab"></div>');
        $(this).find('tr:first').addClass('ftr');
        $(this).find('td:nth-child(1)').addClass('ltd');
        $('.ftr').each(function() {
            $(this).find('td:first').addClass('ftd');
        });

    });

    //Table style
    $('.bulin table').each(function() {
        $(this).wrap('<div class="rtab"></div>');
        $(this).find('tr:first').addClass('ftr');
        $(this).find('td:nth-child(1)').addClass('ltd');
        $('.ftr').each(function() {
            $(this).find('td:first').addClass('ftd');
        });

    });

    var currentTab = 0; // Set to a different number to start on a different tab.
    function openTab(clickedTab) {
        var thisTab = $(".tabbed-box .tabs a").index(clickedTab);
        $(".tabbed-box .tabs li a").removeClass("active");
        $(".tabbed-box .tabs li a:eq(" + thisTab + ")").addClass("active");
        $(".tabbed-box .tabbed-content").hide();
        $(".tabbed-box .tabbed-content:eq(" + thisTab + ")").show();
        currentTab = thisTab;
    }

    $(document).ready(function() {
        $(".tabbed-box .tabs li a").click(function() {
            openTab($(this));
            return false;
        });
        $(".tabbed-box .tabs li a:eq(" + currentTab + ")").click();
    });

    function getRed() {
        $('.tak').addClass('red');
    }

    function getGrey() {
        $('.tak').removeClass('red');
    }

    $('#goto').click(function() {
        getRed();

    });

    $('.mtab .tabbed-box').hover(
            function() {
                getRed();
            },
            function() {
                getGrey();
            }
            );
    $('.title span').hover(
            function() {
                getRed();
            },
            function() {
                getGrey();
            }
            );

    function miX() {
        $('.gn').fadeOut(500);
        $('.pl').fadeOut(500);
        $('.dr').fadeOut(500);
        $('.g1').fadeOut(500);
        $('.tag').fadeIn(1000);
        $('.opit').fadeIn(1000);
        $('.g2').fadeIn(1000);
    }

    $('.dr span').click(function() {
        miX();
    });

    //Modal box
    $('.vdn span').click(function() {
        $('.fixed .modal').parent().fadeIn('1000');
        return false;
    });

      //Modal box
    $('.con a').click(function() {
        $('.fixed .modal1').parent().fadeIn('1000');
        return false;
    });

         //Modal box
    $('.sert img').click(function() {
        $('.fixed .modal1').parent().fadeIn('1000');
        return false;
    });

    $('.fixed-in').click(function() {
        $('.fixed .modal').parent().fadeOut('1000');
    });

       $('.modal1').click(function() {
        $('.fixed .modal1').parent().fadeOut('1000');
    });
    $('.klz').click(function() {
        $('.fixed .modal').parent().fadeOut('1000');
    });
    $('.fixed-in').click(function() {
        $('.fixed .modal1').parent().fadeOut('1000');
    });
   

    //css resolution
    function ResizeCSS() {
        if ($('body').width() < 1100) {
            $('.tm ul li').css("margin-right", "3%");
            $('.t3').css("margin-right", "180px");
            $('.c3').css("background-position", "57px 0");
            $('.c2').css("background-position", "88px 0");
            $('#wrapper').css('padding-right', '0');
        }
        if ($('body').width() > 1100) {
            $('.c3').css("background-position", "0 0");
            $('.c2').css("background-position", "0 0");
            $('.t3').css("margin-right", "260px");
        }
        if ($('body').width() < 1200 && $('body').width() > 1100) {
            $('.tm ul li').css("margin-right", "6%");
        }
        if ($('body').width() < 1250 && $('body').width() > 1200) {
            $('.tm ul li').css("margin-right", "7%");

        }
        if ($('body').width() < 1300 && $('body').width() > 1250) {
            $('.tm ul li').css("margin-right", "8.5%");

        }
        if ($('body').width() < 1190) {
            $('#wrapper').css('padding', '0 0 0 5px');
            $('#wrapper').css('min-with', '1010px');
            $('.pp1').css('margin-left', '6px');
            $('.pp2').css('margin-right', '3px');
            $('.mtab .tabbed-box .tabs').css('width', '960px');
            $('.mtab .tabbed-box').css('width', '960px');
            $('.pl').css('margin-left', '20px');
            $('.bf').css('margin-top', '33px');
            $('.tc').css('margin-right', '5px');
            $('.opit').css('margin-left', '1%');
            $('.dr').css('margin-left', '12px');
            $('.con').css('left', '10px');
        }
        if ($('body').width() > 1190) {
            $('.tc').css('margin-right', '0');
            $('#wrapper').css('padding', '0 30px');
            $('#wrapper').css('min-with', '940px');
            $('.pp1').css('margin-left', '36px');
            $('.pp2').css('margin-right', '13px');
            $('.mtab .tabbed-box .tabs').css('width', '1000px');
            $('.mtab .tabbed-box').css('width', '1000px');
            $('.pl').css('margin-left', '80px');
            $('.opit').css('margin-left', '7%');
            $('.dr').css('margin-left', '44px');
            $('.con').css('left', '60px');
            $('.bf').css('margin-top', '105px');
        }
        if ($('body').width() < 1300) {

        }
        if ($('body').width() > 1300) {
            $('.tm ul li').css("margin-right", "9%");

        }
        if ($('body').width() > 1350) {
            $('.tm ul li').css("margin-right", "9.5%");

        }
        if ($('body').width() > 1380) {
            $('.tm ul li').css("margin-right", "10.5%");
        }
    }

    ResizeCSS();
    $(window).resize(function() {
        ResizeCSS();
    });

    for (var i = 0; i < $('.drab ul li a').length; i++) {
        $('.drab ul li a').eq('' + i + '').addClass('li-' + i + '');
    }

    for (var b = 0; b < $('.dseb ul li a').length; b++) {
        $('.dseb ul li a').eq('' + b + '').addClass('il-' + b + '');
    }

    $('.drab a').click(function() {
        $('.drab').find('.active').removeClass('active');
        $(this).parent().addClass('active');

    });


    $('.read').click(function() {
        if ($(this).parent().hasClass('closed')) {
            $('.rilz .lr4').removeClass('opened').addClass('closed').next().next().slideUp(400);
            $(this).parent().removeClass('closed').addClass('opened');
            $(this).parent().next().next().slideDown(400);

        }
        else if ($(this).parent().hasClass('opened')) {
            $(this).parent().removeClass('opened').addClass('closed');
            $(this).parent().next().next().slideUp(400);
            $('.rilz .closed');
        }
    });


    $('.project').next().addClass('nzt');

    $('.opacity').css('opacity', '0.6');




     $('.pj img').click(function() {

        if ($(this).hasClass('bigg')) {
              $(this).attr('width', '133');
                $(this).attr('height', '185');
                $(this).removeClass('bigg');
                $(this).addClass('bigg1');




        }
         else if ($(this).hasClass('bigg1')) {
                $(this).parent().parent().find('.bigg').attr('height', '185');
                $(this).parent().parent().find('.bigg').attr('width', '133');
                $(this).parent().parent().find('.bigg').removeClass('bigg').addClass('bigg1');
                $(this).attr('width', '600');
                $(this).removeAttr('height');
                $(this).addClass('bigg');
                $(this).removeClass('bigg1');


        }


    });

    if ($.browser.msie && $.browser.version == "6.0") {
        if ($.cookie('ieshown') == null) {
            $('#upie6').show();
        }

        else if ($.cookie('ieshown') == 'true') {
            $('#upie6').hide();
        }

        $('.clox').click(function() {
            $.cookie('ieshown', 'true', { expires: 3 });
            $('#upie6').hide();
        });

        $('#upie6 a').click(function() {
            $.cookie('ieshown', 'true', { expires: 3 });
            $('#upie6').hide();
        });
    }

    if ($('div').hasClass('forma')) {

        //Clear form input on focus
        $('textarea').clearOnFocus();
        $('input:text').clearOnFocus();
    }
});
