var a_elements=new Array();
var a_slide_time=8;
var a_counter;

$(document).ready(function() {
 
	$(window).resize(function() {
	 realign_style_elements();
	});

	
	realign_style_elements();
	
	


	
	//default value field
	$("[ftype=def_value]").each( function(index) {
		$(this).bind("focusin", function() {
			clear_field($(this).get(0));
		});
		
		$(this).bind("focusout", function() {
			restore_field($(this).get(0));
		});		
	});
	
	
	
});



function realign_style_elements(){
	if ($("#google_map").length!=0){
		map_initialize("google_map");
		map_change_type(a_map_type);
		map_set_zoom(a_map_zoom);
		map_set_center(a_coord_x,a_coord_y);
		map_add_marker(a_coord_x,a_coord_y,a_map_marker_text);
	}
}

//map utils
var map;

function map_initialize(container_id) {
var latlng = new google.maps.LatLng(0,0);
var myOptions = {
	zoom: 2,
	mapTypeControl: false,
	center: latlng,
	mapTypeId: google.maps.MapTypeId.ROADMAP,
	
    navigationControl: true,
    navigationControlOptions: {
        style: google.maps.NavigationControlStyle.ZOOM_PAN,
        position: google.maps.ControlPosition.TOP_RIGHT
		},
    scaleControl: true,
    scaleControlOptions: {
        position: google.maps.ControlPosition.TOP_LEFT
		}

	};

map = new google.maps.Map(document.getElementById(container_id), myOptions);
  
}


function map_set_center(coordx,coordy) {
map.setCenter(new google.maps.LatLng(coordx, coordy),map.getZoom(),google.maps.MapTypeId.SATELLITE);
}

function map_set_zoom(zoom_level) {
map.setZoom(parseInt(zoom_level)); 
}

function map_change_type(map_type){
map.setMapTypeId(map_type);
} 

function map_add_marker(coordx,coordy,text) {
var marker = new google.maps.Marker({
 position: new google.maps.LatLng(coordx,coordy)  
});  
 
var infowindow = new google.maps.InfoWindow({
    content:text
});

 
marker.setMap(map); 
if (text!="") infowindow.open(map,marker);

}





//jquery effects
function visual_effect(action,id)
{
	if (action=="fadeout")	$('#'+id).fadeOut('slow', function() { }); 
	if (action=="fadein")	$('#'+id).fadeIn('slow', function() { }); 
	if (action=="hide")	$('#'+id).hide('slow', function() { }); 
	if (action=="fasthide")	$('#'+id).hide('fast', function() { }); 
	if (action=="show")	$('#'+id).show('slow', function() { }); 
	if (action=="slidetoggle")	$('#'+id).slideToggle('slow', function() { }); 
	if (action=="slideup")	$('#'+id).slideUp('slow', function() { }); 
	if (action=="slidedown")	$('#'+id).slideDown('slow', function() { }); 
}



function clear_field(e)
{
var i=-1;
//check if element is already added
for (var a=0;a<a_elements.length;a++)
	{
	if (a_elements[a][0]==e.name)
		{
		i=a;
		break;
		}
	}

//add new element
if (i==-1)
	{
	var a_item=new Array(3);
	a_item[0]=e.name;
	a_item[1]=e.value;
	a_item[2]=1;
	e.value="";
	a_elements.push(a_item);
	} else
	{
	if (a_elements[i][2]==0)
		{
		if (e.value==a_elements[i][1])
			{
			e.value="";
			}
		a_elements[i][2]==1;
		}
	}

}

function restore_field(e)
{
//restore default value if element value is empty
if (e.value=="")
	{
	var i=-1;
	for (var a=0;a<a_elements.length;a++)
		{
		if (a_elements[a][0]==e.name)
			{
			i=a;
			break;
			}
		}
	if (i>-1)
		{
		e.value=a_elements[i][1];
		a_elements[i][2]=0;
		}
	
	}
	
}

