var xmlWork;
var xmlPeople;
var xmlNews;
var xmlJobs;
var xmlWorldWide;

function getContactCities(a_intRegionID, a_strThisOffice) {
	$('#divOfficeList').html('<p align="center"><img src="/img/ajax-loader-transparent.gif" height="16" width="16" align="absmiddle" alt="Loading ..." /></p>');

	$.get('/index/offices/region/' + a_intRegionID, {}, function(a_objResponse){
		var arrThisOffice = a_strThisOffice.split(',');

		$('#divOfficeList').html('');
		$('#divOfficeList').html(a_objResponse);

		if (a_intRegionID == arrThisOffice[0]) {
			$('#divOfficeList ul li a[rel=' + arrThisOffice[1] + ']').parent().remove();
			$("#divOfficeList ul li:first").before('<li><a class="aOfficeList-JQ-OFF" rel="' + arrThisOffice[1] + '" href="javascript:void(0);">' + arrThisOffice[2] + '</a></li>');//get(0)
		}

		$('#divOfficeList ul li a').each(function(){$(this).click(function(){hilteOfficeList($(this).attr('rel')); getContactInfo($(this).attr('rel'))});});
		$('#divOfficeList').jScrollPane();

		getContactInfo(arrThisOffice[1]);
		hilteOfficeList(arrThisOffice[1]);
	}, 'text');
}

function getContactInfo(a_intOfficeID) {
	$('#divOfficesR').html('<p align="center"><img src="/img/ajax-loader-transparent.gif" height="16" width="16" align="absmiddle" alt="Loading ..." /></p>');

	$.get('/index/officesinfo/office/' + a_intOfficeID, {}, function(a_objResponse){
		$('#divOfficesR').html('');
		$('#divOfficesR').html(a_objResponse);

	}, 'text');
}
/*
function getWorkCount(a_intClientID) {
	$('#divWorkContentR').html('<p align="center"><img src="/img/ajax-loader-transparent.gif" height="16" width="16" align="absmiddle" alt="Loading ..." /></p>');

	$.get('/index/thework/client/' + a_intClientID, {}, function(a_objResponse){
		$('#divWorkContentR').html('');
		$('#divWorkContentR').html(a_objResponse);
		getWorkInfo($('#divWorkContentR ul li:first a').attr('rel'));
		hilteWorkAction($('#divWorkContentR ul li:first a').attr('rel'));
		$('#divWorkContentR ul li a').each(function(){$(this).click(function(){hilteWorkAction($(this).attr('rel'));});});
	}, 'text');
}

function getWorkInfo(a_intWorkID) {

	$('#divTheWorkR').html('<p align="center"><img src="/img/ajax-loader-transparent.gif" height="16" width="16" align="absmiddle" alt="Loading ..." /></p>');

	$.get('/index/viewwork/work/' + a_intWorkID, {}, function(a_objResponse){
		$('#divTheWorkR').html('');
		$('#divTheWorkR').html(a_objResponse);
		$('#divYTInfoL').jScrollPane();
		$('#divYTInfoLALT').jScrollPane();
	}, 'text');
}

*/

function getPeopleBio(a_intPersonID) {
	$('#divPeopleRContent').html('<p align="center"><img src="./img/ajax-loader-transparent.gif" height="16" width="16" align="absmiddle" alt="Loading ..." /></p>');

	$.get('./index/peoplebio/person/' + a_intPersonID, {}, function(a_objResponse){
		$('#divPeopleRContent').html('');
		$('#divPeopleRContent').html(a_objResponse);
		$('#divPeopleRContent').jScrollPane();
	}, 'text');
}

function hiliteOfficeBubbles(a_intID) {
	$('#divOfficesL a').each(function(){
		if ($(this).attr('rel') == a_intID) {
			if (a_intID == 1) {
				$(this).addClass('aOfficeBubble1-JQ-ON');
			}
			else if (a_intID == 2) {
				$(this).addClass('aOfficeBubble2-JQ-ON');
			}
			else if (a_intID == 3) {
				$(this).addClass('aOfficeBubble3-JQ-ON');
			}
			else if (a_intID == 4) {
				$(this).addClass('aOfficeBubble4-JQ-ON');
			}
		}

		else {
			$(this).removeClass('aOfficeBubble1-JQ-ON');
			$(this).removeClass('aOfficeBubble2-JQ-ON');
			$(this).removeClass('aOfficeBubble3-JQ-ON');
			$(this).removeClass('aOfficeBubble4-JQ-ON');
		}
	});
}

