function box_thema_over(layer_id) {
	
	document.getElementById(layer_id).style.backgroundImage = 'url(../images/xx_box_thema.jpg)'; 
	document.getElementById(layer_id).style.backgroundPosition = 'bottom';

}
function box_thema_out(layer_id) {
	
	document.getElementById(layer_id).style.backgroundImage = 'url()';

}



function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}


function play_flash_file(video_url,video_width,video_height) {
	
	document.getElementById('flash_player_bg').style.visibility = "visible";
	var arrayPageSize = getPageSize('flash_player_bg');
	var arrayPageScroll = getPageScroll();

	document.getElementById('flash_player_bg').style.width = arrayPageSize[0] +"px";
	document.getElementById('flash_player_bg').style.height = arrayPageSize[1] +"px";

	
	document.getElementById('flash_player').style.visibility = "visible";
	
	
	frame_height = video_height + 20;
	
	document.getElementById('flash_player').style.width = video_width +"px";
	document.getElementById('flash_player').style.height = frame_height +"px";
	
	document.getElementById('flash_player_film').innerHTML = '<script type="text/javascript" src="../ufo.js"></script><embed src="../mediaplayer.swf" width="'+video_width+'" height="'+video_height+'" allowscriptaccess="always" allowfullscreen="true" flashvars="width='+video_width+'&height='+video_height+'&file='+video_url+'&image=images/icj.gif&displayheight='+video_height+'&searchbar=false&autostart=true" />';
	

	var position_y = arrayPageScroll[1] + (arrayPageSize[3] / 10);
	
	document.getElementById('flash_player').style.left = "50%";
	document.getElementById('flash_player').style.marginLeft = "-"+ (video_width / 2 ) +"px";
	document.getElementById('flash_player').style.top = position_y +"px";	
		

}


function hide_flash_player() {

	document.getElementById('flash_player_film').innerHTML = '';
	
	document.getElementById('flash_player_bg').style.visibility = "hidden";
	document.getElementById('flash_player').style.visibility = "hidden";

}

//-------------------- Sondersendungen --------------------
function show_sondersendung(weburl,video_width,video_height) {
	
	//var video_width = 990;
	//var video_height = 680;
	
	hideSelectBoxes();
	
	document.getElementById('sondersendung_bg').style.visibility = "visible";
	var arrayPageSize = getPageSize('sondersendung_bg');
	var arrayPageScroll = getPageScroll();

	document.getElementById('sondersendung_bg').style.width = arrayPageSize[0] +"px";
	document.getElementById('sondersendung_bg').style.height = arrayPageSize[1] +"px";

	
	document.getElementById('sondersendung').style.visibility = "visible";
	
	
	frame_height = video_height;
	
	document.getElementById('sondersendung').style.width = video_width +"px";
	document.getElementById('sondersendung').style.height = frame_height +"px";
	
	var position_y = arrayPageScroll[1] + (arrayPageSize[3] / 10) - 30;
	
	document.getElementById('sondersendung').style.left = "50%";
	document.getElementById('sondersendung').style.marginLeft = "-"+ (video_width / 2 ) +"px";
	document.getElementById('sondersendung').style.top = position_y +"px";	
	
	document.getElementById('sondersendung_navi').style.marginLeft = (video_width - 19) +"px";
	
	parent["frame_sondersendung"].width = video_width;
	parent["frame_sondersendung"].height = video_height;
	parent["frame_sondersendung"].location.href = weburl;	

}


function hide_sondersendung() {

	showSelectBoxes();
	
	parent["frame_sondersendung"].location.href = '';	
	document.getElementById('sondersendung_bg').style.visibility = "hidden";
	document.getElementById('sondersendung').style.visibility = "hidden";

}


//------------------ Detail-Tracking --------------------
function show_detailtracking(width,height) {
	
	document.getElementById('detailtracking_bg').style.visibility = "visible";
	var arrayPageSize = getPageSize('detailtracking_bg');
	var arrayPageScroll = getPageScroll();

	document.getElementById('detailtracking_bg').style.width = arrayPageSize[0] +"px";
	document.getElementById('detailtracking_bg').style.height = arrayPageSize[1] +"px";

	document.getElementById('detailtracking').style.visibility = "visible";
	
	
	frame_height = height + 0;
	
	document.getElementById('detailtracking').style.width = width +"px";
	document.getElementById('detailtracking').style.height = frame_height +"px";

	var position_y = arrayPageScroll[1] + (arrayPageSize[3] / 10);
	
	document.getElementById('detailtracking').style.left = "50%";
	document.getElementById('detailtracking').style.marginLeft = "-"+ (width / 2 ) +"px";
	document.getElementById('detailtracking').style.top = position_y +"px";		

}

