$(document).ready(function() {
  
  // Preload
  $.preloadImages("/coconetclassic/images/ticket-mini-hover.png");
  
  // Sign up forms
  $('#sport_terms').hide();
  
  $('#sport_selectors a').click(function() {
    $('#sport_selectors a').each(function(index) {
      $(this).removeClass()
    });    
    $(this).addClass('current');
    $('#sport_target').load($(this).attr('href'));
    $('#sport_terms').show();
    return false;
  });
  
  // Pay
  
  $(function() {
    $(".paybox select").mouseover(function(){
      $(this)
        .data("origWidth", $(this).css("width"))
        .css("width", "auto");
      })
    .mouseout(function(){
      $(this).css("width", $(this).data("origWidth"));
    });
  });

  // Facebox
  
  $('a[rel*=facebox]').facebox() 
	
	// Flash
	
  $('#flash').flash({
   src: '/coconetclassic/images/logo.swf',
   width: 900,
   height: 180,
      wmode: 'transparent'
    }, {
       update: false
  });
	
	// Hover fading
	
	fadees = $("a.fadee, #menu li:not(.current_page_parent, .current_page_item) a, .tickets li.page-item-529:not(.current_page_item) a");
	
	fadees.css('opacity', 0.5);
	
	fadees.hover(function() {
		$(this).fadeTo(400, 1);
	}, function() {
		$(this).fadeTo(1000, 0.5);
	});
	
	fadees.focus(function() {
		$(this).fadeTo(400, 1) });
	fadees.blur(function() {
		$(this).fadeTo(400, 0.5) });
	
	// Competitions submenu	slider

	navComps = $("#menu .page-item-9:not(.current_page_parent, .current_page_item) > ul");

	navComps.hide();

	// Hover over Competitions

	$("#menu .page-item-9:not(.current_page_parent, .current_page_item)").hover(function() {
		$("#menu .page-item-9 > ul").slideDown(500);
	}, function() {} );
	
	// Hover away from Menu
	
  $("#menu .page-item-9:not(.current_page_parent, .current_page_item)").parent().parent().parent().hover(function() {},
  function() {
    // $("#menu .page-item-9 > ul").slideUp(500);
  });
	
	// Cycle
	
	$('#polaroid #pics').cycle({ 
    fx:     'scrollLeft',
	 	easing: 'easeOutElastic',
		random: 1,
		speed: 2000,
		timeout: 6000
	});
	
	$('#tagline').css('z-index',100);
	
  // Search

  $('#s').example(function() {
    return $(this).attr('title');
  }, {className: 'example'});

  $('#subscribe2 .email').val('');

  $('#subscribe2 .email').example(function() {
    return 'your@email.com ';
  }, {className: 'example'});

  // Override Google Toolbar
  
  $('input, select').bind('propertychange', function(event) {
    event.css('background-color', 'none')
  });

	
	// Map
	
  map = new GMap2(document.getElementById("accommodation_map"));
  map.setCenter(new GLatLng(-24.0, 151.355209), 9);
  
  for (i=0; i<pointTitle.length; i++)  {
    var marker = createMarker(i, new GPoint(pointLon[i],pointLat[i]), pointTitle[i]);
   map.addOverlay(marker);
  }
  map.addControl(new GSmallMapControl());
  map.addControl(new GMapTypeControl());
});

// Map

var map;
var pointTitle = [];
var pointLat = [];
var pointLon = [];
var pointAnchor = [];
var pointIcon = [];


pointTitle[0]= 'Music Fesival';
pointIcon[0]= 'event';
pointLat[0]= -23.962813;
pointLon[0]= 151.333537;

pointTitle[2]= 'Kiteboarding & Family Day';
pointIcon[2]= 'event';
pointLat[2]= -23.94692;
pointLon[2]= 151.374661;

pointTitle[1]= 'BMX, Skate, Scooters';
pointIcon[1]= 'event';
pointLat[1]= -23.941956;
pointLon[1]= 151.353369;

// pointTitle[3]= 'Boyne Island, Tannum Sands';
// pointAnchor[3]= '#boyne';
// pointLat[3]= -23.947665;
// pointLon[3]= 151.355209;

pointTitle[3]= 'Gladstone';
pointAnchor[3]= '#gladstone';
pointLat[3]= -23.842117;
pointLon[3]= 151.251054;

pointTitle[4] = 'Benaraby';
pointAnchor[4]= '#benaraby';
pointLat[4] = -24;
pointLon[4] = 151.305209;

pointTitle[5]= 'Calliope';
pointAnchor[5]= '#calliope';
pointLat[5]= -24.006953;
pointLon[5]= 151.206894;

pointTitle[6]= 'Bororen';
pointAnchor[6]= '#bororen';
pointLat[6]= -24.241017;
pointLon[6]= 151.495972;

var baseIcon = new GIcon();
  baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
  baseIcon.iconSize = new GSize(20, 34);
  baseIcon.shadowSize = new GSize(37, 34);
  baseIcon.iconAnchor = new GPoint(9, 34);
  baseIcon.infoWindowAnchor = new GPoint(9, 2);
  baseIcon.infoShadowAnchor = new GPoint(18, 25);

function createMarker(i, point, html) {
	var marker;
	var color;
	var pointIcon = new GIcon(baseIcon);
	var letter = String.fromCharCode("A".charCodeAt(0) + i);
	if (i <= 2)
	  color = "yellow";
	else
	  color = "red";
	pointIcon.image = "/coconetclassic/images/map_markers/" + color + "_Marker" + letter + ".png";
	markerOptions = { icon:pointIcon, title:pointTitle[i] };
  marker = new GMarker(point, markerOptions);
  GEvent.addListener(marker, "click", function() {
    if (pointAnchor[i].length > 0) {
      window.location = pointAnchor[i];
      marker.setCursor("pointer");
    }
  });

	return marker;
}