

function zebraThis(id, tag, color){
    var zebra = document.getElementById(id);
    var zebras = zebra.getElementsByTagName(tag);
    for (var i = 0; i < zebras.length; i++) { 
        if(i%2 ==1){
        zebras[i].style.backgroundColor =color;
        }

    }
}



function articleImages(){

    $("div.block").css("clear", "both");
    $("div.block").next(":not(.image), :not(.imageleft)").css("display", "block").css("clear", "both");
    $("div.block").next().next(":not(.image), :not(.imageleft)").css("display", "block").css("clear", "both");
    
 
    
    $("table.image, table.imagestack, table.sidebar, div.image, div.imageleft, div.imagecenter").each(function(){
      
        if($(this).find("img").get(0)!=undefined){
        
            var widthdefined = false;
           
            if($(this).attr("width")){ 
                widthdefined = true;
                //$(this).css("width", $(this).attr("width") + "px");
                $(this).width($(this).attr("width"));
            }
            if($(this).attr("style")){
                if($(this).attr("style").indexOf("width") >=0){
                        widthdefined = true;
                }
            } 
            if(!widthdefined ){
            $(this).css("width", $(this).find("img").eq(0).width()+ 6 + "px");
            //   $(this).css("width", parseInt($(this).find("img").eq(0).css("width"))+ 6 + "px");
            } 
            
          
            if($(this).find("img").eq(0).next().attr("src") == $(this).find("img").eq(1).attr("src") && $(this).find("img").eq(1).attr("src") != undefined){  
               $(this).find("img").eq(0).css("display", "inline");
               $(this).find("img").eq(1).css("display", "inline");
               $(this).css("width",  $(this).find("img").eq(0).width()+  $(this).find("img").eq(1).width()+ 23 + "px");
            }
               
        }
      
        $(this).find("p").each(function(){
            if($(this).find("img").get(0)!=undefined){
                $(this).css("margin", "0").css("padding", "0");
            }
        });
        
    });
    
    

    $("table.image, table.sidebar").each(function(){
        if($(this).attr("align")=="left"){
           $(this).css("marginRight", "6px").css("clear", "left");
        }else if($(this).attr("align")=="right"){
           $(this).css("marginLeft", "6px").css("clear", "right");
        }
        
    });
    $("img.border, img.noborder, table.image img, table.sidebar img").each(function(){
        if($(this).attr("align")=="left"){
           $(this).css("marginRight", "6px");
        }else if($(this).attr("align")=="right"){
           $(this).css("marginLeft", "6px");
        }
    });
    
    $("img.border, img.noborder, table.image, table.sidebar").each(function(){
        if(($(this).attr("align")=="left" || $(this).attr("align")=="right")){
        
        if($(this).attr("style").toLowerCase().indexOf("margin-bottom")==-1)
           $(this).css("marginBottom", "6px");
        }
    });
    
    
    $("td#rightContent table").each(function(){
        if($("td#rightContent div.green").get(0)){
            //alert($(this).css("width"));
            if($(this).width() > 436 && $(this).offset().top <($("td#rightContent div.green").eq(0).offset().top + $("td#rightContent div.green").eq(0).height())){
               //$(this).css("clear", "right");
            }
        }
    });
    
    $("td#rightContent div.green, div.greenflv").each(function(){
        if(!$(this).find("li, embed, div.content, dl, h3, a").get(0)){
            $(this).css("display","none");
        }
    });
  
    $("td#rightContent div.related").each(function(){
        if($(this).find("div.relatedSmart").get(0)){
        
        }else if($(this).find("a, p").get(1) && $(this).find("a, p").get(1)!=""){
          
        }else if(!$(this).find("a, p").get(0) || $(this).find("a, p").get(0)==""){
            //$(this).prev("hr").css("display","none");
            
			if($.browser.msie){
				$(this).prev().prev("hr").css("display","none");
			}else{
				$(this).prev("hr").css("display","none");
			}
			$(this).css("display","none");
        }else if($(this).find("a").eq(0).attr("href")==undefined){
            $(this).prev("hr").css("display","none");
            $(this).css("display","none");
        }else {
            
        }
    });
    
   
     $("div#ContentBlock1 > p").each(function(i){
        
        var innercontent = jQuery.trim($(this).html());
        innercontent = innercontent.replace(/&nbsp;/,"");
        if(innercontent == "" && $(this).attr("class") == undefined && $(this).attr("style") == undefined){
            if(i==0){
                $(this).css("height", "1px").css("overflow", "hidden").css("margin", 0).css("padding", 0);
                
            }else if($(this).next().get(0)){
                if($(this).next().get(0).tagName){
                if($(this).next().get(0).tagName.toLowerCase() == "table"){
                    $(this).css("display", "none");
                }
                }
            }
        }else if(innercontent == "" && ($(this).attr("class") == "clearleft" || $(this).attr("class") == "clearright")){
            $(this).css("height", "1px").css("overflow", "hidden").css("margin", "0").css("padding", "0");
        }
    });
    
    $("div#ContentBlock1 > ul, div#ContentBlock1 > ol").each(function(i){
        $(this).wrap("<div></div>");
        $(this).find("li").eq(0).prepend("<img src='/templateImgs/spacer.gif' style='border:none; padding:0; margin:0; float:left;'/>");
        var theDiff = 0;
        
         if($.browser.msie){
           theDiff = $(this).find("li img").eq(0).offset().left - $(this).eq(0).offset().left;
        }else if($.browser.mozilla){
           theDiff = $(this).find("li img").eq(0).offset().left - $(this).eq(0).offset().left - parseInt($(this).css("paddingLeft"));
        }
        if(theDiff>0){
           $(this).parent().css("marginLeft", (theDiff + 20) + "px");
        }
        
    });
  
  
}


