/*Add Titles*/
$('.gallery a').each(function(){
   var title = $(this).parent().parent().prev().text()
   $(this).attr('title', title)
})

/*Regular Gallery links*/
$('.gallery a:not([href*=.swf])').colorbox({
	'overlayClose' : true,
	'transition': "elastic",
	'opacity' :	0,
	'speed' : 350,
	'rel' : true,
	'current' : '{current}/{total}',
	'next' : '>>',
	'previous' : '<<'
	})

/*Create VR Div*/
if ( $('.gallery').length > 0 )
	{
		$('.gallery').append('<div id="vr-view"><p><img src="/images/alert.gif" alt="" align="absmiddle"> Please install the latest version of <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash</a> to view the Virtual Tour</p></div>')
	}
	
/*VR links*/
$('.gallery a:[href*=.swf]')
.addClass('vr')
.colorbox({
	'overlayClose' : true,
	'transition': "elastic",
	'opacity' :	0,
	'speed' : 350,
	//'rel' : true,
	'current' : '{current}/{total}',
	'next' : '>>',
	'previous' : '<<',
	'inline' : true,
	'href' : '#vr-view'
	})


/*Floorplan links*/
$('.floorplans a').colorbox({
	'overlayClose' : true,
	'transition': "elastic",
	'opacity' :	0,
	'speed' : 350,
	'rel' : false
	})


//Thumbnail hover
$('.lightbox a').hover(function(){
		$(this).find('img').stop().fadeTo(200, 0.7)								
	},								
	function(){
		$(this).find('img').stop().fadeTo(200, 1)
	})


/*Lightbox extensions*/
$().bind('cbox_complete', function()
	{
        $('#cboxOverlay').fadeTo(500, 0.6)
	});

$().bind('cbox_closed', function()
	{
		if(flashembed.isSupported([8, 0]))
			{
				$('#vr-view').empty()
			}
		$('#cboxInlineTemp').remove() //Get rid of any leftover divs
		//$('#cboxPhoto').remove()
	});

$().bind('cbox_load', function()
	{
		var target = $.fn.colorbox.element()
		if($(target).hasClass('vr') )
			{
				flashembed('vr-view', {src:$(target).attr('href'), version:[8], background:'#ffffff', allowfullscreen: true });
			}
		//$('#cboxPhoto').remove() //div is leftover after flash
	});



/*Gallery Toggle*/
$('.gallery ul[class!=default]').hide()
$('.gallery h2[class*=default]').addClass('expanded')

$('.gallery h2')
.addClass('expandable')
.click(function(){
	$(this).toggleClass('expanded').next().slideToggle();
})



