﻿// JScript File



/*
Up down slideshow Script
By Dynamic Drive (www.dynamicdrive.com)
For full source code, terms of use, and 100's more scripts, visit http://www.dynamicdrive.com
*/



function move1(whichlayer){
    tlayer=eval(whichlayer)
    if (tlayer.top>0&&tlayer.top<=5){
        tlayer.top=0
        setTimeout("move1(tlayer)",pausebetweenimages)
        setTimeout("move2(document.main.document.second)",pausebetweenimages)
        return
    }
    if (tlayer.top>=tlayer.document.height*-1){
        tlayer.top-=5
        setTimeout("move1(tlayer)",100)
    }
    else{
        tlayer.top=parseInt(scrollerheight)
        tlayer.document.write(slideimages[i])
        tlayer.document.close()
        if (i==slideimages.length-1)
        i=0
        else
        i++
    }
}

function move2(whichlayer){
    tlayer2=eval(whichlayer)
    if (tlayer2.top>0&&tlayer2.top<=5){
        tlayer2.top=0
        setTimeout("move2(tlayer2)",pausebetweenimages)
        setTimeout("move1(document.main.document.first)",pausebetweenimages)
        return
    }
    if (tlayer2.top>=tlayer2.document.height*-1){
        tlayer2.top-=5
        setTimeout("move2(tlayer2)",100)
    }
    else{
        tlayer2.top=parseInt(scrollerheight)
        tlayer2.document.write(slideimages[i])
        tlayer2.document.close()
        if (i==slideimages.length-1)
        i=0
        else
        i++
    }
}

function move3(whichdiv){
    tdiv=eval(whichdiv)
    if (parseInt(tdiv.style.top)>0&&parseInt(tdiv.style.top)<=5){
        tdiv.style.top=0+"px"
        setTimeout("move3(tdiv)",pausebetweenimages)
        setTimeout("move4(second2_obj)",pausebetweenimages)
        return
    }
    if (parseInt(tdiv.style.top)>=tdiv.offsetHeight*-1){
        tdiv.style.top=parseInt(tdiv.style.top)-5+"px"
        setTimeout("move3(tdiv)",100)
    }
    else{
    tdiv.style.top=scrollerheight
    tdiv.innerHTML=slideimages[i]
    if (i==slideimages.length-1)
    i=0
    else
    i++
    }
}

function move4(whichdiv){
    tdiv2=eval(whichdiv)
    if (parseInt(tdiv2.style.top)>0&&parseInt(tdiv2.style.top)<=5){
        tdiv2.style.top=0+"px"
        setTimeout("move4(tdiv2)",pausebetweenimages)
        setTimeout("move3(first2_obj)",pausebetweenimages)
        return
    }
    if (parseInt(tdiv2.style.top)>=tdiv2.offsetHeight*-1){
        tdiv2.style.top=parseInt(tdiv2.style.top)-5+"px"
        setTimeout("move4(second2_obj)",100)
    }
    else{
        tdiv2.style.top=scrollerheight
        tdiv2.innerHTML=slideimages[i]
        if (i==slideimages.length-1)
        i=0
        else
        i++
    }
}

function startscroll(){
    if (ie||dom){
        first2_obj=ie? first2 : document.getElementById("first2")
        second2_obj=ie? second2 : document.getElementById("second2")
        move3(first2_obj)
        second2_obj.style.top=scrollerheight
        second2_obj.style.visibility='visible'
    }
    else if (document.layers){
        document.main.visibility='show'
        move1(document.main.document.first)
        document.main.document.second.top=parseInt(scrollerheight)+5
        document.main.document.second.visibility='show'
    }
}

window.onload=startscroll; 

