﻿/*
//======================================================
//  *** BE CAREFUL WITH THIS ****
//
//  NOTE: To change your images, only change the PreLoadList()
//   at the bottom.
//
//  http://www.spiderweblogic.com 
//  Spiderweb Logic Website Design
//  (805) 720-0789
//======================================================
*/

var _iImageName = "unknown";
var _canScroll = false;
var _milisecondPause = 4000;
var _milisecondFade = 1000;
var _num = -1;
var _props = new Array();

// ---------------------------

//http://www.dithered.com/javascript/browser_detect/browser_detect.txt
function BrowserDetect() {
   var ua = navigator.userAgent.toLowerCase(); 

   // browser engine name
   this.isGecko       = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);

   // browser name
   this.isKonqueror   = (ua.indexOf('konqueror') != -1); 
   this.isSafari      = (ua.indexOf('safari') != - 1);
   this.isOmniweb     = (ua.indexOf('omniweb') != - 1);
   this.isOpera       = (ua.indexOf('opera') != -1); 
   this.isIcab        = (ua.indexOf('icab') != -1); 
   this.isAol         = (ua.indexOf('aol') != -1); 
   this.isIE          = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1) ); 
   this.isMozilla     = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isFirebird    = (ua.indexOf('firebird/') != -1);
   this.isNS          = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && !this.isOpera && !this.isSafari && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
   
   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);
   
   // rendering engine versions
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
   this.equivalentMozilla = ( (this.isGecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
   
   // browser version
   this.versionMinor = parseFloat(navigator.appVersion); 
   
   // correct version number
   if (this.isGecko && !this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
   }
   else if (this.isOmniweb) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
   }
   else if (this.isOpera) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
   }
   else if (this.isIcab) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
   }   
   this.versionMajor = parseInt(this.versionMinor); 
   
   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);
   
   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin    = (ua.indexOf('win') != -1);
   this.isWin32  = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac    = (ua.indexOf('mac') != -1);
   this.isUnix   = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux  = (ua.indexOf('linux') != -1);
   
   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);
   
   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);
   
   this.isIE4xMac = (this.isIE4x && this.isMac);
}
var browserDetectObj = new BrowserDetect();





// http://www.quirksmode.org/js/blockinvi.html
function showElement(nr) {  
    if (document.all)
    { 
	    document.all[nr].style.visibility = 'visible';
    }
    else if (document.getElementById)
    {
	    document.getElementById(nr).style.visibility = 'visible';
    } 
    changeOpac(100,nr);
    
}

function hideElement(nr) {    
    if (document.all)
    {
        if (document.all[nr]) {
          changeOpac(0,nr);
          document.all[nr].style.visibility = 'hidden';
	      document.all[nr].style.display = 'none';  //dont take up hidden space
	    }
    }
    else if (document.getElementById)
    {
        if (document.getElementById(nr)) {
          changeOpac(0,nr);
          document.getElementById(nr).style.visibility = 'hidden';
	      document.getElementById(nr).style.display = 'none'; //dont take up hidden space
	    }
    }
}




//opacity changes derived from http://www.brainerror.net/scripts_js_blendtrans.php  
//change the opacity for different browsers 
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 fadeAway(id, millisec) {
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    for(i = 100; i >= 0; i--) { 
        setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
        timer++; 
    } 
}

function fadeIn(id, millisec) {
    var speed = Math.round(millisec / 100); 
    var timer = 0; 
    for(i = 0; i <= 100; i++) { 
        setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
        timer++; 
    }
}

function WriteRandomImage(millisec) {
   PreLoadList();
   
   var imagenumber = _props.length;
   var randomnumber = Math.random() ;
   var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1 ;
   if(rand1>(_props.length-1)) {
	   rand1=_props.length-1;
   }
   document.write('<image width="771px" height="330px" id="fade" src="' + _props[rand1] + '" style="border: 0 none; filter: alpha(opacity=0); -moz-opacity: 0; opacity: 0;" />');
   fadeIn("fade",millisec);
}

function WriteRandomImageSmaller(millisec) {
   PreLoadListSmaller();
   
   var imagenumber2 = _propsSmaller.length;
   var randomnumber2 = Math.random() ;
   var rand2 = Math.round( (imagenumber2-1) * randomnumber2) + 1 ;
   if(rand2>(_propsSmaller.length-1)) {
	   rand2=_propsSmaller.length-1;
   }
   document.write('<image width="330px" height="111px" id="fadeSmaller" src="' + _propsSmaller[rand2] + '" style="border: 0 none; filter: alpha(opacity=0); -moz-opacity: 0; opacity: 0;" />');
   fadeIn("fadeSmaller",millisec);
}

/*
// -----------------------------
// PURPOSE: to make sure the browser knows the list so can randomly choose one
// CHANGING:
//
//    ** setting the array of images **
//     In this section you tell how big is your list of images.
//     for 9 images:
//       _props = new Array(9);
//     for 15 images:
//       _props = new Array(15);
//
//    ** listing the images **
//     for each image in the slide show use: (note: imageIndex starts at 0 in JavaScript)
//        _props[imageIndex] = "images/imagename.jpg";
// -----------------------------
*/
function PreLoadList() {

      //setting the array of images
      _props = new Array(9); //THIS MUST EQUAL COUNT OF PICTURES

           
      //listing the images
      _props[0] = "images/changangkha_best.jpg";
      _props[1] = "images/Jac_reb_nuns.jpg";
      _props[2] = "images/meditation-alex.jpg";
      _props[3] = "images/nelson_grp.jpg";
      _props[4] = "images/Semtokha-Dzong_alex1.jpg";
      _props[5] = "images/Taktshang_alex1.jpg";
      _props[6] = "images/taktshang-tea.jpg";
      _props[7] = "images/TRONGSADZ.jpg";
      _props[8] = "images/bumthang_monks.jpg"; 
      
      
}


function PreLoadListSmaller() {

      //setting the array of images
      _propsSmaller = new Array(8); //THIS MUST EQUAL COUNT OF PICTURES

           
      //listing the images
      _propsSmaller[0] = "images/birdsofheaven_homepage.jpg";
      _propsSmaller[1] = "images/bumthangfest_homepage.jpg";
      _propsSmaller[2] = "images/pemalingpa_homepage.jpg";
      _propsSmaller[3] = "images/october_homepage.jpg";
      _propsSmaller[4] = "images/sacredmythic_homepage.jpg";
      _propsSmaller[5] = "images/sacredheart_homepage.jpg";
      _propsSmaller[6] = "images/yoga_homepage.jpg";
	  _propsSmaller[7] = "images/birdsofheaven_homepage.jpg";
	  
      
      
}




