		function imgTopMargin()
			{
			var imgH = $('#img img').height();
			if (imgH<407) // anything bigger and we don't need the margin.
				{
				marginTop = (408 - imgH) / 2 + 1;
				$('#img img').css("margin-top",marginTop+"px");
				}
			}
		

		$(function()
			{
			var HOST = '';

			$('.listing_head').find('.phoneNo').each(function () {
				var label = $(this).attr('rev').split('|');
				$(this).html('<a href="javascript:;">'+ label[0] +'</a>');

				if (HOST=='')
					HOST = label[1];

				if (label[2]=='buzz')
					$(this).attr('rev','buzz');
				else
					$(this).attr('rev','');
				});

			$(".phoneNo").click(function()
				{
				var coInfo = $(this).attr('rel').split('|');
				var buzz = $(this).attr('rev');
				$(this).html( '<img style="padding-left:4px;" src="/img/icons/ajax-loader-fb.gif" />' );

				$.ajax({
				   type: "POST",
				   async: false,
				   url: HOST+"/inc/log_general.php",
				   data: "log_type=" + coInfo[0] + "&src=advert&co_id=" + coInfo[1]
				   });

				$(this).html( coInfo[2] );
				if (buzz=='buzz')
					$("#ib"+coInfo[1])
						.addClass('triggered')
						.trigger('click');
				});


			
			$('.panel-btn-vid').click(function()
				{
				if($('#map_canvas').css("display")=='block')
					{
					$('.panel-btn-map').removeClass('active');
					$('#map_canvas').css("z-index","10");
					$('#map_canvas').hide();
					}
			
				if($('#vid_canvas').css("display")=='block')
					{
					$('.panel-btn-vid').removeClass('active');
					$('#vid_canvas').hide();
					$('#flv_player').remove();
					
					if (!$.browser.msie)
						{
						$('.galleria_container').css("width","516px");
						$('.galleria_container').css("height","412px");
						}
					
					$('#img .bg').show();
					$('#img img').css("z-index","400");
					$('#img img').show();
					
					if (!$.browser.msie)
						$('#img').css("display","table-cell"); // centers image - does NOT work in IE6.
					else
						imgTopMargin();
					}
				else
					{
					if ($('.c2c_fr'))
						$('.c2c_fr').remove();
					
					$('#vid_canvas').show();
					var html_obj = $('<a id="flv_player" href="' + $('#vid_href').val() + '"></a>');
					$("#vid_canvas").append(html_obj);
					$('.panel-btn-vid').addClass('active');
					flowplayer("flv_player", {src: '/js/libraries/jquery_plugins/flowplayer/flowplayer-3.1.5.swf', wmode: 'transparent'}, { /* flowplayer config */ });
					}
				});
			

			$('.panel-btn-map').click(function()
				{
				if($('#vid_canvas').css("display")=='block')
					{
					$('.panel-btn-vid').removeClass('active');
					$('#vid_canvas').hide();
					$('#flv_player').remove();
					}
				
				if($('#map_canvas').css("display")=='none')
					{
					if (!$.browser.msie)
						{
						$('.galleria_container').css("width","512px");
						$('.galleria_container').css("height","408px");
						$('#img').show();
						}
					
					$('#img .bg').hide();
					$('#img img').css("z-index","10");
					$('#img img').hide();
					
					$('#map_canvas').css("z-index","400");
					$('#map_canvas').show();
					$('#map_canvas').hide().fadeIn(500);
					$('.panel-btn-map').addClass('active');
					}
				else
					{
					$('.panel-btn-map').removeClass('active');
					$('#map_canvas').css("z-index","10");
					$('#map_canvas').hide();
					
					if (!$.browser.msie)
						{
						$('.galleria_container').css("width","516px");
						$('.galleria_container').css("height","412px");
						}
					
					$('#img .bg').show();
					$('#img img').css("z-index","400");
					$('#img img').show();
					if (!$.browser.msie)
						$('#img').css("display","table-cell");
					else
						imgTopMargin();
					}
				});
			
			
			$('#gallery li').each(function(idx) {
				$(this).data('index', (++idx));
			});

			$('#gallery').jcarousel({
				scroll: 5,
				initCallback: initCallbackFunction
			})
			
			function initCallbackFunction(carousel) {
				$('#img').bind('image-loaded',function() {
					var idx =  $('#gallery li.active').data('index') - 2;
					
					carousel.scroll(idx);
					return false;
				});

			};

			// load and fade-in thumbnails
			$('#gallery li img').css('opacity', 0).each(function()
				{    
				if (this.complete || this.readyState == 'complete')
					$(this).animate({'opacity': 1}, 300)
				else
					{
					$(this).load(function()
						{
						$(this).animate({'opacity': 1}, 300)
						});
					}
				});

			$('#gallery').galleria({
				// #img is the empty div which holds full size images
				insert: '#img',
				
				// enable history plugin
				history: false,
				
				// function fired when the image is displayed
				onImage: function(image, caption, thumb)
					{
					if (thumb.attr('img_w') && thumb.attr('img_h'))
						{
						image.css('width',(thumb.attr('img_w')+'px'));
						image.css('height',(thumb.attr('img_h')+'px'));
						}
			
					// fade in the image
					image.hide().fadeIn(500);
					
					// animate active thumbnail's opacity to 1, other list elements to 0.6
					thumb.parent().fadeTo(200, 1).siblings().fadeTo(200, 0.6);
					
					$('#img').trigger('image-loaded');
				
					if ($.browser.msie)
						imgTopMargin();
					},
				
				// function similar to onImage, but fired when thumbnail is displayed
				onThumb: function(thumb)
					{
					var $li = thumb.parent(),
						opacity = $li.is('.active') ? 1 : '0.6';
					
					// hover effects for list elements
					$li.hover(
						function() { $li.fadeTo(200, 1); },
						function() { $li.not('.active').fadeTo(200, opacity); }
						)
					}
				}).find('li:first').addClass('active') // display first image when Galleria is loaded
			    	
			    	
			$('#img .caption').css('height', 0);
			$('#img .caption').hide(); // added by Larry for ie6
			
			$('#slideshow').hide();
			
			var slideshow,
				slideshowPause =  $('#slideshow-pause').val() 

			$('#slideshow-pause').change(function(){
				slideshowPause = this.value
				
				// clear interval when timeout is changed
				window.clearInterval(slideshow)

				// and set new interval with new timeout value
				slideshow = window.setInterval(function(){
					$.galleria.next()
				}, slideshowPause * 1000) // must be set in milisecond
			})


			// hide map or vid if showing when thumb clicked...
			$('#gallery li img').click(function()
				{
				if($('#map_canvas').css("display")=='block')
					{
					$('.panel-btn-map').removeClass('active');
					$('#map_canvas').css("z-index","10");
					$('#map_canvas').hide();
					$('#img .bg').show();

					if (!$.browser.msie)
						{
						$('.galleria_container').css("width","516px");
						$('.galleria_container').css("height","412px");
						$('#img').css("display","table-cell");
						}
					else
						imgTopMargin();
					}

				if($('#vid_canvas').css("display")=='block')
					{
					$('.panel-btn-vid').removeClass('active');
					$('#vid_canvas').hide();
					$('#flv_player').remove();
					
					// this section is necessary if map was clicked (which hides img and bd, then video, then image
					$('#img .bg').show();
					
					if (!$.browser.msie)
						{
						$('.galleria_container').css("width","516px");
						$('.galleria_container').css("height","412px");
						$('#img').css("display","table-cell");
						}
					else
						imgTopMargin();
					}
				});

			if ($.browser.msie)
				{
				$('.galleria_container').css("width","512px");
				$('.galleria_container').css("height","408px");
				}
			
			$('#vid_canvas').hide();
			
			if ($('#gallery').attr("rev")=="no_slide")
				$('.jcarousel-skin-tango').hide();
			
			

			var emailForm=function(hash)
				{
				var HOST_URI = $(hash.t).attr('rev');
				$.ajax({
					type: "POST",
					url: HOST_URI+"/_/contact_biz.php",
					data: "mode=load&coID=" + $(hash.t).attr('rel'),
					success: function(php_output) {
						$('#emailBox').html(php_output);
						
						Recaptcha.create("6LejowwAAAAAAJexXv5FuX4L-DWHAj2OqRf7PCu_", 'recapTarget', {
							theme: 'white',
							tabindex: 0,
							callback: Recaptcha.focus_response_field
							});
						}
					});
				  hash.w.show();
				};

			$('#email_pop')
				.jqDrag('.jqDrag')
				.jqm({ trigger:'.emailPopLnk',
				   modal:true,
				   onShow: emailForm
				 });
			
			
			if (!$.browser.msie)
				{
				$.xLazyLoader({
					js: 'http://s7.addthis.com/js/200/addthis_widget.js',
				    success: function(){
				        $(".addThis").css("display", "block"); }
					});
				}
			
		});
