var currentCountryMap;
var currentCountryInInnerHtml="";
var previousCountryInInnerHtml="";
var previousSelectedCountry="";
var currentCountry="";
var mapcarN
var context="";
usd=0;
function changeMap(countryName,url){
	document.getElementById(countryName).src=url;
}
function changeCountryAddressAndPhoneNo(country,countryOfficeContainer){
	previousCountry = previousSelectedCountry+"headoffice";
	deSelectPreviousCountry = document.getElementById(previousCountry);
	deSelectPreviousCountry.removeAttribute("style");
	deSelectPreviousCountry.innerHTML = previousCountryInInnerHtml;
	
	countryHeadoffice = country+"headoffice";
	_selectCountry = document.getElementById(countryHeadoffice);
	_selectCountry.setAttribute("style","text-decoration:none;font-family:Arial, Helvetica, sans-serif;font-weight:normal;font-style:normal;color:#555;")
	_selectCountry.style.cssText="text-decoration:none;font-family:Arial, Helvetica, sans-serif;font-weight:normal;font-style:normal;color:#555;"
	//_selectCountry.innerHTML = '<p>'+country;
	currentCountry = country;
	previousSelectedCountry = country;
	
	currentCountryInInnerHtml = _selectCountry.innerHTML;
	previousCountryInInnerHtml = _selectCountry.innerHTML;
	
	showOfficesInCarosoul(country);
	
	$(document).ready(function(){
	$(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'light_rounded'});
});
}
function selectCountry(countryName,requestCallBackURL){
	firstIndex = requestCallBackURL.indexOf("/");
	secondIndex = requestCallBackURL.indexOf("/",firstIndex+1);
	context=requestCallBackURL.substring(firstIndex,secondIndex);
	reqClbck = document.getElementById("requestCallBack");
	if(reqClbck!=null){
		calBackUrl = reqClbck.getElementsByTagName("a")[0];
		if(calBackUrl!=null){
			calBackUrl.href=requestCallBackURL;	
		}
	}
	countryHeadoffice = countryName+"headoffice";
	_selectCountry = document.getElementById(countryHeadoffice);
	_selectCountry.setAttribute("style","text-decoration:none;font-family:Arial, Helvetica, sans-serif;font-weight:normal;font-style:normal;color:#555;")
	_selectCountry.style.cssText="text-decoration:none;font-family:Arial, Helvetica, sans-serif;font-weight:normal;font-style:normal;color:#555;"
	//_selectCountry.innerHTML = '<p>'+countryName;
	currentCountry = countryName;
	previousSelectedCountry = countryName;
	
	currentCountryInInnerHtml = _selectCountry.innerHTML;
	previousCountryInInnerHtml = _selectCountry.innerHTML;
	
	showOfficesInCarosoul(countryName);
	
	$(document).ready(function(){
	$(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'light_rounded'});
	});
}

function showOfficesInCarosoul(countryName){
	countryOfficeContainer = countryName+"officecontainer";
	current_cntry = document.getElementById(countryOfficeContainer);
	prevoius_cntry = document.getElementById("officecontainer");
	prevoius_cntry.innerHTML = current_cntry.innerHTML;
	buildCarousel(countryOfficeContainer);
}

function buildCarousel(countryOfficeContainer){
	document.getElementById("officecontainer").style.left="0px";
	mapcarN=null;
	//noOfOffice = document.getElementById(countryOfficeContainer).getElementsByTagName('DIV').length;
	carosId ='mc1';
	carosContent="";
	arrowLeftImageURL=context+'/views/images/carslarrowleft.gif';
	arrowRightImageURL=context+'/views/images/carslarrowright.gif';
	first = '<div onclick=\"mapCar(1)\"><img src=\"'+arrowLeftImageURL+'\" alt=\"previous office\"/></div>'	
	carosContent ='<div id=\"'+carosId+'\"' + ' ' + 'class=\"carosOn\">'+ '&nbsp;'+'</div>';
	carosContent = first+carosContent;
	second = '<div onclick=\"mapCar(2)\"><img src=\"'+arrowRightImageURL+'\" alt=\"next office\"/></div>'
	noOfOffice =  countOffice(countryOfficeContainer);
	for(i=2;i<=noOfOffice;i++){
		 carosId ='mc'+i;
		 carosContent = carosContent+ '<div id=\"'+carosId+'\"' + ' ' + 'class=\"carosOff\">'+ '&nbsp;'+'</div>';
	}
	carosContent=carosContent+second;
	document.getElementById('caros').innerHTML=carosContent;
}

