//background-image:url(images/main/bodyBG1.jpg) fixed no-repeat;
//BG
function init(){
	var bgC = 5;
		if(screen.width <= 1030){
			bgC = 1;
		}else if(screen.width <= 1600){
		    if(screen.height <= 800){
		    	bgC = 2;
		    }else if(screen.height <= 1024){
		        bgC = 3;
		    }
		}else if(screen.height <= 1200){
		    bgC = 4;
		}
		var ran = Math.floor(Math.random()*((parseFloat(globAnz) - parseFloat(1)) + 1)) + parseFloat(1);
		var bod = document.getElementsByTagName("body")[0];
		bod.style.backgroundImage = 'url(tl_files/tp/images/BG/'+globBG+'/'+ran+'/bg_'+bgC+'.jpg)';
		if(screen.width <= 481)	bod.style.backgroundRepeat = 'repeat-y';

}
//--BG
var akt =1;
var neu = 1;
var num;
var logout=0;
var soc_ts_akt = 205;

function linkify(str){
	return str.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&;\?\/.=]+/g, function(m){
		//return m.link(m);
    	var wrap = document.createElement('div');
        var anch = document.createElement('a');
        anch.href = m;
        anch.target = "_blank";
        anch.innerHTML = m;
        wrap.appendChild(anch);
        return wrap.innerHTML;
	});
};
function checkForm(n_Form){
	if(n_Form !== 2){
		if(document.login.username.value == '' || document.login.password.value == '')    	msgHeader('<span style="color:#FF0000;">Please fill out all the fields.</span>');
		else if(document.getElementById('agb').checked == true)    document.login.submit();
		else	msgHeader('<span style="color:#FF0000;">Please submit our conditions</span>');
	}else{
		if(document.login.firstname.value !== '' && document.login.company.value !== '' &&
		   document.login.lastname.value !== '' && document.login.emailtp.value !== ''){
		   		document.login.action='index.html';
		   		document.login.FORM_SUBMIT='ti_sign';
		        document.login.submit();
		}else{	msgHeader('<span style="color:#FF0000;">Please fill out all the fields.</span>'); }
	}
}

function headerMsgOut(){
	$('#signInTxt').fadeOut();
}

function msgHeader(m){
	$('#signInTxt').fadeOut('fast', function() {
		$('#signInTxt').html(m);
	    $('#signInTxt').fadeIn();
	  });
}

function signIn(){
	if(!chkEMail(document.login.emailtp.value)){
		msgHeader('<span style="color:#FF0000;">Please type in a valid E-Mail address.</span>');
	}else if(document.login.firstname.value !== '' && document.login.company.value !== '' &&
		   document.login.lastname.value !== '' ){
				//msgHeader('Thank you for your registration! <br/>We will email you your personal<br/> login ID shortly.');
		   	    $.get('/tl_files/tp/signIn.php?a='+document.login.firstname.value+'&b='+document.login.lastname.value+'&c='+document.login.company.value+'&d='+document.login.emailtp.value,
				   function(data) {
		   	        msgHeader('Thank you for your registration! <br/>We will email you your personal<br/> login ID shortly.<!-- '+data+' -->');
			});
	}else{
		msgHeader('<span style="color:#FF0000;">Please fill out all the fields.</span>');
	}
}

function cont(neu){
	headerMsgOut();
	if(neu==20 && logout==1) document.logout.submit();
	else{
		if(neu !== akt || $('#int_Inh').css('display') == 'none'){
			if($('#int_Inh').css('display') == 'none'){
				if(neu !== akt){
					$('#topTxt_'+neu).css('display', 'block');
					$('#topTxt_'+akt).css('display', 'none');
				}
				$('#int_Inh').slideDown('slow');
				$('#open_img').css("background-image", "url(tl_files/tp/images/main/navi-close.gif)");
			}else{
				var aktH = $('#topTxt_'+neu).height()+10;
				$('#int_Inh').animate({ height: aktH+"px" }, 'slow', function() {
					if($('#topTxt_'+neu).find('.showRoomAcc').length)		$(this).css('height', 'auto');
				});
				$('#topTxt_'+akt).fadeOut('slow', function(){
					$('#topTxt_'+neu).fadeIn('slow');
				});
			}
            moveSocials($('#topTxt_'+neu).height());
			akt=neu;
		}
	}
}