function hilteMainNav(a_intID) {
	$('#divNav ul li a').each(function(){
		if ($(this).attr('rel') == a_intID) {
			$(this).addClass('aNav-JQ-ON');
			$(this).removeClass('aNav-JQ-OFF');
		}

		else {
			$(this).addClass('aNav-JQ-OFF');
			$(this).removeClass('aNav-JQ-ON');
		}
	});
}

function hilteOfficeList(a_intID) {
	$('#divOfficeList ul li a').each(function(){
		if ($(this).attr('id') == "office_" + a_intID) {
			$(this).addClass('aOfficeList-JQ-ON');
			$(this).removeClass('aOfficeList-JQ-OFF');
		}

		else {
			$(this).addClass('aOfficeList-JQ-OFF');
			$(this).removeClass('aOfficeList-JQ-ON');
		}
	});
}

function hilteWorkClient(a_intID) {
	$('#divWorkContentL ul li a').each(function(){
		if ($(this).attr('id') == "work_" + a_intID) {
			$(this).addClass('aWorkContentL-JQ-ON');
			$(this).removeClass('aWorkContentL-JQ-OFF');
		}

		else {
			$(this).addClass('aWorkContentL-JQ-OFF');
			$(this).removeClass('aWorkContentL-JQ-ON');
		}
	});
}

function hilteWorkAction(a_intID) {
	$('#divWorkContentR ul li a').each(function(){
		if ($(this).attr('rel') == a_intID) {
			$(this).addClass('aWorkContentR-JQ-ON');
			$(this).removeClass('aWorkContentR-JQ-OFF');
		}

		else {
			$(this).addClass('aWorkContentR-JQ-OFF');
			$(this).removeClass('aWorkContentR-JQ-ON');
		}
	});
}

function hiltePerson(a_intID) {
	//if (!($.browser.msie && $.browser.version.substr(0,1)<7)) {
		$.each($("#divPeople ul li a"), function(){
			if ($(this).attr("id") == "person_" + a_intID) {
			
				$(this).addClass('aPeopleM-JQ-ON');
				$(this).removeClass('aPeopleM-JQ-OFF');
			}

			else {
				$(this).addClass('aPeopleM-JQ-OFF');
				$(this).removeClass('aPeopleM-JQ-ON');
			}
		});
	//}
}

function showAbout(divId, hrefId){
	$("#divAboutContent > div").css("display","none");
	$("#"+divId).css("display","block");
	$("#subnavAbout > a.active").removeClass("active");
	$("#"+hrefId).addClass("active");
}

