/**
 * SimpleModal Test
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2008 Eric Martin - http://ericmmartin.com
 *
 * Revision: $Id: simplemodal.js 179 2008-12-15 23:02:07Z emartin24 $
 *
 */

$(document).ready(function() {  
	
	/* session cookie test for TOU		 */
	/* -- show popup if not cookie set   */
	var touUs = $.cookies.get('touUs');
	if (touUs == "true") {
		/* do nothing because user is all set */
		$("#flash-wrapper").removeClass('hideme');
		$("#flash-wrapper").addClass('showme');
	} else if (!touUs) {
		/* show modal TOU dialogue and set cookie in the modal TOU dialogue */	
		$('#modalContentTOU').modal({
				onClose: modalClose, 
				onOpen: modalOpen,
				containerCss: {
					height: 310,
					width: 619
				}
		});
		
		$("#tou_disagree").click(function(event) {
			$.cookies.set('international_location', '', -1);
			location = 'index.shtml';			
			return false;
		});
		
	}						   		
		
});

/**
 * When the open event is called, this function will be used to 'open'
 * the overlay, container and data portions of the modal dialog.
 *
 * onOpen callbacks need to handle 'opening' the overlay, container
 * and data.
 */
function modalOpen (dialog) {
	dialog.overlay.fadeIn('fast', function () {
		dialog.container.fadeIn('slow', function () {});
		dialog.data.fadeIn('slow');
		
		$("#flash-wrapper").removeClass('showme');
		$("#flash-wrapper").addClass('hideme');
		
		$("#panel-map").removeClass('showme');
		$("#panel-map").addClass('hideme');
		
		var a = [
				self.pageXOffset ||
				document.documentElement.scrollLeft ||
				document.body.scrollLeft
				,
				self.pageYOffset ||
				document.documentElement.scrollTop ||
				document.body.scrollTop
				];
		$(window).bind('scroll',{pos: a},scrollLock);
		
	});
}

function scrollLock(e) {
    var a=e.data.pos;
    window.scrollTo(a[0],a[1]);
    return false;
}

/**
 * When the close event is called, this function will be used to 'close'
 * the overlay, container and data portions of the modal dialog.
 *
 * The SimpleModal close function will still perform some actions that
 * don't need to be handled here.
 *
 * onClose callbacks need to handle 'closing' the overlay, container
 * data and iframe.
 */
function modalClose (dialog) {
	
	$.cookies.set('touUs','true');

	dialog.data.fadeOut('fast', function () {});
	dialog.container.fadeOut('slow', function () {
		dialog.overlay.fadeOut('slow', function () {
			$.modal.close();
			
			$("#flash-wrapper").removeClass('hideme');
			$("#flash-wrapper").addClass('showme');
			
			$("#panel-map").removeClass('hideme');
			$("#panel-map").addClass('showme');
			
			$(window).unbind('scroll',scrollLock); // unbinds lock

		});									   
	});
	
}

/**
 * After the dialog is show, this callback will bind some effects
 * to the data when the 'button' button is clicked.
 *
 * This callback is completely user based; SimpleModal does not have
 * a matching function.
 */
 
function modalShow (dialog) {
	dialog.data.find('input.animate').one('click', function () {
		dialog.data.slideUp('slow', function () {
			dialog.data.slideDown('slow');
		});
	});
}

