$$('html')[0].className += ' json';



var pingalaCMS = {
		
	load : function() {
		pingalaCMS.openWindow();
		pingalaCMS.printWindow();
		pingalaCMS.formStyle(); 
	},
	
	openWindow : function(){
		
		$$('.openWindow').each(function(node) {
			node.onclick = function() {
				pageTracker._trackEvent('Outbound Links', this.href); //google track out links
				window.open(this.href); return false;
			};
		});
	},
	
	printWindow : function(){
		$$('.printWindow').each(function(node) { node.onclick = function() {window.print()}; });
	},
	
	formStyle : function(){
		
		$$('.textform').each(function(node) {
			
			Event.observe(node, 'focus', 
				function(e){ 
				thisVal = node.value
					if(Event.element(e).nodeName != 'SELECT'){
						Event.element(e).className="textformfocus";
						if (Event.element(e).value.charAt(0) == '-') { Event.element(e).value='' }
					}
					}
				);

			Event.observe(node, 'blur', 
				function(e){ 
					if (this.value == '' && thisVal.charAt(0) == '-') {this.value= thisVal}
					Event.element(e).className="textform";
					}
				);
		});
	}
	
}


var pingalaWeb = {
	
	liLinks : function() {
		
		$A($$('#qlinks>li')).each(function(node) {
				node.className += ' hand';
				node.onclick=function() { window.location = node.getElementsByTagName('A')[0].href }	
		})
	},
	
	
	googleMap : function() {
		
		var mapStyles = [
		{
		  featureType: "all",
			  stylers: [
			  { invert_lightness: true },
			  { saturation: 25 },
			  { hue: "#ff9100" }
			]
			}
		  ];
		
		var mapStylesType = new google.maps.StyledMapType(mapStyles, {name: "MapCSS"});
		
		var myLatlng = new google.maps.LatLng(51.398891,0.497925);
		var myOptions = {
			zoom: 15,
			center: myLatlng,
			backgroundColor: '#262827',
			navigationControl: true,
			mapTypeControl: false,
			scaleControl: false,
			keyboardShortcuts: false,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		}
		var map = new google.maps.Map($("gmap"), myOptions);
		
		map.mapTypes.set('MapCSS', mapStylesType);
		map.setMapTypeId('MapCSS');
		
		var marker = new google.maps.Marker({
			position: myLatlng, 
			map: map,
			title:"We are here"
		});	
		
	
	}
	
}


var pingalaAjax = {
			
	makeRequest : function(url,getID) { 
			
		new Ajax.Request(url, {
			method: 'post',
			//parameters: 'ajax=2',
			onSuccess: function(originalRequest){$(getID).innerHTML = originalRequest.responseText;}
		});
	
	},
	
	submitForm : function(pageUrl) {
		
		$('waiting').innerHTML = '<img src="/_img/layup/loading.gif" />'
		$('submitButton').type == 'button'; 
		$('submitButton').disabled = 'disabled'; 
			
		if(pageUrl) {pageLocation = pageUrl} else {pageLocation = window.location.href}
		
		waitPadd = (Element.getDimensions($('cmsForm')).height - 48)  /2
		$('waiting').style.paddingTop =  waitPadd + "px"
		$('waiting').style.paddingBottom =  waitPadd + "px"
		
		 new Effect.Morph('cmsForm', { 
		  style:  'opacity: 0;', 
		  duration: 0.2,
		  afterFinish: function(){
			  	Element.show('waiting'); 
				new Ajax.Request(pageLocation, {
					method: 'post',
					parameters: 'ajax=1&' + Form.serialize("cmsForm"),
					onSuccess: pingalaAjax.showResponse
				});
			
			 }
		 }); 

			
	},

	showResponse : function(originalRequest) {
			
			if(originalRequest.responseText.substring(0,4) == 'http') {
				window.location = originalRequest.responseText; 
			  } else {
			
				$('cmsForm').innerHTML = originalRequest.responseText; 
					Effect.Fade('waiting'); 
					new Effect.Morph('cmsForm', { 
					  style:  'opacity: 1;', 
					  duration: 0.9,
					  afterFinish: function(){
							if($('submitButton')){new Effect.Shake('submitButton')}
							pingalaCMS.load(); 
							Effect.ScrollTo('contents');
						 }
					 }); 
				
  			}

	}
	
}


Event.observe(window, 'load', pingalaCMS.load, false);
