/* HOMEVIEW */
/* Photo Browser/Viewer Functions
----------------------------------------------------------------------------- */


	var $j = jQuery.noConflict();

	$j(window).load(function() {


/* ADD CONTROLS
----------------------------------------------------------------------------- */


	$j('ul.properties > li').each(function() {

		var $listing = $j(this).children('div.property');
		var $frame = $j(this).children('div.property').children('div.photoscontainer').children('div.photos');	
		var $browser = $j(this).children('div.property').children('div.photoscontainer').children('div.photos').children('ul');	
		var $enlarged = $j('#enlarged');	
		var photos = $browser.children('li').length;

		if ($frame.find('img').length > 1) {
		
			$j('<a class="action next" href="#">Next</a>').appendTo($frame);
			$j('<a class="action back" href="#">Back</a>').appendTo($frame);
			//$j('<a class="action thumbnails" href="#" title="Switch to Thumbnail View">Switch to Thumbnail View</a>').appendTo($frame).hide();
			//$j('<a class="action slideshow" href="#" title="Switch to Slideshow View">Switch to Slideshow View</a>').appendTo($frame).hide();
	
			var $next = $j(this).find('a.next');
			var $back = $j(this).find('a.back');
			//var $thumbnails = $j(this).find('a.thumbnails');
			var $slideshow = $j(this).find('a.slideshow');

		}


/* SLIDESHOW VIEW
----------------------------------------------------------------------------- */


	function loadSlideshow() {

		$browser.addClass('active').children('li').hide();
		$frame.removeClass('thumbnails').addClass('slideshow');
		$slideshow.hide();
		//$thumbnails.show();

	if ($listing.find('div.minipager').length > 0) {

		$browser.cycle({
      fx: 'scrollHorz',
			prev: $back,
			next: $next,
			speed: 500,
			timeout: 5000,
      pager:  $listing.find('div.minipager ul.thepager'), 
      pagerEvent: 'mouseover',
      pagerAnchorBuilder: function(idx, slide) { 
        // return selector string for existing anchor 
        return $listing.find('div.minipager ul.thepager li:eq(' + idx + ') a'); 
      } 

		});

   } else {

		$browser.cycle({
      fx: 'scrollHorz',
			prev: $back,
			next: $next,
			speed: 500,
			timeout: 5000

		});

   }

		$browser.cycle('pause');							


	}

	if ($frame.find('img').length > 1) {
			
				loadSlideshow();

	}


/* ENLARGED VIEW
----------------------------------------------------------------------------- */


	$browser.children('li').children('a.enlarge').click(function() {

    open_overlay_with_galleria($frame.find('img').length, parseInt($j(this).parent().attr('title')), $j(this).parent().parent().parent().parent().parent().attr('id').split("_")[1], imagedata[$listing.attr('id').split("_")[1]]);
		return false;
	
	});


/* END PROPERTY LOOP */

	});

/* END FILE */

	});

function open_overlay_with_galleria(imagecount, imagenumber, property_id, datasource) {
  
    var $enlarged = $j('#enlarged');

/* $j("#prevlargephoto").remove(); $j("#nextlargephoto").remove(); $j("#galleria").empty(); */

		if (imagecount > 1) {
/* should be removed after overlay is closed or something  */
			$j('<a id="nextlargephoto" class="action next" href="#">Next</a>').appendTo($enlarged);
			$j('<a id="prevlargephoto" class="action back" href="#">Back</a>').appendTo($enlarged);
     }
/* might not be needed?  */
    $j('<div class="close" onclick="closeoverlay(); return false;"></div>').appendTo($enlarged);

    $j('#galleria').galleria({ jump: parseInt(imagenumber), property_id: property_id,
        transition: 'slide', data_source: datasource});
	  var api = $j("#enlarged").data("overlay");
		api.load();
		return false;
	
	};
