function loadMap() {
	if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(53.41111787426619, -2.9752349853515625), 13);
        map.setUIToDefault();
        
        // Create our "tiny" marker icon
		/*var blueIcon = new GIcon(G_DEFAULT_ICON);
		blueIcon.iconSize = new GSize(112, 41);
		blueIcon.image = "http://www.theavenuemanchester.com/img/theavenue_icon.png";
                
		// Set up our GMarkerOptions object
		markerOptions = { icon:blueIcon };
		var point = new GLatLng(53.48026965283557, -2.250287532806396);
		map.addOverlay(new GMarker(point, markerOptions)); */
	}
}

function setupSubmenus() {
	$('#main_menu li').hover(
		function() {
			$(this).children('.sub-menu').css('display', 'block');
		},
		function() {
			$(this).children('.sub-menu').css('display', 'none');
		}
	);
	
	$('.sub-menu').hover(
		function() {
			$(this).css('display', 'block');
		},
		function() {
			$(this).css('display', 'none');
		}
	);
}

function loadTwitter() {
	$("#tweets").jCarouselLite({
		vertical: true,
		hoverPause:true,
		visible: 3,
		scroll: 1,
		auto:2800,
		speed:1000,
		wrap: 'last'
	});
};

var oldFeatureID = 'p1';
function loadFeature() {
	
	$('#F_footer').jCarouselLite({
		vertical: false, //orientation of the carousel, in this case we use vertical
		scroll: 1, //the number of items to scroll by
		visible:3,
		auto: 5000, //the interval of scrolling
		speed:1200,
		wrap: 'last', //wrap at last item and jump back to the start
		beforeStart: removeOld,
		afterEnd: showNew
	});
	
	$('div#F_container .featureImg').first().fadeIn('slow', function() {
							$(this).addClass('active');
										});
										
	$('div#F_footer li').click(function () {  
		$('div#F_container #' + oldFeatureID).fadeOut('slow', function() {
								$('div#F_container #' + oldFeatureID).removeClass('active');
																});
		var currID = $(this).find('a').attr('rel');
		oldFeatureID = currID;
	
		var currImg = $('div#F_container #' + currID);
	
		$(currImg).fadeIn('slow', function() {
							$(this).addClass('active');
										});
	});
}


function removeOld(a) {
	var currID = $(a).find('a').attr('rel');
	oldFeatureID = currID;
	$('div#F_footer li .F_footer_item').removeClass('active');
}


function showNew(a) {
	
	//fade old out
	$('div#F_container #' + oldFeatureID).fadeOut('slow', function() {
								$('div#F_container #' + oldFeatureID).removeClass('active');
																});
																
	var currID = $(a).find('a').attr('rel');
	var currImg = $('div#F_container #' + currID);
	
	$(currImg).fadeIn('slow', function() {
							$(this).addClass('active');
										});
	$('div#F_footer #' + currID).addClass('active'); 
        
	//Cufon.refresh('.feature_item_title');
};


function changeFont(size) {
	
	// Increase Font Size
  var currentFontSize = $('#main_menu').css('font-size');
  var currentFontSizeNum = parseFloat(currentFontSize, 10);
  var newFontSize;
  
  if(size == 'bigger') {
  	newFontSize = currentFontSizeNum*1.2;
  } else {
  	newFontSize = currentFontSizeNum*0.8;
  }
  
  $('#main_menu').css('font-size', newFontSize);
  Cufon.refresh('#main_menu');
}


function setSidebarFeature(id, next) {
	$(id).jCarouselLite({
		vertical: false, //orientation of the carousel, in this case we use vertical
		scroll: 1, //the number of items to scroll by
		visible:1,
		hoverPause:false,
		auto: null, //the interval of scrolling
		speed:600,
		btnNext: next,
		wrap: 'last',
		beforeStart: hideOldSnippet,
		afterEnd: showNewSnippet
	});
}

function hideOldSnippet(a) {
	var currID = $('li.' + 'desc_' + $(a).attr('rel'));
	currID.parent().find('li').removeClass('active');
}

function showNewSnippet(a) {
	var currID = $('li.' + 'desc_' + $(a).attr('rel'));
	currID.addClass('active');
}


function setupThumbnails() {
	$('.snippet_over').slideToggle(0);
	$('.gallery_thumb').hover(function() {
			$(this).find('.snippet_over').slideToggle('fast');
	});
	
	$('.gallery_thumb').click(function() {
    	window.location = $(this).attr("url");
	});

}