function moveSocials(y){
	if(y > 0)   y = parseInt(y) -23;
	$('#socialLine').animate({ top:y+soc_ts_akt+'px'}, 'slow');
}
function wo(url){
	if(typeof(url) !== 'undefined')
		window.open(url, '_self');
}
function onAfter(curr, next, opts) {
	if((opts.slideCount - 1) == 1){
	    jQuery('#xchange_next')['hide']();
	    jQuery('#xchange_prev')['hide']();
	}
	var index = opts.currSlide;
    jQuery('#xchange_prev')[index == 0 ? 'hide' : 'show']();
    jQuery('#xchange_next')[index == opts.slideCount - 1 ? 'hide' : 'show']();

}


var const1=0;
function sm(text, event){
	sh(text);
	var scrollPos;
	if (typeof window.pageYOffset != 'undefined') {
	   scrollPos = window.pageYOffset;
	}
	else if (typeof document.compatMode != 'undefined' &&
		 document.compatMode != 'BackCompat') {
	   scrollPos = document.documentElement.scrollTop;
	}
	else if (typeof document.body != 'undefined') {
	   scrollPos = document.body.scrollTop;
	}
	var topPixel = event.clientY + scrollPos - 290;
	var leftPixel = event.clientX - 45;

	document.getElementById('MouseOver').style.top = topPixel + "px";
	document.getElementById('MouseOver').style.left = leftPixel + "px";
	//document.getElementById('MouseOver').style.display = "block";
	if(const1 == 0){
		const1 = 1;
		$('#MouseOver').fadeIn(500, function () {
	        const1=0;
	    });
   }
}

function hm(){
	//document.getElementById('MouseOver').style.display = "none";
	jQuery('#MouseOver').fadeOut(100);
	//document.getElementById('MouseOver').style.top = "0px";
	//document.getElementById('MouseOver').style.left = "0px";
}
function sh(num){
	jQuery("#MouseOver p").each(function (i,elem) {
		$(elem).css('display', 'none');
	});
	jQuery('#tx'+num).css('display', 'block');
}
var more=0;
function getTeam(num, more){
	jQuery('#team_txt').cycle(num);
	jQuery('#team_imgBig').cycle(more);
}

