/******************************/
/*  Functions for Off The Kerb  */
/*     Hazlitt Eastman        */
/******************************/

/* preload images jQuery function extension */
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

/* Google Map */
/* create map marker */
function map_marker(otk_latitide, otk_longitude, otk_title) {
	var myLatlng = new google.maps.LatLng(otk_latitide, otk_longitude);
	var marker = new google.maps.Marker({
	      position: myLatlng, 
	      map: map, 
	      title: otk_title,
		  icon: otk_icon
	});
}

/* reposition the center of the map and display info window */
function map_change(otk_latitide, otk_longitude, otk_content) {
	var club = new google.maps.LatLng(otk_latitide, otk_longitude);
	map.panTo(club);
		
	/* var infowindow = new google.maps.InfoWindow({ */
	infowindow.setOptions ({
	    content: otk_content,
		position: club
	});
	
	infowindow.open(map);
}

/* code for pasting into address bar when veiwing a googlemap to obtain the lat / long */
/* javascript:void(prompt('',gApplication.getMap().getCenter())); */

/**** Dom ready functions ****/

$(document).ready(function() {
	
	/* set the status of the elements */
	$('#header_artists_list').hide();
	$('#footer_artists_list').hide();
	$('#header_advert_1').css('visibility', 'visible');
	$('#header_advert_2').css('visibility', 'visible');
	$('#header_advert_3').css('visibility', 'visible');
	$('.header_head').css('visibility', 'visible');
	$('#telly img').css('visibility', 'visible');
	
	/* correct layout  differences */
	if ($.browser.mozilla) {
		$("#footer_artists_list").css('margin-top', '-378px');
	}
	
	/* Header Image Cycling */
	$('#header_advert_1').cycle({fx: 'fade', timeout:8000, speed:1000});
	$('#header_advert_1 img').click(function (){
	    	link = $(this).attr('rel');
			window.open(link);
		}).css('cursor', 'pointer');
		
	$('#header_advert_2').cycle({fx:'fade', timeout:8000, speed:1000});
	$('#header_advert_2 img').click(function (){
    		link = $(this).attr('rel');
			window.open(link);
		}).css('cursor', 'pointer');
	
	$('#header_advert_3').cycle({fx:'fade', timeout:8000, speed:1000});
	$('#header_advert_3 img').click(function (){
	    	link = $(this).attr('rel');
			window.open(link);
		}).css('cursor', 'pointer');
		
	$('.header_head').cycle({fx: 'fade', timeout:11000, speed:1000});
	
	/* Telly Image Cycling */
	$('#telly').cycle({fx: 'fade', timeout:9500, speed:700});
	$('#telly img').click(function (){
	    	link = $(this).attr('rel');
			window.open(link);
		}).css('cursor', 'pointer');
	
	/* Footer Image Cycling */
	$('#footer_advert_1').cycle({fx: 'fade', timeout:8000, speed:1000});
	$('#footer_advert_1 img').click(function (){
	    	link = $(this).attr('rel');
			window.open(link);
		}).css('cursor', 'pointer');
		
	$('#footer_advert_2').cycle({fx: 'fade', timeout:8000, speed:1000});
	$('#footer_advert_2 img').click(function (){
	    	link = $(this).attr('rel');
			window.open(link);
		}).css('cursor', 'pointer');
	
	$('#footer_advert_3').cycle({fx: 'fade', timeout:8000, speed:1000});
	$('#footer_advert_3 img').click(function (){
	    	link = $(this).attr('rel');
			window.open(link);
		}).css('cursor', 'pointer');	

	/* Featured Gigs Cycling */
	$('#gig_list').cycle({fx: 'fade', timeout:7000, speed:1000});
	
	/* Clear search field */
	$('#s').click(function() {
			$(this).attr('value', '');
		});
		
	/* Artists names rollovers */
	$('ul#greater_artists li').mouseover(function() {
		$(this).addClass('over');
		$(this).children('a').css('color', '#ffffff');
	});
	
	$('ul#greater_artists li').mouseout(function() {
		$(this).removeClass('over');
		$(this).children('a').css('color', '#53707d');
	});
	
	$('ul#lesser_artists li').mouseover(function() {
		$(this).addClass('over');
		$(this).children('a').css('color', '#ffffff');
	});
	
	$('ul#lesser_artists li').mouseout(function() {
		$(this).removeClass('over');
		$(this).children('a').css('color', '#53707d');
	});
	
	/* Display artists header nav */
	$('li.trigger').mouseover(function() {
		$(this).children('div').show();
	});
	$('li.trigger').mouseout(function() {
		$(this).children('div').hide();
	});
});
