/*
 * Downtown Courtenay BIA scripts
 *
 * Targets jQuery 1.3.2.
 *
 * Copyright (c) 2009 Dialect Communications Group (dialect.ca)
 *
 * $Package: DCBIA $
 */

/*jslint browser: true, white: true, plusplus: true, newcap: true,
    eqeqeq: true, evil: true, nomen: true,  regexp: true, undef: true,
    onevar: false */

/*global $,pageTracker */


var DCBIA = {
	initHomepageMap : function (xml_src) {
		$('#map_container').html('').after('<div id="map_container_footer">&nbsp;</div>').flash({
			src: '/fla/map_loader.swf',
			width: '100%',
			height: 436,
			base: '/fla/',
			align: 'bottom',
			scale: 'noscale',
			salign: 'b',

			flashvars: { xml_data_src: xml_src, start_expanded: true }
		});	
	},

	initHeaderMap : function (image_url) {
		var fla_vars = { no_intro: true };
		var map_height = 418;

		if (image_url !== undefined) {
			fla_vars = { pause_map: true, image_url: image_url, start_expanded: true };
			map_height = 436;
		}

		$('#map_container').html('').flash({
			src: '/fla/map_loader.swf',
			width: '100%',
			align: 'bottom',
			scale: 'noscale',
			salign: 'b',
			height: map_height,
			base: '/fla/',
			flashvars: fla_vars
		});	
		
		$('#map_container').after('<div id="map_container_footer">&nbsp;</div>');
		
		$(' #map_toggle a').bind('click.dcbia', function () {
			$('#map_container').show();
			$('#map_container_footer').show();
			$(this).addClass('selected');
			return false;
		});
	},
	
	

	initSelector : function () {
		// handle the selector slide down menu
		$('.selector .select').bind('click.dcbia', function () {
			var opts = $('.options', $(this).parent());
			
			if (opts.is(':visible')) {
				opts.slideUp();
			} else {
				opts.slideDown();
			}

			return false;
		});
	},

	initSubNav : function () {
		// make the entire LI element clickable
		$('.subnav li').css('cursor', 'pointer').bind('click.dcbia', function () {
			try {
				var href = $('a:first', this).attr('href');
				
				if (href !== '') {
					document.location.href = href;
				}
			} catch (e) { }
		});
	},
	
	overlayUIPath : '/inc/jquery-lightbox-0.5/',
	
	initGalleryOverlays : function () {
		$('.thumbs a').lightBox({
			fixedNavigation: false,
			overlayBgColor:  '#fff',
			overlayOpacity:  0.6,
			imageLoading:    DCBIA.overlayUIPath + 'lightbox-ico-loading.gif',
			imageBtnPrev:    DCBIA.overlayUIPath + 'lightbox-btn-prev.gif',
			imageBtnNext:    DCBIA.overlayUIPath + 'lightbox-btn-next.gif',
			imageBtnClose:   DCBIA.overlayUIPath + 'lightbox-btn-close.gif',
			imageBlank:      DCBIA.overlayUIPath + 'lightbox-blank.gif'
		});
	},
	
	initBusinessOverlays : function () {
	
		$('.storefront a').lightBox({
			fixedNavigation: false,
			overlayBgColor:  '#fff',
			overlayOpacity:  0.6,
			imageLoading:    DCBIA.overlayUIPath + 'lightbox-ico-loading.gif',
			imageBtnPrev:    DCBIA.overlayUIPath + 'lightbox-btn-prev.gif',
			imageBtnNext:    DCBIA.overlayUIPath + 'lightbox-btn-next.gif',
			imageBtnClose:   DCBIA.overlayUIPath + 'lightbox-btn-close.gif',
			imageBlank:      DCBIA.overlayUIPath + 'lightbox-blank.gif'
		});
	},
	
	initAddEventForm : function () {
		$("#entry_date_picker").datepicker({ dateFormat: 'yy-mm-dd 00:00:00', altField: '#entry_date'});
		$("#expiration_date_picker").datepicker({ dateFormat: 'yy-mm-dd 00:00:00', altField: '#expiration_date'});
	},
	
	initEntryList : function () {
		$('.entry_list .entry').bind('mouseover.dcbia', function() {
			$(this).css('cursor', 'pointer');
		});
		
		$('.entry_list .entry').bind('click.dcbia', function() {
			var url = $('h3 a', this).attr('href');
			
			if ( url )
				document.location = url;

			return true;
		});
	}
};

$(document).bind('ready.dcbia', function () {
	DCBIA.initSelector();
	DCBIA.initSubNav();
	DCBIA.initEntryList();
});
