$(function(){
	$('body').removeClass('no-js').addClass('js');
	$('div.#intro ul li:nth-child(2n+1)').addClass('firstInRow');
});

$.html5forms();
/*
$(function(){
	$('.teaser-image-text .iPpMod').each(function(i) {
		var img = $('.image-container', this),
				lnk = $('a:first', this),
				c = 'onHover',
				m = {
					over: function(){
						img.addClass(c);
						lnk.addClass(c);
					},
					out: function(){
						img.removeClass(c);
						lnk.removeClass(c);
					}
				};
		lnk.hover(m.over, m.out);
		img.click(function(){
			location.href = lnk.attr('href');
		}).hover(m.over, m.out);
	})
});
*/
$(function(){
	$('#contentFooter ul').each(function(i) {
		var printLink = '<li class="contentFooter-print"><a class="icon icon-print" href="javascript:window.print();">Seite drucken</a></li>';
		$(this).prepend($(printLink));
	})
});



/*Funktion fï¿½r die Suchbox Lupe*/
$(function() {
    $('input#searchInp').css({ background: 'url("../img/icon_search.png") no-repeat scroll 6px 6px #FFFFFF' });
    $('input#searchInp').blur(function() {
        if ($('input#searchInp').val().length == 0) {
            $(this).css({ background: 'url("../img/icon_search.png") no-repeat scroll 6px 6px #FFFFFF' });
        }
    });
    $('input#searchInp').focus(function() {
        $(this).css({ background: 'none' });
    });

});

$(function() {
	$('.article-gallery .item_gallery .fancy').each(function(i) {
		var download = $(this).attr('data-download');
		var download_title = $(this).attr('data-download-title');
		$(this).fancybox({ 'titlePosition': 'inside', 'titleFormat': function(title, currentArray, currentIndex, currentOpts) {
			return '<span class="custom-fancy-bildgalerie-title">' + title + '</span><a class="custom-fancy-bildgalerie-link" target="_blank" href="' + download + '">' + download_title + '</a>';
		}
		});
	})
});

$(function() {
	$('#content .article-rte table tr:first-child th').each(function(i) {
		$(this).addClass('jsfix');
		$(this).wrapInner('<span />');
	})
});

$(function() {
    $('.article-accordion .iPpMod').each(function() {
        $(this).accordion({
			autoHeight: false,
			navigation: true
		});

    });
});

$(function() {
    $('.form-accordion-kongress .acckong').each(function() {
        $(this).accordion({
			autoHeight: false,
			navigation: true
		});

    });
});

$(function() {
    $('.shopping-cart-contact .accordion').click(function() {
        $(this).next().toggle('fast');
        $(this).addClass("active");
    });
});


$(function() {
	$('#player').each(function(i) {
		flowplayer(this, "/system/modules/com.pixelpark.opencms/resources/swf/flowplayer-3.2.5.swf", {
			plugins: {
				controls: {
					timeColor: 'rgba(166, 82, 97, 1)',
					timeFontSize: '11px',
					borderRadius: '0px',
					slowForward: true,
					bufferGradient: 'none',
					backgroundColor: 'rgba(230, 230, 230, 1)',
					volumeSliderGradient: 'none',
					slowBackward: false,
					timeBorderRadius: 0,
					time: true,
					progressGradient: 'none',
					height: 22,
					tooltips: {
						marginBottom: 5,
						volume: true,
						scrubber: true,
						buttons: false
					},
					fastBackward: false,
					opacity: 1,
					volumeSliderColor: '#ffffff',
					border: '0px',
					bufferColor: 'rgba(110, 110, 110, 1)',
					buttonColor: 'rgba(112, 26, 50, 1)',
					mute: true,
					autoHide: {
						enabled: true,
						hideDelay: 500,
						hideStyle: 'fade',
						mouseOutDelay: 500,
						hideDuration: 400,
						fullscreenOnly: true
					},
					backgroundGradient: 'none',
					width: '100pct',
					display: 'block',
					buttonOverColor: 'rgba(166, 113, 128, 1)',
					//url:'flowplayer.controls-tube-3.2.3.swf',
					fullscreen: false,
					timeBgColor: 'rgba(0, 0, 0, 0)',
					scrubberBarHeightRatio: 0.15,
					bottom: 0,
					stop: false,
					zIndex: 1,
					sliderColor: '#C9C9C9',
					borderColor: 'rgba(161, 161, 161, 1)',
					scrubberHeightRatio: 0.82,
					tooltipTextColor: '#D00000',
					sliderGradient: 'none',
					spacing: {
						all: 0
					},
					timeBgHeightRatio: 0.6,
					volumeSliderHeightRatio: 0.4,
					name: 'controls',
					volumeBarHeightRatio: 0.28,
					left: '50pct',
					tooltipColor: '#C9C9C9',
                    playlist: false,
                    durationColor: 'rgba(59, 59, 59, 1)',
                    play: true,
                    fastForward: true,
                    timeBorder: '1px solid rgba(0, 0, 0, 0.3)',
                    progressColor: 'rgba(185, 185, 185, 1)',
                    volumeBorderRadius: 0,
                    scrubberBorderRadius: 0,
                    scrubber: true,
                    volume: false,
                    builtIn: false,
                    margins: [0, 0, 0, 0]
				}
			}
		})
	});
});