$(document).ready(function() {
//check if screen.height is smaller than document.height
 
 if(screen.availHeight<760){
	$("#pageWrapper").css("height","760px");
}
						   
	swfobject.embedSWF("./img/swf/pixelBoard.swf", "divPixelBoard", "950", "444", "8.0.0", "", {}, {wmode: "opaque"}, {});
	swfobject.embedSWF("./img/swf/picMask.swf", "divFaceSWF", "306", "444", "8.0.0", "", {imagepath:"./img/swf/dude.jpg"}, {wmode: "opaque"}, {})
	swfobject.embedSWF("./img/swf/grid.swf", "divBulbsSWF", "234", "444", "8.0.0", "", {}, {wmode: "opaque"}, {})
	swfobject.embedSWF("./img/swf/grid.swf", "divBulbsSWF2", "234", "444", "8.0.0", "", {}, {wmode: "opaque"}, {})
	swfobject.embedSWF("./img/swf/grid.swf", "divBulbsSWF3", "234", "444", "8.0.0", "", {}, {wmode: "opaque"}, {})
	swfobject.embedSWF("./img/swf/fakeGif.swf", "divPSWF", "450", "444", "8.0.0", "", {}, {wmode: "opaque"}, {})

	$('#aMN1').click(function(){$("#pageWrapper").scrollTo('#divIntro', 800); pageTracker._trackPageview('/Welcome');showAbout('whoWeAreAgency','aboutProxGer'); });
	$('#aMN2').click(function(){$("#pageWrapper").scrollTo('#divTheWork', 800);pageTracker._trackPageview('/TheWork');showAbout('whoWeAreAgency','aboutProxGer'); });
	$('#aMN3').click(function(){$("#pageWrapper").scrollTo('#divOffices', 800); pageTracker._trackPageview('/Worldwide');showAbout('whoWeAreAgency','aboutProxGer');});
	$('#aMN4').click(function(){$("#pageWrapper").scrollTo('#divNews', 800);pageTracker._trackPageview('/News');showAbout('whoWeAreAgency','aboutProxGer'); });
	$('#aMN5').click(function(){$("#pageWrapper").scrollTo('#divContact', 800);pageTracker._trackPageview('/Contact');showAbout('whoWeAreAgency','aboutProxGer'); });
	$('#aMN6').click(function(){$("#pageWrapper").scrollTo('#divAbout', 800);pageTracker._trackPageview('/Who_we_are/Proximity_Germany');showAbout('whoWeAreAgency','aboutProxGer'); });
	$('#aMN7').click(function(){$("#pageWrapper").scrollTo('#divPeople', 800);pageTracker._trackPageview('/People');showAbout('whoWeAreAgency','aboutProxGer');});
	$('#aMN8').click(function(){$("#pageWrapper").scrollTo('#divJobs', 800);pageTracker._trackPageview('/Jobs');showAbout('whoWeAreAgency','aboutProxGer'); });
	$('#aMN9').click(function(){$("#pageWrapper").scrollTo('#divImpressum', 800);pageTracker._trackPageview('/Impressum');showAbout('whoWeAreAgency','aboutProxGer'); });
    
	//getWorkCount($('#divWorkContentL ul li:first a').attr('rel'));
	//getContactCities(1, strThisOffice);

	$('#divPeopleMContent').jScrollPane();
	$('#divNewsRList').jScrollPane();
	
/*	$.get('xml/proximity.xml', function(xml){ 
		var json = $.xml2json(xml, true); 
		
		xmlWhoWeAre = new WhoWeAre(json.whoweare[0]);
		xmlWhoWeAre.getText();
	});
*/
	$.get('xml/work.xml', function(xml){ 
		var json = $.xml2json(xml, true); 
		
		xmlWork  = new Work(json.work[0]);
		xmlWork.getCustomerList();
		xmlWork.loadProjects(0,0);
	});
	
	$.get('xml/people.xml', function(xml){ 
		var json = $.xml2json(xml, true); 
		
		xmlPeople = new People(json.people[0]);
		xmlPeople.getPeopleList();
		xmlPeople.loadVita(0);
	});
	
	$.get('xml/jobs.xml', function(xml){ 
		var json = $.xml2json(xml, true); 
		
		xmlJobs = new Jobs(json.jobs[0]);
		xmlJobs.getJobList();
	});
		
	$.get('xml/news.xml', function(xml){ 
		var json = $.xml2json(xml, true); 
		
		xmlNews = new News(json.news[0]);
		xmlNews.getNewsList();
	});	
	
	$.get('xml/worldwide.xml', function(xml){ 
		var json = $.xml2json(xml, true); 
		
		xmlWorldWide = new WorldWide(json.worldwide[0]);
		xmlWorldWide.getCityList(0);
	});
	
	
	hiliteOfficeBubbles(2);
	//getPeopleBio($('#divPeopleM ul li:first a').attr('rel'));
	hiltePerson($('#divPeopleMContent ul li:first a').attr('rel'));
	hilteMainNav($('#divNav ul li:first a').attr('rel'));
	
	
	$('#divNav ul li a').each(function(){$(this).click(function(){hilteMainNav($(this).attr('rel'));});});
	$('#divOfficesL a').each(function(){$(this).click(function(){hiliteOfficeBubbles($(this).attr('rel'));});});
	
	$('#divImpressumRList').jScrollPane();
});