/** ----------------------------------------------------------------------
 * globaler jQuery-Initblock
 * @project PI/UM-Micro
 * @(#) jInit.js
 * @caller htnlHeader, 
 * @calling (list)
 * @internal
 *	- (spazials)
 * @see (var.list)
 * @since jQuery 1.3.x
 * @internal
 *		- FancyBox (1.3.0)
 *		- Flowplayer (3.1.0)
 *		- beautyOfCode (3.0.83)
 * @mantis #16931, #16034
 *
 * -----------------------------------------------------------------------
 */

function jRelPos(id, relObjId, x, y)
{
	var pos = $("#"+relObjId).position();
	$("#"+id).css("left",pos.left - x);
	$("#"+id).css("top",pos.top - y);
}

function jAbsPos(id, x, y)
{
	$("#"+id).css("left",x+'px');
	$("#"+id).css("top",y+'px');
}
var timeobject;
function jZeitlimit(){
	window.clearTimeout(timeobject);
	timeobject=window.setTimeout('$("div.raumlayer").hide()',3000);
	
}

function jAlleLayerAus() {
	$("div.raumlayer").hide();
}

function preloadImages()
{
  for(var i = 0; i<arguments.length; i++)
  {
	$("<img>").attr("src", arguments[i]);
  }
}


/* jINIT starts here */
$(function(){
/*
		if ( $('#showGlossar').length ) {

			$('#showGlossar').mouseover(function(){
				 jRelPos('glossarLayer', 'InhaltContainer', 5, 25);
				 $('#glossarLayer').show();
			});
      }
*/
	    $.fn.extend({
	        // Tooltip for glossary items
	        glossarTip : function() {
	            $('dl[class*="glossarEintrag"]').hide();
	            $('dfn')
	            .hover(
	            function(e) {
	                var g = $('dl[class*="'
	                + $(this).attr('class').replace('g', '') + '"]');
	                var t = g.children('dt').html();
	                var i = g.children('dd').html();
	                $('body')
	                .append(
	                '<div id="glossarTip"><h6>' + t + '</h6><p>' + i + '</p></div>');
	                $('#glossarTip').css({
	                    top : ((e.pageY + 15) + 'px'),
	                    left : (e.pageX + 'px')
	                });
	            }, function() {
	                $('#glossarTip').remove();
	            });
	            $('dfn').mousemove(function(e) {
	                $('#glossarTip').css({
	                    top : ((e.pageY + 15) + 'px'),
	                    left : (e.pageX + 'px')
	                });
	            });
	        }
	    });
	    $('body').glossarTip();

		$("#InhaltContainer table.Features tr:nth-child(2n)").addClass("even");

		//see mantis #16931
		if ($(".accordion").size()>0)
			$(".accordion").accordion({ animated: 'slide', collapsible: true, autoHeight: false, active: false });

		/* beautyOfCode: ab Version 3.x */
		if (typeof SyntaxHighlighter != "undefined") {		
			SyntaxHighlighter.defaults['toolbar'] = false;
			SyntaxHighlighter.all();
		}

		//fancybox: bildvergroesserung
		$("a[rel=FancyBox]").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'inside'
		});
		//Trick 0-8-14: damit die LupenVersionen nicht in der gleichen Gruppe sind, wird eine extra angelegt - leider wird die Shadowbox-schreibweise hier unbekannt
		$("a[rel=FancyBoxLupe]").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'inside'
		});
		//Trick 0-8-15: wenn die "alte" shadowbox Aufruf passt, uebernimmt FancyBox diesen - ich kenne nur 2 Schreibweisen und diese klappen - bin aber nicht sicher ob immer... 
		$("a[rel^=shadowbox]").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'inside'
		});

	if ( $('a.fancybox-media').length )
	{
		  /* HTML5+- */
        $("a.fancybox-media").fancybox({
            'autoScale'     : true,
            'autoDimensions': true,
            'width'         : _videowidth || 640,
            'height'        : _videoheight || 480,
            'transitionIn'  : 'fade',
            'transitionOut' : 'fade',
            'easingIn'      : 'easeOutBack',
            'easingOut'     : 'easeInBack',
            'type'          : 'ajax',
            'titleShow'     : false,
            'onComplete'    : function () {
                jQuery(html5media);
                $("audio#fancybox_media_tag").parent().parent().parent().width($("#fancybox_media_tag").width()+26);
                $("video#fancybox_media_tag").parent().parent().parent().width($("#fancybox_media_tag").width()+26);
                $("span#fancybox_media_tag").parent().attr({style: "overflow:hidden;"});
                $("span#fancybox_media_tag").parent().parent().parent().width($("#fancybox_media_tag").width()+16);
                $("#fancybox-inner").width($("#fancybox_media_tag").width()+8);
                $.fancybox.resize();
            }
        });		
	}
		
	//flowplayerINfancybox: nur wenn vorhanden
	if ( $('.video_link').length )
	{
		var videoclip='';
		var player='';
		
		$(".video_link").hover(function(){
			videoclip=$(this).attr('href');
			$(this).attr({"href":"#video_box"});
			},
			function(){
				$(this).attr({"href":videopath+videoclip+""});
			}
		);
		
 		/* ACHTUNG: fundamentale Ã„nderungen an fancybox1.3.x im CSS, Classennamen, JS-API */
		$(".video_link").fancybox({
			'hideOnContentClick':false,
			'titlePosition' 	: 'inside',
			'overlayOpacity' :.6,
         'width'         : _videowidth || 640,
         'height'        : _videoheight || 480,
			'zoomSpeedIn'    :400,
			'zoomSpeedOut'   :400,
			'easingIn'		 : 'easeOutBack',
			'easingOut'		 : 'easeInBack',
			'onComplete' :function(){
					/* normales flowplayerobjekt */
					/* player = $f("fancy_div",swfplayer,{ */
					player = $f("fancybox-inner",swfplayer,{
					play:{opacity:0},
					plugins: {
							controls: {
								 url: 'http://www.universal-messenger.de/libs/flowplayer.controls-3.1.1.swf',
								 autoPlay: true,
								 fullscreen: true,
								 backgroundColor: '#333333',
								 backgroundGradient: 'low',
								 all: false,
								 play: true,
								 time: false,
								 scrubber: true,
								 mute: true,
								 height: 25,
								 progressColor: '#999999',
								 bufferColor: '#333333',
								 opacity: 0.5,
								 autoHide: 'always'
							}
					},
					clip:{
						autoPlay:true,
						autoBuffering:true,
						url:videopath+videoclip+'',
						onStart:function(clip){
							//alert('onStart: ');
							/* piMiniPimp fÃ¼r eine feste WunschhÃ¶he */
							/* see $.fn.fancybox.defaults: autoScale + autoDimensions ; ist damit scheinbar nicht mehr nÃ¶tig ;) */
							/* Test im Gange...
							*/
						},
						onFinish:function(){
							$('#fancy-close').trigger('click');
						}
					}
				});
				player.load();
				$('#fancy-close').click(function(){
					$("#fancy_div_api").remove();
				});
			},
			'callbackOnClose':function(){
				$("#fancy_div_api").remove();
			}
		});

	}//4flowpayer-end
		
	});

