var journals = function() {
    return {
        init : function() {
            $('form').not("#main_search_box").not("[name=journal_search_form]").submit(function() {
                    return false;
                });

            $('.email').each(function() {
                    var href = $(this).attr('href');
                    $(this).attr('href', '');
                    $(this).attr('freh', href);
                    $(this).click(function() {
                            document.location.href = $.rotate13($(this).attr('freh'))
                            return false;
                        });
                });

            if($.uri.segment(2) == 'article' || $.uri.segment(3) == 'preview_full_text') {
                $("a[rel^='prettyPhoto']").prettyPhoto({
                        animation_speed:'fast',
                        show_title:false
//                        theme:'dark_rounded'
                    });


		/*****************  for full_text *****************/
		if($('#full_text').length){
		    
		    $('title').each(function(){
			var asHtml = '<b>'+$('<div>').html($(this).html()).text()+'</b>';
			$(this).replaceWith(asHtml);
		    });

		    var pageWidth = 'auto';
		    if(document.body.clientWidth < 3000){ pageWidth ='1250px'}
		    $('body').css('width', pageWidth);
		    $('img[role!=""]').click(function() {
			var div_id = $(this).attr('role');
			$(div_id).toggle();
			if($(div_id).css('display') == 'none'){
			    $('img[role="'+div_id+'"]').attr('src', '/icons/add.png');
			}else{
			    $('img[role="'+div_id+'"]').attr('src', '/icons/delete.png');
			}
		    });
		    
		    //load figures
		    $('fig[fig-type != "video"]').each(function() {
			if(!$(this).hasClass('loaded_img')){
			    var fig_name = $('graphic', this).attr('href');
			    var img_src = '/article_figure/journals/'+$('#journal_short_name').val()+'/'+fig_name;
			    $(this).prepend('<div style="text-align:center;"><a href="'+img_src+'"><img src="'+img_src+'" align="middle" style="margin:4px;"/></a></div>');
			    $(this).wrap('<div style="background:#f2faf8;border:1px solid #DDD; padding:10px 12px; margin:30px 0px;"/>');
			    //$(this).find('img').width($('#full_text').width());
			    $(this).addClass('loaded_img');
			}
		    });
		    $('fig').find('a').prettyPhoto({
			animation_speed:'fast',
			show_title:false
                    });

		    //load videos
		    $('fig[fig-type="video"]').each(function() {
			if(!$(this).hasClass('loaded_img')){
			    var fig_name = $('graphic', this).attr('href');
			    var label = $(this).find('label');
			    if($(this).find('caption').size()) {label.text('See '+label.text())}
			    label.css('cursor', 'pointer');
			    label.wrap('<xref rid="'+fig_name.replace('.', '\\.')+'">');
			    $(this).addClass('loaded_img');
			    if(!$(this).find('caption').size()) {
				label.after('<br/>');
			    }
			}
		    });

		    //load equations
		    $('disp-formula graphic').each(function() {
			if(!$(this).hasClass('loaded_img')){
			    var equ_name = $(this).attr('href');
			    var img_src = '/article_figure/journals/'+$('#journal_short_name').val()+'/'+equ_name;
			    //$(this).wrap('<div style="background:#f2faf8;border:1px solid #DDD; padding:10px 12px; margin:30px 0px;"/>');
			    $(this).after('<div style="text-align:center;"><img src="'+img_src+'" align="middle" style="margin:4px;"/></div>');
			    //$(this).find('img').width($('#full_text').width());
			    $(this).addClass('loaded_img');
			}
		    });
		    $('inline-graphic').each(function() {
			if(!$(this).hasClass('loaded_img')){
			    var equ_name = $(this).attr('id');
			    if(!equ_name) equ_name = $(this).attr('href');
			    var img_src = '/article_figure/journals/'+$('#journal_short_name').val()+'/'+equ_name;
			    //$(this).wrap('<div style="background:#f2faf8;border:1px solid #DDD; padding:10px 12px; margin:30px 0px;"/>');
			    $(this).after('<img src="'+img_src+'" style="margin:4px;vertical-align:text-bottom;"/>');
			    //$(this).find('img').width($('#full_text').width());
			    $(this).addClass('loaded_img');
			}
		    });

		    
		    $('xref, #jump_button, #step_top, #step_back').css('cursor', 'pointer').css('color', $('.landes_content_center a').css('color')).css('font-weight', 'bold');
		    $('xref').click(function(){
			document.last_position = $(this).offset().top-40;
			var rid = $(this).attr('rid');
			$(window).scrollTop($('#'+rid).offset().top);
			$('#step_back').fadeIn();
			$('#step_back').click(function(){
			    $(window).scrollTop(document.last_position);
			    $('#step_back').fadeOut();
			});
		    });
		    $('.section_title').css('color', $('.j_color1').css('color'));
		    $(window).scroll(function(){
			if((window.pageYOffset > window.innerHeight)){
			    $('#step_top').fadeIn();
			}else{
			    $('#step_top').fadeOut();
			}
		    });
		    $('#step_top').click(function(){
			$(window).scrollTop(0);
		    });
		    document.jump_height = $('#section_jump').height();
		    document.jump_width = $('#section_jump').width();
		    $('#section_jump td:not(#jump_button)').hide();
		    $('#jump_button').click(function(){			
			$('#section_jump').animate({			    
			    height: $('#section_jump').height() > 81 ? 80 : document.jump_height,
			    opacity: $('#section_jump').css('opacity') < 10 ? 10 : 0.4
			}, 200, function(){
			    if($('#section_jump td:not(#jump_button)').css('display') == 'none'){
				$('#section_jump td:not(#jump_button)').toggle('slow');
				$('#jump_text').html('Close');
			    }else{
				$('#section_jump td:not(#jump_button)').toggle(); 
				$('#jump_text').html('Jump to Section');
			    }
			});
		    });
		    $('#section_jump li').css('cursor', 'pointer').css('color',  $('.landes_content_center a').css('color'));
		    $('#section_jump li').click(function(){
			var div_class = $(this).find('img').attr('role');
			$(window).scrollTop($($(div_class).prevAll('h4')[0]).offset().top - 20);
		    });
		    $('table-wrap').wrap('<fieldset/>');
		    /*$('table-wrap title').each(function(){
			$(this).text($("<div/>").html($(this).text()).text());
		    });*/
		    $('#full_text').width($('#landes_content_east').position().left - $('#full_text').position().left - 40).attr('align', 'justify').css('float', 'left');
		}
		/*****************  end full_text *****************/

                $(".show_email_page_button").click(function() {
                        $("#email_window").show();
                    });

                $(".cancel_email_button").click(function() {
                        $("#email_window").hide();
                    });

                $(".send_email_button").click(function() {
                        name = $("[name=recipient]").val();
                        if(name == '') {
                            alert("Please enter an email address to send this article to.");
                            return false;
                        }

                        title = $("#article_title").text();
                        link = $("#article_url").val(); 
                        nl = "\n";

                        body = "The following article appears in Volume "+$("#volume").val()+", Issue "+$("#issue").val()+" of "+$("#journal_name").val()+":"+nl+nl+title+nl+nl+link;

                        $("#email_window").hide();
                        mailto = name+"?subject="+escape(title)+"&body="+escape(body);
                        document.location.href = "mailto:"+mailto;
                    });

                $(".author_toggle").click(function() {
                        $(".author_toggle").toggle();
                        $("#author_fulllist").toggle();
                    });
            }
        }
    }
}();
$(journals.init); 

 

