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);
	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')) + 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>');

		}


	});

}

function swap_video(id, flvFile) {

	$('.current-video').removeClass('current-video');
	$('.video-' + id).addClass('current-video');

	$('#video-container').html('<div id="video-player"></div>');

	var flashvars = {};
	flashvars.file = flvFile;
	var params = {};
	params.wmode = "transparent";
	params.allowscriptaccess = "always";
	params.allowfullscreen = 'true';
	var attributes = {};
	attributes.id = "video-player";
	swfobject.embedSWF("http://lightboxfilms.com.au/website/mediaplayer/mediaplayer.swf", "video-player", "512", "308", "7.0.0", "swf/expressInstall.swf", flashvars, params, attributes);

	var html = '';
	$.getJSON('./json_video/' + id, function(json) {
		if(json.agent != false) {
			for(var i in json.agent) {
				html = html + '<div class="video-agent">';
				html = html + '<h3>' + json.agent[i].title + '</h3>';
				html = html + '<p>' + json.agent[i].mobile + '<br />';
				html = html + '<a href="mailto:' + json.agent[i].email + '">Email Me</a><br />';
				html = html + '<a href="team/' + json.agent[i].id + '">View Profile</a></p>';
				html = html + '</div>';
			}
			$('#video-container')
				.addClass('left')
			
			$('#video-agents').show();
		}  else {
			$('#video-agents').hide();
			$('#video-container')
				.removeClass('left')
				.css('margin', '0 auto')
				.width(512);
		}
		$('.video-agents').html(html);
	});

	return false;


}

function addToInfoKit(propid) {

	$.getJSON(
		'add_info_kit/' + propid,
		function(data) {
		var propAddress = $('#property-overlay-content .property-address').text();
		$('#property-dialog').html('<p>' + propAddress + ' (ID: ' + propid +') has been added to your Property Short-list.</p>')
			$("#property-dialog").dialog({
				modal: true,
				buttons: {
					Ok: function() {
						$(this).dialog('destroy');
					}
				}
			});
			updateInfoKitCount(data.count)
		}
	)
	
}

function removeFromInfoKit(propid) {
	$.getJSON(
		'remove_info_kit/' + propid,
		function(data) {
			var propertyAddress = $('#' + propid + ' .property-address').text();
			$('#dialog-property-address').html(propertyAddress);
			$('#dialog-property-id').html(propid);
			$("#remove-property-dialog").dialog({
				modal: true,
				buttons: {
					Ok: function() {
						$(this).dialog('close');
					}
				}
			});
			$('#' + propid).remove();
			updateInfoKitCount(data.count)
		}
	)
}

function updateInfoKitCount(count) {
	var ik_text;
	ik_text = 'properties';
	count = parseInt(count, 10);
	if(count == 1) {
		ik_text = 'property';
	}
	$('.ik_count').html(count);
	$('.ik_properties').html(ik_text);

}

function infoKitCheck() {
	$.getJSON(
		'info_kit_count/',
		function(data) {
			if(parseInt(data.count, 10) > 0) {
				return true;
			} else {
				return false;
				alert('Your Property Kit is currently empty. Please add more properties before continuing.');
			}

		}
	)
}

function agent_grid() {
	var currentTallest = 0;
	$('.agent-grid').each(function(i){
		if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
	});
	$('.agent-grid').height(currentTallest);
}

function showDate(selectedDate) {
	$('.show-all-open-times').hide();
	$('.open-times-day').not('#ot_' + selectedDate).toggle();
	if($('.open-times-day:visible').size() == 1) {
		$('#ot_' + selectedDate + ' .show-all-open-times').show();
	}
}




