/**
 * additional functions which are active in all views
 * see teaser_placement.js
 */
$(function() {
	function tableColorizer() {
		$('table').each(function(index, element) {
			//alert("tabelle #" + index + ": " + $(element).find("tr").size() + ", " + $(element).find("tr:eq(1)").find("th").size());
			if ($(element).find("tr:eq(1)").find("th").size() < 1) {
				$(element).find("tr").each(function(trIndex, trElement) {
					if (trIndex > 1) {
						if (trIndex % 2 == 0) {
							$(trElement).addClass("even");
						}
						else {
							$(trElement).addClass("odd");
						}
					}
				});
			}
		});
	}
	function newWindow() {
		$('.neuesFenster').click(function() {
			window.open(this.href);
			return false;
		});
	}
	
	function popupVorbereiten() {
		$('.neuesPopupFenster').each(function() {
			var blank = ': ';
            if (this.title == '') {
                blank = '';
            }
            
            if (this.lang == 'de') {
            	this.title = 'Neues Popup Fenster' + blank + this.title;
            }else{
            	this.title = 'New Popup Window' + blank + this.title;
            }
		});
	}
	
	function newPopupWindow() {
		$('.neuesPopupFenster').click(function() {
			var windowname = 'KfW_popup_page'
			var scroller = "yes";
		    var menubar = "no";
		    var toolbar = "no";
		    var location = 'no';
		    var resizable= 'yes';
		    var status= 'yes';
		    var breite = '800';
		    var hoehe = '1000';
		    var params = "width="+breite+",height="+hoehe+",scrollbars="+scroller+",menubar="+menubar+",toolbar="+toolbar+",location="+location+",resizable="+resizable+",status="+status+",top=1,left=1";
			window.open(this.href, windowname, params);
			return false;
		});
	}
	
	

	function moveSBSConditions() {
		var contextNode= $('#Kond3:parent').parent();
		$('#Kond3:parent').parent().after($('#zins3'));
		//$('#zins3').insertAfter('#Kond3:parent:parent');
	}
	
	/* bewegt die Topkonditionen in die Checkliste, falls vorhanden.
	 */
	function moveTopConditions() {		 
	// m399: class checklist is from editor content, so need to test checklist exist, before remove zins1		 
		if ($('#zins1').size() > 0) {
			$('.checklist li:eq(0)').before("<li>" + $('#zins1 p').text() + "</li>");
			if( ($('.checklist li').length) > 0 )
					$('#zins1').remove();
		}
	}
	
	var positionTimer;
	function getCorrectPositions() {
		var inProgress = false;
		$('#individualContact .vipisetoolbar').each(function() {
			t = $(this).parent().position().top;
			l = $(this).parent().position().left;
			tc = $(this).position().top;
			lc = $(this).position().left;
			if ((t != tc) || (l != lc)) {
				$(this).css('top', t);
				$(this).css('left', l);
				inProgress = true;
			}
		});
		if (!inProgress) {
			window.clearInterval(positionTimer);
			window.status="done";
		}
	}

	if ($.browser.msie) {
		positionTimer = window.setInterval(getCorrectPositions, 1000);
	}
	tableColorizer();
	newWindow();
	moveSBSConditions();
	
	moveTopConditions();
	
	popupVorbereiten();
	newPopupWindow();
	
});

