/**************************************************************
 Script			: Wallpaper plugin for neuland
 Version		: 1.0
 Authors		: Alexander Maier
 Desc			:
 Licence		: Copyright by zweigang.de
 **************************************************************/
window.addEvent('domready', function(){
	if ($('wallPaperBtn')) {
		var wallpaper = new Wallpaper({
			wallpaperNumber: 4,
			path: 'fileadmin/wallpapers/',
			wallpaperBtn: $('wallPaperBtn'),
			target: $('wallPaper')
		});
		wallpaper.show();		
	}
});


var Wallpaper = new Class({

	getOptions: function(){
		return {
			wallpaperNumber: 4,
			path: 'fileadmin/wallpapers/',
			wallpaperBtn: $('wallPaperBtn'),
			target: $('wallPaper')
		};
	},
	
	initialize: function(options){
		this.setOptions(this.getOptions(), options);
		this.wallpaper = 0;
		this.boxes = new Array();
		
		this.options.wallpaperBtn.addEvent('click', function(e){
			this.setNew();
		}.bind(this));
		this.createNavigation();
	},
	
	show: function(){
		this.getNew();
		this.options.target.setStyle('background', 'url(' + this.options.path + this.wallpaper + '.jpg)');
		if (this.oldWallpaper-1 > -1)
			this.boxes[this.oldWallpaper-1].setStyle('background', '#990c15');
		this.boxes[this.wallpaper-1].setStyle('background', '#ced00f');
	},
	
	getNew: function(){
		if (Cookie.get('neulandWallpaper')) {
			this.wallpaper = Cookie.get('neulandWallpaper');
		}
		else {
			this.setNew();
		}
	},
	
	setNew: function(){
		this.oldWallpaper = this.wallpaper;
		this.wallpaper++;
		if (this.wallpaper > this.options.wallpaperNumber) this.wallpaper = 1;
		Cookie.set('neulandWallpaper', this.wallpaper);
		this.show();
	},
	
	createNavigation: function (){
		this.box = new Element('span').addClass('wp-nav-container').injectBefore(this.options.wallpaperBtn.getElement('span'));
		for (var i = 0; i < this.options.wallpaperNumber; i ++ ) {
			this.boxes.push(new Element('div').addClass('wp-inactive').injectInside(this.box));
		}
	}
	
	
});
Wallpaper.implement(new Options);
Wallpaper.implement(new Events);

/*************************************************************/



