/**
 * WD Ebay Slider Script
 * @author WD - Moritz, Henning
 * @package com.wd.ebay
 *
 * @copyright  2009 Web-Dynamic
 * @version    0.1 $Revision: 2407 $
 */


 /**
  * _load
  */
function _load()
{
	Slider.load({
		onslide : function(size)
		{
			var b = parseInt( (size / 960) * -1 );

			if (Slider.Btn) {
				Slider.Btn.setNormal();
			};

			if (Slider.Buttons[b])
			{
				Slider.Btn = Slider.Buttons[b];
				Slider.Btn.setActive();
			};
		}
	});
	Ebay = new WdEbay();


	var Buttons = [
		{
			name    : '_Home',
			image   : 'bin/32x32/home.png',
			onclick : function (_me)
			{
				if (Slider.Btn) {
					Slider.Btn.setNormal();
				};

				Slider.goTo($('About'));

				Slider.Btn = _me;
				Slider.Btn.setActive();
			},
			text  : 'Startseite',
			width : 150
		},
		{
			name    : '_Create',
			image   : 'bin/32x32/useit.png',
			onclick : function (_me)
			{
				if (Slider.Btn) {
					Slider.Btn.setNormal();
				};

				Slider.goTo($('Settings'));

				Slider.Btn = _me;
				Slider.Btn.setActive();
			},
			text : 'Los gehts',
			width : 150
		},
		{
			name    : '_Faq',
			image   : 'bin/32x32/info.png',
			onclick : function (_me)
			{
				if (Slider.Btn) {
					Slider.Btn.setNormal();
				};

				Slider.goTo($('Faq'));

				Slider.Btn = _me;
				Slider.Btn.setActive();
			},
			text  : 'Wie funktionierts?',
			width : 150
		}
	];

	// Liste Größe festlegen erweitern
	var lists = $('content-slider').getElementsByTagName('li');
	var l = 0;

	for (var i = 0; i < lists.length; i++)
   	{
		if (lists[i].parentNode != $('content-slider')) {
			continue;
		}

		l++;
   	};

	$('content-slider').style.width = (l*960) +'px';

	Slider.Buttons = [];

	for (var b = 0, len = Buttons.length; b < len; b++)
	{
		var Btn = new _ptools.Button( Buttons[b] );

		Slider.Buttons[b] = Btn;
		$('Menu').appendChild( Btn.create() );
	};

	Slider.Btn = Slider.Buttons[0];
	Slider.Btn.setActive();


	$('action').appendChild(
		new _ptools.Button({
			name    : '_cPreview',
			image   : 'bin/32x32/preview.png',
			onclick : function (){
				Ebay.getPreview();
			},
			text  : 'Vorschau',
			width : 150
		}).create()
	);

	$('action').appendChild(
		new _ptools.Button({
			name    : '_cPreview',
			image   : 'bin/32x32/code.png',
			onclick : function () {
				Ebay.createCode();
			},
			text  : 'Code erstellen',
			width : 150
		}).create()
	);


	$('infobuttons').appendChild(
		new _ptools.Button({
			name    : '_Create',
			image   : 'bin/32x32/useit.png',
			onclick : function (_me)
			{
				if (Slider.Btn) {
					Slider.Btn.setNormal();
				};

				Slider.goTo($('Settings'));
			},
			text : 'Los gehts',
			width : 150
		}).create()
	);

	$('infobuttons').appendChild(
		new _ptools.Button({
			text    : 'Demo',
			image   : 'bin/32x32/screenshots.png',
			width   : 150,
			onclick : function(_me)
			{
				Slider.goTo($('Example'));

				if (Slider.Btn) {
					Slider.Btn.setNormal();
				};
			}
		}).create()
	);

	if (CONTACT) {
		Slider.goTo($('Contact'), 'contact');
	};

	function hide_free_button()
	{
		var elm = $('free');

		elm.set('opacity', 1);
		elm.set('tween', {
			duration: 500
		});

		elm.tween('opacity', [1, 0]);
	};

	hide_free_button.delay(5000);


	function switchText()
	{
		var orig = $('infotext1');
		var next = $('infotext2');

		if ($('infotext1').get('opacity'))
		{
			orig = $('infotext1');
			next = $('infotext2');
		} else if ($('infotext2').get('opacity'))
		{
			orig = $('infotext2');
			next = $('infotext3');
		} else if ($('infotext3').get('opacity'))
		{
			orig = $('infotext3');
			next = $('infotext1');
		};


		orig.set('opacity', 1);
		orig.set('tween', {
			duration: 500
		});
		orig.tween('opacity', [1, 0]);


		next.set('opacity', 0);
		next.set('tween', {
			duration: 500
		});
		next.tween('opacity', [0, 1]);


		switchText.delay(6000);
	};

	switchText.delay(6000);
};

