/*
######################################################################################
######                                                                        #######
######     POPUP SCRIPTS			                                         #######
######                                                                      #######
##################################################################################
*/

	var popupState	= 'closed';
	var popupWindow = new Object();
	var popupActive	= '';
	var currentTotalHeight	= 0;
	var currentTotalWidth	= 0;
	
/***** GET THE FUNCTIONS STARTED *****/

	var popup;
	var fade;
	var container;
	
	var bgTop;
	var bgMiddle;
	var bgBottom;
	
	var overlay;
	var header;
	var content;
	var footer;
	var shareThis;
	
	popupWindow.Start = function(popupId) {
		
		shareThis = $('#at20mc');
		
		$('#at20mc').remove();
		
	// On resizing the page, run this function to reset the values
		$(window).resize(function() { popupWindow.contentPos(); });
		$(window).change(function() { popupWindow.contentPos(); });
		
	/***** SET GLOBALS *****/
		popup 		= '.popup'
		fade 		= '#fade';
		container 	= '#container';
		
		bgTop		= container + ' .bg_top';
		bgMiddle	= container + ' .bg_middle';
		bgBottom	= container + ' .bg_bottom';
		
		overlay		= container + ' .overlay';
		header		= container + ' .header';
		content		= container + ' .content';
		footer		= container + ' .footer';
	
	/***** REUSABLE FUNCTIONS *****/
		
		var bodyTag = $(document).find('form');
		$(bodyTag).append($(popup));
		
	// Activate the popup
		popupWindow.Open(popupId);
	}

	// changing wrapper properties
		popupWindow.setWrapper = function() { 
			$('#wrapper').css({'overflow':'hidden','height':$(window).height() + 'px'});
		}
		popupWindow.unsetWrapper = function() {
			$('#wrapper').css({'overflow':'visible','height':'auto'});
		}
	
	// Scroll
		popupWindow.scrolling = function() {
			var v = ($(window).height() / 2) - ($(container).height() / 2) + $(window).scrollTop();
			$(container).css({'top': v + 'px'});
		}
		popupWindow.scrollBarsRemove = function() {
			$(content).jScrollPaneRemove({ 'showArrows':true, 'scrollbarWidth':'9', 'wheelSpeed':'30', 'showArrows ':true });
		}
		popupWindow.scrollBars = function() {
			$(content).jScrollPane({ 'showArrows':true, 'scrollbarWidth':'9', 'wheelSpeed':'30', 'showArrows ':true });
		}
	// Close
		popupWindow.Close = function() { popupWindow.Open(); }


/********************************************************************************/
/****** REUSABLE FUNCTIONS *****************************************************/
/******************************************************************************/

/***** VERTICALLY ALIGN CENTRE THE CONTENT *****/

	popupWindow.contentPos = function() {
		$(popup).css({
			'width':$(document).width() + 'px',
			'height':$(document).height() + 'px'
		});
		$(fade).css({
			'width':$(document).width() + 'px',
			'height':$(document).height() + 'px'
		});

	// Set container position
		if(($(container).height() + 30) > $(window).height()) {
			var v = 30 + $(window).scrollTop();
		} else {
			var v = ($(window).height() / 2) - ($(container).height() / 2) + $(window).scrollTop();
		}

		
		var h = ($(window).width() / 2) - ($(container).width() / 2);
		$(container).css({ 'top': v + 'px', 'left': h + 'px' });
	}


/***** OPEN / CLOSE THE POPUP WINDOW *****/

	popupWindow.Open = function(popupId) {
		if(popupState == 'closed') {
	
	/***** FADING *****/
		/*
		// Set opacity to 0
			$(fade).css({
				opacity: 0
			});
			$(container).css({
				opacity: 0
			});
			$(popup).css({
				visibility: 'visible'
			});
		// Show the areas
			$(popup).show();
			$(fade).show();
			$(container).show();
			$('#' + popupId).show();
			
		// Set content positioning
			popupWindow.contentPos();
			popupActive = popupId;
		// Run the animations
			$(fade).animate({
				opacity: 0.50
			}, 500, function() {
				if(sifrStart()) {
				setTimeout("sifrStart()", 200);
				}
				$(container).animate({
					opacity: 1
				}, 500, function() {
					popupState = 'open';
					$(fade).click(function() {
						popupWindow.Open();
					});
				});
			});
			*/
		/***** NO FADING *****/
		// Set opacity to 0
			$(fade).css({ opacity: 0.5 });
			$(container).css({ opacity: 1 });
			$(popup).css({ visibility: 'visible' });
		// Show the areas
			$(popup).show();
			$(fade).show();
			$(container).show();
			$('#' + popupId).show();

			if (typeof sifrStart == 'function') {
			    sifrStart();
			}
			
		// Set content positioning
			popupWindow.contentPos();
			popupActive = popupId;
			popupState = 'open';
			$(fade).click(function() {
				popupWindow.Open();
			});
		} else {

		/***** FADING *****/
		/*
		// Run the animations
			$(container).animate({ opacity:0 }, 500, function() {

				popupWindow.unsetWrapper();
				
				$(fade).animate({ opacity:0 }, 500, function() {
					popupState = 'closed';
					popupActive = '';
				// Hide all areas
					$(popup).hide();
					$(fade).hide();
					$(container).hide();
					$('#' + popupId).hide();
				// Hide all FORM error messages
					$('div.error_message').html('');
					$('div.error_message').hide();
				});
			});
			*/
		/***** NO FADING *****/
		// Show the areas
			$(popup).hide();
		/*
			$(fade).hide();
			$(container).hide();
			$('#' + popupId).hide();
			*/
			
		// Set content positioning
			popupWindow.contentPos();
			popupActive = '';
			popupState = 'closed';
			
			var bodyTag = $(document).find('body');
			$(bodyTag).append($(shareThis));
		}
	}
	

/********************************************************************************/
/****** REUSABLE FUNCTIONS *****************************************************/
/******************************************************************************/

var emailFriend = new Object();
var rowCount	= 0;

emailFriend.Add = function() {
	var fList = $('.email_row_list fieldset');
	var row = 0;
	
	if(rowCount < 5) {
		rowCount = rowCount + 1;
		for(var i=0; i<fList.length; i++) {
			$(fList[i]).hide();
		}
		for(var i=0; i<rowCount; i++) {
			$(fList[i]).show();
		}
	}
	popupWindow.contentPos();
}

emailFriend.Remove = function(row) {
	
	/*var fList = $('#email_friends fieldset');
	$(fList[row]).hide();*/
	var fullRow = $('.fld_float.row' + row);
	var inputList = $(fullRow).find('input');
	for(var i=0; i<inputList.length; i++) {
		$(inputList[i]).val('');
	}
	$(fullRow).hide();
	$('.email_row_list').append($(fullRow));
	
	/*	
	var fList = $('.email_row_list fieldset');
	var row = 0;
	
	if(rowCount > 0) {
		rowCount = rowCount - 1;
		for(var i=0; i<fList.length; i++) {
			$(fList[i]).hide();
		}
		for(var i=0; i<rowCount; i++) {
			$(fList[i]).show();
		}
	}
	*/
	popupWindow.contentPos();
}









