
fn = {}

fn.message = function(str, cla)
{	$message = $('#message');
	if(!cla) cla = 'default';
	$message.hide();	
	$message.html('<div class="message"><div class="'+cla+'">'+str+'</div></div>');
	$message.fadeIn();
	setTimeout('$message.fadeOut();', '8000');
}

fn.check_form = function(elem, mem)
{
	var elem_id = $(elem).attr('id');
	var errors = "";
	$("form[id='"+$(elem).attr('id')+"'] input[accept='true'], form[id='"+$(elem).attr('id')+"'] textarea[accept='true']").each(function(){
		$(this).removeClass('error');
		var mask = $(this).attr('mask');
		
		switch(mask)
		{
		case "email":
			if(!fn.is_email($(this).val())) 
			{
				errors += $(this).attr('alt')+"\n";
				$(this).addClass('error');
				$(this).focus(function(){$(this).removeClass('error');});
			}	
		break; 
		default:
			if($(this).val().length < 1) 
			{
				errors += $(this).attr('alt')+" \n";
				$(this).addClass('error');
				$(this).focus(function(){$(this).removeClass('error');});
			}	
		break;
		}
		
	});
	
	
	if(errors.length < 1) return true;
	var str = "Please amend the following before continuing:\n"+errors;
	if(mem) fn.mem('<div class="error">'+str+'</div>');
	else alert(str);
	
	return false;
}

fn.is_email = function(email)
{
	//var email = email.value;
	//var email = document.forms[target].elements[field].value;
	var atSym = email.indexOf('@');
	var dot = email.lastIndexOf('.');
	var space = email.indexOf(' ');
	var len = email.length;
	if (atSym < 1 || dot < atSym || len - dot <= 2 || space != -1) {
		return false;
	}
	else { 
		return true; 
	}
}

jQuery.fn.extend({
	tabs : function(clk)
	{
		var group = "#"+this.attr('id');
		$(group+" div.tab").hide();
		$(group+" div.tabs>h1>a").click(function(){
			$(group+" div.tabs>h1>a").removeClass('active');
			var href = $(this).attr('href');	
			$('a[href="'+href+'"]').addClass('active');
			$(group+" div.tab").hide();
			$(group+" div#"+href).show();
			return false;
		});
		if(clk) $(group+" div.tabs>h1>a[href='"+clk+"']").click();
		else $(group+" div.tabs>h1>a:first").click();
		return $(this);
	}
	,
	checkboxes : function()
	{
		var parent = "#"+this.attr('id');
		$(parent+' a[class="checkbox"]').each(function(){
		$(this).click(function(){
			var elem_id = '#'+$(this).attr('title');
			if($(elem_id).attr('checked')) $(elem_id).attr('checked', false);
			else $(elem_id).attr('checked', true);
			return false;
		});
		});	
		return $(this);
	}
	,
	buttons : function()
	{
		var parent = "#"+this.attr('id');
		$(parent+' a[class="button"], a[class="button-small"]').each(function(){
		$(this).prepend('<img src="'+fn.ext+fn.media+'icons/'+$(this).attr('title')+'.png" /> ');	
		if($(this).attr('href').length < 2) { $(this).click(function(){ return false; }); $(this).css('cursor', 'default'); }	
		});	
		return this;
	}
	,
	radios : function()
	{
		var parent = "#"+this.attr('id');
		$(parent+' a[class="radio"]').each(function(){
		$(this).click(function(){
			var elem_id = '#'+$(this).attr('title');
			if($(elem_id).attr('checked')) $(elem_id).attr('checked', false);
			else $(elem_id).attr('checked', true);
			return false;
		});
		});	
		return $(this);
	}	
});

$(document).ready(function(){

	//$('div#container').buttons();
});

function initialize() {
    var latlng = new google.maps.LatLng(53.76809437901597, -1.064300537109375);
    var myOptions = {
      zoom: 12,
	  pushpin: true,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	
	var contentString = '<div id="map_content"><h3>Selby Livestock Auction Mart</h3></div>';

var infowindow = new google.maps.InfoWindow({
    content: contentString
});

	
	  var marker = new google.maps.Marker({
      position: latlng, 
      map: map, 
      title:"Selby Livestock Auction Mart"
  });
  
  google.maps.event.addListener(marker, 'click', function() {
  infowindow.open(map,marker);
});

}
