/*	VFW Post 9601
 *	11/01/11
 *	
 *	master.js
 *
 */
 
(function ($){
	$(document).ready(function() {
		$('#main')
			.bind('ajaxStart', function() {
				var t = setTimeout(function() {
					var _html = "<div id=ajaxLoadSpinner><div>Loading&hellip;</div></div>";
					$('#main').append(_html);
				}, 1500);
				jQuery.data(document.body, 'tid', t);
			})
			.bind('ajaxComplete', function(){
				var t = jQuery.data(document.body, 'tid');
				clearTimeout(t); // Clear before timer fires
				$('#ajaxLoadSpinner').remove(); // Clear after timer fires
			});
		$.ajaxSetup({
			cache: true,
			dataType: 'json',
			error: function(xhr, status, error){
				alert('An error occurried: ' + error);
			},
			timeout: 30000, 
			type: 'POST',
			url: ''
		});
	});
})(jQuery);
	
	

$(function()
{
	 $(".dialog").bind('click', function()
	{
		var url = $(this).attr("href");
		url += ".html";
		var title = $(this).html();
		
		var height=$(window).height() * .8;
		var width=600;
		
		$("#dialog")
		.load(url, function() {
			$(this).scrollTop(0);
		})
		.dialog(
			{
				modal: true,
				height: height,
				width: width,
				title: title,
				open: function() { 
					$(this).addClass('content');
				},
				close: function() {
					$('.content', this).remove();
				}
			}
		);
		
		return false;
	});
});

$(function()
{
	 $(".eventDialog").bind('click', function()
	{
		var url = $(this).attr("href");
		var title = $(this).attr("title");
		var content =  "<div id=myDialog><img src=" + url + " alt='crab and spaghetti feed event poster image'><div>";
			content += "<img id=eMinus class=eMinus src='../images/navigation/collapse.png' height=32 width=32 alt='show smaller event poster control icon'>";
			content += "<img id=ePlus  class=ePlus  src='../images/navigation/expand.png'   height=32 width=32 alt='show larger event poster control icon'>";
			content += "</div></div>";
		var width="auto";  // default
		var height="auto";
		
		$("#dialog")
		.dialog(
			{
				modal: true,
				width: width,
				position: ["center", 60],
				title: title,
				resizable: false,
				open: function() {
					$(this)
					.append(content)
					.find("#eMinus")
					.bind('click', function()
					{
						//alert("eMinus called");
						var myDialogMinus$ = $("#myDialog > img");
						myDialogMinus$.css("width", parseInt(myDialogMinus$.css("width").slice(0,-2)) - 30);
					})
					.end()
					.find("#ePlus")
					.bind('click', function()
					{
						//alert("ePlus called");
						var myDialogPlus$ = $("#myDialog > img");
						myDialogPlus$.css("width", parseInt(myDialogPlus$.css("width").slice(0,-2)) + 30);
					});
					
					return false;
				},
				close: function() {
					$('#myDialog', this)
					.remove();
					
					return false;
				}
			}
		);
		
		return false;
	});
});


// Go directly to image
	var imageText = 
	[
		"VFW Post 9601 Members",
		"Lake Chabot Rd billboard",
		"Wilbeam and Castro Valley Rd billboard",
		"Pat, Billy, Mike at Wilbeam and Castro Valley Rd site",
		"Rendering for billboard installed on Lake Chabot Rd",
		"Rendering for billboard installed at Wilbeam and Castro Valley Rd"
	];
	$("#imageNbrBar a").click(function()
	{
		// Get handle
		var $imgOn = $("#imageNbrBar a.on");
		var $legend = $("#legend");
		var $imgNext = $(this);
		
		// Get position
		var _imgOnNbr = $imgOn.attr("href");
		var _imgNextNbr = $imgNext.attr("href");
		
		// If same object, just return
		if ( _imgOnNbr == _imgNextNbr) {return false;}
		
		// Turn on/off
		$imgOn.removeClass('on');
		$imgNext.addClass('on');
		
		// Add text msg
		$legend.html(imageText[$imgNext.attr("href")]);
		
		// Animation
		$slider = $("#slider > img");
		$slider.eq(_imgOnNbr).slideUp(1200).hide(4000);
		$slider.eq(_imgNextNbr).slideDown(2000).show(1200);
		
		return false;
	});
	
	// Play / Pause button
	$("#playPause").click(function()
	{	
		if ($(this).hasClass("play"))
		{
			$(this).toggleClass("play");
			
			var i = time = 20400;
			$("#imageNbrBar a").each(function(index)
			{
				var that = this;
				time -= 4000;
				setTimeout(function()
				{
					$(that).click();
				}, time);
			});
			
			setTimeout(function(){
				$("#imageNbrBar a").eq(5).click();
				$("#playPause").addClass("play");
				
			}, i);
		} 
		
		return false;
	});



	

	
/************** end of page ****************/