$(function() {
    $('.article-accordion .iPpMod').each(function(){
    $(this).accordion({
        autoHeight: false,
        navigation: true
    });

	});
});

//flash container
$(function() {
	var defaultParams = {
		quality: 'high',
		allowscriptaccess: 'sameDomain',
		allowfullscreen: 'true',
		scale: 'noscale',
		wmode: 'transparent'
	};
	var ID = {};
	(function(context) {
		var id = 0;

		context.next = function() {
			return id++;
		};

		context.current = function() {
			return id;
		};

		context.reset = function() {
			id = 0;
		}
	})(ID);
	var defaultAttributes = {
		align: "left"
	};

	$('.article-flash').each(function(i) {
		var id = 'article-flash-' + ID.next();
		$('.iPpMod', this).attr('id', id);
		$('span', this).remove();
		var flash_source = $(this).attr('data-flashfile'),
		width = ($(this).attr('data-width') != '') ? $(this).attr('data-width') : 300,
		height = ($(this).attr('data-height') != '') ? $(this).attr('data-height') : 200,
		flashvars = ($(this).attr('data-flashvars') != '') ? $.parseJSON($(this).attr('data-flashvars')) : null,
		params = $.extend({}, defaultParams),
		attributes = $.extend({}, defaultAttributes, { name: id + '-obj', id: id + '-obj' });
		console.debug(flashvars, params, attributes);
		console.debug(flash_source, width, height);
		swfobject.embedSWF(flash_source, id, width, height, "9.0.0", '/system/modules/com.pixelpark.opencms/resources/swf/expressInstall.swf', flashvars, params);
	});
});

//datepicker
$(function() {
	var options = {
		showOn: "button",
		buttonImage: "/system/modules/com.pixelpark.opencms/resources/img/datepickerIcon.png",
		buttonImageOnly: true,
		maxDate: new Date(2011, 11, 31),
		minDate: new Date(2011, 0, 1)

	};

	if ($('#field-date input[type="text"]').length) {
		options.beforeShow = function(input, inst) {
			var p = inst.dpDiv.parent();
			var off = $(input).offset();
			var sib = $(input).siblings('img').offset();
			p.offset({ left: off.left * -1 + sib.left + 24, top: off.top * -1 + sib.top - 27 });

		};
		options.onSelect = function(dateText, inst) {
			if (inst.id == "date-from") {

				$("#date-till").datepicker("option", "minDate", dateText);
			}
		};

	}
	$('#field-date input[type="text"]').each(function() {
		$(this).datepicker(options);
	});

});

//startseite mehrfachteaser
$(document).ready(function() {
	var ss_t = '';
	var ss_delaytime = 5000;
	clearInterval(ss_t);
	ss_einblenden();
	ss_t = setInterval('ss_einblenden()', ss_delaytime);
	
	$('#entry1').mouseover(function() {
		clearInterval(ss_t);
		$('.article-homepage-intro ol li').removeClass('active');
		$(this).addClass('active');
		$(".article-homepage-intro .detail div").hide();
		$("#news1").show();
	});

	$('#entry2').mouseover(function() {
		clearInterval(ss_t);
		$('.article-homepage-intro ol li').removeClass('active');
		$(this).addClass('active');
		$(".article-homepage-intro .detail div").hide();
		$("#news2").show();
	});

	$('#entry3').mouseover(function() {
		clearInterval(ss_t);
		$('.article-homepage-intro ol li').removeClass('active');
		$(this).addClass('active');
		$(".article-homepage-intro .detail div").hide();
		$("#news3").show();
	});

	$('#entry4').mouseover(function() {
		clearInterval(ss_t);
		$('.article-homepage-intro ol li').removeClass('active');
		$(this).addClass('active');
		$(".article-homepage-intro .detail div").hide();
		$("#news4").show();
	});

	$('#entry5').mouseover(function() {
		clearInterval(ss_t);
		$('.article-homepage-intro ol li').removeClass('active');
		$(this).addClass('active');
		$(".article-homepage-intro .detail div").hide();
		$("#news5").show();
	});

	$('#entry6').mouseover(function() {
		clearInterval(ss_t);
		$('.article-homepage-intro ol li').removeClass('active');
		$(this).addClass('active');
		$(".article-homepage-intro .detail div").hide();
		$("#news6").show();
	});

	$('#entry7').mouseover(function() {
		clearInterval(ss_t);
		$('.article-homepage-intro ol li').removeClass('active');
		$(this).addClass('active');
		$(".article-homepage-intro .detail div").hide();
		$("#news7").show();
	});

	$('#entry8').mouseover(function() {
		clearInterval(ss_t);
		$('.article-homepage-intro ol li').removeClass('active');
		$(this).addClass('active');
		$(".article-homepage-intro .detail div").hide();
		$("#news8").show();
	});

	$('#entry9').mouseover(function() {
		clearInterval(ss_t);
		$('.article-homepage-intro ol li').removeClass('active');
		$(this).addClass('active');
		$(".article-homepage-intro .detail div").hide();
		$("#news9").show();
	});

	$('#entry10').mouseover(function() {
		clearInterval(ss_t);
		$('.article-homepage-intro ol li').removeClass('active');
		$(this).addClass('active');
		$(".article-homepage-intro .detail div").hide();
		$("#news10").show();
	});

	$('.article-homepage-intro ol li').mouseout(function() {
		ss_t = setInterval('ss_einblenden()', ss_delaytime);
	});
});

