/* $Id$ */

/*
 * Absortech
 * Javascript Functions Document
 * Produktion und Umsetzung:
 * dialoop GmbH - www.dialoop.de
*/

/*
 * ------------------------------------------------------------------------------------------------------
 * Standard Funktionen beim laden des Dokuments
 * ------------------------------------------------------------------------------------------------------
*/
$(document).ready(function() {     

	
	// Kontaktformular Fix
	if ( window.location.href.search("/de/") != -1 ) {
		if ( $("#mailform").is("form") ) {
			$("#mailform").attr("action", "/de/danke.html");
		}
	}
	if ( window.location.href.search("/es/") != -1 ) {
		if ( $("#mailform").is("form") ) {
			$("#mailform").attr("action", "/es/gracias.html");
		}
	}
	
	
	// UL nach dem Layout bauem (Punkte in anderer Farbe als der Text)
	$('#contentArea ul li').wrapInner('<span style="color: #000; font-size:12px;"></span>');
	$('#contentArea ul').css({'color':'#005496','font-size':'18px','list-style-type':'disc','margin':'0 0 0 25px','padding':'5px 0 0 5px'}); // , 'line-height':'14px'
	
	$('<span>&nbsp;&#124;&nbsp;</span><a class="normal" href="http://www.absortech.com.cn" target="_new" title="chinese version">汉语</a>').appendTo('.tx-srlanguagemenu-pi1');
		
		
	// die schatten unter den boxen
	$('.csc-frame').each(function(i, e) {
		$('.bottomBorder').each(function(j, f) {
			if (i == j) {
				$(f).css({'width':$(e).width() + 1});
				$(f).css({'background':'url("fileadmin/templates/img/bottomMask.png") ' +  (($(f).position().left%125)* (-1)+35)  + 'px repeat'});
			} 
		});
	});
	
	// neuauflage download links
	$('.download ').css({'background-color':'#33BCAD', 'color':'#fff', 'padding': '1px 3px', 'margin-right':'3px'});
	$('.download').mouseout(function() {$(this).css({'background-color':'#33BCAD', 'color':'#fff'})});
	$('.download').mouseover(function() {$(this).css({'background-color':'#005496', 'color':'#fff'})});
	
	
	$('.internal_link_button').css({'background-color':'#33BCAD', 'color':'#fff', 'padding': '1px 3px', 'margin-right':'7px'});
	$('.internal_link_button').mouseout(function() {$(this).css({'background-color':'#33BCAD', 'color':'#fff'})});
	$('.internal_link_button').mouseover(function() {$(this).css({'background-color':'#005496', 'color':'#fff'})});
	
	$('.internal-link').mouseout(function() {$(this).css({ 'color':'#78CDD0'})});
	$('.internal-link').mouseover(function() {$(this).css({'color':'#005496'})});
	
	
	$('.internal_shift_left').mouseout(function() {$(this).css({ 'color':'#78CDD0'})});
	$('.internal_shift_left').mouseover(function() {$(this).css({'color':'#005496'})});

	$('.video').mouseout(function() {$(this).css({ 'color':'#78CDD0'})}).mouseover(function() {$(this).css({'color':'#005496'})});
	
	$('.external-link-new-window').mouseout(function() {$(this).css({ 'color':'#78CDD0'})});
	$('.external-link-new-window').mouseover(function() {$(this).css({'color':'#005496'})});
	
	$('.faqQuestion').click(function() {
		
		if ($('#faqA' + $(this).attr('rel')+ ':hidden').is('div')) {
			$('#faqA' + $(this).attr('rel')).show();
			$('#faqP' + $(this).attr('rel')).html('-');
		} else {
			$('#faqA' + $(this).attr('rel')).hide();
			$('#faqP' + $(this).attr('rel')).html('+');
		}
		resizeBackground(false);
	});	
	$('.faqAnswer').click(function() {
		$(this).hide();
		$('#faqP' + $(this).attr('rel')).html('+');
		resizeBackground(false);
	});
	
	
	
	// links auf dateien als button 
	// $('.csc-frame-120 > .bodytext > .download').each(function(i, e) {
	$('.download_text_button').each(function(i, e) {
	
		if (!$.support.opacity) {
			$(e).replaceWith('<div class="imText"><div class="bg_lt"><div class="bg_lb"><div class="bg_rt"><div class="bg_rb"><a target="blank" href="' + $(this).attr('href') + '">' + $(e).html() + '</a></div></div></div></div></div><div style="clear:both"></div>'); 
		} else {
			$(e).replaceWith('<div class="imText"><a target="blank" href="' + $(this).attr('href') + '">' + $(e).html() + '</a></div><div style="clear:both"></div>'); 
		
		}	
	});
	
	$('.internal_shift_left').each(function(i, e) {
		$(e).replaceWith('<div class="shiftLeft"><a target="_self" href="' + $(this).attr('href') + '">' + $(e).html() + '</a></div>'); 
	});	
	
	$('.video').each(function(i, e) {
		$(e).replaceWith('<div class="shiftLeft"><a target="_self" rel="' + $(this).attr('href') + '" class="videolink">' + $(e).html() + '</a></div>'); 
		
	});
	
	
	$('.csc-frame-frame2 > .bodytext .shiftLeft').css({'width':'220px'});
	if (!$.support.opacity) {
		$('.shiftLeft').parent().css({'display':'inline-block','float':'left'});
	} else {		
		$('.shiftLeft').parent().css({'display':'inline-block'});	
	}
	
	$('.videolink').click(function(){
		$('#videoFrame').html('');
		var so = new SWFObject('/fileadmin/templates/swf/player.swf','mpl','395','296','9');
			so.addParam('allowfullscreen','true');
			so.addParam('allowscriptaccess','always');
			so.addParam('wmode','transparent');
			so.addVariable('author','Absortech');
			so.addVariable('file','http://' + location.host + '/' + $(this).attr('rel'));
			so.addVariable('start','0');
			so.addVariable('autostart','true');
			so.addVariable('provider','video');
			so.addVariable('backcolor','#fff');
			so.addVariable('frontcolor','#005496');
			so.addVariable('lightcolor','#78CDD0');
			so.addVariable('screencolor','#fff');
			so.addVariable('controlbar','over');
			so.addVariable('volume','100');
			so.write('videoFrame');

	});	
	
	$('.videolink').colorbox({'inline':'true', 'href':"#videoFrame", 'innerWidth':'395'});

	

	
	
	
	// interne links einrücken in der schmalen a
	$('.csc-frame-120 > .bodytext > .download').each(function(i, e) {
	
		if (!$.support.opacity) {
			$(e).replaceWith('<div class="imText"><div class="bg_lt"><div class="bg_lb"><div class="bg_rt"><div class="bg_rb"><a target="blank" href="' + $(this).attr('href') + '">' + $(e).html() + '</a></div></div></div></div></div>'); 
		} else {
			$(e).replaceWith('<div class="imText"><a target="blank" href="' + $(this).attr('href') + '">' + $(e).html() + '</a></div>'); 
		
		}	
	});
	
	
	$('.csc-frame-frame2 > .bodytext > .download').each(function(i, e) {
	
		if (!$.support.opacity) {
			$(e).replaceWith('<div class="imText"><div class="bg_lt"><div class="bg_lb"><div class="bg_rt"><div class="bg_rb"><a target="blank" href="' + $(this).attr('href') + '">' + $(e).html() + '</a></div></div></div></div></div>'); 
		} else {
			$(e).replaceWith('<div class="imText"><a target="blank" href="' + $(this).attr('href') + '">' + $(e).html() + '</a></div>'); 
		
		}	
	});
	
	
	$('.download').each(function(i, e) {
		if (!$.support.opacity) {
			$(e).replaceWith('<div class="imText" style="margin-left:0px"><div class="bg_lt"><div class="bg_lb"><div class="bg_rt"><div class="bg_rb"><a target="blank" href="' + $(this).attr('href') + '">' + $(e).html() + '</a></div></div></div></div></div><div style="clear:both;"></div>'); 
		}
	});
	$('.internal_link_button').each(function(i, e) {
		if (!$.support.opacity) {
			$(e).replaceWith('<div class="imText" style="margin-left:0px"><div class="bg_lt"><div class="bg_lb"><div class="bg_rt"><div class="bg_rb"><a target="blank" href="' + $(this).attr('href') + '">' + $(e).html() + '</a></div></div></div></div></div><div style="clear:both;"></div>'); 
		}
	});

	$('.csc-frame-frame2 >  .bodytext > .imText').each(function(i, e) {
		$(e).css({'width':'220px'});
	});
	
	$('.csc-frame-120 >  .bodytext > .imText').each(function(i, e) {
		$(e).css({'width':'180px'});
	});
	
	$('.csc-frame-frame1 >  .bodytext > .imText').each(function(i, e) {
		$(e).css({'margin-left':'0'});
	});
	
	
	
	
	
	if ($('#distributorSelect').is("select")) {
		$('#distributorSelect').change(function() {
			window.location.href = 'http://' + window.location.host + '/' + $('#distributorSelect').val();
		});
	}
	
	
	// menu umbauen
	if ($('.navLayer').is("div") || $('.navLayerC').is("div")) {
		// menu-pfad zum nachvollziehen
		if (level[0] !== '') {
			$(".navButton:contains('" + level[0] + "')").removeClass('navButtonCur').addClass('navButtonC');
		} 	
		if (level[1] !== '') {
			$(".navLayer:contains('" + level[1] + "')").removeClass('navLayerCur').addClass('navLayerC');
		} 
		
		// auslagern der zweiten menu-ebene
		if ($('.navL').is("div")) {
			$('.navL').detach().appendTo($('#innerLine'));
		}
		
		// auslagern der dritten menu-ebene
		if ($('.nav2').is("div")) {
			$('.nav2').detach().appendTo($('#innerLine2'));
			$('#line4').css({'height':'25px'});
		}
	
		// anzeigen der 2. menu-ebene  
		// die stelle für die 3. ebene ist im template immer sichtbar
		$('#lineMenu2').show();
	}
	
	if (!$.browser.webkit) {
		if (!$('#left').is('div')) {
			$('#middle').css('margin-left','15px');
		}
	} else {
		if (!$('#left').is('div')) {
			$('#middle').css('margin-left','10px');
		} else {
			$('#middle').css('margin-left','5px');
		}
	}
	
	// schatten unter dem menu der ersten ebene
	$('#topNaviBottom').css({'width':$('#topnavi').width()-10});
	
	// zentrieren der 2. ebene unterhalb des aktuellen menu-punktes
	if ($('.navL').is("div")) {
		var widthL = 0;
		$('.navL').each(function(index) {
			widthL += $(this).width() + 10;
		});
	
		var potPos = $('.navButtonC').position().left + $("#topNaviBottom").position().left + ($('.navButtonC').width()/2) - ($('#innerLine').width() / 2);
		
		if (925 < (potPos + widthL)) {
			potPos = 925 - widthL;
		}
		
		$('#innerLine').css({'left':potPos});
		// hier
		$('.layerBottom').css({'left':potPos +15, 'width':widthL -15, 'background':'url("fileadmin/templates/img/bottomMask.png") ' +  ((potPos +15) * (-1)+35)  + 'px repeat'});
	}
	
	// zentrieren der 3. ebene unterhalb des aktuellen menu-punktes
	if ($('.nav2').is("div")) {
		widthL = 0;
		$('.nav2').each(function(index) {
			widthL += $(this).width() + 5;
		});
		potPos = $('.navLayerC').position().left + $("#innerLine").position().left + ($('.navLayerC').width()/2) - ($('#innerLine2').width() / 2);

		if (900 < (potPos + widthL)) {
			$('#innerLine2').css({'position':'absolute','left':(900 - widthL -30)});
		} else {	
			$('#innerLine2').css({'position':'absolute','left':potPos});
		}
	}
	
	// absende button bunt
	
	$('[name=formtype_mail]').css({'background-color':'#005496', 'width':'200px', 'color':'white'});
	
	$('#topnavi').show();
	
	
	// $('#right').css({'top': $('#contentArea').position().top});
	// hintergrund bis zum ende des browserfensters erweitern
	resizeBackground(false);
	
});