function setupLargeGallery () {
	//@ id of div where the loading informations visible
	var _loadDivId = 'imageDetails';
	//@ id of the ul container
	var _imgContainerId = 'largeGallery_UL';
	//@ style of li loading (spinner image)
	var _imageLoadClassName = 'loading';
	//@ grab the images
	var images = $('ul#'+_imgContainerId+' li img');
	//@ image length
	var max = images.length;
	
	var galIndex = 0;
	//@ remove them from DOM to prevent normal load
	$('ul#'+_imgContainerId+' li').remove();
	//@ loading div object
	var loadDiv = null;
	//@ start loading
	if(max>0){
		loadDiv = $('<div id="'+_loadDivId+'" style="display:none"></div>').appendTo($('body'));
		LoadImage(max);
	}
	
	$('#largeGallery').hover(  
        //Mouseover, fadeIn the hidden hover class    
        function() {  
            //$('.snippet_over').fadeOut('1000');   
        },   
      
        //Mouseout, fadeOut the hover class  
        function() {  
          //$('.snippet_over').fadeIn('1000');      
          
    	}).click (function () {  
     	 $("li#_img"+galIndex).fadeOut('slow', function() {
			$("li#_img"+galIndex).remove();
			galIndex ++;
			if(galIndex > max-1) galIndex = 0;
			LoadImage(max);
		});
    }); 
    
  
	
	//@ Loading Function Handler
	function LoadImage(max) {
		if(galIndex<max) {
			
			$('#gallerySidebar #imagedescription').html($(images[galIndex]).attr('title') + "<br /><br /><span class='small'>" + "Image " + (galIndex+1) + " of " + max + "</span>");
			// loading div update
			//$('#'+_loadDivId).html("Image "+(galIndex+1)+" of "+max);
			// add list to ul
			var list = $('<li id="_img'+galIndex+'"></li>').attr('class',_imageLoadClassName).appendTo('ul#'+_imgContainerId);
			// new image object
			var img = new Image();
			// current image
			var curr = $("li#_img"+galIndex);
			// load current image
			$(img).load(function () {
				//@ hide it first + .hide() failed in safari
				$(this).css('display','none');
				//@ remove loading class from li and insert the image into it
				$(curr).removeClass(_imageLoadClassName).append(this);
				//@ fade it in
				$(this).fadeIn('slow',function() {
					
				});
			}).error(function () {
				//@ if loading error remove li
				$(curr).remove();
				//@ try to load next item
				LoadImage(galIndex+1,max);
			}).attr('src', $(images[galIndex]).attr('src'));
		}
	}
};





function snippet_over(snippet_bar, snippet_title, colorStr) {

	var bar = document.getElementById(snippet_bar);
	var title = document.getElementById(snippet_title);
	
	bar.style.backgroundColor = colorStr;
	title.style.color = colorStr;
	title.style.textDecoration = 'underline';
}

function snippet_out(snippet_bar, snippet_title) {
	
	var bar = document.getElementById(snippet_bar);
	var title = document.getElementById(snippet_title);
	
	bar.style.backgroundColor = 'white';
	title.style.textDecoration = 'none';
}

function open_feature() {
	if(CURR_F_URL != '') {
		document.location = CURR_F_URL;
	}
}

function openpage(link) {
	document.location = link;
}



function openStore(id, container) {
	$(container).accordion( "activate" , id );
}


function swapImage(id, img) {
	//alert(document[id]);
	if(id == 'signupBtn') {
		if(!signup_open) {
			document[id].src = img;
		}
	} else {
		document.getElementById(id).src = img;
	}	
}


function submitform(formID) {
	$(formID).submit();
	
}

//CALENDAR FILTERING
var offset=0;
var endofresults="false";

function filterVenue(venueData, method) {
	offset=0;
	endofresults = "false";
	var today = false;
	if(method == 'today') today = true;
	queryCalendar("&venue=" + venueData + "&method=" + method + '&offset=0', false, today);
}

function checkMore() {
	 var resultsSize = $('#eventHolder').children().size();
	if(resultsSize < 10) {
		$('#loadMore').css({visibility:'hidden'});
	}
}


function loadMoreEvents() {
	offset += 10;
	$('#loadMore_preloader').css({visibility:'visible'});
	queryCalendar("&venue=all&method=more&offset=" + offset, true);
}

function queryCalendar(datastring, append, today) {
	$('#venue_preloader').css({visibility:'visible'});
		
	jQuery.ajax({
		type: "GET",
		data: datastring,
		url: "/queries/queries-calendar.php",
		success: function(results) {
			$('#venue_preloader').css({visibility:'hidden'});
			$('#loadMore_preloader').css({visibility:'hidden'});
			
			if(append) {
				$(results).appendTo('#eventHolder');
			} else {
				$('#eventHolder').html(results);
				$('#upcoming_title').css('margin', '0');
				$('#today').detach();
				$('#today_title').detach();
				
				if(today) $('#upcoming_title h3').html('EVENTS ON TODAY')
				else $('#upcoming_title h3').html('UPCOMING EVENTS');
			}
			
			var resultsSize = $(results).children().size();
			if(resultsSize % 10 != 0 || resultsSize < 10) {
				$('#loadMore').css({visibility:'hidden'});
			}
			
			$('#eventHolder').accordion("destroy").accordion({header: ".e_snippet", active: false, autoHeight: false, collapsible : true, animated: 'easeInOutQuad'});
			Cufon.refresh('h3');
			$(".event a").click(function(event){ event.stopPropagation(); });
		}
	});
}
