// jQuery code for all subpages

jQuery(function($){
	
	$('a[href=galaxy://print_this_page/]').click(function(e){
		e.preventDefault();
		window.print();
	});
	
	$('a[href=galaxy://tab/]').click(function(e){
		e.preventDefault();
		$('a[href=galaxy://tab/]').removeClass('current');
		$(this).addClass('current');
		var index = $("a[href=galaxy://tab/]").index(this);
		$('.tab_content').hide('fast');
		$('.tab_content:eq('+index+')').show('fast');
	});
	
	$('a[href=galaxy://send_this_to_a_friend/]').click(function(e){
		e.preventDefault();
		if ($('.email_form_container').is(':hidden')) {
			$('.email_form_container').stop(true,true).slideDown('slow');
		} else {
			$('.email_form_container').stop(true,true).slideUp('slow');
		}
	});
	
	$('#email_to_friend').submit(function(e){
		e.preventDefault();
		$('a[href=galaxy://send_friend_form/]').click();
	});
	
	$('a[href=galaxy://send_friend_form/]').click(function(e){
		e.preventDefault();
		var str = '#email_to_friend';
		var email  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if ($(str+' #my_name').attr('value')=='') {
			alert('You must enter your name');
			$(str+' #my_name').focus();
			return false;
		}
		if (!$(str+' #to').attr('value').match(email)) {
			alert('You must enter the email address you want to send this to');
			$(str+' #to').focus();
			return false;
		}
		var data = {my_name:$(str+' #my_name').attr('value'),to:$(str+' #to').attr('value'),message:$(str+' #message').val(),url:$(str+' #url').attr('value')}
		$.post($('#email_to_friend').attr('action'),data,function(){alert('Email successfully sent.');$('.email_form_container').stop(true,true).slideUp('slow');});
	});
	
	if ($('a[href=galaxy://view_image/]').length) {
		$('a[href=galaxy://view_image/]').mouseover(function(){
			$('#main_img').attr('src',$('img',this).attr('src'));
		});
		$('a[href=galaxy://view_image/]').click(function(e){
			e.preventDefault();
			$(this).mouseover();
		});
	}
	
	if ($('a[href=galaxy://view_description/]').length) {
		$('a[href=galaxy://view_description/]').click(function(e){
			e.preventDefault();
			var d = $('#description');
			var s = $('#specification');
			$('a[href=galaxy://view_specifications/]').removeClass('current');
			$(this).addClass('current');
			if (d.is(':hidden')) {
				s.fadeOut('fast',function(){d.fadeIn('fast')});
			}
		});
	}
	
	if ($('a[href=galaxy://view_specifications/]').length) {
		$('a[href=galaxy://view_specifications/]').click(function(e){
			e.preventDefault();
			var s = $('#description');
			var d = $('#specification');
			$('a[href=galaxy://view_description/]').removeClass('current');
			$(this).addClass('current');
			if (d.is(':hidden')) {
				s.fadeOut('fast',function(){d.fadeIn('fast')});
			}
		});
	}
	
});
