var keys=["ero","busStand","campSchool","balnilayam","primary","badi","hospital","gandhi","subhash","sarojini","mandakini","gangotri","chitranjan","nehru","pant","shastri","shivalik","vs","store","sj","patel","tagore","pct","nct","cbsh","vm","homeSc","agri","audi","adm","cabm","library","ccf","sbi","pnb","uco","pcp","research","crc","igh","tarai","choti","stadium"];

var autoCompleteEntries=["AeroDrome","Bus Stand","Campus School","Balnilayam School","Primary School","Badi Market","Hospital","Gandhi Bhawan","Subhash Bhawan","Sarojini Bhawan","Mandakini Bhawan","Gangotri Bhawan","Chitranjan Bhawan","Nehru Bhawan","Pant Bhawan","Shastri Bhawan","Shivalik Bhawan","Vishveshvariya Bhawan","Central Store","Silver Jubilee Bhawan","Patel Bhawan","Tagore Bhawan","PCT","New College of Technology(NCT)","College of Basic Science and Humanities","Veterinary College","College of Home Science","College of Agriculture","Gandhi Auditorium","Administrative Building","College of Agri Business Mgmt.","University Library","Central Computing Facility","State Bank of India","Punjab National Bank","UCO Bank","PCP","Research Labs Complex","CRC","International Guest House(IGH)","Tarai Bhawan","Choti Market","Stevenson Stadium"];

//initial marker position. Changes during pan and zoom
var initMarkersPos = [[170,270],[360,260],[410,300],[520,320],[400,360],[390,410],[450,460],[600,540],[630,470],[700,420],[700,500],[800,430],[780,360],[850,340],[940,340],[1030,360],[1120,420],[1170,480],[1120,500],[1220,540],[1220,640],[1220,720],[1080,680],[1080,600],[990,500],[900,450],[800,500],[720,580],[880,600],[910,630],[850,650],[890,710],[960,610],[960,650],[940,690],[1010,660],[1050,760],[680,800],[680,860],[400,560],[310,660],[1170,360],[1380,740]];
//for reset function
var initMarkersPosCopy = [[170,270],[360,260],[410,300],[520,320],[400,360],[390,410],[450,460],[600,540],[630,470],[700,420],[700,500],[800,430],[780,360],[850,340],[940,340],[1030,360],[1120,420],[1170,480],[1120,500],[1220,540],[1220,640],[1220,720],[1080,680],[1080,600],[990,500],[900,450],[800,500],[720,580],[880,600],[910,630],[850,650],[890,710],[960,610],[960,650],[940,690],[1010,660],[1050,760],[680,800],[680,860],[400,560],[310,660],[1170,360],[1380,740]];

