//
// General Userdb functions
//
// @author 		<dho@reichl.cc> David HOHL
// @copyright 	Reichl und Partner eMarketing
// @access 		public
// @package 	LyL
//
// @version 	0.1
// @desc
//			0.1 @dho

var fadelook = false;
function welcome() {
	// initialize the member variables for this instance

	// content right - registrationbox
	this.registration = '';
	this.image = '';					// image left
	this.content = new Array();			// content
	this.headline = new Array();		// headline
	this.content_index = 0;				// index
	this.pager = '';					// pager content
	this.show_welcome = '';
	this.page_id = 1;
	this.translator = new Array();		// translator
	this.fade = false;
	this.debugtest = false;

	// welcomebox configuration
	this.startitem = 1;
	this.classname = 'obj_welcome';

	//troubles with IE 7
	this.fadeeffect = false;

	// initialize the member function references

	// for the class prototype
	if (typeof(_welcome_prototype_called) == 'undefined') {
		_welcome_prototype_called = true;

		welcome.prototype.loadWelcome 			= loadWelcome;
		welcome.prototype.setImage				= setImage;
		welcome.prototype.setRegistration 		= setRegistration;
		welcome.prototype.setContent			= setContent;

		welcome.prototype.buildPager			= buildPager;

		welcome.prototype.output				= output;
		welcome.prototype.loadPage				= loadPage;
		welcome.prototype.outputPager			= outputPager;
		welcome.prototype.outputImage			= outputImage;
		welcome.prototype.outputRegistration	= outputRegistration;
		welcome.prototype.getnextUrl			= getnextUrl;
		welcome.prototype.getbackUrl			= getbackUrl;
		welcome.prototype.openWelcomebox		= openWelcomebox;
		welcome.prototype.sethtml				= sethtml;
	}

	// init welcomeitems
	function loadWelcome() {
		this.buildPager();
	}

	// output welcomebox content
	function output(page_id) {
		if(page_id == 0) {
			//first page load
			this.outputImage();
			this.loadPage(this.startitem);
			this.outputPager();
			page_id = 1;
		} else {
			this.loadPage(page_id);
			this.buildPager();
			this.outputPager();
		}

		for (var index = 1, len = this.content.length; index < len; ++index) {
			$('welcomebox-page-url-'+index).className = 'welcomebox-page-unset';
		}
		$('welcomebox-page-url-'+page_id).className = 'welcomebox-page-set';
	}

	// load welcomebox
	function loadPage(page_id) {
		if(page_id > 1 && this.page_id != page_id && this.fadeeffect) {
			$('welcomebox-registration').hide();
			$('welcomebox-headline').hide();
			$('welcomebox-content').hide();
		}
		this.sethtml('welcomebox-headline',this.headline[page_id]);
		this.sethtml('welcomebox-content',this.content[page_id]);
		if(page_id > 1 && this.page_id != page_id && this.fadeeffect) {
			if(this.show_welcome) this.show_welcome.cancel();
			this.show_welcome = Effect.Appear('welcomebox-headline', {duration:1.8})
			this.show_welcome = Effect.Appear('welcomebox-content', {duration:1.8})
			this.show_welcome = Effect.Appear('welcomebox-registration', {duration:1.8})
		}
		this.page_id = page_id;
	}

	function outputPager() { this.sethtml('welcomebox-pager',this.pager); }
	function outputImage() { this.sethtml('welcomebox-image','<img src="'+this.image+'" />'); }
	function outputRegistration() { this.sethtml('welcomebox-registration',this.registration); }

	// build pager
	function buildPager() {
		this.pager = '<table class="welcomebox-pagerbox"><tr><td class="welcomebox-pager-url-left">'+this.getbackUrl()+'</td><td align="center"><span class="welcomebox-page-page">'+this.translator[3]+'</span>';
		for (var index = 1, len = this.content.length; index < len; ++index) {
			seturl = 'unset';
			if(index == 1) seturl = 'set';
			this.pager = this.pager + '<a href="#" onClick="'+this.classname+'.output('+index+');" class="welcomebox-page-'+seturl+'" id="welcomebox-page-url-'+index+'">'+index+'</a>';
		}
		this.pager = this.pager + '</td><td class="welcomebox-pager-url-right">'+this.getnextUrl();+'</td></tr></table>';
	}
	// build pager next url
	function getnextUrl() {
		var next_page_id = this.page_id + 1;
		if(next_page_id < this.content.length) return '<a href="#" class="paging-next" onClick="'+this.classname+'.output('+next_page_id+')">'+this.translator[1]+'&nbsp;</a>';
		return '&nbsp;';
	}
	// build pager back url
	function getbackUrl() {
		var last_page_id = this.page_id - 1;
		if(last_page_id > 0) return '<a href="#" class="paging-previous" onClick="'+this.classname+'.output('+last_page_id+')">&nbsp;'+this.translator[0]+'</a>';
		return '&nbsp;';
	}
	// set content
	function setContent(headline, content) {
		this.content_index = this.content_index + 1;
		this.headline[this.content_index] = headline;
		this.content[this.content_index] = content;
	}

	// set image
	function setImage(image) { this.image = image; }

	// set registration content
	function setRegistration(content) { this.registration = content; }

	// open welcomebox
	function openWelcomebox() {
		if(!fadelook) {
			if(!this.fade) this.fade = 'down';
			if(this.fade == 'down') {
				Effect.BlindDown('welcomebox-large', {beforeStart: function() {fadelook = true;}, afterFinish: function() {fadelook = false}});
				this.fade = 'up';
				this.sethtml('welcome-url',this.translator[4]);
				$('welcome-url').className = 'more-close';
			} else {
				Effect.BlindUp('welcomebox-large', {beforeStart: function() {fadelook = true;}, afterFinish: function() {fadelook = false}});
				this.fade = 'down';
				this.sethtml('welcome-url',this.translator[5]);
				$('welcome-url').className = 'mehr';
			}
		}
	}
	function sethtml(id,str) {
		$(id).innerHTML = str;
	}
}

