//
// jResizer 2.0
// unobtrusive resizing of font sizes and line heights
// vm @ Sonce.net
//
// Change only config options here
//

var ContentBoxId       = 'resizable_text';      // ID elementa z vsebino
var FontResizeButton   = 't-fontsize';          // ID gumba za povecavo teksta
var LineHeightButton   = 't-fontsize';	        // ID gumba za povecavo razmaka med vrsticami
var PrintButton        = 't-print';          	// ID gumba za tiskanje
var FontCssSizeUnits   = 'px';                  // Enota za velikost pisave (px ali em)
var LineCssSizeUnits   = 'px';                  // Enota za razmak vrstic (px ali em)
var UniqueCookieName   = 'frutek';      		// Unikatno ime za piskotke tega site-a
var AllFontSizes       = Array(13, 14, 16);     // Seznam velikosti pisav - prva se nastavi sama
var AllLineHeights     = Array(16, 18, 20);     // Seznam razmakov vrstic - prva se nastavi sama

//
// jQuery Cookie implementation
//

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

//
// Array Prototype implementation
//

Array.prototype.indexOf = function(a) {
	for (var i in this) {
		if (this[i]==a) {
			return i;
		}
	} 
	return false;
}

//
// Text resizing and line height functions
//

$(document).ready(function(){

	// Font resize
	if($.cookie('fontsize_' + UniqueCookieName) == null) {
		$.cookie('fontsize_' + UniqueCookieName, AllFontSizes[0], { expires: 7, path: '/', domain: '', secure: false });
		$('.' + ContentBoxId).css({
			'font-size': AllFontSizes[0] + FontCssSizeUnits
		});
	} else {
		$('.' + ContentBoxId).css({
			'font-size': $.cookie('fontsize_' + UniqueCookieName) + FontCssSizeUnits
		});
	}
	
	$('#' + FontResizeButton).click(function(){
		var CurrentFontSize = parseFloat(AllFontSizes.indexOf($.cookie('fontsize_' + UniqueCookieName))) + parseFloat(1);
		if(CurrentFontSize == AllFontSizes.length) {
			NewFontSize = AllFontSizes[0];
		} else {
			NewFontSize = AllFontSizes[CurrentFontSize];
		}
		$.cookie('fontsize_' + UniqueCookieName, NewFontSize, { expires: 7, path: '/', domain: '', secure: false });
		$('.' + ContentBoxId).css({
			'font-size': NewFontSize + FontCssSizeUnits
		});
		return false;
	});
	
	// Change line height
	/*
	if($.cookie('lineheight_' + UniqueCookieName) == null) {
		$.cookie('lineheight_' + UniqueCookieName, AllLineHeights[0], { expires: 7, path: '/', domain: '', secure: false });
		$('.' + ContentBoxId).css({
			'line-height': AllLineHeights[0] + LineCssSizeUnits
		});
	} else {
		$('.' + ContentBoxId).css({
			'line-height': $.cookie('lineheight_' + UniqueCookieName) + LineCssSizeUnits
		});
	}
	
	$('#' + LineHeightButton).click(function(){
		var CurrentLineHeight = parseFloat(AllLineHeights.indexOf($.cookie('lineheight_' + UniqueCookieName))) + parseFloat(1);
		if(CurrentLineHeight == AllLineHeights.length) {
			NewLineHeight = AllLineHeights[0];
		} else {
			NewLineHeight = AllLineHeights[CurrentLineHeight];
		}
		$.cookie('lineheight_' + UniqueCookieName, NewLineHeight, { expires: 7, path: '/', domain: '', secure: false });
		$('.' + ContentBoxId).css({
			'line-height': NewLineHeight + LineCssSizeUnits
		});
		return false;
	});
	*/
	// Print
	
	$('#' + PrintButton).click(function(){
		print();
		return false;
	});
	

});
