var selectedFont = 'wooriSoyoung';
var fontSizeLimit = {
    'wooriDotum' : 7,
    'wooriDotum90c1' : 9,
    'wooriDotum90c2' : 9,
    'wooriBatang' : 8,
    'wooriSaebom' : 8,
    'wooriSinmoon' : 8,
    'wooriSoyoung' : 8
}
$(function() {

        $('.ms_font a').click(function() {
            $('.ms_font li[class=selected]').removeClass('selected');
            $(this).parent().addClass('selected');
            $('#ms-area').css('fontFamily', $(this).text().substr(3)); 
            return false;
        })
        
        $('div.entry:first a').click(function() {
            currentSize = $('div.entry textarea').css('fontSize');
            fontSize = returnPt(currentSize);
            symbol = $(this).attr('title')
            if(fontSize <= fontSizeLimit[selectedFont] && symbol == '-')
                return false;
            changeTargetSize('div.entry textarea', symbol);
            areaSize = $('div.entry textarea').css('fontSize');
            $(this).parent().siblings('h4').find('span').text(' '+areaSize);
            return false
        });

        $('#zoom_in').click(function() {
            changeTargetSize('body', '+');
            return false;
        });
        $('#zoom_out').click(function() {
            currentSize = returnPt($('body').css('fontSize'));
            if(currentSize <= 8)
                return false;
            changeTargetSize('body', '-');
            return false;
        });

        $('#sidebar ul a').click(function() {
            $('#sidebar ul li[class*=selected]').removeClass('selected');
            $(this).parent().addClass('selected');
            selectedFont = $(this).attr('title');
            $('#woori-title').css('fontFamily', selectedFont);
            $('#woori-area').css('fontFamily', selectedFont);
            $('div.entry textarea').css('fontSize', '12pt');
            $('div.entrytitle h4 span').text('12pt')
            $('#font-info').html($('#'+selectedFont).html()); 
            setGoSizePage();
            return false;
            });


        setGoSizePage();
        setInterval('synchro()', 1000);

        if(predefined) {
            $('a[title='+predefined+']').click();
        }
    });


function changeTargetSize(target, symbol) {
    currentValue = $(target).css('fontSize');
    fontSize = returnPt(currentValue);
    newSize = (symbol == '+' ? ++fontSize : --fontSize) + 'pt';
    $(target).css('fontSize', newSize);
}

function synchro() {
    $('#ms-area').val($('#woori-area').val());
}
        
function setGoSizePage() {
    $('#font-info .more_size').click(function() {
            window.open('per_size.php', 'persize'+selectedFont, 'width=770,height=800,scrollbars=yes');
            return false;
            });
}

function returnPt(currentValue) {
    fontSize = parseInt(currentValue);
    unit = currentValue.substr(fontSize.toString().length);
    if(unit == 'px') {
        fontSize = Math.round(fontSize/1.3);
    }
    return fontSize;
}
