
function getFlvPlayerLibPath(){	return '/en/system/Scripts/flvplayer/'; }

/**
* execute when the DOM is loaded
* @author ctietze
*/
$(document).ready(function(){
  var imgLinks = $("a[rel^='lightbox']");

  if (imgLinks.length > 0) {
	imgLinks.prettyPhoto();
	}
});

//////////////////////////////////////////////////////////////////////////
// Author: mkalmes
// Synopsis: used by velocity callback template snippets
// Call: javascript:doRecommendPageDialog('${docData.get("uuid")}','/nbg/anwendungen/seiteweiterempfehlen.jsp','Seite weiterempfehlen','de')
//
function doRecommendPageDialog( uuid, href, title, lang )
{
	var params = "?uuid="+uuid;
	var hrefVal = "/en/Applications/recommend-Page.jsp";
	if( href && typeof(href) != "undefined" )
	{
		hrefVal = href;
	}
	href += params;
	var height=610;
	var width=600;
	doGenericDialog(height,width,title,lang,href);
}

//////////////////////////////////////////////////////////////////////////
//Author: mkalmes
//Synopsis: used by velocity callback template snippets
//Call: javascript:doSendFeedbackDialog('${docData.get("uuid")}','/nbg/Kontakt/Feedback.jsp','Geben Sie uns Ihr Feedback zu unserem Internetauftritt','de')
//
function doFeedbackDialog( uuid, href, title, lang )
{
	var params = "?uuid="+uuid;
	var hrefVal = "/en/Kontakt/Feedback.jsp";
	if( href && typeof(href) != "undefined" )
	{
		hrefVal = href;
	}
	href += params;
	var height=610;
	var width=600;
	doGenericDialog(height,width,title,lang,href);
}

//////////////////////////////////////////////////////////////////////////
// Author: mkalmes
// Date: 1.10.2009
// Synopsis: used by velocity callback template snippets
// Call: javascript:doCallbackDialog('$cb_mail_1','$cb_mail_2','${docData.get("uuid")}','/nbg/Kontakt/callback.jsp','R&uuml;ckruf anfordern','de')
//
function doCallbackDialog( mail1, mail2, uuid, href, title, lang, pid )
{
	if( mail1 && typeof(mail1) != "undefined")
	{
		if( mail1.indexOf("$") > -1 )
		{
			mail1 = "";
		}
	}
	if( mail2 && typeof(mail1) != "undefined")
	{
		if( mail2.indexOf("$") > -1 )
		{
			mail2 = "";
		}
	}
	
	var pidReq = "";
	if( pid && typeof(pid) != "undefined")
	{
		pidReq = "&pid="+pid;
	}
	
	var params = "?mail1="+mail1+"&mail2="+mail2+"&uuid="+uuid+pidReq;
	var hrefVal =	"/en/Kontakt/callback.jsp";
	if( href && typeof(href) != "undefined" )
	{
		hrefVal = href;
	}
	href += params;
	var height=660;
	var width=600;
	doGenericDialog(height,width,title,lang,href);
}

//////////////////////////////////////////////////////////////////////////
// Author: ischwarzer
// Date: 23.03.2011
// Synopsis: used by velocity callback template snippets
// Call: javascript:doSendMailDialog('$cb_mail_1','$cb_mail_2','${docData.get("uuid")}','/nbg/Kontakt/Email.jsp','E-Mail','de')
//
function doSendMailDialog( mail1, mail2, uuid, href, title, lang, pid )
{
	if( mail1 && typeof(mail1) != "undefined")
	{
		if( mail1.indexOf("$") > -1 )
		{
			mail1 = "";
		}
	}
	if( mail2 && typeof(mail1) != "undefined")
	{
		if( mail2.indexOf("$") > -1 )
		{
			mail2 = "";
		}
	}
	
	var pidReq = "";
	if( pid && typeof(pid) != "undefined")
	{
		pidReq = "&pid="+pid;
	}
	
	var params = "?mail1="+mail1+"&mail2="+mail2+"&uuid="+uuid+pidReq;
	var hrefVal =	"/en/Kontakt/callback.jsp";
	if( href && typeof(href) != "undefined" )
	{
		hrefVal = href;
	}
	href += params;
	var height=790;
	var width=600;
	doGenericDialog(height,width,title,lang,href);
}