function topnavAct ()
{
    if(!document.getElementById("nav_breadCrumb"))
        return;
    else{
    
    
       selectObj = document.getElementById(document.getElementById("nav_breadCrumb").value);
       selectObj.className = "select";
       if(selectObj.id.indexOf('subnav_')!=-1 && selectObj.getElementsByTagName('a')[0].rel!=''){
         selectObj = document.getElementById(selectObj.getElementsByTagName('a')[0].rel);
         selectObj.className ='select dbl';
       }
    }
    
    var sideNav  = document.createElement('ul');
    sideNav.id = 'sideNav';
    sideNav.appendChild(selectObj.cloneNode(true));
    
    
    
    var liSelection = sideNav.getElementsByTagName('li');
    for(var i=0; i<liSelection.length;i++){
        
        if (liSelection[i].className=='select')
        {
			if(liSelection[i].id=='subnav_servicesipad')
            {
				liSelection[i].style.textTransform='none';
            }
            if(liSelection[i].id=='subnav_servicespubs')
            {
                var thdlvnav = document.createElement('ul');//'<ul class="thdlvnav"><li><a href="#">services</a></li><li><a href="#">Gallery</a></li><li><a href="#">Audit Process</a></li></ul>';      
                thdlvnav.className = 'thdlvnav';
                thdlvnav.innerHTML = '<li><a href="revenue.aspx">Revenue</a></li><li><a href="circulation.aspx">Circulation</a></li><li><a href="auditable.aspx">Audit and Reporting</a></li><li><a href="subscription.aspx">Subscription</a></li>';
                liSelection[i].appendChild(thdlvnav);
            }
            //if(liSelection[i].id=='subnav_servicescops')
            //{
                //var thdlvnav = document.createElement('ul');//'<ul class="thdlvnav"><li><a href="#">services</a></li><li><a href="#">Gallery</a></li><li><a href="#">Audit Process</a></li></ul>';      
                //thdlvnav.className = 'thdlvnav';
                //thdlvnav.innerHTML = '<li>B2B</li><li><a href="#b2b_services">services</a></li><li><a href="#b2b_gallery">Gallery</a></li><li><a href="#b2b_audit_process">Audit Process</a></li>';
                //liSelection[i].appendChild(thdlvnav);
                //var thdlvnav = document.createElement('ul');
                //thdlvnav.className = 'thdlvnav';
                //thdlvnav.innerHTML = '<li>B2C</li><li><a href="#b2c_services">services</a></li><li><a href="#b2c_gallery">Gallery</a></li><li><a href="#b2c_audit_process">Audit Process</a></li>';
                //liSelection[i].appendChild(thdlvnav);
            //}
            if(liSelection[i].id=='subnav_gallery')
            {
                var thdlvnav = document.createElement('ul');//'<ul class="thdlvnav"><li><a href="#">services</a></li><li><a href="#">Gallery</a></li><li><a href="#">Audit Process</a></li></ul>';      
                thdlvnav.className = 'thdlvnav';
                //thdlvnav.innerHTML = '<li><a href="#magzines">Magazines</a></li><li><a href="#newspapers">Newspapers</a></li><li><a href="#catalogues">Catalogues</a></li><li><a href="#newsletters">newsletters</a></li><li><a href="#brochures">Brochures</a></li><li><a href="#annualreports">Annual Reports</a></li>';
                thdlvnav.innerHTML = '<li><a href="#magzines">Magazines</a></li><li><a href="#newspapers">Newspapers</a></li><li><a href="#catalogues">Catalogues</a></li><li><a href="#newsletters">newsletters</a></li><li><a href="#annualreports">Annual Reports</a></li>';
                liSelection[i].appendChild(thdlvnav);
            }
        }    
            
        if (liSelection[i].className.indexOf('dbl')!=-1)
        {
            liSelection[i].className = '';
        }
        
        
        liSelection[i].id ='';
    }
    
    var refObj = document.getElementById('leftContent').getElementsByTagName('div')[0];
    
    if(typeof refObj == 'undefined')
        document.getElementById('leftContent').appendChild(sideNav);
    else
        document.getElementById('leftContent').insertBefore(sideNav,refObj);
};

/*
 * This is sort of a wrapper function to the doHighlight function.
 * It takes the searchText that you pass, optionally splits it into
 * separate words, and transforms the text on the current web page.
 * Only the "searchText" parameter is required; all other parameters
 * are optional and can be omitted.
 */
function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
  // if the treatAsPhrase parameter is true, then we should search for 
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually
  
  if (treatAsPhrase) {
    searchArray = [searchText];
  } else {
    searchArray = searchText.split(" ");
  }
  
  if (!document.body || typeof(document.body.innerHTML) == "undefined") {
    if (warnOnFailure) {
      alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    }
    return false;
  }
  
  var bodyText = document.body.innerHTML;
  for (var i = 0; i < searchArray.length; i++) {
    bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
  }
  
  document.body.innerHTML = bodyText;
  return true;
}


/*
 * This is the function that actually highlights a text string by
 * adding HTML tags before and after all occurrences of the search
 * term. You can pass your own tags if you'd like, or if the
 * highlightStartTag or highlightEndTag parameters are omitted or
 * are empty strings then the default <font> tags will be used.
 */
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<font style='color:#fff; background-color:#ff9933;'>";
    highlightEndTag = "</font>";
  }
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }
  
  return newText;
}

