/*
Functions for dRei Architekten
*/
/* -----------------------------------------------------------
// the div handler functions
// -----------------------------------------------------------*/

$(document).ready(function(){
//initSwappi();
	/*
	$("a.sub_navi").livequery("click",function(){
		alert('geht');
	});
	*/
		//$.livequery.run();
	//$("#container a").livequery(function(){
//-------------------------------------------------------------
$("#map_big").load("../php/map_big.php?pro_id=0");
$("#text").load("../php/home.php");
//$("#sub_nav").load("../html/sub_nav.html");
//$("#lang").load("../php/lang.php");
$("#pic_nav").load("../php/pic_nav.php?pro_id=0");
    if(navigator.userAgent.indexOf("MSIE") != -1){
    	$("#pic_nav").css("margin-left","-350");
    	$("#text").css("witdth","350");
    }
/* ------------------------
  $("img.swappi").hover(
      function () {
        $(this).attr("src", function() { 
	          return this.src + '.jpg';
        });
        //console.log(this.src);
      }, 
      function () {
        $(this).attr("src", function() { 
          return this.src.substring(0,this.src.lastIndexOf("."));
        });
        //console.log(this.src);
      },
      function () { 
        // unbind the mouseover and mouseout events 
        $(this) 
            .unbind('mouseover') 
            .unbind('mouseout'); 
      });
    //);

--------------------------- */
/* ------------------------
$("img.swappi").livequery(function(){

 $(this).hover(
      function () {
       $(this).attr("src", function() { 
          return this.src + '.jpg';
        });
		
    console.log(this.src);
      }, 
      function () {
        $(this).attr("src", function() { 
          return this.src.substring(0,this.src.lastIndexOf("."));
        })		
    console.log(this.src);
      });

    }, function() { 
        // unbind the mouseover and mouseout events 
        $(this) 
            .unbind('mouseover') 
            .unbind('mouseout'); 
    });
--------------------------- */
    $("#main_nav a.buero").click(function () {
    	$("#map_big").load("../php/map_big.php?pro_id=0");
    	$("#pic_nav").load("../php/pic_nav.php?pro_id=0");
    	$("#text").load("../php/home.php");
			$("#pro_nav").load("../html/buero.html");
			$("#text_nav").load("../html/text_nav.html");	
			$("#sub_nav").load("../html/sub_nav.html");
    });    
    $("#main_nav a.kontakt").click(function () {
			$("#map_big").load("../php/map_big.php?pro_id=0");
			$("#text").load("../php/home.php");
			$("#pic_nav").load("../php/pic_nav.php?pro_id=0");
			$("#pro_nav").load("../html/kontakt.html");
			$("#text_nav").load("../html/text_nav.html");	

    });
    $("#main_nav a.impressum").click(function () {
			$("#map_big").load("../php/map_big.php?pro_id=0");
			$("#text").load("../php/home.php");
			$("#pic_nav").load("../php/pic_nav.php?pro_id=0");    	
			$("#pro_nav").load("../html/impressum.html");
			$("#text_nav").load("../html/text_nav.html");	
		
    });          
//});

//});
});
/* -----------------------------------------------------------
// General functions
// -----------------------------------------------------------*/
//function initSwappi(){
$("img.swappi").livequery(function(){
    $(this).hover(
        function () {
        $(this).attr("src", function() { 
              return this.src + '.jpg';
        });
      }, 
      function () {
        $(this).attr("src", function() { 
          return this.src.substring(0,this.src.lastIndexOf("."));
        });
      },
      function () { 
        $(this) 
            .unbind('mouseover') 
            .unbind('mouseout');
        });
    });
//}
function goHome(){
	document.location.href="drei_neu.php";
}

function changeSubNav(kat){	
	$("#map_big").load("../php/map_big_kat.php?kat="+kat);
	$("#text").load("../php/home.php");
	$("#pic_nav").load("../php/pic_nav.php?pro_id=0");	
	switch(kat){
		case 'interior':
			$("#sub_nav").load("../html/sub_nav_inter.html");
			$("#text_nav").load("../html/text_nav_inter.html");	
			$("#pro_nav").load("../php/pro_inter.php");
			break;
		case 'wettbewerb':
			$("#sub_nav").load("../html/sub_nav_wett.html");
			$("#text_nav").load("../html/text_nav_wett.html");	
			$("#pro_nav").load("../php/pro_wett.php");
			break;
		case 'kooperation':
			$("#sub_nav").load("../html/sub_nav_koop.html");
			$("#text_nav").load("../html/text_nav_koop.html");	
			$("#pro_nav").load("../php/pro_koop.php");
			break;
		case 'projektmanagement':
			$("#sub_nav").load("../html/sub_nav_manag.html");
			$("#text_nav").load("../html/text_nav_manag.html");	
			$("#pro_nav").load("../php/pro_manag.php");
			break;			
		case 'architektur':
		  //alert(kat);
		  $("#sub_nav").load("../html/sub_nav_archi.html");
			$("#text_nav").load("../html/text_nav_archi.html");	
			$("#pro_nav").load("../php/pro_archi.php");
			break;
	}
	//initSwappi();
}

