//#########################################################
// Erstellt jegliche Items (Bilder / Videos) auf der Seite
//#########################################################
var ITEM = {
	//---- Basis zum erstellen des Items
	//@author     Sven Schollmeyer
	//@param
	//target      Element in das das Item geschrieben werden soll
	//options     Alle Informationen zu dem Item
	//size        Größe in der das Item erstellt werden soll (s,m,l, etc)
	//preview     Ob die Video Vorschau angezegit werden soll (Optional)
	_base: function(target, options, size, preview) {
		
		// Hauptdiv des Items
		this.maindiv = UPDOM.createElement('div', target, {
			className: 'item ' + size
		});
		
		// Wenn es sich um ein Video handelt
		// Video Icon anzeigen
		if(options.type == "v") {
			UPDOM.createElement('div', this.maindiv, {
				className: 'video'
			});
		}

		// Tabelle erstellen zur zentrierung des Bildes
		this.table = UPDOM.createElement('table', this.maindiv);
		this.tr    = UPDOM.createElement('tr', this.table);
		this.td    = UPDOM.createElement('td', this.tr);
		
		// Link zum Item erstellen
		this.a     = UPDOM.createElement('a', this.td, {
			href:      options.view_url + '/sliderPage/' + options.pagination_page,
			title:     options.title,
			className: 'title'
		});
		
		// Bild
		this.img = UPDOM.createElement('img', this.a, {
			imageUrl:    options.thumb_url,
			title:       options.title
		});
				
		// Wenn es sich um ein Video handelt
		// Video Vorschaueinbinden
		if(options.type == "v" && preview) {
			eventsparser({
				onmouseover: function() {
					ITEM.show_preview($(this[0]), this[1]);
				}.bind(Array(this, options.preview_url)),
				onmouseout:  function() {
					ITEM.hide_preview($(this));
				}.bind(this.img)}, this.img
			);
		}
				
		return {
			maindiv: this.maindiv,
			img:     this.img
		};
	},
	//#########################################################
	// Vordefinierte größen
	//#########################################################
	size: {
		xxs: function(target, options) {
			this.item = ITEM._base(target, options, 'xxs');
			
			$(this.item.img).width  = options.thumb_width.max(CONFIG.ITEMS.xxs.width);
			$(this.item.img).height = options.thumb_height.max(CONFIG.ITEMS.xxs.height);
			
			return $(this.item.maindiv);
		},
		
		m: function(target, options) {
			this.item = ITEM._base(target, options, 'm', true);
			
			$(this.item.img).width  = options.thumb_width.max(CONFIG.ITEMS.m.width);
			$(this.item.img).height = options.thumb_height.max(CONFIG.ITEMS.m.height);
			
			return $(this.item.maindiv);
		},
		l: function(target, options) {
			this.item = ITEM._base(target, options, 'l', true);

			$(this.item.img).width  = options.thumb_width.max(CONFIG.ITEMS.l.width);
			$(this.item.img).height = options.thumb_height.max(CONFIG.ITEMS.l.height);

			return $(this.item.maindiv);
		},
		home: function(target, options) {
			this.item = ITEM._base(target, options, 'home', true);

			$(this.item.img).width  = options.thumb_width.max(CONFIG.ITEMS.home.width);
			$(this.item.img).height = options.thumb_height.max(CONFIG.ITEMS.home.height);

			return $(this.item.maindiv);
		},
		xl: function(target, options) {
			this.item = ITEM._base(target, options, 'xl', true);

			$(this.item.img).width  = options.thumb_width.max(CONFIG.ITEMS.xl.width);
			$(this.item.img).height = options.thumb_height.max(CONFIG.ITEMS.xl.height);

			return $(this.item.maindiv);
		}
	},
	
	//---- Gekürzter Titel für das Item
	//@author   Sven Schollmeyer
	//target      Element in das das Item geschrieben werden soll
	//options     Alle Informationen zu dem Item
	title_short: function(target, options) {
		this.t = UPDOM.createElement('a', target, {
			href:      options.view_url,
			className: 'plain',
			innerHTML: options.title_short
		});
		
		return $(this.t).id;
	},
	
	//---- Alle Informationen zudem Item
	// Titel, Rating, Author, Views, Comments, Länge
	//@author   Sven Schollmeyer
	//target      Element in das das Item geschrieben werden soll
	//options     Alle Informationen zu dem Item
	//mode        Welcher anzeige Modus angewandt werden soll (Optional)
	options: function(target, options, mode) {
		this.a  = UPDOM.createElement('a', target, {
			href:      options.view_url + '/sliderPage/' + options.pagination_page,
			title:     options.title
		});
		
		this.text = UPDOM.createElement('text', this.a);
		$(this.text).innerHTML = options.title_short;

		if(undef(mode)) {
			this.div = UPDOM.createElement('div', target);
			$(this.div).innerHTML = options.rating_html;
	
			this.div = UPDOM.createElement('div', target, {
				className: 'graytext'
			});
	
			UPDOM.createElement('text', this.div, {
				text:      __('Von:') + ' '
			});
	
			this.a = UPDOM.createElement('a', this.div, {
				className: 'graytext',
				href:      options.author_url,
				innerHTML: options.author_short
			});
	
			UPDOM.createElement('span', target, {
				className: 'views',
				text:      ' ' + options.views
			});
	
			this.sep = UPDOM.createElement('span', target);
			this.septext = UPDOM.createElement('text', this.sep);
			$(this.septext).innerHTML = '&nbsp;&nbsp;';
	
			UPDOM.createElement('span', target, {
				className: 'comments',
				text:      ' ' + options.comments
			});
	
			UPDOM.createElement('br', target);
	
			if(options.type == "v") {
				UPDOM.createElement('span', target, {
					className: 'graytext',
					text:   __("Länge:") + " " + options.length
				});
			}
		}
	},
	
	//---- Video Vorschau anzeigen
	show_preview: function(object, animation) {
		if (animation.indexOf(".gif") != -1) {
			object._src = object.src;
			object.src = animation;
		}
	},
	
	//---- Video Vorschau ausblenden
	hide_preview: function(object) {
		if (object._src) {
			object.src = object._src;
			object._src = false;
		}
	}
};