var flashPhotos = new Array('RV1_sml.jpg','RV2_sml.jpg','RV3_sml.jpg','RV4_sml.jpg','RV5_sml.jpg','RV6_sml.jpg','RV7_sml.jpg','RV8_sml.jpg', 'RV9_sml.jpg','RV10_sml.jpg');
var imgID='flash_thumbs';
function doImgLoop()
{
    opacity(imgID, 100, 0, 3000);
    setTimeout('nextImg()',3000);
    //setTimeout('doImgLoop()',9000); 
}

function nextImg()
{

    var name = document.getElementById(imgID).src;
    var path ='images/'
    if(name=="")
    {
        name = path + flashPhotos[0]
    }
    else
    {
    name = name.slice(name.lastIndexOf('/')+1);
    
    for(j=0;j<10;j++)
    {
        if (flashPhotos[j]==name)
        {
            if(j==9)
            { 
                name = path + flashPhotos[0]
            }
            else
            { 
                name= path + flashPhotos[j+1];
            }
            break;
        }
    }
    }
    
    changeOpac(0,imgID);
    document.getElementById(imgID).src = name;
   opacity(imgID, 0, 100, 1500);
}


function opacity(id, opacStart, opacEnd, millisec) {
//speed for each frame
var speed =Math.round(millisec / 100);
var timer = 0;

//determine the direction for the blending, if start and end are the same nothing happens
if(opacStart > opacEnd) {
for(j = opacStart; j >= opacEnd; j--) {
setTimeout("changeOpac(" + j+ ",'" + id + "')",(timer * speed));
timer++;
}
} else if(opacStart < opacEnd) {
for(j = opacStart; j <= opacEnd; j++)
{
setTimeout("changeOpac(" + j + ",'" + id + "')",(timer * speed));
timer++;
}
}
} 

function changeOpac(opacity, id) {
var object = document.getElementById(id).style;
object.opacity = (opacity / 100);
object.MozOpacity = (opacity / 100);
object.KhtmlOpacity = (opacity / 100);
object.filter = "alpha(opacity=" + opacity + ")";
}

function  ReadersScroll()
{
    var flag= document.getElementById('readersscroll');
    if (!flag || flag.value != 'no')
    {
        var count = Math.round((Math.random()*10))
        var newObj = document.createElement('img');
        newObj.src = '../images/RV' + count + '_sml.jpg';
        newObj.id=imgID;
        document.getElementById('rightContent').appendChild(newObj);
        setTimeout('doImgLoop()',3000);
    }
};

function loadWPImages()
{
    var images = document.getElementById('midContent').getElementsByTagName('img');
    for(i=0;i<images.length;i++)
    {
        if (images[i].className == 'attachment-thumbnail')
        {
            var s = images[i].src.split('?');
            images[i].src = s[0];
            
            images[i].parentNode.href = s[0]+"?w=800";
            images[i].parentNode.rel="lightbox";
       }
       if( (images[i].src.indexOf('comments')!=-1) && (images[i].parentNode.rel == 'nofollow') )
       {
        images[i].style.display='none';
       }
    }
};

function track_utube_video()
{
    var imgs = document.getElementById('midContent').getElementsByTagName('img');
    if(imgs.length==0)
    {
        return;
    }
    for(i=0;i<imgs.length;i++)
    {
        if(imgs[i].src.indexOf('youtube')!=-1)
        {
            vi_img = imgs[i].src.split('/')
            utube_src = 'http://www.youtube.com/v/'+vi_img[vi_img.length-2]+'&amp;rel=1&amp;fs=1&amp;showsearch=0';
            v_str = '<object height="350" width="425">'
            v_str += '<param value="'+ utube_src +'" name="movie">';
            v_str += '<param value="true" name="allowfullscreen"><param value="opaque" name="wmode">'
            v_str += '<embed height="350" width="425" wmode="opaque" allowfullscreen="true" type="application/x-shockwave-flash" src="'+utube_src+'">';
            v_str +='</object>';
            
            imgs[i].parentNode.parentNode.innerHTML = v_str;
        }
    }
};

function show_submenu(t)
{
    if( t.id.indexOf('topnav_')!=-1)
    {
    var submenu= document.getElementById(t.id).getElementsByTagName('ul')[0];
    if(submenu!=null)
        submenu.style.display = 'block';
        }
}

function hide_submenu(t)
{
    if( t.id.indexOf('topnav_')!=-1)
    {
    var submenu=document.getElementById(t.id).getElementsByTagName('ul')[0];
    if(t.id.indexOf('topnav_')!=-1 && submenu!=null)
    submenu.style.display = 'none';
    }
}
