// JavaScript Document for lightbox.

function openPopUp(linkURL) {
window.open(linkURL,'popup','width=625,height=450,scrollbars=yes,resizable=yes')
}


$(document).ready(function() {
													 
	$('#container').after(
														
		'<div id="lightBoxBg"></div>' + 
		'<div id="lightBoxContainer">' +
			'<div id="lightBox">' +
				'<div id="close"><a id="closeLightBox" href="">X Close</a></div>' +
				'<div id="lightBoxContent"></div>' +
			'</div>' +
		'</div>'
		
	);												 
													 
	$('.openLightBox').click(function() {
																		
		$('#lightBoxContent').load('taf.php #lightBoxPage1', function() {
			
			// create an array of objects of each link in the document 
			var popuplinks = document.getElementsByTagName("a");
			// loop through each of these links (anchor tags) 	
			for (var i=0; i < popuplinks.length; i++) {	
				// if the link has a class of "popup"...	
				if (popuplinks[i].className == "popup") {	
					// add an onclick event on the fly to pass the href attribute	
					// of the link to our second function, openPopUp 	
					popuplinks[i].onclick = function() {	
					openPopUp(this.getAttribute("href"));	
					return false; 	
					} 	
				}
			} 
			
			validateLightBox();
			$('.gotoLightBoxPage').click(function() {	
																						
				if (!($('#taf').valid())) {	
								
					$(':input').each(function() {
					
						if ($(this).valid()) {
						
							$(this).parent('div').find('label').css('color', '#000');													 
							$(this).css('borderColor', '#ccc');
							
						} else {
							
							$(this).parent('div').find('label').css('color', '#f00');	
							$(this).fadeOut(function() {
																			 
								$(this).css('borderColor', '#f00');
								$(this).fadeIn();
								
							});
							
						}
					
					});
					
				}
				
				
			});
		
		});
		
		if ($(document).height() > $(window).height()) {
			
			$('#lightBoxBg').height($(document).height());
			$(window).resize(function() {
			
				if ($(document).height() > $(window).height()) {
					
					$('#lightBoxBg').height($(document).height());
				
				} else {
					
					$('#lightBoxBg').height($(window).height());
					
				}
		
			}); 
			
		} else {
			
			$('#lightBoxBg').height($(window).height());
			$(window).resize(function() {
			
				if ($(document).height() > $(window).height()) {
					
					$('#lightBoxBg').height($(document).height());
				
				} else {
					
					$('#lightBoxBg').height($(window).height());
					
				}
		
			});
		
		}
		
		$(document).scrollTop(0);
		$('#lightBoxBg').css('opacity', '0.60');
		$('#lightBoxBg').fadeIn('slow');
		$('#lightBoxContainer').fadeIn('slow');
		// $('#lightBox').width($('#lightBoxPage1').width());
		$('#close').slideDown('slow');
		if (($('#lightBox').height() + 50) > $(window).height()) {
			
			$('#lightBoxBg').height($(document).height() + 60);
			$(window).resize(function() {
			
				if ($(document).height() > $(window).height()) {
					
					$('#lightBoxBg').height($(document).height());
				
				} else {
					
					$('#lightBoxBg').height($(window).height());
					
				}
		
			}); 
			
		}
		
		return false;
		
	});
	
	$('#close').click(function() {
																		 
		$('#close').slideUp('slow');
		$('#lightBoxBg').fadeOut('slow');
		$('#lightBoxContainer').fadeOut('slow');
		$('#lightBoxContainer').queue(function() {
																					 
			$('#lightBoxPage2').css('display', 'none');
			$('#lightBoxPage1').css('display', 'block');
			$('#lightBox').width(442);
			$(this).dequeue();
			
		});
		
		return false;
			
	});
																			
});

