﻿(function($) {
  $.extend($.fx.step,{
      backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
      }
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
  });
})(jQuery);

function linkify2(textitem)
{
    if(textitem.indexOf(",") != -1)
    {
      var holdingtext = "";
      var urls_array = textitem(",");
      for(i=0;i<urls_array.length;i++) {
        if(urls_array.indexOf("http:") != -1)
          holdingtext += "<a href='" + urls_array+ "' target='_blank'>" + urls_array+ "</a>, ";
        else
          holdingtext += "<a href='http://" + urls_array+ "' target='_blank'>" + urls_array+ "</a>, ";
      }
      return holdingtext.substring(0,holdingtext.length-2);
    }
    else
    {
      if(textitem.indexOf("http:") != -1)
        return "<a href='" + textitem + "' target='_blank'>" + textitem + "</a>";
      else
        return "<a href='http://" + textitem + "' target='_blank'>" + textitem + "</a>";
    }
}

function openNewWindow() {
 popupWin = window.open(document.location.href + '?alttemplate=printtemplate',
 'open_window',
 'menubar, toolbar, location, directories, status, scrollbars, resizable, dependent, width=640, height=480, left=0, top=0')
}

function cursorOver(){
    $(this).find("ul").show("slide", { direction: "up" }, 400);
    $(this).addClass("subhover");
}

function cursorOut(){ 
    $(this).find("ul").hide("slide", { direction: "up" }, 400);
    $(this).removeClass("subhover");
}

function doSearch(){
    var searchfor = document.getElementById("txtsearch").value
    
    if (searchfor == "Projects, news & features")
        window.location = "http://" + window.location.host + "/search.aspx";
    else
        window.location = "http://" + window.location.host + "/search.aspx?search=" + searchfor;
}

function searchclearText(obj){
    if (obj.value == "Projects, news & features")
        obj.value = "";
}

function searchdefaultTextback(obj){
    if (obj.value == "")
        obj.value = "Projects, news & features";
}

var config = {     
     over: cursorOver,   
     timeout: 500,   
     out: cursorOut
};
    
$(document).ready(function(){
 
    /*$("#topnav li.mainnavitem").hoverIntent(config);*/
    $("#topnav li.mainnavitem").hover(
        function(){$(this).find("ul").css("top", "40px")},
        function(){$(this).find("ul").css("top", "-999px")}
    );
                            
    $("#socialtabs").tabs();

    $(".articleURLs").html(linkify2($(".articleURLs").text()));
    
    if ($.browser.msie)
    {
        $('img[height=""]').removeAttr('height');
        $('img[height="1"]').removeAttr('height');
    }
});



