// MENU CONTROLS

var DDSPEED = 10;
var DDTIMER = 15;

// main function to handle the mouse events //
function ddMenu(id,d){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){return}
    else if(!c.maxh){
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
    }
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }else{
    h.timer = setTimeout(function(){ddCollapse(c)},50);
  }
}

// collapse the menu //
function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
}

// cancel the collapse if a user rolls over the dropdown //
function cancelHide(id){
  var h = document.getElementById(id + '-ddheader');
  var c = document.getElementById(id + '-ddcontent');
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / DDSPEED));
  }else{
    dist = (Math.round(currh / DDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  c.style.height = currh + (dist * d) + 'px';
  c.style.opacity = currh / c.maxh;
  c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    clearInterval(c.timer);
  }
}



// END OF MENU CONTROLS




















function pagechange(tmp)
{	
	window.location = tmp;	
}


var Music
function musicWindow()
{
	if (opener && !opener.closed)
	{	
		opener.focus()
	} else{
		Music = window.open('music.htm', "","toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no, left=0,top=0,width=285,height=650") 
		opener = Music
	
		//now we check to see if visitor is on home page, if so we stop embed music player as user is loading music player window
		page_name = "'" + window.location + "'"
		home_page = page_name.indexOf('index')		
		if (home_page >= 0) {MPlyr.Stop();}
		if (page_name == "'http://www.jeep4ever.ca/'") {MPlyr.Stop();}
		
	}	
}


var em1 = "admin"
var em2 = "@"
var em3 = "jeep4ever"
var em4 = "."
var em5 = "ca"
function emailer()
{
	document.write("<a href='mailto:" + em1+em2+em3+em4+em5 + "?subject=from jeep4ever.ca' ");
}



//show pics and videos
var windowTag = 0
var Images
function showPic(pic)
{
   if (windowTag)
   {
        Images.close()
   }
   windowTag = 1
   picName = pic + ".jpg"
   Images = window.open(picName, "","toolbar=0,resizable=1,scrollbars=1,left=0,top=0")   
}

function showVideo(thevideo, thewidth, theheight)
{
  windowName = "vids/" +  thevideo
  Images = window.open(windowName, "","toolbar=0,resizable=1,scrollbars=1,left=0,top=0,height=" + theheight
        + ", width=" + thewidth)
}



//array variables for holding/random pics
var seqArray = new Array()
var rndArray = new Array()
//slide show variables for sliding the pics
var picstoshow = totalpics - 1
var global_counter = 0
var image_counter = 0
var opacity = 0
var fade_counter =0;
//Adjustable variables
var img_width = 133;
var img_height = 100;
var fadeout_start_delay = 1500; 
var fadeoutspeed = 10;
var fadeinspeed = 10; 
var fadeincrement = 2; 
var total_divs = 1 //total pics

//Slideshow 
function fillseqArray()
{	
	//load an Array with numbers (equal to number of pics) in sequence 
	for (cnt=0;cnt<=totalpics;cnt++)
	{
		seqArray[cnt] = cnt
	}			
	fillrndArray()
}

function fillrndArray()
{ 
	//load an Array with numbers (equal to number of pics) in random 
	for (cnt=0;cnt<=totalpics;cnt++)
	{
		//randomly pic an element from sequence array
		tmp = (Math.random() * picstoshow); //gives you a range of 0 to picstoshow
		rndpic = Math.round(tmp);     // rounding #.99 up
		newpic = seqArray[rndpic]
		rndArray[cnt] = newpic			
		//shrink seqArray by one removing the element (newpic) just selected.	
		adder = 0;
		for (cnt2=0;cnt2<picstoshow;cnt2++)
		{		
			if (seqArray[cnt2] == newpic)
			{
				adder = 1
			}
			seqArray[cnt2] = seqArray[cnt2+adder]
		}
		picstoshow--										
	}
	picstoshow = 0
	StartingImageLoad()
}


function StartingImageLoad()
{ 	
 
 if (image_counter < total_divs)
 {	
    rndpic = rndArray[global_counter];
    full_size= arrayPic[rndpic]
    full_size = full_size.replace(/_tb.jpg/,"")
    full_size = full_size.replace(/_tb.JPG/,"")				
  		
    global_counter++;
    if (global_counter >= totalpics) 
    { 
      global_counter = 0;   
    }
    //document.getElementById('tracker1').value = global_counter 
    //document.getElementById('tracker2').value = arrayPic[rndpic]
   
    
    imagename = 'image' + image_counter
      
    //eval(picDiv).innerHTML += "<a href='#'>" - had to change to below for Firefox
    document.getElementById("picDiv").innerHTML += "<a href='#'>"   
    + "<img id='" + imagename + "' width=" + img_width + " height=" + img_height + "  style='opacity:0.0;filter:alpha(opacity=0)'"  
    + " src='" + arrayPic[rndpic] + "' border='0' onClick=showPic('" + full_size + "')>"
    + "</a>" 	
   
    image_counter++;	  
    StartingImageLoad()
	    
 } else {  
    image_counter = 0;
	imageLoaded(); 	   
 }
}

function imageLoaded()
{
  //objImg = eval('image' + (total_divs-1))
  objImg = document.getElementById('image' + (total_divs-1))  
  if(!objImg.complete)  
  {  
	 setTimeout("imageLoaded();", 500);				 
  } else {
  	  fadeIn('image0',0);
  } 
}

function fadeIn(objId,opacity) 
{
 if (image_counter < total_divs)
 {
    if (document.getElementById) 
    {
      obj = document.getElementById(objId);
        if (opacity <= 100) 
    	{
          setOpacity(obj, opacity);
          opacity += fadeincrement;
          window.setTimeout("fadeIn('"+objId+"',"+opacity+")",fadeinspeed);
        } else {
      	  image_counter++;
      	  nextimg = 'image' + image_counter;
      	  fadeIn(nextimg, 0);      
    	}
    }  
 } else {
    image_counter = 0;
    setTimeout("fadeOut(100);", fadeout_start_delay);
 } 
}

function fadeOut(opacity) 
{
  objId = "image" + fade_counter;
  if (document.getElementById)
  {
    obj = document.getElementById(objId);
    if (opacity > -fadeincrement) 
	{
      setOpacity(obj, opacity);
	  //alert(opacity)
      opacity -= fadeincrement;
      window.setTimeout("fadeOut(" + opacity + ")",fadeoutspeed);
    } else {
    	fade_counter++;
    	if (fade_counter < total_divs)
    	{
    	  fadeOut(100);
    	} else {
		
    	  fade_counter = 0;
		  //eval(picDiv).innerHTML = ""; 
		  document.getElementById("picDiv").innerHTML = "";		 
    	  StartingImageLoad(0)
    	}
     }
  }  
}

function setOpacity(obj, opacity) 
{
  opacity = (opacity == 100)?99.999:opacity;
    
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}










//Snow Fall 1 - no images - Java Script Visit http://rainbow.arch.scriptmania.com/scripts/ for this script and many more

// Set the number of snowflakes (more than 30 - 40 not recommended)
var snowmax=40

// Set the colors for the snow. Add as many colors as you like
var snowcolor=new Array("#AAAACC","#DDDDFF","#CCCCDD","#F3F3F3","#F0FFFF")

// Set the fonts, that create the snowflakes. Add as many fonts as you like
var snowtype=new Array("Arial Black","Arial Narrow","Times","Comic Sans MS")

// Set the letter that creates your snowflake (recommended: * )
var snowletter="*"

// Set the speed of sinking (recommended values range from 0.3 to 2)
var sinkspeed=0.6

// Set the maximum-size of your snowflakes
var snowmaxsize=42

// Set the minimal-size of your snowflakes
var snowminsize=8

// Set the snowing-zone
// Set 1 for all-over-snowing, set 2 for left-side-snowing 
// Set 3 for center-snowing, set 4 for right-side-snowing
var snowingzone=1


//   * NO CONFIGURATION BELOW HERE *


// Do not edit below this line
var snow=new Array()
var marginbottom
var marginright
var timer
var i_snow=0
var x_mv=new Array();
var crds=new Array();
var lftrght=new Array();
var browserinfos=navigator.userAgent 
var ie5=document.all&&document.getElementById&&!browserinfos.match(/Opera/)
var ns6=document.getElementById&&!document.all
var opera=browserinfos.match(/Opera/)  
var browserok=ie5||ns6||opera

function randommaker(range) {		
	rand=Math.floor(range*Math.random())
    return rand
}

function initsnow() {
	if (ie5 || opera) {
		marginbottom = document.body.scrollHeight  //clientHeight
		marginright = document.body.clientWidth
	}
	else if (ns6) {
		marginbottom = window.innerHeight
		marginright = window.innerWidth
	}
	var snowsizerange=snowmaxsize-snowminsize
	for (i=0;i<=snowmax;i++) {
		crds[i] = 0;                      
    	lftrght[i] = Math.random()*15;         
    	x_mv[i] = 0.03 + Math.random()/10;
		snow[i]=document.getElementById("s"+i)
		snow[i].style.fontFamily=snowtype[randommaker(snowtype.length)]
		snow[i].size=randommaker(snowsizerange)+snowminsize
		snow[i].style.fontSize=snow[i].size
		snow[i].style.color=snowcolor[randommaker(snowcolor.length)]
		snow[i].sink=sinkspeed*snow[i].size/5
		if (snowingzone==1) {snow[i].posx=randommaker(marginright-snow[i].size)}
		if (snowingzone==2) {snow[i].posx=randommaker(marginright/2-snow[i].size)}
		if (snowingzone==3) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/4}
		if (snowingzone==4) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/2}
		snow[i].posy=randommaker(2*marginbottom-marginbottom-2*snow[i].size)
		snow[i].style.left=snow[i].posx
		snow[i].style.top=snow[i].posy
	}
	movesnow()
}

function movesnow() {
	for (i=0;i<=snowmax;i++) {
		crds[i] += x_mv[i];
		snow[i].posy+=snow[i].sink
		snow[i].style.left=snow[i].posx+lftrght[i]*Math.sin(crds[i]);
		snow[i].style.top=snow[i].posy
		
		if (snow[i].posy>=marginbottom-2*snow[i].size || parseInt(snow[i].style.left)>(marginright-3*lftrght[i])){
			if (snowingzone==1) {snow[i].posx=randommaker(marginright-snow[i].size)}
			if (snowingzone==2) {snow[i].posx=randommaker(marginright/2-snow[i].size)}
			if (snowingzone==3) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/4}
			if (snowingzone==4) {snow[i].posx=randommaker(marginright/2-snow[i].size)+marginright/2}
			snow[i].posy=0
		}
	}
	var timer=setTimeout("movesnow()",50)
}