//onhover messages
var markersMsg = [
["na.jpg","Aerodrome - A state-of-the art facility bringing Pantnagar on the Air Traffic Map."],
["na.jpg","Bus Stand - Proposed site for a common Bus Stand."],
["campus.jpg","Campus School - CBSE affiliated school from Montessori to 12th Standard."],
["bal.jpg","Balnilayam School - School from Nursery to 8th Standard."],
["primary.jpg","Primary School"],
["badi.jpg","Badi Market - Main Shopping Cetnre."],
["hosp.jpg","Central University Hospital "],
["na.jpg","Gandhi Bhawan - Girls Hostel. <br> Residents:  M.Sc. 1st year, B.Sc.(Veterinary) 2nd, 3rd & final year"],
["na.jpg","Subhash Bhawan - Girls Hostel. <br> Residents:  B.Sc.(Agriculture) 2nd, 3rd & final year, B. Tech(Food Technology) 1st to final year"],
["na.jpg","Sarojini Bhawan - Girls Hostel. <br> Residents:  Under Graduate 1st year"],
["mand.jpg","Mandakini Bhawan - Girls Hostel. <br> Residents: B. Tech 2nd, 3rd & final year"],
["na.jpg","Gangotri Bhawan - Girls Hostel. <br> Residents:  B.Sc.(Home Science) 2nd, 3rd & final year"],
["cb.jpg","Chitranjan Bhawan - Boys Hostel. <br> Residents:  B.Sc.(Home Science) 2nd, 3rd & final year"],
["nehru.jpg","Nehru Bhawan - Boys Hostel. <br> Residents:  Under Graduate first year (except B. Tech.)"],
["pant.jpg","Pant Bhawan - Boys Hostel. <br> Residents:  B.Sc.(Fisheries & Veterinary) 2nd, 3rd & final year"],
["shashtri.jpg","Shastri Bhawan - Boys Hostel. <br> Residents:  All Ph.D. students"],
["shivalik.jpg","Shivalik Bhawan - Boys Hostel. <br> Residents:  M.Sc. ,MCA, B.Tech(Civil Engineering) 3rd & final year"],
["vs.jpg","Vishveshvariya Bhawan - Boys Hostel. <br> Residents:  B. Tech final year(except Civil Engineering)"],
["na.jpg","Central Store - University warehouse all college have a common supply form this store "],
["sj.jpg","Silver Jubilee Hostel - Boys Hostel. <br> Residents:  B. Tech 3rd year(except Civil Engineering)"],
["patel.jpg","Patel Bhawan - Boys Hostel. <br> Residents:  B. Tech 2nd year"],
["tagore.jpg","Tagore Bhawan - Boys Hostel. <br> Residents:  B. Tech 1st year"],
["na.jpg","Old College of Technology (Old Building) <br> Departments: - Civil Engineering,<br> Agricultural Engineering."],
["nct.jpg","New College of Technology (New building) <br> Departments: - Computer Engineering, <br> Electrical Engineering, <br> Electronics Engineering, <br> Mechanical Engineering, <br> Production Engineering"],
["cbsh.jpg","College of Basic Science and Humanities <br> Departments:  - Biochemistry, <br> Biological Science, <br> Chemistry, <br> Environmental Science, <br> Humanities & Social Science, <br> Mathematics Statistics & Computer Science, <br> Microbiology, <br> Molecular Biology & Genetic Engineering, <br> Physics, <br> Plant Physiology"],
["vat.jpg","Veterinary College <br> Departments:  - Animal Nutrition, <br> Animal Reproduction, <br> Gynecology & Obstetrics, <br> Clinical Veterinary Medicine Ethics & Jurisprudence, <br> Epidemiology & Preventive Medicine, <br> Genetics & Animal Breeding, <br> Livestock Production & Management, <br> Livestock Products Technology, <br> Veterinary Anatomy, <br> Veterinary & Animal Husbandry Extension, <br> Veterinary Biochemistry, <br> Veterinary Microbiology, <br> Veterinary Parasitology, <br> Veterinary Pathology, <br> Veterinary Pharmacology & Toxicology, <br> Veterinary Physiology, <br> Veterinary Public Health, <br> Veterinary Surgery & Radiology"],
["homescience.jpg","College of Home Science <br> Departments:  - Clothing and Textiles, <br> Human Development and Family Studies, <br> Foods and Nutrition,  <br> Family Resource Management, <br> Home Science Extension"],
["agcol.jpg","College of Agriculture <br> Departments:  - Agricultural Communication, <br> Agricultural Economics, <br> Agrometerology, <br> Agronomy, <br> Entomology, <br> Food Science and Technology, <br> Genetics and Plant Breeding, <br> Horticulture, <br> Plant Pathology, <br> Soil Science, <br> Vegetable Science"],
["na.jpg","Gandhi Auditorium - A fully air conditioned facility for holding majority of University Functions. "],
["na.jpg","Administrative Building - This building houses most of the administrative offices including Vice Chancellor's office"],
["na.jpg","College of Agri Business Management <br> Departments:  - Business Economics and Policy, <br> Finance Management, <br> Human Resource and Personnel Management, <br> Marketing Management, <br> Production Management"],
["esize.jpg","University Library - Central library for the whole university."],
["ccf.jpg","Central Computing Facility - Provides Computation + Internet surfing facility with more then 450 terminals"],
["sbi.jpg","State Bank of India - ATM Facility Available"],
["pnb.jpg","Punjab National Bank - ATM Facility Available"],
["uco.jpg","UCO Bank - ATM Facility Available"],
["na.jpg","PCP"],
["na.jpg","Research Labs Complex"],
["na.jpg","CRC"],
["igh.jpg","International Guest House - It is one of the three university guest houses."],
["na.jpg","Tarai Bhawan - Vice chancellor\'s residence."],
["choti.jpg","Choti Market - Small Shopping Complex"],
["steven.jpg","Stevenson Stadium - University stadium."] 
];

var imagePath="images/";