WdEbay = function()
{
        var t = this;
        var attributes = [];

	t.Code 	= null;

 	t.getAttribute = function( name )
	{
		if (attributes[ name ]) {
			return attributes[ name ];
		};

		return false;
	};

	t.setAttribute = function(name, value)
	{
		attributes[ name ] = value;
	};
};

 WdEbay.prototype.createCode = function()
{
	var t = this;
	t.getSettings();
	t.createPopup();

	if (!t.Code)
	{
		$('PopupHTML').innerHTML = 'Bitte gebe zuerst einen eBay Verkäufer Namen ein.';
		return false;
	};

	var area = document.createElement('textarea');

	area.value = t.Code;

	area.style.width    = '650px';
	area.style.height   = '280px';
	area.style.overflow = 'auto';
	area.style.border   = '1px solid #EBE4D8';
	area.style.padding  = '5px';

	if (_ptools._Browser.isMSIE)
	{
	    area.style.position = 'relative';
	    area.style.left = '-20px';
	};

	$('PopupHTML').appendChild( area );
};

 WdEbay.prototype.getSettings = function()
{
	var t = this;
	var f = document.forms['ebay_settings'];

	var data    = [];
	var url_dir = 'http://www.myelisting.de/usr/bin/ebay/';

	for (var i = 0, len = f.elements.length; i < len; i++)
	{
		if (f.elements[i].type == 'checkbox' || f.elements[i].type == 'radio')
		{
			if (f.elements[i].checked)
			{
				data[f.elements[i].name] = 1;
			} else
			{
				data[f.elements[i].name] = 0;
			};
		} else
		{
			data[f.elements[i].name] = f.elements[i].value;
		};
	};

	if (data['ebayname'] == ""){
		return false;
	};

	var code = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="640" height="200">'+
		'<param name="movie" value="'+ url_dir + data['flashstyle'] +'.swf" />'+
		'<param name="quality" value="high" />'+
		'<param name="bgcolor" value="#ffffff" />'+
		'<param name="wmode" value="transparent" />'+
		'<param name="allowScriptAccess" value="always" />'+
		'<param name="flashvars" value="' +
		'folder=' + url_dir + '&' +
		'thumbfolder=&' +
		'limit=' + data['limit'] +'&' +
		'ebayname='+ data['ebayname'] +'" />'+
		'<param name="menu" value="false" />'+
		'<param name="allowfullscreen" value="true" />'+
		'<embed id="" quality="high" width="640" height="200" type="application/x-shockwave-flash" '+
		'allowScriptAccess="always" '+
		'src="' + url_dir + data['flashstyle'] +'.swf" bgcolor="#FFFFFF" wmode="transparent" name="Ebay" '+
		'flashvars="' +
		'folder=' + url_dir + '&' +
		'thumbfolder=&' +
		'limit=' + data['limit'] +'&' +
		'ebayname='+ data['ebayname'] +'" '+
		'menu="false" /> '+
		'</object>';

	t.Code = code;
	return code;
};

 WdEbay.prototype.getPreview = function()
{
	var t = this;
	var content = $('showPreview');
	var code 	= t.getSettings();

	t.createPopup();

	if (!code)
	{
	  var url_dir = 'http://www.myelisting.de/usr/bin/ebay/';
	  code = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="640" height="200">'+
		'<param name="movie" value="'+ url_dir + 'style2' +'.swf" />'+
		'<param name="quality" value="high" />'+
		'<param name="bgcolor" value="#ffffff" />'+
		'<param name="wmode" value="transparent" />'+
		'<param name="allowScriptAccess" value="always" />'+
		'<param name="flashvars" value="' +
		'folder=' + url_dir + '&' +
		'thumbfolder=&' +
		'limit=15&' +
		'ebayname=random" />'+
		'<param name="menu" value="false" />'+
		'<param name="allowfullscreen" value="true" />'+
		'<embed id="" quality="high" width="640" height="200" type="application/x-shockwave-flash" '+
		'allowScriptAccess="always" '+
		'src="' + url_dir + 'style2' +'.swf" bgcolor="#FFFFFF" wmode="transparent" name="Ebay" '+
		'flashvars="' +
		'folder=' + url_dir + '&' +
		'thumbfolder=&' +
		'limit=15&' +
		'ebayname='+ 'random' +'" '+
		'menu="false" /> '+
		'</object>';



	};

	$('PopupHTML').innerHTML = code;
	t.Code = code;

	return code;
};

 WdEbay.prototype.createPopup = function()
{
	var oBG  = document.createElement('div');
	var oMsg = oBG.cloneNode(true);

	var scrollWidth  = document.documentElement.scrollWidth;
	var scrollHeight = window.innerHeight || document.documentElement.scrollHeight;

	var style = null;
	var wpo   = _ptools._System.getScrollXY()[1];
	var top   = (_ptools._System.getMaxHeight()/2)+wpo-300;

	if (top <= 180) {
		top = 180;
	};

	oBG.id  = 'PopupBg';
	oMsg.id = 'PopupMsg';
	oMsg.innerHTML = '<div style="margin: 20px; height: 270px" id="PopupHTML"></div>' +
		'<div id="PopupButton" style="width: 100px; margin: 0 auto; text-align: center"></div>';

	style = oBG.style;
	style.backgroundColor = '#000';
	style.position   = 'absolute';
	style.MozOpacity = '0.6';
	style.width   = scrollWidth +'px';
	style.height  = scrollHeight +'px';
	style.top     = '0';
	style.left    = '0';
	style.zIndex  = 1000;
	style.opacity = '0.6';
	style.filter  = 'progid:DXImageTransform.Microsoft.Alpha(opacity=60)';

	style = oMsg.style;
	style.top    = top +'px';
	style.left   = '50%';
	style.border = '2px solid #551C1C';
	style.height = '350px';
	style.width  = '700px';
	style.color  = '#000';
	style.zIndex = 1001;
	style.marginLeft      = '-350px';
	style.position        = 'absolute';
	style.backgroundColor = '#fff';

	document.body.appendChild( oMsg );
	document.body.appendChild( oBG );

	$('PopupButton').appendChild(
		new _ptools.Button({
			text    : 'Schließen',
			onclick : function()
			{
				$('PopupBg').parentNode.removeChild( $('PopupBg') );
				$('PopupMsg').parentNode.removeChild( $('PopupMsg') );
			},
			width: 100
		}).create()
	);
};



