// JavaScript Document
//var Casto={};
Casto.center_info={};
Casto.center_info={
		active:false,
		current:0,
		loader:true,
		data_html:'',
		mapObj:new Array(),
		directions:false,
		init:function(obj) {
			if(this.active) return;
			if(Casto.center_info.image.current) Casto.center_info.image.hide();
			this.current = $(obj);
			this.loader=true;
			Casto.center_info.show();
			this.active=true;
			setTimeout('Casto.center_info.loader=false;Casto.center_info.show();',1300);
		},
		show: function() {
				var offsets = this.current.cumulativeOffset();
				var offsetScroll = document.viewport.getScrollOffsets();
				offsets[0]-=offsetScroll[0];
				offsets[1]-=offsetScroll[1];
				var startoffset=new Array();
				if(this.loader==true) {
					this.directions=false;
					$('start').value='';
					$$('.casto-popup .pop-up-text #bigmapArea')[0].update('');
					$$('.casto-popup .pop-up-text #route')[0].update('');
					$('popup').setOpacity(0).show();
					$$('#popup .casto-popup-border')[0].setStyle('height:'+this.current.getHeight()+'px;width:'+this.current.getWidth()+'px;');
					$$('.casto-popup-close')[0].hide();
					$('popup').setStyle('top:'+(offsets[1])+'px;left:'+offsets[0]+'px;');
					$$('.casto-popup .pop-up-text')[0].setOpacity(0).show();
					var height = $$('.casto-popup .pop-up-text')[0].getHeight();
					
					//$('popup').hide();
					
					//alert(document.viewport.getHeight());
					startoffset[0] = (document.viewport.getWidth()/2)-450;
					startoffset[1] = (document.viewport.getHeight()/2)-((height-30)/2);
					
					$('popup').appear({duration:0.3}).morph('top:'+(startoffset[1])+'px;left:'+(startoffset[0])+'px;',{duration:1});
					$$('#popup .casto-popup-border')[0].morph('height:'+(height)+'px;width:900px;',{duration:1});
				} else {
					this.showmap('bigmapArea', 15, true);
					var height = $$('.casto-popup .pop-up-text')[0].getHeight();
					startoffset[0] = (document.viewport.getWidth()/2)-450;
					startoffset[1] = (document.viewport.getHeight()/2)-((height-30)/2);
					$$('.casto-popup-close')[0].setStyle('top:'+(startoffset[1]-15)+'px;left:'+(startoffset[0]+900)+'px;').appear({duration:0.3,delay:0});
					$$('#popup .pop-up-text').each(function(ob) {
						ob.show().setOpacity(0).appear({duration:0.3,delay:0});
					});
					////
				}
				
			
		
			
		},
		hide: function() {
			$$('#popup .pop-up-text','.casto-popup-close').each(function(ob) {
				ob.fade({duration:0.2});
			});
			var offsets = this.current.cumulativeOffset();
			var offsetScroll = document.viewport.getScrollOffsets();
			offsets[0]-=offsetScroll[0];
			offsets[1]-=offsetScroll[1];
			$('popup').morph('top:'+offsets[1]+'px;left:'+offsets[0]+'px;',{delay:0.2,duration:0.5}).fade({delay:0.6,duration:0.3});
			$$('#popup .casto-popup-border')[0].morph('height:'+this.current.getHeight()+'px;width:'+this.current.getWidth()+'px;',{delay:0.2,duration:0.5});
			setTimeout('Casto.center_info.active=false;Casto.center_info.current=false;',700);
		},
		googleMap:function(id, lat, long, mapCaption) {
			this.id = id;
			this.lat = lat,
			this.long = long;
			this.mapCaption = mapCaption;
			//this.showmap(id, 13, false);
			//
		},
		
		showmap: function(id, zoom, view) { //alert("here");
			this.mapObj[id] = new GMap2($(id));
			
			this.mapObj[id].setCenter(new GLatLng(this.lat, this.long), zoom);
			
			if(view) {
				this.mapObj[id].setUIToDefault();
				this.mapObj[id].openInfoWindowHtml(new GLatLng(this.lat, this.long), this.mapCaption);
			}
			var point = new GLatLng(this.lat, this.long);
			this.mapObj[id].addOverlay(Casto.center_info.createMarker(point, 1, this.mapCaption));
		},
		createMarker:function(point, number,mapCaption) {
		  var marker = new GMarker(point);
		  marker.value = number;
		  GEvent.addListener(marker, "click", function() {
			if(Casto.center_info.active) 
				Casto.center_info.mapObj['bigmapArea'].openInfoWindowHtml(point, mapCaption);
			else
				Casto.center_info.mapObj[Casto.center_info.id].openInfoWindowHtml(point, mapCaption);
		  });
		  return marker;
		},
		getDirections: function() {
			var start = $('start').value; 
			if(!this.directions) {
				directionsPanel = document.getElementById("route");
				this.directions = new GDirections(this.mapObj['bigmapArea'], directionsPanel);
			}
			this.directions.load("from: "+start+" to: "+this.lat+","+this.long, {travelMode:G_TRAVEL_MODE_DRIVING});
		}
		
	};