function countOffice(countryOfficeContainer){
		obj = document.getElementById(countryOfficeContainer).getElementsByTagName('DIV');
		count=0;
		for(i=0;i<obj.length;i++){
			if(obj[i].className=='officecontainerInt'){
				count++;
			}
		}
		return count;
}

function hideoffice(){
	cxlr=document.getElementsByName("offdet")
	for(j=0;j<cxlr.length;j++){
		cxlr[j].style.display="none"	
	}	
}

function showoffice(y){
	cxlr=document.getElementsByName("offdet")
	ahRef = y.getElementsByTagName("a")[0];
	if(currentCountryInInnerHtml!=ahRef.innerHTML){
		ahRef.setAttribute("style","color:#009DE0;");
		ahRef.style.cssText="color:#009DE0;"
	}
	
	for(j=0;j<cxlr.length;j++){
		cxlr[j].style.display="none"	
	}
	nos=y.getElementsByTagName("div")
	for (s=0;s<nos.length;s++){
		if(nos[s].id=="offdet"){
			nos[s].style.display="block"
		}
	}
}

/*function showmap(countryName,imageUrl,country){
	changeMap(countryName,imageUrl);

	mp=document.getElementById(country);
	ovbg=document.getElementById("ovrbg")
	screenW = screen.width;
	screenH = screen.height;

	if(mp.style.display=="block"){
		mp.style.display="none"
		ovbg.style.display="none"
	
	}else{
		mp.style.display="block"
		ovbg.style.display="block"
		ovbg.style.width=screenW+"px"
		ovbg.style.height=screenH+"px"
}
	
}*/

/*function showmap(countryName,imageUrl,country){
changeMap(countryName,imageUrl);
w=0;
h=0;
mpY=0
mp=document.getElementById(country);
mContainer="mcontainer"+country;

mpCont=document.getElementById(mContainer)
if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    mpY = window.pageYOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    mpY = document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    mpY = document.documentElement.scrollTop;
    
  }
mpX=document.getElementById("container").offsetLeft

mp.style.top=mpY+200+"px"
mp.style.left=mpX+75+"px"
mi=document.getElementById(mContainer)
ovbg=document.getElementById("ovrbg")
screenW = screen.availWidth
screenH = document.getElementById("container").offsetHeight
	if(mp.style.display=="block"){
	OverlayfClose(w,h,country)
	ovbg.style.display="none"
	
	}else{
	mp.style.display="block"
	mpw=mpCont.offsetWidth
	mph=mp.offsetHeight
	mp.style.width=1+"px"
	mp.style.height=1+"px"
	ovbg.style.display="block"
	
		if ( browserName=="Microsoft Internet Explorer"){
        ovbg.style.width  = document.documentElement.clientWidth+"px";
       	ovbg.style.height = screenH+55+"px";
    	}else{
		ovbg.style.width  = screenW-17+"px";
		ovbg.style.height  = screenH+55+"px";
    	}


	Overlayef(w,mpw,country)
	
	divHeight(h,mph,country);
	}
}
function Overlayef(w,j,country){
	mContainer="mcontainer"+country
	y=document.getElementById(country)
	z=document.getElementById(mContainer)

	if (w>=j) {
		
	w=j
	y.style.width = j+"px";
	document.getElementById("mapbottom").style.width=j+"px";
	}else {
	w = w+41;
	y.style.width = w+"px";
	setTimeout("Overlayef("+w+","+j+")", "1 * 1000");
	}
}
function divHeight(h,l,country) {
mContainer="mcontainer"+country
y=document.getElementById(country)
z=document.getElementById(mContainer)

if (h>=l) {
h=l	
y.style.height = l+"px";
		if(document.getElementById("emailOV")){
		document.getElementById("emailOV").style.display="block"
	}

}else {
h = h+23;
y.style.height = h+"px";
setTimeout("divHeight("+h+","+l+")", "1 * 1000");
}
}


	
	function OverlayfClose(w,h,country){
	mContainer="mcontainer"+country
	y=document.getElementById(country)
	z=document.getElementById(mContainer)
	y.style.display="none";
	y.style.width="";
	y.style.height="";
	
	}*/
	
function showmap(countryName,url,country){
currentCountryMap=country;
w=0;
h=0;
changeMap(countryName,url);
mpY=0

mp=document.getElementById(country)
mContainerCountry = "mcontainer"+country
mpCont=document.getElementById(mContainerCountry)
if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    mpY = window.pageYOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    mpY = document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    mpY = document.documentElement.scrollTop;
    
  }
