var fontSize = '';
var fontSizeCookieName = 'orlenlietuva_font_size';

function changeFontSize(newSize) {

    var elements = new Array();
    elements.push(
		'.content .news h3.newsTitle, h3.pdf-login, .content .news2 h3.newsTitle, .newsList .oneNews h3.title, .newsList .oneNews h3.title a',
		'.oneColumn.date, .dateAndCategory, .content .news h4.newsDateAndCategory, .content .news2 h4.newsDateAndCategory, table.tableLight td, table.tableLight th, table.tableFull td, table.tableFull th, table.ms-rteTable-OrlenLight td, table.ms-rteTable-OrlenLight th, table.ms-rteTable-OrlenFull td, table.ms-rteTable-OrlenFull th, #TableJobs table td, #TableJobs table th, #tradeContactQueryControl .regulationChb label, .newsList .oneNews .date, .investorRelationsContact .chbRegulation .label, .investorRelationsContact .addInfo, .pressCenterVideoConferences .list .date',
		'.gallery_list .header, .box220 .content p, .oneColumn .box h4, .oneColumn, .oneColumn span, .oneColumn .neotablerow1, .oneColumn .neotablehead, .oneColumn li, .oneColumn p, .oneColumn.title, .oneColumn.teaser, .newsContent p, .content .news p, .content .news2 p, #leftNavigation a, .newsPage .newsContent, .newsPage .newsContent p, .mainContentThin, .mainContentThin p, .mainContentWide, .mainContentWide p, .mainPage, .sideBox .content h4, .sideBox .contentGray h4, .sideBox .content, .carrerPage, .SA-F0, .SA-F1, .SA-F2, .SA-F3, .SA-F4, .SA-F5, #JDescContent h4, table.produkty a, .ms-WPBody, .ms-WPBody td, .newsList .oneNews .teaser, .pressCenterVideoConferences .mainVideoDesc, .pressCenterVideoConferences .list .desc, .latestVideoConferences .list .titleAndDate, .latestVideoConferences .list .titleAndDate a, #infoGate .linkList a',
		'table.tableLight tr.hdRow *, table.tableFull tr.hdRow *, table.ms-rteTable-OrlenLight tr.ms-rteTableHeaderRow-OrlenLight *, table.ms-rteTable-OrlenFull tr.ms-rteTableHeaderRow-OrlenFull *, #TableJobs table tr.Lst-Header *, #JDescContent h5, #tradeContactQueryControl .oneLine, .latestVideoConferences .list .desc',
		'#JDescContent h3, .pressCenterVideoConferences .mainVideoTitleAndDate, .pressCenterVideoConferences .list .title, .pressCenterVideoConferences .list .title a'
	);

    var normalSizes = new Array();
    normalSizes.push(
	  '15px',
	  '10px',
	  '13px',
	  '11px',
	  '14px'
	);
    var smallSizes = new Array();
    smallSizes.push(
	  '13px',
	  '9px',
	  '11px',
	  '10px',
	  '12px'
	);
    var bigSizes = new Array();
    bigSizes.push(
	  '16px',
	  '11px',
	  '14px',
	  '12px',
	  '15px'
	);


    var boxes = new Array();
    boxes.push(
		'.box230 .content',
		'#forDriversMainPageInfoGate #infoGate .box230 .content',
		'.mainPage .box230 .content, .box220 .content'
	  );


    var smallHeights = new Array();
    smallHeights.push(
	  '90px',
	  '243px',
	  '90px'
	);
    var normalHeights = new Array();
    normalHeights.push(
	  '130px',
	  '243px',
	  '110px'
	);
    var bigHeights = new Array();
    bigHeights.push(
	  '150px',
	  '270px',
	  '120px'
	);

    var widthElements = new Array();
    widthElements.push(
		'.macroDataYearTableLabelsContainer, .macroDataQuarterTableLabelsContainer, table.macroDataYearTableLabels',
		'.macroDataYearTableContainer, .macroDataQuarterTableValuesContainer',
		'table.macroDataYearTableValues'
	  );

    var smallWidth = new Array();
    smallWidth.push(
	  '390px',
	  '320px',
	  '1000px'
	);
    var normalWidth = new Array();
    normalWidth.push(
	  '430px',
	  '280px',
	  '960px'
	);
    var bigWidth = new Array();
    bigWidth.push(
	  '465px',
	  '245px',
	  '925px'
	);


    var sizeArray, heightsArray, widthArray;

    if (fontSize != newSize) {
        fontSize = newSize;

        createCookie(fontSizeCookieName, fontSize, 7);

        switch (fontSize) {
            case 'small':
                sizeArray = smallSizes;
                heightsArray = smallHeights;
                widthArray = smallWidth;
                $j("#fontSmall").css('font-weight', 'bold');
                $j("#fontNormal").css('font-weight', 'normal');
                $j("#fontBig").css('font-weight', 'normal');
                break;
            case 'normal':
                sizeArray = normalSizes;
                heightsArray = normalHeights;
                widthArray = normalWidth;
                $j("#fontSmall").css('font-weight', 'normal');
                $j("#fontNormal").css('font-weight', 'bold');
                $j("#fontBig").css('font-weight', 'normal');
                break;
            case 'big':
                sizeArray = bigSizes;
                heightsArray = bigHeights;
                widthArray = bigWidth;
                $j("#fontSmall").css('font-weight', 'normal');
                $j("#fontNormal").css('font-weight', 'normal');
                $j("#fontBig").css('font-weight', 'bold');
                break;
        }

        for (i = 0; i < elements.length; i++) {
        	$j(elements[i]).css('font-size', sizeArray[i]);
        }
        for (i = 0; i < boxes.length; i++) {
        	$j(boxes[i]).css('height', heightsArray[i]);
        }
        for (i = 0; i < widthElements.length; i++) {
        	$j(widthElements[i]).css('width', widthArray[i]);
        }
    }
}


function checkFontSize() {
    var fontSizeCookie;
    fontSizeCookie = readCookie(fontSizeCookieName);
    if (fontSizeCookie != null) {
        if (fontSizeCookie != 'small') {
            changeFontSize(fontSizeCookie);
        }
        else {
        	$j("#fontSmall").css('font-weight', 'bold');
        }
        fontSize = fontSizeCookie;
    }
    else {
        fontSize = 'small';
        $j("#fontSmall").css('font-weight', 'bold');
        createCookie(fontSizeCookieName, fontSize, 7);
    }
}

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