jQuery(document).ready( function(){

//center the page
var width1 = jQuery("#a").width();
var halfWidth = ((width1/2)*(-1));
jQuery("#a").css({width:width1,position:'absolute',left:'50%',marginLeft:halfWidth});

var h,w,constrainY=360,constrainX=600,noteLeft=0,noteTop=0;
var linkRef =new Array();
var msgRef= new Array();
var mapImage= jQuery("#map img");

jQuery.each(initMarkersPos,function(i,n){
jQuery("#map").after('<div class="marker" id="'+keys[i]+'Link" style="left:'+n[0]+'px;top:'+n[1]+'px;"><a class="thickbox">Hidden Message.</a></div>');
});

jQuery.each(markersMsg,function(i,n){
jQuery('#'+keys[i]+'Link a').attr({href:imagePath+n[0],title:n[1]});
});

jQuery.each(initMarkersPos,function(i,n){
linkRef.push(jQuery('#'+keys[i]+'Link'));
});

jQuery.each(keys,function(i,n){
jQuery('#'+n+'Link a').tooltip({
	track: true,
	delay: 0,
	showURL: false,
	fixPNG: true,
	showBody: " - ",
	top: -15,
	left: 5
});
});

//-- zoom out 
jQuery('#out').click(function(){

h=mapImage.height(); w=mapImage.width();
l= parseInt(mapImage.css("left").replace(/px/,""));
t= parseInt(mapImage.css("top").replace(/px/,""));
if((h+t)<590 || (w+l)<1030 ) return false;
changeCSS('false',w,h,'false');
mapImage.animate({height:h-57,width:w-100},"slow");

});
//--zoom in
jQuery('#in').click(function(){
h=mapImage.height();w=mapImage.width();
changeCSS('false',w,h,'true');
mapImage.animate({height:h+57,width:w+100},"slow");
});

//reset map
jQuery('#reset').click(function(){
mapImage.animate({height:893,width:1568,left:0,top:0},"slow");
initMarkersPos=initMarkersPosCopy;
for(var i=0;i<linkRef.length;i++)
{
 linkRef[i].css("left",initMarkersPos[i][0]);
 linkRef[i].css("top",initMarkersPos[i][1]);
 }
 noteLeft=0;
 noteTop=0;
});

mapImage.draggable({helper:'original',drag:constrain,stop:posFinal});

jQuery("#toolBox").draggable({helper:'original'});

//--called continuously during drag of map 
function constrain(e,ui)
{
 constrainX = mapImage.width()-1010;
 constrainY= mapImage.height()-550;
 if(ui.position.left>0) ui.position.left=0;
 if(ui.position.top>0) ui.position.top=0;
 if(ui.position.left<-constrainX) ui.position.left=-constrainX;
 if(ui.position.top<-constrainY) ui.position.top=-constrainY;
}

 //--called on drag over
function posFinal(e,ui)
{ 
 tempX=ui.position.left;
 tempY=ui.position.top; 
 changeCSS('true',tempX,tempY,false); 
 noteLeft=ui.position.left;
 noteTop=ui.position.top;
}

//synchronize left and top positions of the markers with their text on the image

function changeCSS(panBool,tempX,tempY,zoomInBool)
{
for(i=0;i<linkRef.length;i++)
{
 if(panBool=='true')//panning
 {   
	if(tempX>noteLeft) 	//right
	initMarkersPos[i][0] = initMarkersPos[i][0]+Math.abs(tempX-noteLeft);					
	else 					//left 
	initMarkersPos[i][0] = initMarkersPos[i][0]-Math.abs(tempX-noteLeft);						
	if(tempY>noteTop) 		//down 
	initMarkersPos[i][1] = initMarkersPos[i][1]+Math.abs(tempY-noteTop);
	else 					//top 
	initMarkersPos[i][1] = initMarkersPos[i][1]-Math.abs(tempY-noteTop);					
 }
 else//zooming
 {
	if(zoomInBool=='true')	//zoom in
	{
		initMarkersPos[i][0]=initMarkersPos[i][0]*(tempX+100)/(tempX);
		initMarkersPos[i][1] =initMarkersPos[i][1]*(tempY+57)/(tempY);
		
	}
	else					//zoom out
	{
		initMarkersPos[i][0]=initMarkersPos[i][0]*(tempX-100)/(tempX);
		initMarkersPos[i][1] = initMarkersPos[i][1]*(tempY-57)/(tempY);
		
	}
 }

 linkRef[i].css("left",initMarkersPos[i][0]);
 linkRef[i].css("top",initMarkersPos[i][1]);
}
}

});//end ready

