function openVideo(url)
{
	$('#VideoWinContent').html('<iframe width="480" height="310" frameborder="0" scrolling="no" src = "'+url+'"></iframe>');
	$('#VideoWin').jqmShow();
	return false;
}

function eml(ch1, ch2)
{
	var display_eml = ch2 + ch1;
	document.write(display_eml);
}

function checkNL(formid)
{
	if ($('#email'+formid).val().length < 6)
	{
		alert('Bitte geben Sie eine gültige E-Mail-Adresse an.')
		return(false);
	}
	
	if ($('#dse'+formid).attr('checked'))
	{
		return(true);
	} else {
		alert('Bitte stimmen Sie der Datenschutzerklärung zu.')
		return(false);
	}
}


$().ready(function() {
	$('#VideoWin').jqm({overlay: 75, modal: false, trigger: false, toTop: true,
		onHide: function(h) { 
			h.o.remove();
			h.w.hide();
			$('#VideoWinContent').html('');
		}
	});
	
	$.tools.validator.localize("de", {
		'*'			: 'Bitte &uuml;berprüfen Sie Ihre Eingebe!',
		':email'  	: 'Bitte geben Sie eine g&uuml;ltige E-Mail-Adresse ein!',
		':number' 	: 'Bitte geben Sie eine Zahl ein!',
		':url' 		: 'Bitte geben Sie eine Internet-Adresse ein!',
		'[max]'	 	: 'Bitte geben Sie einen Wert kleiner als $1 ein!',
		'[min]'		: 'Bitte geben Sie einen Wert gr&ouml;&szlig;er als $1 ein!',
		'[required]': 'Bitte f&uuml;llen Sie dieses Pflichtfeld aus!'
	});

	$(".checkform").validator({
		lang: 'de', 
		singleError: true,
		position: 'top left', 
		offset: [-11, -9],
		message: '<div><em/></div>'
	});

	$(".checkform_v").validator({
		lang: 'de', 
		singleError: true,
		position: 'top left', 
		offset: [-11, 30],
		message: '<div><em/></div>'
	});

	$(".checkform, .checkform_v").bind("onFail", function(e, errors)  {

	// we are only doing stuff when the form is submitted
	if (e.originalEvent.type == 'submit') {

		// loop through Error objects and add the border color
		$.each(errors, function()  {
			var input = this.input;
			input.css({borderColor: '#cc0000'}).focus(function()  {
				input.css({borderColor: '#999999'});
			});
			
			$.scrollTo(input, 200, { axis: 'y' , offset: -50 } );
		});
	}
	
	});

	$('.input_date').inputmask("99.99.99?99");
	
	$('video,audio').mediaelementplayer({
		videoWidth: $('.player_parent').width(),
		videoHeight: parseInt($('.player_parent').width()/16*9)+1,
		features: ['playpause','progress','current','duration','volume']
	});
	
	$("a[rel]").overlay({
		top: '5%',
		fixed: true,
		closeOnClick: false,
		closeOnEsc: false,
		mask: {
				color: '#fff',
				opacity: 0.9
			},
		effect: 'apple',

		onBeforeLoad: function() {
			if (this.getTrigger().attr("rel") != 'nofollow') {
				if (this.getOverlay().attr('id') != 'overlay_480') this.getOverlay().find(".contentWrap").html("<iframe src=\""+this.getTrigger().attr("href")+"\" frameborder=\"0\" width=\"100\" height=\"100\" id=\"ovIframe\"><iframe>");
				else this.getOverlay().find(".contentWrap").html('<video src="'+this.getTrigger().attr("href")+'" width="480" height="270" id="VideoPlayer" controls="controls" autoplay="true" preload="none"><source type="video/mp4" src="'+this.getTrigger().attr("href")+'" /></video>');
			}
		},
		onLoad: function() {
			if (this.getOverlay().attr('id') == 'overlay_480')
			{
				var mediaplayer = new MediaElementPlayer('#VideoPlayer', {
					pluginPath: '/eh-content/js/mediaelement/',
					flashName: 'flashmediaelement.swf',
					silverlightName: 'silverlightmediaelement.xap',
					plugins: ['flash','silverlight'],
					features: ['playpause','progress','volume']
				});
			}
		},
		onBeforeClose: function() {
			if (this.getOverlay().attr('id') == 'overlay_480')
			{
				$("#VideoPlayer").remove();
			} else {
				$("#ovIframe").remove();
			}
		}
	});


	$(".catch_form").submit(function() {
		$('#overlay_800').overlay({
			top: '5%',
			fixed: true,
			closeOnClick: false,
			closeOnEsc: false,
			load: true,
			mask: {
					color: '#fff',
					opacity: 0.9
				},
			effect: 'apple',
	
			onBeforeLoad: function() {
				this.getOverlay().find(".contentWrap").html("<iframe frameborder=\"0\" width=\"100\" height=\"100\" id=\"ovIframe\" name=\"ovIframe\"><iframe>");
			},
			onBeforeClose: function() {
				$("#ovIframe").remove();
			}
		});
		$('#overlay_800').data("overlay").load();
	});
	
});

$(window).load(function(){
	if ($(".submenu").outerHeight() > $("#sidebar").outerHeight()) 
	{
		if ($("#contentcontainer").outerHeight() < $(".submenu").outerHeight()) $("#contentcontainer").height($(".submenu").outerHeight()+50);
	}
	else if ($(".submenu").outerHeight() < $("#sidebar").outerHeight()) 
	{
		if ($("#contentcontainer").outerHeight() < $("#sidebar").outerHeight()) $("#contentcontainer").height($("#sidebar").outerHeight()+50);
	}
	
	
	var position = $('.sidebar_inside_add_first_element').offset();
	if (position != null) 
	{
		var sidebar_top = position.top;
		var positionOk = 0;
	
		var i = 0;
		$('.elementborder_adminedit').each(function() {
			i = i+1;
			var position = $(this).offset();
			var element_top = position.top;
		
			if ((i == 1) || (((element_top-old_element_top) < 230) && (positionOk != 1))) {
				$('.sidebar_inside_add_first_element').offset({ top: element_top+65 });
			} else {
				positionOk = 1;
			}
			
			old_element_top = element_top;
		});
	}
});

