//document.write("<style type='text/css'>#favoriteLinks {display:none}</style>");addLoadEvent(shareInit);addLoadEvent(prepareEmail);addLoadEvent(moveFavoriteLinks);var imageSources=new Array("/environment/assets/images/icons/newsvine.gif","/environment/assets/images/icons/facebook.gif","/environment/assets/images/icons/digg.gif","/environment/assets/images/icons/delicious_sm.gif");var nextImage=0;var nextText=1;var imageTimeout=2000;var timeout=null;showing=false;function moveFavoriteLinks(){var A=document.getElementById("favoriteLinks");A.style.margin="0px";}function swapImage(){var A=document.getElementById("sharePlaceholder");nextImage++;if(nextImage==imageSources.length){nextImage=0}A.setAttribute("src",imageSources[nextImage])}function shareInit(){var C=3000;alert("shareInit being called");var B=document.getElementById("sharePlaceholder");B.onclick=function(){popUpLinks();if(showing){timeout=setTimeout(popUpLinks,C)}else{clearTimeout(timeout)}};var A=document.getElementById("share");A.onclick=function(){popUpLinks();if(showing){timeout=setTimeout(popUpLinks,C)}else{clearTimeout(timeout)}};var popupDiv=document.getElementById('favoriteLinks');popupDiv.onmouseover=function(){clearTimeout(timeout);};popupDiv.onmouseout=function(){timeout=setTimeout(popUpLinks,2000);};setInterval(swapImage,imageTimeout)}function popUpLinks(){if(showing){showing=false}else{showing=true}var A=document.getElementById("favoriteLinks");A.style.display=(A.style.display!="block"?"block":"none")}function prepareEmail(){function B(){var G=location.href;var C=document.title;var E="Your friend wants you to check out "+C;var F="Read the entire article at "+G;var D="mailto:?subject="+E+"&body="+F;win=window.open(D,"emailWindow");if(win&&win.open&&!win.closed){win.close()}}if(document.getElementById){var A=document.getElementById("email_this_article");A.onclick=function(){B();return false}}}
document.write("<style type='text/css'>#favoriteLinks {display:none}</style>");function addLoadEvent(shareInit){};function addLoadEvent(prepareEmail){};function addLoadEvent(moveFavoriteLinks){};var imageSources=new Array("/environment/assets/images/icons/newsvine.gif","/environment/assets/images/icons/facebook.gif","/environment/assets/images/icons/digg.gif","/environment/assets/images/icons/delicious_sm.gif");var nextImage=0;var nextText=1;var imageTimeout=2000;var timeout=null;showing=false;function moveFavoriteLinks(){var A=document.getElementById("favoriteLinks");A.style.margin="0px";};function swapImage(){varA=document.getElementById("sharePlaceholder");nextImage++;if(nextImage==imageSources.length){nextImage=0;}A.setAttribute("src",imageSources[nextImage]);};function shareInit(){var C=3000;alert("shareInit being called");varB=document.getElementById("sharePlaceholder");B.onclick=function(){popUpLinks();if(showing){timeout=setTimeout(popUpLinks,C);}else{clearTimeout(timeout);}};varA=document.getElementById("share");A.onclick=function(){popUpLinks();if(showing){timeout=setTimeout(popUpLinks,C);}else{clearTimeout(timeout);}};var popupDiv=document.getElementById('favoriteLinks');popupDiv.onmouseover=function(){clearTimeout(timeout);};popupDiv.onmouseout=function(){timeout=setTimeout(popUpLinks,2000);setInterval(swapImage,imageTimeout);};function popUpLinks(){if(showing){showing=false;}else{showing=true;}var A=document.getElementById("favoriteLinks");A.style.display=(A.style.display!="block"?"block":"none");};function prepareEmail(){function B(){var G=location.href;var C=document.title;var E="Your friend wants you to check out "+C;var F="Read the entire article at "+G;var D="mailto:?subject="+E+"&body="+F;win=window.open(D,"emailWindow");if(win&&win.open&&!win.closed) { win.close() }};if(document.getElementById){var A=document.getElementById("email_this_article");A.onclick=function(){B();return false;}}}
// hide the article gallery initially
document.write("<style type='text/css'>#article_gallery{display:none;visibility:hidden;}</style>");

// function to you guessed it... prepare the image gallery for article pages
function prepare_gallery(){
    if(!document.getElementsByTagName) return false;
    if(!document.getElementById) return false;
    if(!document.getElementById('article_gallery')) return false;
    
    //grab the article_gallery div
    var gallery = document.getElementById('article_gallery');
    
    //grab all the links and images within that div, at launch there will likely only be one link and one image
    var gLinks = gallery.getElementsByTagName('a');
    var gImages = gallery.getElementsByTagName('img');
    
    
    var num_images = gLinks.length;
    
    //if there are no images exit
    if(num_images==0)return;
    //if there are more than 6 images we hide the extras
    if(num_images>6){
        num_images=6;
        for(var i=6; i<gLinks.length; i++){
            gLinks[i].style.visibility="hidden";
            gLinks[i].style.display="none";
        }
    }
    
    //if there is only one image, we hide the thumbnail of it
    if(num_images===1){
        gLinks[0].style.visibility="hidden";
        gLinks[0].style.display="none";
    }
    
    //grab the href of the anchor tag, which should be a reference to a large image
    var link_source=gLinks[0].getAttribute("href");
    var link_title=gLinks[0].getAttribute("title");
    
    //grab the href and the alt of the image tag, which should be a reference to a medium image
    var image_source=gImages[0].getAttribute("src");
    var image_alt=gImages[0].getAttribute("alt");
    
    //grab the placeholder link
    var placeholder=document.getElementById("galleryPlaceholder");
    
    //create an image element, with the medium src and alt, size, and append it to the placeholder link
    var placeimage=document.createElement('img');
    placeimage.setAttribute("src",image_source);
    placeimage.setAttribute("alt",image_alt);
    placeimage.setAttribute("width","257");
    placeimage.setAttribute("height","169");
    placeholder.appendChild(placeimage);
    
    //show the placeholder now
    placeholder.style.display ="block";
    placeholder.style.visibility ="visible";
    
    //grab the caption p tag and put in the medium images alt tag, and display it
    if(document.getElementById("galleryCaption")){
        var description = document.getElementById("galleryCaption");
        description.firstChild.nodeValue=link_title;
        description.style.display="block";
        description.style.visibility="visible";
    }

    //compare the link and images sources, if they are the same ie "something_med.jpg", then dont put in the zoom, but if they are different ie one is for "somethign_large.jpg", then put in the zoom
    var regex = new RegExp(image_source);
    var zoom=document.getElementById("galleryZoom");
    
    if(!link_source.match(regex)){
        zoom.setAttribute("href",link_source);
        zoom.style.visibility="visible";
        zoom.style.display="block";
        alert("attaching href to placeholder link : "+link_source);
        //if large image exists link, set placeholder link to it.
        placeholder.setAttribute("href",link_source);
    } else {
        zoom.style.display="none";
        zoom.style.visibility="hidden";
        //no large image so placeholder doesn't link anywhere
        placeimage.style.cursor ="default";
        placeholder.style.cursor="default";
        placeholder.onclick=function(){return false;}
    }
    
    //attach onclick events to all the thumbnails
    for(var i=0; i<num_images; i++){
        gLinks[i].onclick = function(){
            showPic(this);
            return false;
        }
    }
    
    //onclick function which changes out the placeholder image, puts in a zoom if needed
    function showPic(whichpic){
        
        //link_source is large image, image_source is medium image
        var link_source=whichpic.getAttribute("href");
        var link_title=whichpic.getAttribute("title");
        
        var placeholder=document.getElementById("galleryPlaceholder");
        var placeholder_img=placeholder.getElementsByTagName("IMG");
        
        var image=whichpic.getElementsByTagName("img");
        var image_source=image[0].getAttribute("src");
        var image_alt=image[0].getAttribute("alt");
        
        placeholder_img[0].setAttribute("src",image_source);
        placeholder_img[0].setAttribute("alt",image_alt);
        
        //hide/show zoom as needed
        var regex = new RegExp(image_source);
        var zoom=document.getElementById("galleryZoom");
        
        if(!link_source.match(regex)){
            if(document.getElementById("galleryZoom")){
                alert("regex did no match");
                
                zoom.setAttribute("href",link_source);
                zoom.style.visibility="visible";
                zoom.style.display="block";
                //if there is a large, link to it
                placeholder.setAttribute("href",link_source);
                placeholder_img[0].style.cursor="pointer";
                placeholder.style.cursor="pointer";
                placeholder.onclick=function(){};
            }
        } else {
            alert("regex did match");
            if(document.getElementById("galleryZoom")){
                zoom.style.display="none";
                zoom.style.visibility="hidden";
                //no large so placeholder doesn't link anywhere
                placeholder_img[0].style.cursor="default";
                placeholder.style.cursor="default";
                placeholder.onclick=function(){return false;}
            }
        }
        
        //change out the caption
        if(document.getElementById("galleryCaption")){
            var description=document.getElementById("galleryCaption");
            description.firstChild.nodeValue=link_title;
        }
        return false;
    }
    //show the gallery
    gallery.style.display="block";
    gallery.style.visibility="visible";
}
function addLoadEvent(prepare_gallery){};
};