/* -----------------------------------------------------------
// mapping function for login
// -----------------------------------------------------------*/
var mapVis=0;
function showBigMap(){
      $("#map_big").load("../php/map_big.php");
      $("#map_big").animate({
        width: "600px",
        opacity: 1.0,
        marginLeft: "0in",
        fontSize: "12pt",
        borderWidth: "0px"
      }, 1500 );
      $("#map_small").animate({
        width: "300px",
        opacity: 0.0,
        marginLeft: "0in",
        fontSize: "12pt",
        borderWidth: "0px"
      }, 1500 );
	  mapVis = 1;
}

/* -----------------------------------------------------------
// security function for login
// -----------------------------------------------------------*/
function zeigMal(){
	var txt = "This workarea is strictly confidential.<br>if u are not associated with this project, please click cancel!<br>Otherwise enter password and click OK!";
	txt += "<form name='checkForm'><input type='password' id='passwd' name='passwd' value=''></form>";
	$.prompt(txt,
		{ buttons: { Ok: true, Cancel: false },
		callback: function(v,m){
			var upass = m.find('#passwd').val();
			if(v){
				if(upass!=''){
					 document.location.href="./php/testseite_neu.php?upass="+upass;
				}
				else{
					 document.location.href="http://www.diebrigade.de";
				}
			}
			else{
				document.location.href="http://www.diebrigade.de";
			}
		}
	});
}
/* -----------------------------------------------------------
// projecttable functions
// -----------------------------------------------------------*/
var lastPro=0;
function changeBg(difx,proId,group){
difx-=1;
/*$("#text td:eq("+difx+")").css("background-color","red");*/
/*alert(group);*/
$("#map_small").load("../php/pro_info.php?proId="+proId+"&group="+group);
      $("#map_small").animate({
        width: "300px",
        opacity: 1.0,
        marginLeft: "0in",
        fontSize: "12pt",
        borderWidth: "0px"
      }, 1500 );
	if(lastPro!=0&&lastPro!=difx){
 		/*$("#text td:eq("+lastPro+")").css("background-color","white");*/  
	}
lastPro=difx;
}
function bgDefault(difx){
	alert(proLoaded);
	if(proLoaded=='none'){
	difx-=1;
	$("#text1 td:eq("+difx+")").css("background-color","white");
	$("#map_small").load("../php/pro_info.php");
	}
}
/* -----------------------------------------------------------
// project functions
// -----------------------------------------------------------*/
//var proLoaded = "none";
function showProject(difx,pro_id){
		 if(pro_id!=0){
		 //$("#pic_left").load("../php/pro_img.php?proId="+proId);
		 //$("#pic_left").show("slow");
		 //$("#sub_nav").load("../php/pro_img_small.php?proId="+proId);
		 $("#map_big").load("../php/map_big.php?pro_id="+pro_id);
		 $("#pic_nav").load("../php/pic_nav.php?pro_id="+pro_id);
	  	 $("#text").load("../php/pro_text.php?pro_id="+pro_id);
	  	 $("#text").show("slow");
		 //proLoaded  = document.getElementById('pic_left').style.display;
		 }
		 else{
		 	//if(proLoaded=='none'){
			//difx-=1;
			$("#text1 td:eq("+difx+")").css("background-color","white");
			$("#map_small").load("../php/pro_info.php?difx="+difx);
			//}
			//proLoaded="none";
		 }
		 //
}
function showGroupPro(difx,group){
		 $("#text").load("../php/pro_group.php?proGroup="+difx);
		 $("#map_small").load("../php/pro_info.php?group="+group);
}
/* -----------------------------------------------------------
// image functions
// -----------------------------------------------------------*/
function changeProPic(src,pic_id,pro_id){
  if(pic_id != 1){
    //$("#text").hide("slow");
    $("#text").load("../php/pro_text_blank.php?pro_id="+pro_id);    
		$("img.pro_pic").attr("src","../img/"+src);
	}
	else{
    //$("#text").show("slow");
    $("#text").load("../php/pro_text.php?pro_id="+pro_id);
		$("img.pro_pic").attr("src","../img/"+src);	
	}
}
// +++++++++++++++++++++++++++++++++++++++
// email encrypting
// +++++++++++++++++++++++++++++++++++++++
function UnCryptMailto(s, shift) {
	var n=0;
	var r="";
	for(var i=0;i<s.length;i++) {
		n=s.charCodeAt(i);
		if (n>=8364) {n = 128;}
		r += String.fromCharCode(n-(shift));
	}
	return r;
}
function linkTo_UnCryptMailto(s, shift)	{
	location.href=UnCryptMailto(s, shift);
}
