$(document).ready(function() {
    if($.browser.msie){ 
        var ie = 1;
        var userAgent = $.browser.version;
        var userAgent = userAgent.substring(0,userAgent.indexOf('.'));
        version = userAgent;

        if(version <= 6){
            var old_ie = 1;
        }
    } 

    $("a[rel=gallery]").fancybox({
        'titleShow'     : false,
        'transitionIn'  : 'elastic',
        'transitionOut' : 'elastic'
    });
    
    $('.content__project_item').hover(
        function () {
            $(this).animate({borderColor: '#E68319'});
            $(this).children('img').fadeTo('50', '1');
            $(this).children('.content__project_item_details').fadeIn();
            $(".info").tipTip({defaultPosition: 'left', maxWidth: "350px"});
        },
        function () {
            $(this).animate({borderColor: '#CBCBC9'});
            $(this).children('img').fadeTo('50', '0.7');
            $(this).children('.content__project_item_details').fadeOut();
        }
    );
    $('#content__bottom button').hover(
        function () {
            $(this).animate({color: '#E68319'}, 150);
        },
        function () {
            $(this).animate({color: '#575656'}, 150);
        }
    );
    $('#header__contact_email').hover(
        function () {
            $(this).children('img').fadeIn();
        },
        function () {
            $(this).children('img').fadeOut();
        }
    );
    $('#header__contact_phone').hover(
        function () {
            $(this).children('img').fadeIn();
        },
        function () {
            $(this).children('img').fadeOut();
        }
    );
    $('#header__lang div').hover(
        function () {
            $(this).fadeTo('50', '1');
        },
        function () {
            if($(this).hasClass('active')){}else{
                $(this).fadeTo('50', '0.5');
            }
        }
    ); 
    $('#header__lang div').click(
        function () {
            $.cookie('lang', $(this).attr('id'));
            window.location.reload();
        }
    ); 
    $('#content__bottom button').click(function () {
        var item_count = $('.content__project_item').size();
        var item_tmp = 0;
        for(var i=0;i<item_count;i++){
            if($('#'+(item_count-i)).css('display') == 'none' && item_tmp < 4){
                $('#'+(item_count-i)).fadeIn();
                item_tmp++;
            }
        }    
        if($('#1').css('display') !== 'none'){
            $('#content__bottom button').remove();
        }
    });
    if(ie !== 1){
        $('#footer__contact').hover(
            function () {
                $('#footer__contact_arrow').fadeTo('50', '1');
            },
            function () {
                $('#footer__contact_arrow').fadeTo('50', '0');
            }
        );
    }    
    
    var email_anchor = $("a#e-mail").html();
    if(email_anchor === null){}else{
        email_anchor = email_anchor.replace('#','@');
        email_anchor = email_anchor.replace(/_/g,'.');
        $("a#e-mail").html(email_anchor);
    }

    var email = $("a#e-mail").attr("href");
    if(email === undefined){}else{
        email = email.replace('#','@');
        email = email.replace(/_/g,'.');
        $("a#e-mail").attr("href", email);
    }
    
    var phone = $("a#phone").html();
    if(phone === null){}else{
        phone = phone.replace('___-___-___','790-837-774');
        $("a#phone").html(phone);
    }
});
