$(document).ready(function(){

   var readOnce=false;
   
   function hideElements(){
    
       // hide non wmode elements
       $("#ipEvideo-module").css("display","none");
       if(jQuery.browser.msie){
            $.scrollTo(0);
        }
     
      // hide the objects and embeds
      $("embed").css("display","none");
      $("object").css("display","none");
  
      // hide trans gifs and misc
      $("#aroundTheWorld").css("display","none");
   }
   
   function showElements(){
   
        // show the elements which we hid
        $("#ipEvideo-module").css("display","block");
        
        if(jQuery.browser.msie){
            $.scrollTo( $("a[href='" + url + "']") );
        }
        
        // hide our content div
        $("#eweekexpress").css("display","none");

        // hide the objects and embeds
        $("embed").css("display","block");
        $("object").css("display","block");

        // show misc and trans gif
        $("#aroundTheWorld").css("display","block");
   }
   
   
   $('a').click(function(e) {
        
        
        // if we have displayed our modal once, don't do it again
        if (readOnce){
            return;
        }
        
        // if this is not a Security article, do nothing
        if(this.href.indexOf('/c/a/')==-1){
            return;
        }
        
        // cancel the click
        e.preventDefault();
 
        // save the url
        url = this.href;
        
        // get the target
        url_parts = url.split("/");
        target_page=url_parts[url_parts.length-2];
        
        // ajax server
        var ajax_endpoint = "http://www.eweek.com/index2.php?option=com_eweekexpress&no_html=1&target_page=" + 
                             target_page;
    
        // get the article info
        $("#eweekexpress").load(ajax_endpoint,
        function (e){
        
            // set this article to read
            readOnce=true;
            
            // for IE, we need to scroll to the top and then back again
            // after the close button is clicked
            if(jQuery.browser.msie){
                settings = {
                 bgColor: '#3333cc',
                 width:645,
                 closeSelector: '#eweek_express_close',
                 content: $("#eweekexpress").html(),
                 processHandler: hideElements,
                 endRemove: showElements,
                 padding: 0
                }
            }else{
                settings = {
                 bgColor: '#3333cc',
                 width:644,
                 closeSelector: '#eweek_express_close',
                 content: $("#eweekexpress").html(),
                 processHandler: hideElements,
                 endRemove: showElements
                }
            }
        
           // display the modal
           $.nyroModalManual(settings);
            
            // set the click for reading the full story
            $(".eweek_express_title").click(function(e){e.preventDefault();location.href=url});
            $(".readstory").click(function(e){e.preventDefault();location.href=url});

        });
    
  });
  
});
