function validateEmail(email) { 
    var re =/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
} 

function submitNewsletter()
{
  var sex = $('input[name=sex]:checked').val(); 
  var email = $('input#email').val(); 
  var age = $('input#age').val();   
  
  if( sex && email && age )
  {  
    
	if( validateEmail(email) )
	{
	  $.get('/subscribe.php?&email='+email+'&sex='+sex+'&age='+age, function(data) {
      $('#message').html(data);
	    $("#newspopup").fadeIn().delay(2000).fadeOut();
      }); 
    }
	else
	{
	  $('#message').html("Please enter a valid email address");
	}
  }
  else
  {
     $('#message').html("Please complete every fields");
  }
}

$(document).ready(function() {

$('#newspopup .p_tl').click(function (){
		$('#newspopup').css('display','none');
	});
	
$('#newslink').click(function (){
		$('#newspopup').css('display','block');
	});
	
	
jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}

jQuery.extend({
	random: function(X) {
	    return Math.floor(X * (Math.random() % 1));
	},
	randomBetween: function(MinV, MaxV) {
	  return MinV + jQuery.random(MaxV - MinV + 1);
	}
});

/*
$.preload( '/renew/images/icon_folder_off.gif',
  '/renew/images/icon_folder_on.gif',
  '/renew/images/icon_docu_off.gif',
  '/renew/images/icon_docu_on.gif',
  '/renew/images/top_bg_l.gif',
  '/renew/images/top_bg_r.gif',
  '/renew/images/top_bg.gif'
);
*/
	/*랜덤하게 이미지 표시*/
	var files = ["pimg_1.jpg","pimg_2.jpg","pimg_3.jpg","pimg_5.gif","pimg_1b.jpg","pimg_3b.jpg"];
	var imgNumRan = $.random(files.length);
	var ranFilename= files[imgNumRan];
	var $newdiv1 = $('<div class="img_popup"><div class="popup_top"><div class="p_tl"></div></div><div class="popup_content"><a href="#"><img src="/renew/popup_img/'+ranFilename+'"/></a></div></div>');
	if($randomImage=="1"){
		$("body").append($newdiv1);
	}

	//random(#) 숫자가 높아질수록 나타나는 확률이 낮아진다
	var s = $.random(10);
	if(s>'4'){
		winWidth = $(window).width() -150;
		winHeight = $(window).height() -150;

		popup_posx=$.random(winWidth);
		popup_posy=$.random(winHeight);
		$('.img_popup').css("left",popup_posx);
		$('.img_popup').css("top",popup_posy);
		$('.img_popup').show();			
	}


	
	if($.browser.msie && $.browser.version.substring(0, 1) === "6"){
		if($('.img_popup').is(':visible')){
			var ppimgwidth = $('.img_popup img').width();
			var ppimgheight = $('.img_popup img').height();
			$('.img_popup').css("width",ppimgwidth+15);
			$('.img_popup').css("height",ppimgheight+15);
		}

	}

//	popup_posx2=100+$.random(500);
//	popup_posy2=100+$.random(100);
//	$('#mainVid').css("left",popup_posx2);
//	$('#mainVid').css("top",popup_posy2);



/*상단클릭시 얼렛창 표시*/

	$(window).resize(function() {
		$('#allertWindow').center();
	});
	$('.t1,.t2,.t3,.t4,.t5,.t6').click(function (){
		$('#allertWindow').center();
		$('#allertWindow').show();
	});

	//휴지통 동작
	var $trashPopup = $('<div id="treshWindow"><img src="images/window_tresh.gif"></div>');
	$('.f_trash').click(function (){
//		$('body').append($trashPopup);
		$('#treshWindow').center();
		$('#treshWindow').show();
	});

	//팝업 클릭시 닫기
	$('#allertWindow').click(function(){	$(this).hide();	});
	$('#treshWindow').click(function(){	$(this).hide();	});
	$('.img_popup').click(function(){	$('.img_popup').hide();	});



/*
	$('#mainVid').click(function(){
		$(this).remove();
//		$(this).hide();
	});
*/

	//work 게시판
	$('.logoImg').each(function() {
		var imgwidth = $(this).width();
		var imgheight = $(this).height();
		var tHeight = 110;
		var imgPadding = (tHeight - imgheight)/2;

		if( imgwidth  > 250){
			$(this).css("width","250px");
		}

		$(this).parent().css({"padding-top":imgPadding+"px","padding-bottom":imgPadding+"px"});
	});


});