/*
 * ------------------------------------------------------------------------------------------------------------------------------------------------------------
 * Funktion zum Dynamisschen Erweitern des Layout Hintergrund ( Funktion anpassen je nach Layout aufbau)
 * ------------------------------------------------------------------------------------------------------------------------------------------------------------
*/
function resizeBackground(scrolling) {
	
	// bedingung wenn nicht gescrollt wird
	if (!scrolling) {
	
	
		$(".col").each(function() {
			if (($(this).height() +80) > $("#contentArea").height()){
				if ($(this).height() > $(window).height()) {
					$("#contentArea").height($(this).height() +80);
				} 	
			}
			
			if ($("#contentArea").height() < ($(window).height() - ($('#line4').height() + $('#line3').height() + $('#line2').height() + $('#line1').height() )) ) {
				$("#contentArea").height($(window).height() - ($('#line4').height() + $('#line3').height() + $('#line2').height() + $('#line1').height() ));
			}		
		});	
	}
	
	
	
	// $("#contentArea").height($(window).height()+$(window).scrollTop() - $('#contentArea').position().top);
	
}

/*
 * -------------------------------------------------------------------------------------------------------------------------------------
 * Wenn Fenster gescrollt oder verkleinert wird, Funktion resizeBackground starten
 * -------------------------------------------------------------------------------------------------------------------------------------
*/
$(window).scroll(function() { resizeBackground(true); });
$(window).resize(function() { resizeBackground(true); });
