function popUp(URL)
{
	
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=800,height=600,left = 440,top = 125');");
	
}

$.swapImage(".swapImage");

$(document).ready(function(){
						   
	if ( $.browser.msie )
	{ 
 
		$("ul#menu img.over").css({'display':'none'});
	
	 
		$('ul#menu a').live('mouseover',function(){
				
			$(this).children('img.live').stop().fadeOut(500);
			$(this).children('img.over').stop().fadeIn(500);
			
		}).live('mouseout',function(){
			
			$(this).children('img.live').stop().fadeIn(500);
			$(this).children('img.over').stop().fadeOut(500);
			
		});
	
	}
	else
	{
 
		$("ul#menu img.over").css({'opacity':'0'});
	
	 
		$('ul#menu a').live('mouseover',function(){
				
			$(this).children('img.live').stop().animate({'opacity': '.5'}, 'slow');
			$(this).children('img.over').stop().animate({'opacity': '1'}, 'slow');
			
		}).live('mouseout',function(){
			
			$(this).children('img.live').stop().animate({'opacity': '1'}, 'slow');
			$(this).children('img.over').stop().animate({'opacity': '0'}, 'slow');
			
		});
	
	}
	
	
						   		   
	//When you click on a link with class of poplight and the href starts with a # 
	$('a.poplight[href^=#]').click(function() {
		
		var popID = $(this).attr('rel'); //Get Popup Name

		//Fade in the Popup and add close button
		$('#' + popID).fadeIn().prepend('<a href="#" class="popup-close"><img src="/images/close.png" width="52" height="84" id="popup-close" class="btn_close swapImage {src: \'/images/closeRO.png\'}" title="Close Window" alt="Close" /></a>');
		
		$('html, body').animate({scrollTop:0}, 'slow');
	
		$.swapImage(".swapImage");
		
		$('body').append('<div id="page-fade"></div>'); //Add the fade layer to bottom of the body tag.
		$('#page-fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer 
		
		return false;
		
	});
	
	
	//Close Popups and Fade Layer
	$('a.popup-close, img#popup-close').live('click', function() { //When clicking on the close or fade layer...
																   
	  	$('#page-fade , .popup_block').fadeOut(function() {
			$('#page-fade, a.popup-close').remove();  
		}); //fade them both out
		
		return false;
		
	});
 
});


function tellFriends()
{
		
	$('#tell-friends-loading').fadeIn();	
	$('html, body').animate({scrollTop:0}, 'slow');
	$('#tell-your-friends-content').append('<div id="tell-friends-fade"></div>');
	$('#tell-friends-fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer 
	
	var name = $('#t_name').val();	
	var email = $('#t_email').val();
	var msg = $('#t_msg').val();
	var friends = $('#t_friends').val();
	
	$.swapImage(".swapImage");	
	
	$.ajax({
		type: "POST",
		url: "/includes/eventHandler.php",
		data: 'mode=send-to-friend&name='+name+'&email='+email+'&friends='+friends+'&msg='+msg,
		success: function(data){
			
			//alert(data);
		   
			if(data == 0)
			{
						
				// FAILED
				jAlert('There was an error.  Please try again.','Error');
				closeLoading();	
			
			}
			else if(data == 1)
			{
				
				// SUCCESS		
				closeLoading();	
				
				//$('a.popup-close').trigger('click');
				
				jAlert('Emails have been sent your friends.','Thank You!');
			
			}
			else
			{
						
				// FAILED
				jAlert('There was an error.  Please try again. '+data,'Error');
				closeLoading();	
			
			}
	   },
		error : function(request, textStatus, errorThrown) {
			
			var process = '';
			
			switch (request.readyState)
			{
				
				case 1:
					process = 'loading';
					break;
				
				case 2:
					process = 'loaded';
					break;
				
				case 3:
					process = 'interactive';
					break;
				
				case 4:
					process = 'complete';
					break;
				
				
			}
			
			var status = '';
			
			switch (request.status)
			{
			
				case 400:
					status = 'Bad Request';
					break;
					
				case 401:
					status = 'Permission Error';
					break;
					
				case 403:
					status = 'Forbidden';
					break;
					
				case 404:
					status = 'Not Found';
					break;
					
				case 405:
					status = 'Action Forbidden';
					break;
					
				case 408:
					status = 'Time Out';
					break;
					
				case 500:
					status = 'Internal Error';
					break;
					
				default:
					status = 'Unspecified';
					break;
				
				
			}
			
			jAlert(' There was an error. Process - '+process+' Status - '+status,'Error');
		}
	 });
	
	return false;
	
}

function closeLoading()
{
															   
	$('#tell-friends-fade, #tell-friends-loading').fadeOut(function() {
		$('#tell-friends-fade').remove();  
	}); //fade them both out
	
}
