/*
*
* Global site settings
*
 */

if(document.domain == 'www-cms.dialog.pl') {
	var basePath = 'https://'+document.domain+'/';
} else {
	var basePath = 'http://'+document.domain+'/';
}


//fon size step (from -3 to 3, default 0)
var step = 0;

//text resize functions
$(document).ready(function(){


  $(".textNormalSwitch").click(function(){
    step = 0;
    createCookie('Dialog-step',step,30);
    location.reload();
    return false;
  });
  // Increase Font Size
  $(".textBigger").click(function(){
    if(step<3) {
      $('*').each(function() {
        var currentFontSize = $(this).css('fontSize');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = Math.max(currentFontSizeNum*1.05, currentFontSizeNum+1);
        $(this).css('font-size', newFontSize);
      });
      step++;
      createCookie('Dialog-step',step,30)
    }
    return false;
  });
  // Decrease Font Size
  $(".textSmaller").click(function(){
    if(step>-3) {
      $('*').each(function() {
        var currentFontSize = $(this).css('fontSize');
        var currentFontSizeNum = parseFloat(currentFontSize, 10);
        var newFontSize = Math.min(currentFontSizeNum/1.05, currentFontSizeNum+1);
        $(this).css('font-size', newFontSize);
      });
      step--;
      createCookie('Dialog-step',step,30);
    }
    return false;
  });
  
  if(readCookie('Dialog-step') != 0) {
    cstep = readCookie('Dialog-step');
    if(cstep > 0) {
      for(i=0;i<cstep;i++) {
        $('*').each(function() {
          var currentFontSize = $(this).css('fontSize');
          var currentFontSizeNum = parseFloat(currentFontSize, 10);
          var newFontSize = currentFontSizeNum*1.05;
          $(this).css('font-size', newFontSize);
        });
      }
      step = cstep;
    }
    if(cstep < 0) {
      for(i=0;i>cstep;i--) {
        $('*').each(function() {
          var currentFontSize = $(this).css('fontSize');
          var currentFontSizeNum = parseFloat(currentFontSize, 10);
          var newFontSize = currentFontSizeNum/1.05;
          $(this).css('font-size', newFontSize);
        });
      }
      step = cstep;
    }
  } 
	  
});


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;
}

