var popup_win;
var global_id;
var global_name;
var global_language;
	
function popup(url,id,width,height,calcPos) 
{
	var x;
	if (calcPos !== false)
	{
		pos_horizon = ((screen.width/2)-(width/2));
		pos_vertical = ((screen.height/2)-(height/2));
		x = ',left='+pos_horizon+',top='+pos_vertical;
	}
	popup_win = window.open(url,id,'width='+width+',height='+height+x+',resizable=no,scrollbars=no,menubar=no,status=no');
}

function show_product(id,name,language)
{
	/*GET AND SET DATA*/
	
	global_id = id;
	global_name = name;
	global_language = language;
	
	new Ajax.Updater(
	$('product'),
	'/get.produkt.php', {
	method: 'post',
	parameters: 'language=' + language + '&id=' + id,
	asynchronous: true,
	onComplete: load_flash}
	);
}

function load_flash(setVisibility)
{
	var html = return_AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','356','height','301','src','/image/ImageZoom.swf?xmlPath=/images.xml.php%3Flanguage=' + global_language + '%26id=' + global_id,'quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','/image/ImageZoom.swf?xmlPath=/images.xml.php%3Flanguage=' + global_language + '%26id=' + global_id,'wmode','transparent','AllowScriptAccess','always','id','image_zoom' );
	$('product_view').innerHTML = html;
	var html = return_AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','356','height','20','src','/image/h1.swf?value=' + escape(global_name),'quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','/image/h1.swf?value=' + escape(global_name),'wmode','transparent','AllowScriptAccess','always','id','header_1' );
	$('product_header_1').innerHTML = html;
	var html = return_AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','356','height','20','src','/image/h1.swf?value=' + escape(global_name),'quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','/image/h1.swf?value=' + escape(global_name),'wmode','transparent','AllowScriptAccess','always','id','header_2' );
	$('product_header_2').innerHTML = html;
	
	if (setVisibility !== false)
	{
		$('product').style.visibility='visible';
		$('info').style.display = 'none';
		$('view').style.display = 'block';
	}
}

function close_product()
{
	$('product').style.visibility='hidden';
	$('product').innerHTML = '';
}

function navigate_product()
{
	if ($('view').style.display == 'none')
	{
		$('info').style.display = 'none';
		$('view').style.display = 'block';
	}
	else
	{
		$('view').style.display = 'none';
		$('info').style.display = 'block';
	}
	load_flash(false);
	if (navigator.userAgent.indexOf('Mac') != -1 && navigator.userAgent.indexOf('Gecko') != -1)
	{
		window.scrollTo(0, 1);
		window.setTimeout(function(){
			window.scrollTo(0, 0);
		}, 0);
	}
}

function return_AC_Generateobj(objAttrs, params, embedAttrs, id) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  return str;
}

function return_AC_FL_RunContent()
{
  var ret = 
    AC_GetArgs
    (  arguments, "", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  return return_AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function wheel_handle(delta)
{
	var stepAmount = 10;
	if ($('container') && $('container').offsetHeight*containerHeightFactor>height)
	{
		var scrollHeight = height-2;
		var maxScroll	 = scrollHeight-$('handle').height;
		var curPos		 = parseInt($('handle').style.top);
		var newPos		 = curPos + stepAmount*-delta;
		
		if (newPos < 0) newPos = 0;
		else if (newPos > maxScroll) newPos = maxScroll;
		
		$('handle').style.top = newPos+'px';
		
		var pct = newPos/maxScroll;
		$('container').style.top = '-'+(pct*($('container').offsetHeight*containerHeightFactor-height))+'px';
	}
	return;
}

function wheel(event){
        var delta = 0;
        if (!event) /* For IE. */
                event = window.event;
        if (event.wheelDelta) { /* IE/Opera. */
                delta = event.wheelDelta/120;
                /** In Opera 9, delta differs in sign as compared to IE.
                 */
                if (window.opera)
                        delta = -delta;
        } else if (event.detail) { /** Mozilla case. */
                /** In Mozilla, sign of delta is different than in IE.
                 * Also, delta is multiple of 3.
                 */
                delta = -event.detail/3;
        }
        /** If delta is nonzero, handle it.
         * Basically, delta is now positive if wheel was scrolled up,
         * and negative, if wheel was scrolled down.
         */
        if (delta)
                wheel_handle(delta);
        /** Prevent default actions caused by mouse wheel.
         * That might be ugly, but we handle scrolls somehow
         * anyway, so don't bother here..
         */
        if (event.preventDefault)
                event.preventDefault();
	event.returnValue = false;
}

/** Initialization code. 
 * If you use your own event management code, change it as required.
 */
if (window.addEventListener)
        /** DOMMouseScroll is for mozilla. */
        window.addEventListener('DOMMouseScroll', wheel, false);
/** IE/Opera. */
window.onmousewheel = document.onmousewheel = wheel;