function e(id){
     return document.getElementById(id);
}

function onRollOver(obj_img){	
	obj_img.src = obj_img.src.split("-off").join("-on");
}

function onRollOut(obj_img){
	obj_img.src = obj_img.src.split("-on").join("-off");
}

function launchPrintPopup(anchor_obj,width,height) {
	if (width == null){
		width = 700;
	}
	if (height == null){
		height = 700;
	}
	 var new_win = window.open(anchor_obj.href,'popup','resizable=yes,scrollbars=yes,width='+width+',height='+height+',left='+String((screen.width-width)/2)+',top='+ String((screen.height-height)/2) );
	 if (new_win ) {
		 new_win .focus();
		 return false;
	 } else {
		return true;
	 }
	 
}

function onRollOver(obj_img){
	obj_img.src = obj_img.src.split("-off").join("-on");
}

function onRollOut(obj_img){
	obj_img.src = obj_img.src.split("-on").join("-off");
}


/*--------------- HOMEPAGE BOX ROLLOVERS -------------*/

function enableLink(section) {
	if (document.getElementById(section + '-over')) {
		document.getElementById(section + '-over').className='hero-box-on';
	}
	
	if (document.getElementById(section + '-title')) {
		document.getElementById(section + '-title').src = 'images/ttl-' + section + '-on.gif';
	}
	
	if (document.getElementById(section + '-text-title')) {
		document.getElementById(section + '-text-title').className='new-article-title-on';	
	}
}

function disableLink(section) {
	if (document.getElementById(section + '-over')) {
		document.getElementById(section + '-over').className='hero-box-off';
	}
	
	if (document.getElementById(section + '-title')) {
		document.getElementById(section + '-title').src = 'images/ttl-' + section + '-off.gif';
	}
	
	if (document.getElementById(section + '-text-title')) {
		document.getElementById(section + '-text-title').className='new-article-title-off';	
	}
}



/*----------------------- GOOGLE MAP CODE ---------------------*/

var geocoder;
var map;
var infoWindow;

closeInfoWindow = function() {
	infoWindow.close();
};

openInfoWindow = function(obj_marker) { 
	var markerLatLng = obj_marker.getPosition();
 
	//Get the title which will be the id number
	var int_marker_num = Number(obj_marker.title);
	if (objData[int_marker_num]["street_suburb"].length > 0) {
		var str_suburb_or_city = objData[int_marker_num]["street_suburb"];	
	} else {
		var str_suburb_or_city = objData[int_marker_num]["street_city"];		
	}
	
	var str_data = '<h1 style="color: red; font-weight: bold;">'+objData[int_marker_num]["company"]+'</h1>';
	
	if (objData[int_marker_num]["street_address"].length > 0) {
		str_data += objData[int_marker_num]["street_address"]+' '+str_suburb_or_city+'<br>';
		str_data += objData[int_marker_num]["street_state"]+' ' + objData[int_marker_num]["street_postcode"]+'<br>';
	}
	
	if (objData[int_marker_num]["phone"].length > 0) { str_data += 'ph: '+objData[int_marker_num]["phone"]+'<br>'; }
	if (objData[int_marker_num]["mobile"].length > 0) { str_data += 'mobile: '+objData[int_marker_num]["mobile"]+'<br>'; }
	if (objData[int_marker_num]["fax"].length > 0) {str_data += 'fax: '+objData[int_marker_num]["fax"]+'<br>'; }
	if (objData[int_marker_num]["email"].length > 0) {str_data += 'email: '+objData[int_marker_num]["email"]+'<br>'; }
	
	infoWindow.setContent(str_data);
	infoWindow.open(map, obj_marker);
}

function initialize() {
	if (int_override_zoom > 0) {
		var zoom_level = int_override_zoom;	
	} else {
		var zoom_level = 10;		
	}

	var latlng = new google.maps.LatLng(28.129031,136.659232);
	var myOptions = {
		zoom: zoom_level,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		backgroundColor: "#FFFFFF"
	}
	map = new google.maps.Map(document.getElementById("google-map"), myOptions);
	
	plotPoints();	
	
	infoWindow = new google.maps.InfoWindow();
	google.maps.event.addListener(map, 'click', closeInfoWindow);
}

function resetMap() {
	//alert("resetting map");
	google.maps.event.trigger(map, 'resize');
	map.setZoom( map.getZoom() - 1 );
	 map.setZoom( map.getZoom() + 1 );
}
var int_total_map_count = 0;
var int_test_count = 0;
var int_marker_count = 0;

function plotPoints() {
	var bounds = new google.maps.LatLngBounds( );
	var previous_marker = null;
  
	for (i = 0; i < arr_needed_map_data.length; i++) {
		
		if (objData[arr_needed_map_data[i]]) {
		
			var obj = objData[arr_needed_map_data[i]];
			var myLatLng = new google.maps.LatLng(obj['latitude'],obj['longitude']);
			var marker = new google.maps.Marker({
				map: map, 
				position: myLatLng,
				title:String( obj['id'])
			}); 
	
			//Don't enable click if it's the popover due to bugs in IE
			if (document.getElementById("google-map-container").className == "gm_embedded") {
				google.maps.event.addListener(marker, 'click', function () { 
				openInfoWindow(this);
				});
			} 
			
			if (int_override_zoom == 0) {
				bounds.extend( myLatLng  );
				map.fitBounds( bounds );
			} else {
				map.setCenter(myLatLng);
				map.setZoom(int_override_zoom);	
			}
		}
	}
} 

/*=================================== Subscribe panel ================================*/


//Create reused cookie functions and add them to jquery
$.extend({
	createCookie:function(name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
		}
	 }
);

$.extend({
	readCookie:function(name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null; 
	 }
});

function eraseCookie(name) {
	jQuery.createCookie(name, "", -1);
}

//Switch this on to enable the panel to only show once.
var bln_enable_cookies = true;
var bln_show_panel = false;
var bln_dont_animate = true;
/*------------------------------------------*/

function fadeInMap() {
	resetMap();	
}

function showMapsPanel() {
	if (!bln_dont_animate) {
		jQuery('#google-map-container').animate({ 'height' : '460px' });
	}
	else {
		jQuery('#google-map-container').css({ 'height' : '460px' });
	}
	jQuery('#btn-region-map .off').hide();
	jQuery('#btn-region-map .on').show();
	
	
	
	
	eraseCookie('hidemaps');
}

function hideMapsPanel() {
	jQuery('#google-map-container').animate({ 'height' : '1px' });
	jQuery('#btn-region-map .off').show();
	jQuery('#btn-region-map .on').hide();
	
	if (bln_enable_cookies) { jQuery.createCookie('hidemaps', true, 1); }
	

}


jQuery(document).ready(function() {
	jQuery('#close-map-view').click(function() {
		hideMapsPanel();
	});
	jQuery('#open-map-view').click(function() {
		bln_dont_animate = false;
		showMapsPanel();
	});
	
	
	if  (jQuery.readCookie('hidemaps') == null) {
		bln_show_panel = true;
	}
	
	if (bln_show_panel) {
		showMapsPanel();
	}
	else {
		hideMapsPanel();
		jQuery('#btn-region-map .off').show();
		jQuery('#btn-region-map .on').hide();
	}
});