/*
client:          meistro
client website:  www.meistro.de
author:          Michael Eichelsdoerfer
author website:  www.michael-eichelsdoerfer.de
*/

// // config: equal heights
// var equalHeights = function(){
// 	// $("#col2").children().equalHeights();
// 	// $("#col2").children().css({'background': '#fff'});
// 	// $("#col1, #col2, #col3").equalHeights();
// 	// $(".teaser-4").equalHeights();
// }

// cufon

$(document).ready(function(){
	$("#keyvisual h3").removeLfAfterBr();
	Cufon.replace("#keyvisual h3", {
		fontFamily: "meistro",
		fontSize: "13px"
	});
});

// dom ready
$(document).ready(function(){

	// new windows for outbound links
	$("a[href^=http]").each(function(){
		// if (window.location.hostname != this.hostname){
		if (this.hostname.indexOf('meistro.de') == -1){
			$(this).attr("target","_blank");
		}
	});

	// new windows for certain file suffixes
	$("a[href$='.pdf'], a[href$='.PDF']").attr("target","_blank");

	// new windows for certain classes
	$(".pdf").attr("target","_blank");
	$(".newsletter").attr("target","_blank");

	// lightboxes
	$(".lightbox").each(function(){
		$(this).find("a[rel*=lightbox]").lightBox({
			imageLoading:  '/workspace/assets/jquery.lightbox/images/ajax-loader.gif',
			imageBtnClose: '/workspace/assets/jquery.lightbox/images/close.gif',
			imageBtnPrev:  '/workspace/assets/jquery.lightbox/images/prev.gif',
			imageBtnNext:  '/workspace/assets/jquery.lightbox/images/next.gif',
			imageBlank:    '/workspace/assets/jquery.lightbox/images/lightbox-blank.gif',
			containerResizeSpeed: 600,
			txtImage: 'Bild',
			txtOf: 'von',
			overlayOpacity: 0.5
		});
	});

	positionFooter();

	// // big target
	// $(".unternehmen-teaser a").bigTarget({
	// 	hoverClass: 'hover', // CSS class applied to the click zone onHover
	// 	clickZone : 'div:eq(0)' // jQuery parent selector
	// });

	// equal heights
	// equalHeights();
	// $("#col2").children().equalHeights();
	// $("#col2").children().css({'background': '#fff'});
	// $("#col1, #col2, #col3").equalHeights();

});

// // font resize
// $(document).bind("fontresize", function(event, data){
// 	// Cufon.refresh();
// 	// equalHeights();
// 	positionFooter();
// });


$(window).bind("resize", function(){
    positionFooter();
});

// HTML manipulation
(function($){
	$.fn.removeLfAfterBr = function() {
		this.each(function() {
			$(this).html(
				$(this).html()
					.replace(/(<br>\n)/gi, "<br>")
			);
		});
	};
})(jQuery);

function positionFooter(){
	$("#content .wrap").css({
		'min-height': ($(window).height()-$("#header").height()-$("#keyvisual").height())-104+"px"
	});
	if($.browser.msie && $.browser.version < 7){
		$("#content .wrap").css({
			'height': ($(window).height()-$("#header").height()-$("#keyvisual").height())-104+"px"
		});
	}
}


/*
 * label2value
 * jquery based script for using form labels as text field values
 * more info on http://cssglobe.com/post/1500/using-labels-
 *
 * Copyright (c) 2008 Alen Grakalic (cssglobe.com)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 */

this.label2value = function(){

	// CSS class names
	// put any class name you want
	// define this in external css (example provided)
	var inactive = "inactive";
	var active = "active";
	var focused = "focused";

	// function
	$("label").each(function(){
		obj = document.getElementById($(this).attr("for"));
		if(($(obj).attr("type") == "text") || (obj.tagName.toLowerCase() == "textarea")){
			$(obj).addClass(inactive);
			var text = $(this).text();
			$(this).css("display","none");
			if (!$(obj).attr("value")) { // me 2009-05-10
				$(obj).val(text);
			};
			$(obj).focus(function(){
				$(this).addClass(focused);
				$(this).removeClass(inactive);
				$(this).removeClass(active);
				if($(this).val() == text) $(this).val("");
			});
			$(obj).blur(function(){
				$(this).removeClass(focused);
				if($(this).val() == "") {
					$(this).val(text);
					$(this).addClass(inactive);
				} else {
					$(this).addClass(active);
				};
			});
		};
	});
};
// on load
$(document).ready(function(){
	// label2value();
});
