$(document).ready(function() {

if  (( $.browser.msie )  && (parseInt(jQuery.browser.version)==6)) {
} else { 
	FLIR.init();
	FLIR.auto( [ 'h1.replace', 'h2.replace', 'h3.replace',  'li.level1',  'li.level2',  'li.level3' ] );	

}


/* ============= Begin Modulform CMS  Login Form  ============*/
		var name = $("#name"),
			password = $("#password"),
			allFields = $([]).add(name).add(password),
			tips = $("#validateTips");

		function updateTips(t) {
			tips.text(t).effect("highlight",{},1500);
		}

		function checkLength(o,n,min,max) {

			if ( o.val().length > max || o.val().length < min ) {
				o.addClass('ui-state-error');
				updateTips("Length of " + n + " must be between "+min+" and "+max+".");
				return false;
			} else {
				return true;
			}

		}

		function checkRegexp(o,regexp,n) {

			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass('ui-state-error');
				updateTips(n);
				return false;
			} else {
				return true;
			}

		}
		
		$("#dialog").dialog({
			bgiframe: true,
			autoOpen: false,
//			height: 250,
			modal: true,
			buttons: {
				'Login': function() {
					var bValid = true;
					allFields.removeClass('ui-state-error');

					bValid = bValid && checkLength(name,"username",3,16);
					bValid = bValid && checkLength(password,"password",5,16);
					bValid = bValid && checkRegexp(name,/^[a-z]([0-9a-z_])+$/i,"Username may consist of a-z, 0-9, underscores, begin with a letter.");
					bValid = bValid && checkRegexp(password,/^([0-9a-zA-Z])+$/,"Password field only allow : a-z 0-9");
					
					if (bValid) {
						parent.location="/_system/mf_login.php?login="+name.val()+"&password="+password.val()+"&redirect="+document.location;
/*
						$('#users tbody').append('<tr>' +
							'<td>' + name.val() + '</td>' + 
							'<td>' + password.val() + '</td>' +
							'</tr>'); 
						$(this).dialog('close');
*/
					}
				},
				Cancel: function() {
					$(this).dialog('close');
				}
			},
			close: function() {
				allFields.val('').removeClass('ui-state-error');
			}
		});
		
		$('#create-user').click(function() {
			$('#dialog').dialog('open');
		});

/* ============= End Modulform CMS  Login Form  ============*/

	// hopefully fix safari onload fckup
	var ignoreMe = document.body.offsetWidth;
	var ignoreMe = document.body.offsetLeft;
			
	$('#logo').bind("click", function() {
		document.location="/";
		
	});

		$("a[rel='lightbox-milestones']").colorbox();
			
		$('#naviLevel1 a').bind("mouseover", function() {
			var self = this;
	      	$(self).animate({opacity: .5}, { duration: "fast", easing: "swing", queue: false} );
		});

		$('#naviLevel1 a').bind("mouseleave", function() {
			var self = this;
	      	$(self).animate({opacity: 1}, { duration: "fast", easing: "swing", queue: false} );
		});


	$('#searchField').bind("focus", function() {
		var self = this;
		$(self).val("");
	});

$('.tooltip').tooltip({
	delay: 0,
	fade: 250,
    track: true, 
   	showURL: false,
	bodyHandler: function() {
		var self = this;
		var thesrc = $(self).find("img").attr("src");
//alert(thesrc);
//		return $("<img/>").attr("src", this.src);
		return $("<img/>").attr("src", thesrc);
	}
});

	$('#teaserGallery').cycle({ 
   		fx: 'fade', 
	    speed: 1000,
    	pause: 1 
	 });

	$('.revealItem').bind("mouseenter", function() {
		var self = this;
		$(self).animate({'height' : 100}, { duration: "fast", easing: "swing", queue: false });
		$(self).find(".slideText").css("display", "block");
		$(self).find(".slideText").animate({'opacity' : 1}, { duration: "fast", easing: "swing", queue: false });
	});
	$('.revealItem').bind("mouseleave", function() {
		var self = this;
		$(self).animate({'height' : 15}, { duration: "slow", easing: "swing", queue: false });
		$(self).find(".slideText").animate({'opacity' : 0}, { duration: "fast", easing: "swing", queue: false });
	});

	$('#factboxContainer').bind("mouseenter", function() {
		var self = this;
		$('#factboxHandle').animate({'height' : 0}, { duration: "fast", easing: "swing", queue: false });
		$('#factboxHandle').animate({'opacity' : 0}, { duration: "fast", easing: "swing", queue: false });
		$('#factboxHandle').animate({'marginTop' : 0}, { duration: "fast", easing: "swing", queue: false });
	});
	$('#factboxContainer').bind("mouseleave", function() {
		var self = this;
		$('#factboxHandle').animate({'height' : 45}, { duration: "fast", easing: "swing", queue: false });
		$('#factboxHandle').animate({'opacity' : 0.85}, { duration: "fast", easing: "swing", queue: false });
		$('#factboxHandle').animate({'marginTop' : 215}, { duration: "fast", easing: "swing", queue: false });
	});




		$('.ProjekteUebersicht li.projektLive').bind("mouseover", function() {
			var self = this;
			$(self).find("a").animate({"color": "#000000"}, { duration: "fast", easing: "swing", queue: false} );
	      	$(self).animate({"paddingLeft": "20px", backgroundPosition: "(5px 5px)"}, { duration: 50, easing: "swing", queue: false} );
		}).bind("mouseleave", function() {
			var self = this;
			$(self).find("a").animate({"color": "#505050"}, { duration: "fast", easing: "swing", queue: false} );
	      	$(self).animate({"paddingLeft": "20px", backgroundPosition: "(0 05px)"}, { duration: 50, easing: "swing", queue: false} );
		});		

		$('.WettbewerbeUebersicht li.active').bind("mouseover", function() {
			var self = this;
			$(self).find("a").animate({"color": "#000000"}, { duration: "fast", easing: "swing", queue: false} );
	      	$(self).animate({"paddingLeft": "20px", backgroundPosition: "(5px 5px)"}, { duration: 50, easing: "swing", queue: false} );
		}).bind("mouseleave", function() {
			var self = this;
			$(self).find("a").animate({"color": "#505050"}, { duration: "fast", easing: "swing", queue: false} );
	      	$(self).animate({"paddingLeft": "20px", backgroundPosition: "(0 05px)"}, { duration: 50, easing: "swing", queue: false} );
		});		


});  