Casto.center_info.image={
		active:false,
		current:false,
		loader:true,
		data_html:'',
		mapObj:new Array(),
		init:function(obj, imgPath,width,height) {
			if(this.active) return;
			if(Casto.center_info.current) Casto.center_info.hide();
			if(this.current) {
				this.hide();
				setTimeout(function() { Casto.center_info.image.current = $(obj); Casto.center_info.image.show(imgPath,width,height); },800);
				
			} else {
				this.current = $(obj);
				this.active=true;
				this.show(imgPath,width,height);
			}
			
		},
		show: function(imgPath,width,height) {
				this.active=true;
				var offsets = this.current.cumulativeOffset();
				var offsetScroll = document.viewport.getScrollOffsets();
				offsets[0]-=offsetScroll[0];
				offsets[1]-=offsetScroll[1];
				var startoffset=new Array();
				
				$$('.casto-popup-image #bigmapArea')[0].update('<img src="'+this.current.down('img').readAttribute('src')+'" />');
				
				$('popup-image').show();
				$$('#popup-image .casto-popup-border')[0].setStyle('height:100px;width:150px;');
				$$('.casto-img-popup-close')[0].hide();
				$('popup-image').setStyle('top:'+(offsets[1])+'px;left:'+(offsets[0])+'px;');
					
				
				startoffset[0] = (document.viewport.getWidth()/2)-(width/2);
				startoffset[1] = (document.viewport.getHeight()/2)-((height-30)/2);
				
				$('popup-image').morph('top:'+(startoffset[1])+'px;left:'+(startoffset[0])+'px;',{duration:1});
				
				var startheight = (100 - this.current.down('img').getHeight())/2;
				var startwidth = (150 - this.current.down('img').getWidth())/2;
				
				//alert('top:'+(startoffset[1]-15)+'px;left:'+(startoffset[0]+parseInt(width))+'px;');
				$$('.casto-img-popup-close')[0].setStyle('top:'+(startoffset[1]-15)+'px;left:'+(startoffset[0]+parseInt(width))+'px;').appear({duration:0.3,delay:1});
				
				$$('#popup-image .casto-popup-border')[0].morph('height:'+height+'px;width:'+width+'px;',{duration:1});
				//alert('height:'+this.current.down('img').getHeight()+'px;width:'+this.current.down('img').getWidth()+'px;margin-left:'+startwidth+'px;margin-top:'+startheight+'px;');
				$$('.casto-popup-image #bigmapArea img')[0].setStyle('height:'+this.current.down('img').getHeight()+'px;width:'+this.current.down('img').getWidth()+'px;margin-left:'+startwidth+'px;margin-top:'+startheight+'px;').morph('height:'+(height)+'px;width:'+width+'px;margin-left:0px;margin-top:0px;',{duration:1});
				var newImage = new Image();
				newImage.onload = function() {
					$$('.casto-popup-image #bigmapArea img')[0].src = this.src;
				}
				newImage.src = imgPath;
				this.current.setOpacity(0);
				setTimeout('Casto.center_info.image.active=false;',1000);
		},
		hide: function() {
			$$('.casto-img-popup-close').each(function(ob) {
				ob.fade({duration:0.2});
			});
			var offsets = this.current.cumulativeOffset();
			var offsetScroll = document.viewport.getScrollOffsets();
			offsets[0]-=offsetScroll[0];
			offsets[1]-=offsetScroll[1];
			$('popup-image').morph('top:'+offsets[1]+'px;left:'+offsets[0]+'px;',{duration:0.5,delay:0.2});
			$$('#popup-image .casto-popup-border')[0].morph('height:100px;width:150px;',{duration:0.5,delay:0.2});
			
			var startheight = (100 - this.current.down('img').getHeight())/2;
			var startwidth = (150 - this.current.down('img').getWidth())/2;
			
			$$('#popup-image #bigmapArea img')[0].morph('height:'+this.current.down('img').getHeight()+'px;width:'+this.current.down('img').getWidth()+'px;margin-left:'+startwidth+'px;margin-top:'+startheight+'px;',{duration:0.5,delay:0.2});
			this.active=true;
			setTimeout('$("popup-image").hide();Casto.center_info.image.current.setOpacity(1);Casto.center_info.image.active=false;Casto.center_info.image.current=false;',700);
		}
	};