$(document).ready(function(){
	//showRoomACC
	if($('.showRoomAcc').length){
			$('.showRoomAcc').accordion({
			    active: '.selected',
			    selectedClass: 'active',
			    header: "dt",
			    autoheight: false
			}).bind("change.ui-accordion", function(event, ui) {
				$('#socialLine').animate({ top: $('#int_Inh').height()+182+'px'}, 'slow');
			});
	  }
	
	//check res
	if($.browser.msie){
		$('#container').css('min-height', (screen.height-405)+'px');
		//$(this).find("div").fadeTo(500, 0.7);
	}
	//exeption-xchange
	var inh_xchange = $('#home-xchange').html();
	$('#home-xchange').html('<div class="gallery teni"><div class="gal_xchange" id="xchange" >'+inh_xchange+
	'</div><p class="pfeil-rechts"><a id="xchange_next"><img src="tl_files/tp/images/main/pfeil_gal.png" width="38" height="38" alt="rechts" /></a></p>'+
    '<p class="pfeil-links"><a id="xchange_prev"><img src="tl_files/tp/images/main/pfeil_gal2.png" width="38" height="38" alt="links" /></a></p>'+
    '</div>');

	//teni
	 $("div.teni").each(function (i,elem) {
		var w = $(elem).innerWidth();
		var h = $(elem).innerHeight();
		var sp = "";
		if($(elem).attr("id").length >0 ){
			sp += " id='"+$(elem).attr("id")+"' ";
			$(elem).removeAttr("id");
		}

	  var inh = $(elem).html();
		if($(elem).css('position') !== 'relative'){
			sp += " style='position:relative' ";
		}else sp += "";
		$(elem).html("<div class='teni_wrap' "+sp+">"+inh+
		"<div class='shT' style='width:"+(w+5)+"px;'></div>"+
		"<div class='shB' style='top:"+h+"px; width:"+(w+5)+"px;'></div>"+
		"<div class='shR' style='left:"+(w)+"px; height:"+(h+4)+"px;'></div>"+
		"<div class='shL' style='width:"+5+"px; height:"+(h+5)+"px;'></div>"+
		"</div>");
     });

	//textTop
	$('#open').click(function() {
		$('#int_Inh').css('height', 'auto');
		if($('#int_Inh').css('display') == 'none'){
			$('#open_img').css("background-image", "url(tl_files/tp/images/main/navi-close.gif)");
			var ic=0;
		}else{
			headerMsgOut();
			$('#open_img').css("background-image", "url(tl_files/tp/images/main/navi-open.gif)");
            moveSocials(0);
            var ic=1;
		}
		$('#int_Inh').slideToggle('slow');
		if(!ic) moveSocials($('#topTxt_'+akt).height());
	});

	$('#topTxt_'+akt).css('display', 'block');

	//XCHANGE
	$('#xchange').cycle({
		fx: 'scrollHorz',
		next:'#xchange_next',
		prev:'#xchange_prev',
		after:onAfter,
		timeout:  0,
		startingSlide:0
	});


	//Team
	$('#team_imgBig').cycle({
		fx: 'scrollVert',
		before: function (){
			if($.browser.msie) $(this).css('background', 'none');
		},
		timeout:  0,
		startingSlide:0
	});

	$('#team_txt').cycle({
		fx: 'scrollVert',
		next:   '.teamNext', 
		prev:   '.teamPrev',
		before: function (){
			if($.browser.msie) $(this).css('background', 'none');
		},
		/*
		easing:  'easeOutQuad',*/
		timeout:  0,
		startingSlide:0
	});


 	//rollOver
	$(".mhover").hover(function(){ 
		if($.browser.msie){
			$(this).find("div").fadeTo(500, 0.7);
		}else	$(this).find("div").fadeIn(500);
	},
	function(){
		if($.browser.msie){
			$(this).find("div").fadeTo(500, 0.001);
		}else	$(this).find("div").fadeOut(500);
	});


 	//rollOver2 w
	/*
	$("#w1").hover(function(event){
		$('#MouseOver').css('top',  (event.pageY-5));
		$('#MouseOver').css('left',  (event.pageX-2));
		$('#MouseOver p#tx1').fadeIn(500);
	},
	function(){
		$('#MouseOver p#tx1').fadeOut(500);
	});
*/

});
function chkEMail(s)  {
  var a = false;
  var res = false;
  if(typeof(RegExp) == 'function')    {
    var b = new RegExp('abc');
    if(b.test('abc') == true){a = true;}
  }

  if(a == true)    {
    reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
                     '(\\@)([a-zA-Z0-9\\-\\.]+)'+
                     '(\\.)([a-zA-Z]{2,4})$');
    res = (reg.test(s));
  }  else    {
    res = (s.search('@') >= 1 &&
           s.lastIndexOf('.') > s.search('@') &&
           s.lastIndexOf('.') >= s.length-5)
  }
  return(res);
}

function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;

	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";

	if(typeof(arr) == 'object') { //Array/Hashes/Objects
	 for(var item in arr) {
	  var value = arr[item];

	  if(typeof(value) == 'object') { //If it is an array,
	   dumped_text += level_padding + "'" + item + "' ...\n";
	   dumped_text += dump(value,level+1);
	  } else {
	   dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
	  }
	 }
	} else { //Stings/Chars/Numbers etc.
	 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}