function hide_detailtracking() {
	
	document.getElementById('detailtracking_bg').style.visibility = "hidden";
	document.getElementById('detailtracking').style.visibility = "hidden";

}


function hideSelectBoxes() {
	$("select").hide();
}

var kundenList = []

/* JQuery Init */

function loadEditor() {

	if($('textarea.editor').length > 0) {
		$('textarea.editor').tinymce({
	
			script_url : '../libs/tinymce/tiny_mce.js',
	    	
	    	theme : "advanced",
	    	plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advimage,advlink,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,noneditable,nonbreaking,template,ibrowser",
	    	theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
	    	theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,undo,redo,|,link,unlink,anchor,image,media,ibrowser,code,|,forecolor,backcolor",
	    	theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid",
	    	theme_advanced_toolbar_location : "top",
	    	theme_advanced_toolbar_align : "left",
	    	force_br_newlines : false,
			force_p_newlines : true,
	    	content_css : "master.css?" + new Date().getTime(),
	    	height: 400
		});
	}
}

function animateScroll(height){

	$('html, body').animate({
		scrollTop: height + 'px'
	}, 'slow');

}


$(document).ready(function() {

	/* Navigations-Layer */
	
	var timeout    = 500;
	var closetimer = 0;
	var ddmenuitem = 0;
	
	function jsddm_open()
	{  jsddm_canceltimer();
	   jsddm_close();
	   ddmenuitem = $("#navbox_" + $('a.navbox').index(this)).slideDown(300);
	}
	
	function jsddm_close()
	{  if(ddmenuitem) ddmenuitem.slideUp(200);}
	
	function jsddm_timer()
	{  closetimer = window.setTimeout(jsddm_close, timeout);}
	
	function jsddm_canceltimer()
	{  if(closetimer)
	   {  window.clearTimeout(closetimer);
	      closetimer = null;}}
	
	$('a.navbox').bind('mouseover', jsddm_open);
	$('a.navbox').bind('mouseout',  jsddm_timer);

	$('div.navi_layer').bind('mouseover', jsddm_canceltimer);
//	$('div.navi_layer').bind('mouseout',  jsddm_timer);

	document.onclick = jsddm_close;

	$(".erweiterteSucheLink").click(function() {
		$("#erweiterte_suche").slideToggle(500);
		$("#head_suche").toggle();
	});
	
	/* Loading autocomplete */

	$( "#suchbegriff" ).autocomplete({
		source: kundenList
	});
	$( "#suchbegriff_erweitert" ).autocomplete({
		source: kundenList
	});
	$( "#kundenpflege" ).autocomplete({
		source: kundenList
	});

	$( "#userpflege" ).autocomplete({
		source: kundenList
	});
	
	$('form[name="news_edit"] input[type="submit"]').click(function(event) {

		event.preventDefault();
		$('form[name="news_edit"] .error').each(function() {
			$(this).removeClass("error");
		});

		// check news picture
		if($("#newsbild").val() == "" && $("#containerNewsbild img").length < 1) {
	
		    if(!confirm('Sie haben noch kein Bild ausgewählt. Wollen Sie die News trotzdem veröffentlichen?'))
		    	$("#containerNewsbild").addClass("error");
		}

		// max. 2 entries per day
		var kunde_id = null;

		if($('form[name="news_edit"] input[name="kunde_id"]').length > 0)
			kunde_id = $('form[name="news_edit"] input[name="kunde_id"]').val();
		else
			kunde_id = $('form[name="news_edit"] select[name="kunde_id"]').val();

		$.get("news.php", {count: kunde_id, day: $('form[name="news_edit"] input[name="datum_jjjj"]').val() + '-' + $('form[name="news_edit"] input[name="datum_mm"]').val() + '-' + $('form[name="news_edit"] input[name="datum_tt"]').val()}, function(data) {
		
			if(parseInt(data) > 1) {
		    	$("#containerDatum").addClass("error");
		    } else {
				if($('form[name="news_edit"] .error').length < 1)
					$('form[name="news_edit"]').submit();
			}

		});

	});
	
	loadEditor();
	
	/* Content-Tabs */
	
	$('table.tabcontent a').click(function() {
	
		$(this).parents('table.tabcontent').fadeOut(500);
		$(this).parents('table.tabcontent').find('input, textarea').val('');
	
	});
	
	$('table.tabcontent select[name^="modultyp"]').change(function() {

			$(this).parents("table.tabcontent").find('.tabtext').toggle();
			$(this).parents("table.tabcontent").find('.tablink').toggle();
	});
	
	$('a.addtab').click(function() {
	
		$('table.tabcontent:last').after($('table.tabcontent:first').clone());
		$('table.tabcontent:last').fadeIn(500);
		$('table.tabcontent:last textarea').tinymce({
	
			script_url : '../libs/tinymce/tiny_mce.js',
	    	
	    	theme : "advanced",
	    	plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
	    	theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
	    	theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
	    	theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
	    	theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
	    	theme_advanced_toolbar_location : "top",
	    	theme_advanced_toolbar_align : "left",
	    	force_br_newlines : false,
			force_p_newlines : true,
	    	content_css : "master.css?" + new Date().getTime(),
	    	height: 400
		});

	});

	/* Eventregistrierung */

	$('form[name="eventRegister"] input[name="mtic"]').keyup(function() {
		if(!isNaN($(this).val()) && $(this).val().length == 8) {

			$.getJSON('http://mice-card.multi-pass.info/script_cardauth.x4?cardnr=' + $('form[name="eventRegister"] input[name="mtic"]').val() +'&cardmail=' + $('form[name="eventRegister"] input[name="email_pers"]').val(), function(data) {

				/* if data set is available, fill input fields */
				if(data.error === undefined) {

					// persönliche Daten
					if(data.anrede == 1)
						$('form[name="eventRegister"] select option[value="w"]').attr('selected',true);
					else
						$('form[name="eventRegister"] select option[value="m"]').attr('selected',true);
					

					$('form[name="eventRegister"] input[name="vorname"]').val(data.vorname);
					$('form[name="eventRegister"] input[name="nachname"]').val(data.nachname);

					// Firmendaten
					$('form[name="eventRegister"] input[name="firma"]').val(data.firma.firma);
					$('form[name="eventRegister"] input[name="strasse"]').val(data.firma.strasse);
					$('form[name="eventRegister"] input[name="plz"]').val(data.firma.plz);
					$('form[name="eventRegister"] input[name="ort"]').val(data.firma.ort);
					$('form[name="eventRegister"] input[name="email"]').val(data.firma.mail);
					$('form[name="eventRegister"] input[name="uri"]').val(data.firma.www);
					var tel1 = data.firma.tel.split("/");
					var tel2 = tel1[1].split("-");
					$('form[name="eventRegister"] input[name="vorwahl"]').val($.trim(tel1[0]));
					$('form[name="eventRegister"] input[name="telefon"]').val($.trim(tel2[0]));
					$('form[name="eventRegister"] input[name="durchwahl"]').val($.trim(tel2[1]));

					// Info ausgeben
					$('#autofillInfo').hide().html('<br />Ihre Daten wurden weitesgehend automatisch vervollständigt. Bitte überprüfen Sie die Angaben!<br />&nbsp;').fadeIn(500);

				}
			});
		}
	});
	
	$('form[name="eventRegister"] input[type="checkbox"][name="bild_vorhanden"]').click(function() {
	
		$('#registerUpload').fadeToggle(500);
	
	});
	
	/* Tab Slider */
	$("a.tabsection").click(function() {
		position = $('#tabsection'+($("a.tabsection").index(this) + 1)).position().left + 1000;
		$('#tabcontainer').animate({'left': '-='+position}, 1000);
	});

	$("a.tabsliderBack").click(function() {
		position = $(this).parent().find("a.tabsliderBack").position().left;
		$('#tabcontainer').animate({'left': '+='+position}, 1000);
	});

	if($('div.tabsection').length > 0) {
	
		parents = $('.detail_navi_aktiv').parents('div.tabsection');
		if(parents.length > 0) {
			position = parents.position().left + 1000;
			$('#tabcontainer').animate({'left': '-='+position}, 1000);
		}
	
	}
	
	/* Individueller Messestand */
	if($(".boothItem").length > 0) {

		$(".boothItem").css('opacity', '0.6');

		$(".boothItem").draggable({
			stop: function(event, ui) {
				$.ajax({
				   type: "POST",
				   url: "messestand.php",
				   data: ({icon_position : $(this).attr('id').replace(/boothItem/, ""), messestand: $('input[name="id"]').val(), x: $(this).position().top, y: $(this).position().left })
				});
			},
			containment: '#boothEdit'
		});

		$(".boothItem").click(function() {
			id = $(this).attr('id').replace(/boothItem/, "");
			if($("#messestand_icon" + id).css('display') == "none") {
				$(".messestand_icon").slideUp(500);
				$("#messestand_icon" + id).slideDown(500);
					//animateScroll($("#messestand_icon" + id).position().top);
			} else {
				$("#messestand_icon" + id).slideUp(500);
			}
		});
		
		$(".boothItem").mouseover(function() {
			$(this).animate({opacity: 1.0}, 'fast');
		});
	
		$(".boothItem").mouseout(function() {
			$(this).animate({opacity: 0.6}, 'fast');
		});
		
		$(".messestand_icon input[name='abort']").click(function() {
			$(this).parent().slideUp(500);
		});

		$(".messestand_icon input[name='save']").click(function() {

			$.ajax({
			   type: "POST",
			   url: "messestand.php",
			   data: ({icon_edit : $(this).parent().attr('id').replace(/messestand_icon/, ""), messestand: $('input[name="id"]').val(), titel: $(this).parent().find("input[name='titel']").val(), url: $(this).parent().find("input[name='url']").val() })
			});

			$(this).parent().slideUp(500);
		});

		$(".messestand_icon a.delete").click(function() {

			$.ajax({
			   type: "POST",
			   url: "messestand.php",
			   data: ({icon_delete : $(this).parent().attr('id').replace(/messestand_icon/, ""), messestand: $('input[name="id"]').val() })
			});

			$("#boothItem" + $(this).parent().attr('id').replace(/messestand_icon/, "")).fadeOut(500, function() {
				$(this).remove();
			});
			$(this).parent().slideUp(500);
		});

	}

	$("#new_icon").click(function() {

		$('div.new_icon:last').after($('div.new_icon:first').clone());
		$('div.new_icon:last').fadeIn(500);

	});
	
	$("form[name='news_edit'] select[name='kunde_id']").change(function() {

		if($(this).val() == 511)
			$(".agenturmail").fadeIn();
		else
			$(".agenturmail").fadeOut();

	});
	
	/* Location Map */
	
	$(".locationmap").mouseover(function() {
	
		$('#inf').html($(this).attr('rel'));
		$('#inf').show();
		$('#inf').css('left', $(this).position().left+9);
		$('#inf').css('top', $(this).position().top+9);
	});
	
	$(".locationmap").mouseout(function() {
	
		$("#inf").hide();
	
	});
	
	/* Kundennachricht */
	
	$("#kunden_messaging_all").click(function() {

		if($(this).attr("checked"))
			$("input[type='checkbox'][name^='empfaenger']").attr("checked", "checked");
		else
			$("input[type='checkbox'][name^='empfaenger']").attr("checked", "");
	
	});

	$("#kunden_messaging_mf").click(function() {

		if($(this).attr("checked"))
			$("input[type='checkbox'].mitgliedschaft_micefair_aktiv").attr("checked", "checked");
		else
			$("input[type='checkbox'].mitgliedschaft_micefair_aktiv").attr("checked", "");
	
	});

	$("#kunden_messaging_location").click(function() {

		if($(this).attr("checked"))
			$("input[type='checkbox'].mitgliedschaft_location").attr("checked", "checked");
		else
			$("input[type='checkbox'].mitgliedschaft_location").attr("checked", "");
	
	});

	$("#kunden_messaging_premium").click(function() {

		if($(this).attr("checked"))
			$("input[type='checkbox'].mitgliedschaft_premium").attr("checked", "checked");
		else
			$("input[type='checkbox'].mitgliedschaft_premium").attr("checked", "");
	
	});
	
	/* Diamonds Slider */
	
	$(".slidetabs").tabs(".diamondimages > div", {

	// enable "cross-fading" effect
	effect: 'fade',
	fadeOutSpeed: "slow",

	// start from the beginning after the last tab
	rotate: true

// use the slideshow plugin. It accepts its own configuration
	}).slideshow({
		autoplay: true,
		interval: 5000
	});

	$(".slidetabs").data("slideshow").stop();
	$(".slidetabs").data("slideshow").play();
		
});

