$(document).ready(function(){ 
	
	$('#gallery').cycle({
		fx: 'fade',
		prev: '#move_left',
		next: '#move_right'
	});	
		
	$(window).resize(function() {	
		repositionDialog();
	});
	
	$(window).scroll(function () { 
		repositionDialog();
    });	
	
	$('body').supersleight(); 
		   
	
});


function showAreal() {
	$("#dialog").dialog({
			modal: true,
			width: 625			
			
		});
}

//////////// DIALOG //////////////

var MAIN_URL = 'http://www.riversidecaravanpark.com/';

function closeDialog(theID) {
	$.post(MAIN_URL + "assets/includes/setPopUpSession.php", { }, function(data){ 			
		$(theID).remove();
		$('#overlay').remove();																									 
	});	
}

function openDialog(theID) {
	if ($('#' +theID).length == 0) {
		$('.dialog_holder').remove();
		$('#overlay').remove();
	$("body").append('<div id="overlay"></div><div class="dialog_holder" id="'+ theID +'"><div class="dialog_box"><img src="'+ MAIN_URL +'assets/images/dialog_top.png" width="758" height="13" alt="dialog top" /><div class="dialog_relative"><div class="close_btn"><a href="javascript:closeDialog(\'#'+ theID +'\');">CLOSE X</a></div><div class="dialog_box_content"></div></div><img src="'+ MAIN_URL +'assets/images/dialog_bottom.png" width="758" height="13" alt="dialog bottom" /></div></div>');
	$('#overlay').hide();
	$('.dialog_box').hide();

	$(".dialog_box_content").load(MAIN_URL + "assets/includes/"+ theID +"_content.php", function() {
		$('.requiredFields').html('');		
		$('#overlay').show();
		$('.dialog_box').show();
		$('#overlay').css("opacity", "0.65");
		$('#overlay').width('100%');
		$('#overlay').height($(document).height());	
		
		repositionDialog();
		$('.sold_results_container table').find('tr:odd').css({ background: '#e5f3f6' });
		$('body').supersleight();
	});		
	}
}

function repositionDialog() {
	if ($('.dialog_box').height() < $(window).height()) {
			$('.dialog_box').each(function(){	
				$(this).centerInClient({ container: window });
			});
	} else {
		var newleft = ($(window).width() - $('.dialog_box').width()) / 2;
		$('.dialog_box').css({ 'position':'absolute','top': '0px', 'left': newleft + 'px' });	
	}
}

//////////// DIALOG END //////////////

