$(window).load(function() {
	// Reflection
	if ($("img").hasClass("reflect")) {
		$.include('jquery/jquery.reflection.js', function() {$("img.reflect").reflect({height: 0.2, opacity: 0.3})});
	}
});

$(document).ready(function() {

	var prepareIframe = function(iframe) {
		var iframeContent = iframe.contents();
		iframeContent.find("body").addClass("layerContent");
		iframeContent.find('#link-box.warning a').click(function() {
			self.callbackOnClose();
			return false;
		});
	};
	
	// fancy box autoload
	if ($('a').hasClass('fancybox')) {
		$.include('jquery/jquery.fancybox.js',
			function() {
				$.include('/site/css/screen/jquery.fancybox.css', function() {
					$('a.fancybox').each(function() {
						var obj = $(this);
						obj.addClass('iframe').fancybox({
							overlayOpacity: 0.5,
							overlayColor: '#000',
							frameWidth: 750,
							frameHeight: 550,
							centerOnScroll: false,
							callbackOnShow: function() {
								// Close-Link im IFrame
								var iframe = $('#fancy_content iframe').load(function() {
									prepareIframe(iframe);
								});							
								iframe = $('#fancy_content iframe');
								if (iframe) {
									prepareIframe(iframe);
								}
							},
							callbackOnClose: function() {
								if (obj.hasClass('reload-fancy')) {
									top.location.replace(self.location.href);
								}
							}
						});	
					});
				});
			}
		);
	}
	
	// allgemeine Togglebox
	if ($("[class*=togglebox-v]").length > 0) {
		$.include('jquery/jquery.togglebox.js', function() {
			$("[class*=togglebox-v]").toggleBox();
		});
	}
	
	// bei Input-Boxen mit class="onfocus" wird das value auf '' gesetzt
	$(".onfocus").one("focus", function() {
		$(".onfocus").val('');
	});
	
	if ($.fn.tooltip) {
		$('.tooltipInformation').each(function(index) {
			$(this).tooltip();
		});
	}
	
	// IE 7 Reflection Overflow Fix
	if ($.browser.msie) $("img.reflect").css("overflow", "hidden");
	
	// Loginbox
	var _yabDefaultUser = $("#yabLoginForm").find("#yabLoginBox-user").attr("title") ? $("#yabLoginForm").find("#yabLoginBox-user").attr("title") : '';
	var _yabDefaultPwd = "xxxxxxxx";
	
	$("#yabLoginForm").find("#yabLoginBox-user").val(_yabDefaultUser).focus(function() {
		if ($(this).val() == _yabDefaultUser) $(this).val("");
	});
	
	$("#yabLoginForm").find("#yabLoginBox-pass").val(_yabDefaultPwd).focus(function() {
		if ($(this).val() == _yabDefaultPwd) $(this).val("");
	});
	
	$("#yabLoginForm").submit(function(event) {
		
		// das wird beim keyCode == 13 in den Formularen noch abgefragt, so wird das absenden dessen Formulars unterbunden
		keysubmit = false;
		
		if ($(this).find("#yabLoginBox-login").is("input")) {
			if ($(this).find("#yabLoginBox-user").val() == _yabDefaultUser || $.trim($(this).find("#yabLoginBox-user").val()) == "") {
				$(this).find("#yabLoginBox-user").val("").addClass("marker").focus();
				return false;
			} else {
				$(this).find("#yabLoginBox-user").removeClass("marker");
			}
			
			if ($(this).find("#yabLoginBox-pass").val() == _yabDefaultPwd || $.trim($(this).find("#yabLoginBox-pass").val()) == "") {
				$(this).find("#yabLoginBox-pass").val("").addClass("marker").focus();
				return false;
			} else {
				$(this).find("#yabLoginBox-pass").removeClass("marker");
			}
		}
		
		$("#yabLoginBox-error").hide();
		$("#yabLoginBox-login").hide();
		$("#yabLoginBox-logout").hide();
		$("#yabLoginBox-wait").show().css("z-index", "100");

	});
	
	// Script fuer forceLoginBox einbinden
	if ($(".forceLoginBox").hasClass("forceLoginBox")) $.include('forceloginbox-jquery.js');

	// Tooltip
	try {
		if ($.fn.tooltip) {
			$("#yabLoginBox-description").tooltip({delay: 0, track: false, showURL: false, fixPNG: true});
		}
	} catch (e) {}
	
	// Cluetip
	
	if ($("[class*=cluetip]").length > 0) {
		$.include('jquery/jquery.cluetip.js', function() {
			$("#yabLoginForm a.cluetip").cluetip({
				onActivate: function(e) {
					// load css
					$.include('/site/css/screen/jquery.cluetip.css');
					
					// move into login box
					var $loader = $('#cluetip-waitimage');
					$('#cluetip-waitimage').remove();
					$('#yabLoginBox').append($loader);
					
					// show loader
					$('#cluetip-waitimage').addClass("yabLoginBox-cluetip-waitimage");
					return true;
				},
				attribute: 'href', dropShadow: true, sticky: true, arrows: true,
			    activation: 'click', width: 600,
			    dropShadowSteps:  7,
			    closePosition: 'title',
			    closeText: '<img src="/site/css/images/cluetip/cross.gif" alt="close" title="close" width="16" height="16" />',
			    ajaxSettings: {data: '_ajaxRequest=true', type: "POST", dataType: 'html'},
			    ajaxCache: true,
			    fx: {open: 'slideDown', hide: 'slideUp'}
			});
		});
	}
});