function headerSpacing(){ 
    if(window.location.href.indexOf("voices_article")!=-1 && window.location.href.indexOf("pagenotfound")==-1){
        $("td#rightContent div.contentTop").eq(0).height($("td#rightContent h2").eq(0).height()+10);
        $("td#rightContent h2").eq(0).css("top", "-"+($("td#rightContent h2").eq(0).height()+10)+"px");
    }
	
    if(window.location.href.indexOf("content")!=-1 || window.location.href.indexOf("ssjournal")!=-1 || window.location.href.indexOf("people_detail")!=-1){
        $("td#rightContent div.contentTop").eq(0).css("paddingTop", ($("td#rightContent div#ContentBlock1 h2").eq(0).height()+10)+"px");
        $("td#rightContent div#ContentBlock1 h2").eq(0).css("top", "-"+($("td#rightContent div#ContentBlock1 h2").eq(0).height()+10)+"px");
    }
	
}

$(document).ready(function(){

    if(readCookie("seedLang")=="1025"){
		/*
        $("td#rightContent").find("img, table").each(function(i){
            if($(this).attr("align").toLowerCase()=="left"){
                $(this).attr("align", "right");
            }else if($(this).attr("align").toLowerCase()=="right"){
                $(this).attr("align", "left");
            }
        });
		*/
		$("td#rightContent").find("table.image, table.imagestack, img").each(function(){
																				  if($(this).attr("align").toLowerCase()=="left"){
                $(this).attr("align", "right");
            }else if($(this).attr("align").toLowerCase()=="right"){
                $(this).attr("align", "left");
            }
																				 });
		
		$("td#rightContent").find(".clearleft").each(function(){
			$(this).css("clear", "right");		
		});
		$("td#rightContent").find(".clearright").each(function(){
			$(this).css("clear", "left");		
		});
		
    }
    
   articleImages();
   headerSpacing();
   $("div.experts").css("cursor", "pointer").click(function(){
        
        window.location = $("div.experts a").eq($("div.experts a").length-1).attr("href");
   });
   
    $("ul#navlang a").mouseover(function(){
        $(this).addClass("active");
    });
    $("ul#navlang a").mouseout(function(){
        $(this).removeClass("active");
    });
    
    
    
});