function ss_einblenden() {

	for (var i = 1; i <= 10; i++) {
		var tempEntryObject = $('#entry' + i);
		if (tempEntryObject.length > 0 && tempEntryObject.hasClass("active").toString() == 'true') {
			var iNextIndex = i + 1;
			var tempNextEntryObject = $('#entry' + iNextIndex);
			var tempNextNewsObject = $('#news' + iNextIndex);
			if (tempNextEntryObject.length < 1) {
				iNextIndex = 1;
				tempNextEntryObject = $('#entry' + iNextIndex);
				tempNextNewsObject = $('#news' + iNextIndex);
			}
			// inactive all teaser (exclude the next)
			for (var j = 1; j <= 10; j++) {
				var tempEntryObjectHide = $('#entry' + j);
				if (tempEntryObjectHide.length > 0 && iNextIndex != j) {
					tempEntryObjectHide.removeClass("active");
					var tempNewsObjectHide = $('#news' + j);
					if (tempNewsObjectHide.length > 0) {
						tempNewsObjectHide.hide();
					}
				}
			}
			// the next active teaser
			tempNextEntryObject.addClass("active");
			if (tempNextNewsObject.length > 0) {
				tempNextNewsObject.show();
			}
			break;
		}
	}
	
};

$(function() {
    if ($("#info_dialogBox").length) {
        $("#dialog").fancybox();
    }
});

$(function() {
    if ($("#show_popup").val() == 'true') {
        $("#dialog").fancybox().trigger('click');
    }
});

$(function() {
    if ($("#show_finish_press").val() == 'true') {
        $("#dialog_finish_press").fancybox().trigger('click');
    }
});

$(function() {
    if ($("#show_dialogBox_press").val() == 'true') {
        $("#dialog_dialogBox_press").fancybox().trigger('click');
    }
});

$(function() {
    if ($("#show_finish_events").val() == 'true') {
        $("#dialog_finish_events").fancybox().trigger('click');
    }
});

$(function() {
    if ($("#show_dialogBox_events").val() == 'true') {
        $("#dialog_dialogBox_events").fancybox().trigger('click');
    }
});

$(function() {
    if ($("#show_finish_recommend").val() == 'true') {
        $("#dialog_finish_recommend").fancybox().trigger('click');
    }
});

$(function() {
    if ($("#show_dialogBox_recommend").val() == 'true') {
        $("#dialog_dialogBox_recommend").fancybox().trigger('click');
    }
});

