/* ---------------------------------------------------------
   kampagnen-motive
--------------------------------------------------------- */
Kampagnenmotive = Class.create({
	motives: null,
	imgsrc: null,
	current:	0,
	rel2rootweb: '',
	abs2rootweb: '',
	insertsid: '',
	overlay: null,

	initialize: function() {
		if(motive)
			this.motives = motive;
		if(motiv)
			this.current =	motiv;
		if(rel2rootweb)
			this.rel2rootweb = rel2rootweb;
		if(abs2rootweb)
			this.abs2rootweb = abs2rootweb;
		if(insertsid)
			this.insertsid = insertsid;
		// event handler fuer next button
		evt = this.next.bind(this);
		Event.observe($('sub-next'), 'click', evt);
		$('sub-next').href = 'javascript:void(0)';
		// event handler fuer prev button
		evt = this.prev.bind(this);
		Event.observe($('sub-prev'), 'click', evt);
		$('sub-prev').href = 'javascript:void(0)';
		// event handler fuer embed overlay
		evt = this.toggleEmbedOverlay.bind(this);
		//Event.observe($('sub-embed'), 'click', evt);
		//Event.observe($('embed-close'), 'click', evt);
		//$('sub-embed').href = 'javascript:void(0)';
		//$('embed-close').href = 'javascript:void(0)';
		// event handler fuer desktop overlay
		evt = this.toggleDesktopOverlay.bind(this);
		//Event.observe($('sub-desktop'), 'click', evt);
		//Event.observe($('desktop-close'), 'click', evt);
		//$('sub-desktop').href = 'javascript:void(0)';
		//$('desktop-close').href = 'javascript:void(0)';
		// event handler fuer ausblenden
		/*
		evt = this.hide.bind(this);
		Event.observe($('container-close'), 'click', evt);
		$('container-close').href = 'javascript:void(0)';
		*/
		// preload images (wichtig fuer IE 5.x und IE 6, sonst werden die Bilder nicht vollständig angezeigt)
		this.preloadMotives();
	},

	next: function() {
		this.current = this.current+1;
		if(this.current>this.motives.size())
			this.current = 1;
		this.changeMotive();
	},

	prev: function() {
		this.current = this.current-1;
		if(this.current<1)
			this.current = this.motives.size();
		this.changeMotive();
	},

	changeMotive: function() {
		m = this.motives.get(this.current);
		img = this.imgsrc.get(this.current);
		$('sub-current').src = (img!=null&&img.src!=null) ? img.src : this.rel2rootweb+'img/kampagnenmotive/'+m.img;
		//$('sub-title').innerHTML = m.title;
		//$('sub-linkbox').innerHTML = m.links;
		$('embed-tiny').href = 'http://twitter.com/home?status=' + encodeURIComponent('Plakatmotiv "'+m.title+'" bei dieGesellschafter.de: '+m.tinyurl);
		$('embed-tiny').innerHTML = m.tinyurl;
		$('embed-img').value = '<img src="'+this.abs2rootweb+'img/kampagnenmotive/'+m.img+'" width="589" height="416" alt="dieGesellschafter Kampagnenmotiv" />';
		$('embed-blog').value = this.abs2rootweb+'index.php?motiv='+this.current;
		//$('sub-empfehlen').href = this.rel2rootweb+'div/empfehlen/index.php'+this.insertsid+'page_url='+escape('index.php?motiv='+this.current)+'&page_title='+escape('Plakatmotiv "'+m.title+'"')+'&ticket='+escape(m.ticket);
		$('desktop-1024x768').href = this.rel2rootweb+'img/kampagnenmotive/1024x768/'+m.img;
		$('desktop-1280x800').href = this.rel2rootweb+'img/kampagnenmotive/1280x800/'+m.img;
		$('desktop-1280x1024').href = this.rel2rootweb+'img/kampagnenmotive/1280x1024/'+m.img;
	},
	
	preloadMotives: function() {
		this.imgsrc = new Hash();
		for(i=1; i<this.motives.size()+1; i++) {
			img = new Image();
			img.src = this.rel2rootweb+'img/kampagnenmotive/'+(this.motives.get(i)).img;
			this.imgsrc.set(i, img);
		}
	},

	toggleEmbedOverlay: function() {
		if(this.overlay=='embed') {
			$('kampagne').removeClassName('overlay-bg');
			$('overlay-embed').style.display = 'none';
			$('modal').style.display = 'none';
			if ( Prototype.Browser.IE )
				$('sub-controller').removeClassName('overlay-bg');
			this.overlay = null;
		}
		else {
			$('kampagne').addClassName('overlay-bg');
			$('overlay-embed').style.display = 'block';
			$('modal').style.display = 'block';
			if ( Prototype.Browser.IE )
				$('sub-controller').addClassName('overlay-bg');
			this.overlay = 'embed';
		}
	},

	toggleDesktopOverlay: function() {
		if(this.overlay=='desktop') {
			$('kampagne').removeClassName('overlay-bg');
			$('overlay-desktop').style.display = 'none';
			$('modal').style.display = 'none';
			if ( Prototype.Browser.IE )
				$('sub-controller').removeClassName('overlay-bg');
			this.overlay = null;
		}
		else {
			$('kampagne').addClassName('overlay-bg');
			$('overlay-desktop').style.display = 'block';
			$('modal').style.display = 'block';
			if ( Prototype.Browser.IE )
				$('sub-controller').addClassName('overlay-bg');
			this.overlay = 'desktop';
		}
	},

	hide: function() {
		$('container-kampagne').addClassName('hide');
	}
});

Motiv = Class.create({
	img: 1,
	titel: '',
	tinyurl: '',
	links: '',
	ticket: '',

	initialize: function(img, title, tinyurl, links, ticket) {
		this.img = img;
		this.title = title;
		this.tinyurl = tinyurl;
		this.links = links;
		this.ticket = ticket;
	}
});


if(!initFunctions)
	initFunctions = new Array();
initFunctions.push(function() {
	new Kampagnenmotive();
});
