
$(document).ready(function () {
	$('a[rel=lightbox]').fancybox();
	$('a[rel^=lightbox]').attr('rel', 'multi').attr('title', '').fancybox(); 
	
	/*$('a.iframe').fancybox({'frameWidth':1050, 'frameHeight':765});*/
	
	$('.newsletter a.iframe').fancybox({'frameWidth':800, 'frameHeight':765});
	
	
	$(".mod_navigation.topnavi ul.level_1 > li").hover(function() {
		var submenu = $("ul.level_2", this);
		submenu.find("li").css("width", submenu.width());
		submenu.show();
	}, function () {
		$("ul.level_2", this).hide();
	});
	
	$(".ce_home_show").each(function() {
		var show = $(this);
		var controlls = show.find(".controlls");
		
		show.find(".slide").hide();
		var first = show.find(".slide:first");
		first.show();
		controlls.find("a[href=#"+first.attr("id")+"]").addClass("active");
		
		var animation = function(link) {
			show.find(".slide").stop(true, true);
			controlls.find("a").removeClass("active");
			var current = show.find(".slide:visible");
			current.remove().appendTo(show);
			if (jQuery.support.boxmodel) {
				show.find(".slide"+link.attr("href")).fadeIn(1000, function() {
					link.addClass("active");
				});
				current.animate({
					left: '-=950'
				}, 600, function() {
					$(this).hide().css("left", "0px");
				});
			} else {
				show.find(".slide"+link.attr("href")).fadeIn(1000, function() {
					link.addClass("active");
				});
				current.fadeOut(1000, function() {
					$(this).hide().css("left", "0px");
				});
			}
		}
		
		controlls.find("a").click(function() {
			show.stopTime("show");
			animation($(this));
			return false;
		});
		
		show.everyTime(8000, "show", function() {
			var next = show.find(".slide:visible + .slide");
			if (next.length == 0) {
				next = show.find(".slide:first");
			}
			animation(controlls.find("a[href=#"+next.attr("id")+"]"));
		});
	});
	
	$(".mod_veranstaltungen").each(function() {
		var elem = $(this);
		$("#region_select", this).change(function() {
			$(".region", elem).hide();
			$("#region_"+$(this).val()).show();
		}).change();
		
		$("input.checkbox", this).click(function() {
			if ($(this).attr("checked") != "") {
				$("."+$(this).attr("id"), elem).attr("checked", "checked");
			} else {
				$("."+$(this).attr("id"), elem).attr("checked", "");
			}
		}).each(function() {
			var all_elem = $(this);
			$("."+$(this).attr("id"), elem).change(function() {
				all_elem.attr("checked", "");
			});
			
			if ($(this).attr("checked") != "") {
				$("."+$(this).attr("id"), elem).attr("checked", "checked");
			}
		});
		
		$("#termin", this).click(function() {
			if ($(this).val() == "-") {
				$("#termin_spanne", elem).show();
			} else {
				$("#termin_spanne", elem).hide();
			}
		}).click();
		
		$("#rubrik_checkbox_all", this).click(function() {
			if ($(this).attr("checked") != "") {
				$(".rubrikcheck", elem).attr("checked", "checked");
			} else {
				$(".rubrikcheck", elem).attr("checked", "");
			}
		}).each(function() {
			$(".rubrikcheck:not(#rubrik_checkbox_all)", elem).change(function() {
				$("#rubrik_checkbox_all", elem).attr("checked", "");
			});
			
			if ($(this).attr("checked") != "") {
				$("."+$(this).attr("id"), elem).attr("checked", "checked");
			}
		});
	});
	
	$("#keywords_simple").each(function() {
		var elem = $(this);
		elem.val("Suche").addClass("inactive");
		elem.focus(function() {
			$("#keywords_simple.inactive").val("").removeClass("inactive");
		}).blur(function() {
			if (elem.val() == "") elem.val("Suche").addClass("inactive");
		});
		elem.parent().find(".submit").click(function() {
			$("#keywords_simple.inactive").val("");
		});
	});

	// GA links
	/*var domains = [	"labhard.de", "bodensee-magazin.de", "sachsenmagazin.de",
	               	"wirtschaftsmagazin.com", "oberschwabenmagazin.de"];
	$("a").each(function() {
		var link = $(this);
		var href = link.attr("href");
		var domain = "";
		if (href && (domain = href.match(/^http:\/\/([^\.]+\.)?([^\.]+\.[a-zA-Z]+)/))) {
			if (jQuery.inArray(domain[2], domains) > -1) {
				link.click(function() {
					if (typeof(pageTracker) != "undefined") {
						pageTracker._link(href);
						return false;
					}
				});
			}
		}	
	});*/
	
});