//////////////////////////////////////////////////////////////////////////
//Author: ischwarzer
//Synopsis: used by velocity callback template snippets
//Call: javascript:doShowGalleryImage(
//	'${docData.get("page")}','${docData.get("gallery_uuid")}','${docData.get("image_uuid")}','/nbg/anwendungen/zeigeGalerieBild.jsp','Bildergalerie','de')
//?page=1&gallery=76c63ac2-15ab-407f-b5f3-f89fa8d074b2&image=8d7370c8-3085-4173-93d7-dd8e277c7e76
function doShowGalleryImage( page, gallery_uuid, image_uuid, href, title, lang )
{
	var params = "?page="+page+"&gallery="+gallery_uuid+"&image="+image_uuid;
	var hrefVal = "/en/anwendungen/zeigeGalerieBild.jsp";
	if( href && typeof(href) != "undefined" )
	{
		hrefVal = href;
	}
	href += params;
	var height=740;
	var width=640;
	doGenericDialog(height,width,title,lang,href);
}


//////////////////////////////////////////////////////////////////////////
// Author: mkalmes
// Date: 1.10.2009
// Synopsis: creates a generic jquery dialog with iframe
//
function doGenericDialog( height,width,title,lang,href )
{
	var html = '';
	html += '<div id="dialogDivGeneric" style=margin: 0px; padding: 0px;">';
	if(href && typeof(href) != "undefined" )
	{
		html += '<iframe src="'+href+'" width="100%" height="100%" frameborder="0" align="center"/></iframe>';
	}
	html += '</div>';

	$("body").append(html);
	
	dialogDiv = $("#dialogDivGeneric");
	
	var heightL = parseInt(height);
	if(isNaN(heightL))
	{
		heightL = 570;
	}
	var widthL = parseInt(width);
	if(isNaN(widthL))
	{
		widthL = 600;
	}
	
	var closeTxt = "Close";
	if(lang != "de" )
	{
		closeTxt = "Close";
	}
	
	// way to pass variable text to button title
	var buttons = {};
	buttons[closeTxt] = function(){$(this).dialog('destroy').remove(); }

	// create dialog
	dialogDiv.dialog(
	{
		autoOpen: false,
		close: function(){$(this).dialog('destroy').remove();},
		height: eval(heightL),
		width: eval(widthL),
		title: title,
		modal: true,
		bgiframe:false,
		overlay: {	background: "gray",opacity: 0.5	},
		buttons: buttons
	});
	dialogDiv.dialog("open");
}