function click_slideshow() {
   		$('#pic-' + active).removeClass('active').fadeOut(2000);
   		if (active < count-1) {
   			active++;
   		}
   		else {
   			active=0;
   		}
   		$('#pic-' + active).addClass('active').fadeIn(3000);
 };

 function add_container() {
     var newHTML = $('#member').html();
     var id = $('#platzhalter div').length;

         if (id % 2 == 0) {
             $('#platzhalter').append('<div class="platzhalter" id="member_' + id + '"></div>');
             newHTML = newHTML.replace(/##id##/g, id);
             $('#platzhalter div#member_' + id).html(newHTML);
         }
         else {
             $('#platzhalter').append('<div class="platzhalter second" id="member_' + id + '"></div>');
             newHTML = newHTML.replace(/##id##/g, id);
             $('#platzhalter div#member_' + id).html(newHTML);
         }


        check_container();

 };

 function delete_container(element) {
     $('#' + element + '').remove();
     check_container();
 };


 function check_container() {
     $('.platzhalter').each(function(index) {
     if (index % 2 == 0) {
            $(this).removeClass('platzhalter').removeClass('second').addClass('platzhalter');
         }
         else {
             $(this).removeClass('platzhalter').removeClass('second').addClass('platzhalter second');
         }
     });

 };


 $(function() {
     $('#date').change(function() {
         var valuesString = $(this).val();
         var values = valuesString.split(";");
         var valueEventplace = values[0];
         var valueBookingForm = "normalBookingForm";
         var valueHalfdayseminar = valueEventplace.replace(/eventplace/, "halfdayseminar");
         if (values.length > 1) {
        	 valueBookingForm = values[1];
         }
         $('.easyClear').each(function() {
             if (this.id == valueEventplace) {
                 $('#' + valueEventplace).removeClass('easyClear inactive').addClass('easyClear active');
             }
             else {
                 $('#' + this.id).removeClass('easyClear active').addClass('easyClear inactive');
             }
         });
         $('.easyClearBooking').each(function() {
             if (this.id == valueBookingForm) {
                 $('#' + valueBookingForm).removeClass('easyClearBooking inactive').addClass('easyClearBooking active');
             }
             else {
                 $('#' + this.id).removeClass('easyClearBooking active').addClass('easyClearBooking inactive');
             }
         });
         $('.easyClearHalfTimeSeminar').each(function() {
             if (this.id == valueHalfdayseminar) {
                 $('#' + valueHalfdayseminar).removeClass('easyClearHalfTimeSeminar inactive').addClass('easyClearHalfTimeSeminar active');
             }
             else {
                 $('#' + this.id).removeClass('easyClearHalfTimeSeminar active').addClass('easyClearHalfTimeSeminar inactive');
             }
         });
     });
 });

 function setHalfdayseminar () {
     $('.easyClearHalfTimeSeminar').each(function() {
    	 var sTempClassName = this.className;
    	 if(sTempClassName.indexOf("easyClearHalfTimeSeminar active") >= 0) {
    		 var sIdActive = this.id.replace(/halfdayseminar/, "");
    		 var sTempElementsName = "halfdayseminar" + sIdActive
    		 document.getElementsByName('halfdayseminar')[0].value = document.getElementsByName(sTempElementsName)[0].value;
    	 }
     });
 }
 
 function fadeInOut() {
    if($('.accordion_div').hasClass('none')) {
        $('.accordion_div').fadeIn('fast', function() {
        });
        $('.accordion_div').removeClass('none');
    }
    else {
        $('.accordion_div').fadeOut('fast', function() {
        });
        $('.accordion_div').addClass('none');
    }
 };



 //startseite mehrfachteaser
   var count, active;
   $(function() {
       var img_ss_t = '';
       var img_ss_delaytime = 10000;
       count = $('.ivisual-startseite img').length;
       if (count > 0) {
           active = $('.ivisual-startseite .active').attr('id').replace('pic-', '');
       }
       clearInterval(img_ss_t);
       img_ss_t = setInterval('click_slideshow()', img_ss_delaytime);
   });

   function doClear(theText) {
       if (theText.value == theText.defaultValue) {
           theText.value = ""
       }
   };
   

		//Zwei Input / Label Kombinationen anpassen
	function resetAllClassCheckbox () {
		var args = resetAllClassCheckbox.arguments; 
		var argObject1Input = args[0];
		var argObject1Label = args[1];
		var argObject2Input = args[2];
		var argObject2Label = args[3];
		var tempClass = "unselected";
		if (typeof argObject1Input == 'undefined' || typeof argObject2Input == 'undefined') {
			return;
		}
		if (argObject1Input.checked == true) {
			changeHTMLObjectClass(argObject1Label, tempClass);
		}
		if (argObject2Input.checked == true) {
			changeHTMLObjectClass(argObject2Label, tempClass);
		}
	}

   //Klasse eines HTML-Label ändern, bei onChange des Eltern-Input
	function changeClassCheckbox () {
		var args = changeClassCheckbox.arguments; 
		var argObjectInput = args[0];
		var argObjectLabel = args[1];
		var tempClass = "unselected";
		if (typeof argObjectInput == 'undefined' || typeof argObjectLabel == 'undefined' || tempClass == "") {
			return;
		}
		if (argObjectInput.checked == true) {
			tempClass = "selected";
		}
		changeHTMLObjectClass(argObjectLabel, tempClass);
	}

 //Klasse eines HTML-Elementobjekt ändern
	function changeHTMLObjectClass () {
		var args = changeHTMLObjectClass.arguments; 
		var object = args[0];
		var tempClass = args[1];
		if (typeof object == 'undefined' || tempClass == "") {
			return;
		}
		object.className = tempClass;
	}
	
	function reset2Site () {
		var args = reset2Site.arguments;
		var uri = args[0];
		if (typeof uri == 'undefined' || uri == "" || uri == null) {
			return;
		}
		window.location.href = uri;
	}
   