mpX=document.getElementById("container").offsetLeft
mp.style.top=mpY+200+"px"
mp.style.left=mpX+75+"px"
mi=document.getElementById(mContainerCountry)
ovbg=document.getElementById("ovrbg")
screenW = screen.availWidth
screenH = document.getElementById("container").offsetHeight
	if(mp.style.display=="block"){
	OverlayfClose(w,h,country)
	ovbg.style.display="none"
	
	}else{
	mp.style.display="block"
	mpw=mpCont.offsetWidth
	mph=mp.offsetHeight
	mp.style.width=1+"px"
	mp.style.height=1+"px"
	ovbg.style.display="block"
	
		if ( browserName=="Microsoft Internet Explorer"){
        ovbg.style.width  = document.documentElement.clientWidth+"px";
       	ovbg.style.height = screenH+55+"px";
    	}else{
		ovbg.style.width  = screenW-17+"px";
		ovbg.style.height  = screenH+55+"px";
    	}


	Overlayef(w,mpw,country)
	
	divHeight(h,mph,country);
	}
}
function Overlayef(w,j,country){
	mapbottomCountry = "mapbottom"+country
	y=document.getElementById(country)
	z=document.getElementById(mContainerCountry)

	if (w>=j) {
		
	w=j
	y.style.width = j+"px";
	document.getElementById(mapbottomCountry).style.width=j+"px";
	}else {
	w = w+41;
	y.style.width = w+"px";
	setTimeout("Overlayef(" +w +"," +j +",'" +country +"'"  +")", "1 * 1000");
	}
}
function divHeight(h,l,country) {
y=document.getElementById(country)
z=document.getElementById(mContainerCountry)

if (h>=l) {
h=l	
y.style.height = l+"px";
		if(document.getElementById("emailOV")){
		document.getElementById("emailOV").style.display="block"
	}

}else {
h = h+23;
y.style.height = h+"px";
setTimeout("divHeight(" +h +"," +l +",'" +country +"'" +")", "1 * 1000");
}
}


	
	function OverlayfClose(w,h,country){
	y=document.getElementById(country)
	z=document.getElementById(mContainerCountry)
	y.style.display="none";
	y.style.width="";
	y.style.height="";
	
	}


	


function mapCar(d){
	if(usd==0){
var getOff = document.getElementById('caros').getElementsByTagName('DIV').length;
getOffN=getOff-2
			if(!mapcarN){mapcarN=1}

	if(d==2){
	 	if(mapcarN<getOffN){
			Cx="mc"+mapcarN
			Nx=mapcarN+1
			mapcarN=Nx
			Nn="mc"+Nx
			document.getElementById(Cx).className="carosOff"
			document.getElementById(Nn).className="carosOn"
			XL=document.getElementById("officecontainer").style.left
			movemapC("r",0,XL)
	}
		}
		
		
	if(d==1){
	 
	 	if(mapcarN>1){
			Cx="mc"+mapcarN
			Nx=mapcarN-1
			mapcarN=Nx
			Nn="mc"+Nx
			document.getElementById(Cx).className="carosOff"
			document.getElementById(Nn).className="carosOn"
			XL=document.getElementById("officecontainer").style.left
			movemapC("l",0,XL)
			}
	}
}
}

function movemapC(d,count,XL,CL){
XL=parseFloat(XL)
count=count+1

	if (count <11){
		if(d=="l"){
		CL=document.getElementById("officecontainer").style.left
		CL=parseFloat(CL)
		CL=CL+52
		document.getElementById("officecontainer").style.left=CL+"px"
		}
		
		if(d=="r"){
		CL=document.getElementById("officecontainer").style.left
		CL=parseFloat(CL)
		CL=CL-52.2
		document.getElementById("officecontainer").style.left=CL+"px"
		}
	usd=1
	t=setTimeout("movemapC('"+d+"'," +count+","+XL+","+CL+")",10)
	}else{
		usd=0
		if(d=="l"){
			document.getElementById("officecontainer").style.left=XL+522+"px"
		}
			if(d=="r"){
			document.getElementById("officecontainer").style.left=XL-522+"px"
		}
				

	}

}
function ovbgclose_map(){
	y=document.getElementById(currentCountryMap)
	ovbg=document.getElementById("ovrbg")
	ovbg.style.display="none";
	y.style.display="none";
	y.style.width="";
	y.style.height="";
}