//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// create method to create swf-player to play core swf files
//
function embedSwfObject(divId, flv_url, sWidth, sHeight, pAutostart) 
{
	if( swfobject )
	{
		var v_width = "520";
		var v_height= "336";
		var v_as = "false";
				
		if( isNaN(parseInt(sWidth)) == false )
		{
			v_width = sWidth + "";
		}
		if( isNaN(parseInt(sHeight)) == false )
		{
			v_height = sHeight + "";
		}
		if( pAutostart == true )
		{
			v_as = "true";
		}
		
		// if(swfobject.hasFlashPlayerVersion("8")) ???
		var att = { data: flv_url, width: v_width, height: v_height };
		var par = { menu:"false", autostart: v_as };
		var myFlashContent = swfobject.createSWF(att, par, divId);
	}
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// create method to create flowplayer flv player
//
function createFlvPlayer( divId, flv_url, autostart) 
{
		var params = "";
		if( flv_url != null || typeof flv_url != "undefined" )
		{
			if( flv_url.toLowerCase().indexOf(".swf") > -1 )
			{
				// swf files to play in flv player
				// no controls autoplay true and duration infinity to prevent showing reply button
				params = 
				{
					plugins: { controls: null },					
			    clip : 
		  	  {  
		    	    autoPlay: true, 
		      	  autoBuffering: true, 
		        	url: flv_url,
 		        	loop: false,		        	
		        	duration: 10000000
		    	},
		    	play: { replayLabel: '' }
				}
			}
			else
			{
				// ordinary flv files			
				if( typeof autostart == "undefined" || autostart == null )
				{
					autostart = true;
				}
				params = 
				{
					plugins:
					{
						controls:
						{
	            url: getFlvPlayerLibPath()+'flowplayer.controls-tube-3.1.4.swf',
							autoHide: 'always',
							hideDelay:	4000,
							stop: true,
							progressColor: '#015B7A',
							bufferColor: '#6c9cbc',
							buttonOverColor: '#92B2BD',
							volumeSliderColor: '#6c9cbc',
							volumeBarHeightRatio: 0.3
						}
					},
			    clip : 
		  	  {  
		    	    autoPlay: autostart, 
		      	  autoBuffering: true, 
 		        	loop: false,
		        	url: flv_url
		    	},
		    	play: { replayLabel: '' }
				}
			}
		}
		flowplayer(divId, getFlvPlayerLibPath()+"flowplayer-3.1.4.swf",params);
}

//////////////////////////////////////////////////////////////////////////
// from mkalmes
//
function embedVideo(divId, videoUrl, autostart)
{
	createFlvPlayer(divId,videoUrl,autostart);
}

//////////////////////////////////////////////////////////////////////////
// from jarek
//
function showVideoDialog(videoUrl,title, sWidth, sHeight, pAutostart) 
{
	if( !title || typeof title == "undefined" )
	{
		title = "Video Dialog";
	}
	
	var dialogDiv = document.getElementById("#div_video");
	
	if(dialogDiv != null)
	{
		document.body.removeChild(dialogDiv);
	}

	var v_width = "520";
	var v_height= "336";
	var v_as = "false";

	if( isNaN(parseInt(sWidth)) == false )
	{
		v_width = sWidth + "";
	}
	if( isNaN(parseInt(sHeight)) == false )
	{
		v_height = sHeight + "";
	}
	if( pAutostart == true )
	{
		v_as = "true";
	}
	if (dialogDiv == null)
	{
		var style = "width="+v_width+"px; height: "+v_height+"px;";
		$("body").append('<div id="div_video"><div id="replaced" style="'+style+'"></div></div>');
	}
	
	dialogDiv = $("#div_video");
	
	// create dialog
	dialogDiv.dialog(
	{
		autoOpen: false
		,close: function(){$(this).dialog('destroy').remove();}
		,height: (parseInt(v_height)+100)
		,title: ""
		,width: (parseInt(v_width)+30)
		,title: title
		,modal: true
		,bgiframe:true
		,overlay: {	background: "gray",opacity: 0.5	}
	});
	
	if( videoUrl.toLowerCase().indexOf(".swf") > -1 )
	{
		embedSwfObject('replaced', videoUrl, v_width, v_height, true);
	}
	else
	{
		createFlvPlayer('replaced',videoUrl);		
	}
		
	$("#div_video").dialog("open");
}

/**
* write mails per javascript to document to complicate reading for bots 
* @author ctietze
* @param String mail prefix
* @param String mail postfix
*/
function writeMail(prefix,postfix) {
	var txtPrefix = (prefix <= 15) ? prefix : prefix + " ";
	document.write("<a href=\"mailto:"+prefix+"@"+postfix+"\">"+txtPrefix+"@"+postfix+"</a>");
}

function initDatepicker(datepicker_id)
{
	datepicker_id = "#" + datepicker_id;
	$(function() {
		$(datepicker_id).datepicker({showOn: 'both', buttonImage: '/en/system/CSS/images/calendar.gif', buttonImageOnly: true});
		$(datepicker_id).datepicker('option', 'dateFormat', 'dd.mm.yy');
		$(datepicker_id).datepicker('option', 'changeMonth', true);
		$(datepicker_id).datepicker('option', 'changeYear', true);
		$(datepicker_id).datepicker('option', 'closeText', 'Schlie&szlig;en');
		$(datepicker_id).datepicker('option', 'currentText', 'Heute');
		$(datepicker_id).datepicker('option', { dayNamesMin: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'] });
		$(datepicker_id).datepicker('option', 'gotoCurrent', true);
		$(datepicker_id).datepicker('option', 'monthNames', ['Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember']);
		$(datepicker_id).datepicker('option', 'monthNamesShort', ['Jan','Feb','Mär','Apr','Mai','Jun','Jul','Aug','Sep','Okt','Nov','Dez']);
		$(datepicker_id).datepicker('option', 'nextText', 'Sp&auml;ter');
		$(datepicker_id).datepicker('option', 'prevText', 'Fr&uuml;her');
		$(datepicker_id).datepicker('option', 'showButtonPanel', true);
		$(datepicker_id).datepicker('option', 'buttonText', 'Chose');
	});
}


function doPrint( hideTitle )
{
	if( typeof(hideTitle) == "undefined" || hideTitle == "true")
	{
		$("title").html("");
	}
	window.print();
}
