$(document).ready(function(){
    var textResizer = '<!--  Text resize --><div id="text-resize"><a id="text-resize-small" class="text-resize-button" href="#"><span class="access">Make text smaller</span>A-</a><a id="text-resize-reset" class="text-resize-button" href="#"><span class="access">Make text smaller</span>A</a><a id="text-resize-large" class="text-resize-button" href="#"><span class="access">Make text smaller</span>A+</a><div id="text-resizer-label">Text resizer</div></div>';
    if($('#sidebar').length > 0){
		$(textResizer)
		.hide()
		.prependTo('#sidebar')
		.slideDown('slow', textResizeControls('text-resize-'));
    } else if ($('#section-content').css('width').substr(0, $('#section-content').css('width').length-2)>900){
        $(textResizer)
		.hide()
		.prependTo('#content')
		.slideDown('slow', textResizeControls('text-resize-'));
    } else {
    $('#footer').before('<div id="sidebar"></div>');
        $(textResizer)
		.hide()
		.prependTo('#sidebar')
		.slideDown('slow', textResizeControls('text-resize-'));

    }

})


//Check if the page is in the preview screen then hide the save and save & exit button
$(document).ready(function(){
      var url = top.location.href; 
      if(url.indexOf("members-area") != -1 ) 
      {    	
    	 $("#metadata").remove();
         $("#tagging").remove();
         $("#dependants").remove();
       };
})




/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
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;
    }
};



function textResizeControls(targetClass){

    // if cookie exists, load saved value
    var $cookie_name = "DiabetesNZFontSize";
    
    if($.cookie($cookie_name)) {
      var $getSize = $.cookie($cookie_name);
      $("div#content").css({fontSize : $getSize + ($getSize.indexOf("px")!=-1 ? "" : "px")}); // IE fix for double "pxpx" error 
    } else {
      $("div#content").css({fontSize:"11px"}); //Added as IE does not compute size if unavailable - purely a fallback mechanism really
    
    }

    // Reset Font Size
    $("#" + targetClass + "reset").click(function(){
      $("div#content").animate({"fontSize": "11"}, 500);
      $.cookie($cookie_name, null, { path: '/' });  // delete cookie
      return false;
    });
    
    // Decrease Font Size
    $("#" + targetClass + "small").click(function(){
      var currentFontSize = $("div#content").css("font-size");
      var currentFontSizeNum = parseFloat(currentFontSize, 10);
      var newFontSize = currentFontSizeNum*0.8;
      if (newFontSize, 11) {
        $("div#content").animate({"fontSize": newFontSize}, 500);
        $.cookie($cookie_name, newFontSize, { path: '/' });
      }
      return false;
    });

    // Increase Font Size
    $("#" + targetClass + "large").click(function(){
      var currentFontSize = $("div#content").css("font-size");
      var currentFontSizeNum = parseFloat(currentFontSize, 10);
      var newFontSize = currentFontSizeNum*1.2;
      if (newFontSize, 11) {
        $("div#content").animate({"fontSize": newFontSize}, 500);
        $.cookie($cookie_name, newFontSize, { path: '/' });
      }
      return false;
    });

}
