var g_aFadeAbleTmp = new Array();

$(document).ready(function()
{
   $('.fadeAble').focus(function(){
      if(!g_aFadeAbleTmp[$(this).attr('name')] || $(this).val() == g_aFadeAbleTmp[$(this).attr('name')])
      {
		  g_aFadeAbleTmp[$(this).attr('name')] = $(this).val();
         $(this).attr('value', '');
         //g_aFadeAbleTmp[$(this).attr('name')] = true;
      }
   });
   
   $('.fadeAble').blur(function(){
      if(g_aFadeAbleTmp[$(this).attr('name')] && $(this).attr('value') == '')
      {
         $(this).attr('value', g_aFadeAbleTmp[$(this).attr('name')]);
      }
   });
}
);


/// ---

/**
 * sprawdza czy przegladarka klienta jest internet explorer
 * @param int minVersion - minimalna akceptowalna wersja
 * @return bool
 */
function clientIsIe(minVersion)
{
   var isIe = (navigator.appName.search(/microsoft/i) > -1);
   var versionMatch = true;
   
   if(isIe && typeof minVersion == 'number')
      {
         var regexp = /MSIE [0-9]+/gi;
         vesrionMatch = regexp.exec(navigator.appVersion);
         versionMatch = String(vesrionMatch).substr(5);
         versionMatch = (versionMatch >= minVersion);
         
         return versionMatch;
      }
   
   return isIe;
}

/**
 * @param mixed mixData in - dane do debugu
 */
var _auDebug = function(mixData)
{
   if(typeof console == 'function' || typeof console == 'object')
      console.log(mixData);
   
   return true;
}
/**
 * Get the value of a cookie with the given key.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String key The key 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 (key, value, options) {
    
    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }
        
        value = String(value);
        
        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

// eof jquery cookie

function alternativeSheet(strSrc){
    
    var that = this;
    
    this.bActive = false;
    
    /**
     * @param string strSheetSrc - link do arkusza
     */
    this.strSheetSrc = strSrc;
    
    this.strCookieName = 'bAlternativeSheet';
    
    var getCookieVar = function(){
        // --- ---
        
        var ret = $.cookie(that.strCookieName);
		
		//console.log( ret );
		//console.log( typeof ret );
		//console.log('pobralem '+ret);
		if( ret ){
			return (ret == 'true');
		}else{
			return null;
		}
    }
    
    var saveToCookie = function(){
        /*var iWazneDni = 30;
        
        var date = new Date();
        date.setTime(date.getTime()+(iWazneDni*24*60*60*1000));
        
        var strWaznosc = "; expires="+date.toGMTString();
        
        document.cookie = name+"="+value+strWaznosc+"; path=/";*/
        $.cookie(that.strCookieName, that.bActive);
    }
    
    this.valueSwitch = function(){
        this.bActive = !(this.bActive =='true' || this.bActive === true);
        this.refresh();
        saveToCookie();
		
    }
    
    this.refresh = function(){
        if(this.bActive){
            $('link[title]').attr('rel', 'stylesheet');
        }else{
            $('link[title]').attr('rel', 'alternate')
        }
		
		
		g_preventFlashHeader = this.bActive;
    }
    
    var loadDefault = function(){
        /*var cookieVar = getCookieVar();
        if( cookieVar != undefined )
            that.bActive = cookieVar;*/
        //console.log(typeof getCookieVar() );
		if( typeof getCookieVar() == 'boolean' ){
			that.bActive = getCookieVar();
			//console.log('okej: '+that.bActive);
		}
		that.refresh();
		saveToCookie();
    }
    
    loadDefault();
}

var g_preventFlashHeader = false;

var g_easyReadMode = null;
$(document).ready(function(){
	g_easyReadMode = new alternativeSheet('css/easyToRead.css');
});
