$(document).ready(function() {
	
	

    $('#uutiskuva').click(function() {
		$(this).parents("a").lightBox({imageBtnClose: '../hallinta/site_img/sulje.gif', overlayOpacity: 0.6});
		//alert('v');
    });

	$('#send_emails').click(function() {
										
		var data = '';
		var email1 = document.getElementById('email1').value;
		var email2 = document.getElementById('email2').value;
		var email3 = document.getElementById('email3').value;
		var email4 = document.getElementById('email4').value;
		var email5 = document.getElementById('email5').value;
		
		var f_name = document.getElementById('f_name').value;
		var topic = document.getElementById('news_topic').value;
		var href = location.href;
		
		
		data += 'email1='+email1+'&email2='+email2+'&email3='+email3+'&email4='+email4+'&email5='+email5+'&topic='+topic+'&href='+href+'&name='+f_name;
		
		
		$.ajax({
		type: "POST",
		url: "send_emails.php",
		data: data,
			success: function(msg){
				
				
				document.getElementById('email_friend').title='';
				$('#emails').fadeOut('slow', function() {
					$('#emails_sent')
						.fadeIn("slow")
						.animate({opacity: 1}, 5000)
						.fadeOut("slow");
				});
			}
		});
	
	});
	
	$('#email_friend').click(function() {
		
		var title = document.getElementById('email_friend').title;
		
		if (title == '') {
		
			document.getElementById('email_friend').title='sulje';
			$('#emails').slideDown('slow');
		}
		else {
			$('#emails').fadeOut('slow');
			document.getElementById('email_friend').title='';		
	
		}
		
 	});
	$('#imageee').click(function() {	
		$('<div class="fade" id="NEWS"></div>')
			
			.animate({opacity: 0.7}, 100)
 		    .insertAfter( $('#image'))
						
			.fadeIn('slow', function () {
									  
			//$("#black")
				//.animate({opacity: 0.8}, 10);
				
			var s = (screen.width / 2) - 365;
					
				$('<div class="news_div" id="news"></div>')
					.insertAfter( $('#NEWS') )
					.css({left:s})
					.fadeIn('slow')
					.animate({opacity: 1}, 1);
					//.animate({opacity: 0.2}, 1000)
					//.animate({opacity: 1}, 1000);
				
				
					
				$(".close_news")
					.css({display:"block"});					
				$(".close_news")					
					.appendTo($("#news"));
			
			
				
			});
		
 	});
	
	$('.close_news').click(function() {	
		
					
		$('.news_div').css({display:"none"});
		$(".close_login").css({display:"none"});
		
	    $('.fade')			
			.animate({opacity: 0.1}, 300, function() {
				
				$('.fade')
					
					.css({display:"none"});	
				
			});
	});
	/*
	$('#uutiskuva').click(function() {	
		/*
		var img_temp = document.getElementById('uutiskuva').src;
		var img = img_temp.split("_");
		//alert('../hallinta/news_img/orig_'+img[2]);
		var orig_img = '../hallinta/news_img/orig_'+img[2];
		
		$('<div class="fade" id="NEWS"></div>')
			
			.animate({opacity: 0.7}, 100)
 		    .insertAfter( $('#top'))
						
			.fadeIn('slow', function () {
		
		
		$("#view_original_image")				
			.appendTo($("#NEWS"));
		$('#view_image_close')
			.appendTo($("#view_original_image"))
			.css({display:"block"});	
		$('<img id="original_image" src="'+orig_img+'" />')
			.appendTo($("#view_original_image"));
			//.slideDown("fast");
		$("#view_original_image")
			.fadeIn("fast");
		});
			var img_temp = this.src;
		var img = img_temp.split("_");
		//alert('../hallinta/news_img/orig_'+img[2]);
		var orig_img = '../hallinta/news_img/orig_'+img[2];
		
		$('<div class="fade" id="NEWS"></div>')
			
			.animate({opacity: 0.7}, 100)
 		    .insertAfter($('#top'))
						
			.fadeIn('slow', function () {
		
		$('<div id="img_pohja"></div>')
			.insertAfter( $('#NEWS') )
			//.css({left:sc})
			.fadeIn('slow')
			.animate({opacity: 1}, 1);
		$("#view_original_image")
		
			.appendTo($("#img_pohja")).css({display:"block"});	
		$('#view_image_close')
			.appendTo($("#img_pohja"))
			.css({display:"block"});	
		$('<img id="original_image" src="'+orig_img+'" />')
			.appendTo($("#img_pohja"));
			
		});	
	});*/
	$('#view_image_close').click(function() {	
		
		$("#view_original_image").css({display:"none"});
		$("#original_image")
			.remove();
		$('#view_image_close').css({display:"none"});
		$('#img_pohja').css({display:"none"});
	    $('.fade')			
			.animate({opacity: 0.1}, 300, function() {
				
				$('.fade')
					
					.css({display:"none"});	
				
			});
	});
	$('.uutiskuva').click(function() {	
		
		$(this).parents("a").lightBox({imageBtnClose: '../hallinta/site_img/sulje.gif', overlayOpacity: 0.6});
	});
	
	$('#hae_uutisia').click(function() {	
		
		var keyword = document.getElementById('search_input').value;
		
		if (keyword != '' && keyword != 'Anna hakusana') {
			document.search_form.submit();
		}
		else {
			document.getElementById('search_input').value="Anna hakusana";		
		}
	});

	$('#search_input').focus(function() {	
		
		var keyword = document.getElementById('search_input').value;
		
		if (keyword == 'Anna hakusana') {
			document.getElementById('search_input').value="";
			$('#search_input').css({color:"#000000"});
		}
	});
	$('#search_input').blur(function() {	
		
		var keyword = document.getElementById('search_input').value;
		
		if (keyword == '') {
			$('#search_input').css({color:"#cccccc"});
			document.getElementById('search_input').value="Anna hakusana";		
		}
	});
	$('#image').click(function() {	
		
		window.location = 'http://www.eliteonline.fi/AGI/';
	});
});


