/**
 * @author marco.filli
 * @date 25.11.2010
 * @comment zoom background and font
 */
var fontS = Cookie.read("fontsize");
var fullBg = picpath;
var fSize = fontS;
window.addEvent('domready', function(){
	$('backgroundp').setStyles({
		'visibility':'hidden'
	})
	new bgResize();
	var exceptionIDs=['zoom','print-link','nav','unav','unav_boxes','search']
	var sizes=['11px','14px']
	new fontZoom({
		exceptions:exceptionIDs,
		fontsize:sizes
	})
});
/**
 * @Class bgResize
 * @comment resizes background-images on click
 * bgbig is the object wich fires the event
 */
var bgResize = new Class({
	initialize: function(){
		this.initScreen();
		$('fullscreen').addEvents({
			'click':function(e){
				this.change();
				return false;
			}.bind(this)
		})
	},
	/**
	 * @function initScreen()
	 * @comment if the cookie is set to small show big image (the cookie set to small is for function change)
	 * if the cookie is set to big show small image (the cookie set to big is for function change)
	 */
	initScreen:function(){
		var size = Cookie.read("screensize");
		if (size == 'small') {
			this.bigScreen();
		}
		else if (size == 'big'){
			this.smallScreen();
		}
	},
	/**
	 *@function change()
	 *@comment event wich handles cookie screensize and function smallScreen / bigScreen
	 */
	change: function(){
		var myCookie;
		var size = Cookie.read("screensize");
		if (size == 'big'||size==null) {
			var myCookie = Cookie.write('screensize', 'small', {
				duration: 0
			});
			this.bigScreen();
		}
		else{
			var myCookie = Cookie.write('screensize', 'big', {
				duration: 0
			});
			this.smallScreen();
		}
		
	},
	/**
	 *@function smallScreen()
	 *@comment writes small background image
	 */
	smallScreen: function(){
		$('main').setStyle('background-color', '#ffffff');
		$('main').setStyle('background-image', 'url(' + root + 'images/mainbg.png)');
		$('pic').setStyle('background-image', bgurl);
		$('backgroundp').setStyles({
			'visibility':'hidden'
		});
		$('footer').setStyles({
			'width': '987px',
			'background-color': 'transparent',
			'position': 'relative',
			'opacity': 1
		});
		
		$('fr').setStyles({
			'right': 0,
			'padding': '0'
		});
		
		$('fl').setStyles({
			'left': '0'
		});
		$('img_fullscreen').src = root + 'images/fullscreen.png';
	},
	/**
	 *@function bigScreen()
	 *@comment writes large background image
	 */
	bigScreen: function(){
		$('main').setStyle('background-image', 'none');
		$('main').setStyle('background-color', 'transparent');
		$('pic').setStyle('background-image', 'none');
		$('backgroundp').src = fullBg;
		$('backgroundp').setStyles({
			'visibility':'visible'
		});
		$('footer').setStyles({
			'width': '100%',
			'background-color': '#fff',
			'position': 'fixed',
			'bottom': '0px',
			'height': '18px',
			'opacity': 0.3,
			'padding': '2px 0 3px 0'
		});
		
		$('fr').setStyles({
			'right': '10px',
			'padding': '3px 0 0 0'
		});
		
		$('fl').setStyles({
			'left': '10px'
		});
		$('img_fullscreen').src = root + 'images/fullscreen_off.png';
	}
});

var fontZoom = new Class({
	Implements: [Options],
	options:{
	},
	initialize: function(options){
		this.setOptions(options);
		this.zoomFont(this.options.exceptions,this.options.fontsize);
		if ($defined($('zoomBig'))) {
			$('zoomBig').addEvents({
				'click': function(e){
					this.eventZoomer(true, this.options.exceptions, this.options.fontsize);
					return false;
				}.bind(this)
			});
		}
		if ($defined($('zoomSmall'))) {
			$('zoomSmall').addEvents({
				'click': function(e){
					this.eventZoomer(false, this.options.exceptions, this.options.fontsize);
					return false;
				}.bind(this)
			});
		}
	},
	zoomFont:function(exceptions,fontsize){
		var size = fontS;
		if (size != 'small'&&size!=null) {
			this.fontLarger(exceptions,size,false);
		}
		else{
			this.fontSmaller(fontsize);
		}
	},
	eventZoomer:function(b,exceptions,fontsize){
		if (b == true) {
			this.fontLarger(exceptions,fontsize,true);
		}
		else {
			this.fontSmaller(fontsize);
		}
	},
	fontLarger: function(exceptions,fontsize,clicked){
		var elements = [];
		if (clicked = true) {
			if (fontS == null) {
				fSize = fontsize[1]
			}
			else {
				fSize = fontsize
			}
			var myCookie = Cookie.write('fontsize', fSize, {
				duration: 0
			});
		}
		else {
			fSize = Cookie.read("fontsize")
		}
		$$('# .text').setStyles({
			'font-size': Cookie.read("fontsize")
		});
		$$('# .text td').setStyles({
			'font-size': Cookie.read("fontsize")
		});
		$$('# .text a').setStyles({
			'font-size': Cookie.read("fontsize")
		});
		$$('# .title').setStyles({
			'font-size': Cookie.read("fontsize")
		});
		elements.each(function(elems){
			exceptions.each(function(exc){
				if (elems.id == exc) {
					elems.setStyles({
						'font-size': '11px'
					})
				}
			})
		})
		if (pType != 'main' && shop != 'true') {
			makeScrollbar($('content_text'), $('track'), $('thumb'));
		}
	},
	fontSmaller: function(fontsize){
		fontS=null;
		$$('# .text').setStyles({
			'font-size': fontsize[0]
		});
		$$('# .text td').setStyles({
			'font-size': fontsize[0]
		});
		$$('# .text a').setStyles({
			'font-size': fontsize[0]
		});
		$$('# .title').setStyles({
			'font-size': fontsize[0]
		});
		
		
		var myCookie = Cookie.write('fontsize', 'small', {
			duration: 0
		});
	}
});
