function new_window( url ) {
	var w = window.open(url, 'previewWindow', 'width=840, height=800, status=1, menubar=0, toolbar=0, location=0, resizable=1, directories=0, scrollbars=1');
	w.focus();
	return false;
}

function new_video_window( url ) {
	var w = window.open(url, 'previewWindow', 'width=1069, height=505, status=1, menubar=0, toolbar=0, location=0, resizable=1, directories=0, scrollbars=1');
	w.focus();
	return false;
}

function shadows() {
	var offset = $('#container').offset();
	var width = $('#container').width();
	var height = $('#container').height();

	$('.shadow-left')
		.css('height', height)
		.css('left', offset.left - 40);
	$('.shadow-right')
		.css('height', height)
		.css('left', offset.left + width + 40);
}

function swap_images( current_img ) {
	$('.prop-image:not(' + current_img + ')').fadeOut(400);
	$( current_img +':hidden').fadeIn(400);
	return false;
}
function ajax_swap_images( url ) {
	$('.waiting-image').css({
		position: 'absolute',
		left: 197.5,
		top: 195,
		zIndex: 1000,
		display: 'block'
	});

	$('#main-image').addClass('remove-image')
		.css('z-index', '950');

	var img = new Image();
	img.src = url;
	img.onload = function() {
		$('#photo-container').append('<img class="prop-image new-image" style="display: none; z-index: 960;" id="main-image" src="' + url + '">');
		$('.new-image').fadeIn(500, function () {
			$('.remove-image').fadeOut(500, function() {
				$(this).remove();
			});
			$('.waiting-image').hide();
		});
	}
}

animationAllowed = true;
function slideImages(slideValue) {

	slideValue = parseInt(slideValue, 10);
	var count = $('#property-thumb-container li').size();
	var gallery = $('#property-thumb-container ul');
	var offset = gallery.offset();

	if(gallery.not(':animated') && animationAllowed === true)  {
		targetLeft = parseInt(gallery.css('left'), 10) + slideValue;
		if(targetLeft <= 0 && targetLeft > count * 155 * -1) {
			animationAllowed = false;
			gallery.animate({left: targetLeft}, 1000, 'swing', function () { animationAllowed = true; });
		}
	}

}

function imageScroller() {

	$('#property-thumb-container').each(function () {

		var count = $('#property-thumb-container li').size();

		if(count > 4) {

			$(this)
				.height(100)
				.width(615)
				.css('position', 'relative');

			$('#property-thumb-container ul')
				.width(155 * count)
				.css('position', 'absolute')
				.css('left', 0);

			$(this).append('<div class="prev sprite scroller-btn" onclick="slideImages(\'620\')"></div><div class="next sprite scroller-btn" onclick="slideImages(\'-620\')"></div>');

		}


	});

}

