﻿/*
	
-------notes--------
	
AUTHOR		Teresa Hurley tree@beingtree.com
DATE				6/16/09
		
based on...: Nicuşor Cheleş http://nicusor.com/programming-stuff/javascript-text-resize-with-cookie/
but i used jquery.
		
-------/notes--------
		
*/
// this should be off when live; only turned on when i need it for testing....
var mycookies = Array("textsizestyle", "lineheightstyle", "headsizestyle", "headlineheightstyle", "bylinesizestyle", "bylinelineheightstyle");
for (i = 0; i < mycookies.length; i++) {
    deleteCookie(mycookies[i], "127.0.0.1");
}
// this deletes the cookie when called
function deleteCookie(name, path) {
    if (readCookie(name)) {
        createCookie(name, '', 0)
    }
}


var textsize = 11;
var lineheight = 17;
var headsize = 22;
var headlineheight = 24;
var bylinesize = 9;
var bylinelineheight = 11;


$(document).ready(function () {
    var text_size_cookie = readCookie("textsizestyle");
    var head_size_cookie = readCookie("headsizestyle");
    var byline_size_cookie = readCookie("bylinesizestyle");
    var line_height_cookie = readCookie("lineheightstyle");
    var byline_line_height_cookie = readCookie("bylinelineheightstyle");

    if (text_size_cookie && head_size_cookie && byline_size_cookie && line_height_cookie && head_line_height_cookie && head_line_height_cookie && byline_line_height_cookie) {
        textsize = text_size_cookie;
        headsize = head_size_cookie;
        bylinesize = byline_size_cookie;
        lineheight = line_height_cookie;
        headlineheight = head_line_height_cookie;
        bylinelineheight = byline_line_height_cookie1;

        new_size = Array(textsize, lineheight, headsize, headlineheight, bylinesize, bylinelineheight);
        fsize(new_size, 'px');
    }


    /* putting this back in the html markup.... why does it need to be in the js? mixes things up
    $('#search_text').append(
    '<div id="text"> \
    <p id="increase" rel="1" title="Increase Text Size"><em>+</em></p>\
    <p id="reduce" rel="0" title="Reduce Text Size"><em>-</em></p>\
    </div>'
    );
    */
    $('#resizer p').click(function () {
        var up = $(this).attr('rel')
        changetextsize(up);
        fsize(new_size, "px");

    });
});



function changetextsize(up) {
    if (up == 1) {
        textsize = parseFloat(textsize) + 2;
        lineheight = parseFloat(lineheight) + 2;
        headsize = parseFloat(headsize) + 2;
        headlineheight = parseFloat(headlineheight) + 2;
        bylinesize = parseFloat(bylinesize) + 2;
        bylinelineheight = parseFloat(bylinelineheight) + 2;
    } else {
        textsize = parseFloat(textsize) - 2;
        lineheight = parseFloat(lineheight) - 2;
        headsize = parseFloat(headsize) - 2;
        headlineheight = parseFloat(headlineheight) - 2;
        bylinesize = parseFloat(bylinesize) - 2;
        bylinelineheight = parseFloat(bylinelineheight) - 2;
    }
    new_size = Array(textsize, lineheight, headsize, headlineheight, bylinesize, bylinelineheight);
    return new_size;
}

function fsize(size, unit) {
    $('.content_wrapper p, .content_wrapper td, .content_wrapper input, .content_wrapper li, .content_left_blog_tag_header span, .index_content_wrapper p, .index_content_wrapper td, .index_content_wrapper input, .index_content_wrapper li').css({
        'font-size': size[0] + unit,
        'line-height': size[1] + unit
    });
    $('.content_left_headline, .content_left_headline a').css({
        'font-size': size[2] + unit,
        'line-height': size[3] + unit
    });
    $('.content_left_byline').css({
        'font-size': size[4] + unit,
        'line-height': size[5] + unit
    });
    createCookie("textsizestyle", size[0], 365);
    createCookie("lineheightstyle", size[1], 365);
    createCookie("headsizestyle", size[2], 365);
    createCookie("headlineheightstyle", size[3], 365);
    createCookie("bylinesizestyle", size[4], 365);
    createCookie("bylinelineheightstyle", size[5], 365);

}

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;
}


//****FUNCTIONS TO CLEAR OR FILL DEFAULT TEXT FOR TEXT BOXES ******//
function ClearText(TextBoxID, DefaultText) {
    var CurrentText = document.getElementById(TextBoxID).value;
    if (CurrentText == DefaultText) {
        document.getElementById(TextBoxID).value = '';
        document.getElementById(TextBoxID).focus();
    }
}

function FillText(TextBoxID, DefaultText) {
    var CurrentText = document.getElementById(TextBoxID).value;
    if (CurrentText == '')
        document.getElementById(TextBoxID).value = DefaultText;
}
 
 
  
  

