// Tooltips
window.addEvent('domready', function() {

	//var tooltips = new Tips($$('.tooltip'));
	
	
	$$('.tooltip').each(function(element,index) {
		var content = element.get('title').split('::');
		element.store('tip:title', content[0]);
		element.store('tip:text', content[1]);
		
		if(Browser.Engine.trident) {
			element.set('alt', '');
		}
	});
	
	//Tooltips erzeugen
	var tooltips = new Tips('.tooltip',{
		className: 'tip-wrap',
		fixed: false,
		hideDelay: 25,
		showDelay: 25
	});
	
});


var pop;
function popupImage(url,width,height,titel) {
	
	// Breite und Höhe setzen
	var w = width || 110;
	var h = height || 110;
	/*
	// Breite und Höhe erweitern
	w += 40;
	h += 40;
	*/
	// Check, ob bereits ein Fenster offen ist. Falls ja, schliessen, um korrekte Größe zu erhalten.
	if(pop && !pop.closed) pop.close();
	
	var sw = screen.availWidth;
	var sh = screen.availHeight;
	
	if(w > sw || h > sh) {
		var pw = sw / w;
		var ph = sh / h;
		var p = pw < ph ? pw : ph;
		
		w = Math.floor(w * p);
		h = Math.floor(h * p);
		
		w -= 100;
		h -= 100;
	}
	
	// Fenster öffnen
	pop = window.open(url, 'ImagePopup', 'width='+(w+40)+',height='+(h+40));
	
	// Inhalt
	var html = '';
	html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
	html += '<html xmlns="http://www.w3.org/1999/xhtml"><head><title>'+titel+'</title>';
	html += '<script type="text/javascript">';
	html += 'function resizePopup() {';
	
	//  Nur, wenn keine Größe übergeben wurde
	if(width == undefined)
	{
		html += 'var x = parseInt(document.images["pImage"].width) + 40;';
		html += 'var y = parseInt(document.images["pImage"].height) + 90;';
		html += 'window.resizeTo(x,y);';
	}
	
	html += '}';
	html += '</script>';
	html += '<style type="text/css">html, body {background:#000;width:100%; height:100%; margin:0; padding:0;}img{border:2px solid #FFF;display:block;margin:0 auto;}</style>';
	html += '</head><body onload="resizePopup()" onblur="window.close()"><table cellspacing="0" cellpadding="0" border="0" width="100%" height="100%"><tr><td align="center" valign="middle"><a href="#" onclick="window.close();" title="Klicken, um das Fenster zu schliessen">';
	html += '<img width="'+(w)+'" height="'+(h)+'" name="pImage" src="'+url+'" alt="'+titel+'" border="0" />';
	html += '</a></td></tr></table></body></html>';
	
	pop.document.open();
	pop.document.write(html);
	pop.document.close();
	pop.focus();
}

/**
 * This script contains embed functions for common plugins. This scripts are complety free to use for any purpose.
 */

function writeFlash(p) {
 
    // FLV-Datei?
    if(p.src.substr(p.src.length-3).toLowerCase() == 'flv') {
      
        p.width = p.width || 320;
        p.height = p.height || 240;
        
        // Unique IDs 
        var embedid = 'embedFLV' + Math.floor(Math.random() * new Date().getTime());
        var playerid = 'player' + Math.floor(Math.random() * new Date().getTime());
        
        // Erstelle DIV für den Player
        document.write('<d'+'iv i'+'d="'+embedid+'" cl'+'ass="autoflvplayer"></d'+'iv>');

        // Erstelle SWF Object Code
        var so = new SWFObject(js_href + 'swf/mediaplayer.swf', playerid, p.width, p.height, '7');
        
        so.addParam('allowscriptaccess', 'always');
        so.addParam('allowfullscreen', 'true');
        so.addVariable('width', p.width);
        so.addVariable('height', p.height);
        so.addVariable('showstop', 'true');
        so.addVariable('showdigits', 'false');
        so.addVariable('usefullscreen', 'true');
        so.addVariable('file', p.src);
        if(p.image) {
        	so.addVariable('image', p.image);
        }
        
        so.write(embedid);
        
        return;
        
    } else if(p.src.substr(p.src.length-3).toLowerCase() == 'mp3') {
        
        p.width = p.width || 320;
        p.height = p.height || 20;
        
        // Unique IDs 
        var embedid = 'embedFLV' + Math.floor(Math.random() * new Date().getTime());
        var playerid = 'player' + Math.floor(Math.random() * new Date().getTime());
        
        // Erstelle DIV für den Player
        document.write('<d'+'iv i'+'d="'+embedid+'" cl'+'ass="automp3player"></d'+'iv>');
        
        try {
            document.getElementById(embedid).parentNode.removeChild(document.getElementById(embedid).previousSibling);
        } catch(e) {}
        
        // Erstelle SWF Object Code
        var so = new SWFObject(js_href + 'swf/mediaplayer.swf', playerid, p.width, p.height, '7');
        
        so.addParam('allowscriptaccess', 'always');
        so.addParam('allowfullscreen', 'true');
        so.addVariable('width', p.width);
        so.addVariable('height', p.height);
        so.addVariable('showstop', 'true');
        so.addVariable('showdigits', 'true');
        so.addVariable('usefullscreen', 'false');
        so.addVariable('file', p.src);
        
        
        so.write(embedid);
        
        return;
        
    }
	
    // Default
	writeEmbed(
		'D27CDB6E-AE6D-11cf-96B8-444553540000',
		'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
		'application/x-shockwave-flash',
		p
	);
	
}

function _writeFlash(p) {
	writeEmbed(
		'D27CDB6E-AE6D-11cf-96B8-444553540000',
		'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
		'application/x-shockwave-flash',
		p
	);
}

function writeShockWave(p) {
	writeEmbed(
	'166B1BCA-3F9C-11CF-8075-444553540000',
	'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0',
	'application/x-director',
		p
	);
}

function writeQuickTime(p) {
	writeEmbed(
		'02BF25D5-8C17-4B23-BC80-D3488ABDDC6B',
		'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0',
		'video/quicktime',
		p
	);
}

function writeRealMedia(p) {
	writeEmbed(
		'CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA',
		'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
		'audio/x-pn-realaudio-plugin',
		p
	);
}

function writeWindowsMedia(p) {
	p.url = p.src;
	writeEmbed(
		'6BF52A52-394A-11D3-B153-00C04F79FAA6',
		'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701',
		'application/x-mplayer2',
		p
	);
}

function writeEmbed(cls, cb, mt, p) {
	var h = '', n;

	h += '<object classid="clsid:' + cls + '" codebase="' + cb + '"';
	h += typeof(p.id) != "undefined" ? 'id="' + p.id + '"' : '';
	h += typeof(p.name) != "undefined" ? 'name="' + p.name + '"' : '';
	h += typeof(p.width) != "undefined" ? 'width="' + p.width + '"' : '';
	h += typeof(p.height) != "undefined" ? 'height="' + p.height + '"' : '';
	h += typeof(p.align) != "undefined" ? 'align="' + p.align + '"' : '';
	h += '>';

	for (n in p)
		h += '<param name="' + n + '" value="' + p[n] + '">';

	h += '<embed type="' + mt + '"';

	for (n in p)
		h += n + '="' + p[n] + '" ';

	h += '></embed></object>';

	document.write(h);
}

