var DDSPEED = 2;
var DDTIMER = 10;

// 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);
  }
}

function ShowProduct(id)
{
		var pageName = '';
		if (id == 'PP500') pageName = 'pee-pod-500';
		if (id == 'PP1600') pageName = 'pee-pod-1600';
		if (id == 'PP2000') pageName = 'power-pod-2000';
		if (id == 'PPclas') pageName = 'power-pod-classic';
		if (id == 'TP100') pageName = 'track-pod-100';
		if (id == 'ACCS') 
			pageName = 'camera-head-accessories.html'
		else
			pageName = pageName + '-general-information.html';
		
		ddMenu('products',-1)
		document.getElementById('PP500').style.display = 'none';
		document.getElementById('PP1600').style.display = 'none';
		document.getElementById('PP2000').style.display = 'none';
		document.getElementById('PPclas').style.display = 'none';
		document.getElementById('TP100').style.display = 'none';
		if (id != 'ACCS'){
			setTimeout(function(){		
				document.getElementById(id).style.display = 'block';
				document.getElementById('ProductOptions').style.display = 'block';
				//window.location='default.aspx?prod=' + id
				window.location = pageName;
			},180);
		} else {
			window.location = pageName;
			//window.location='default.aspx?prod=' + id
		}
}

function fallingOption(c)
{
//		var cc = c;
	  clearInterval(c.timer);
  
    if(c.maxw && c.maxw <= c.offsetWidth){return}
    else if(!c.maxw){
      c.style.display = 'block';
      c.style.width = 'auto';
      c.maxw = c.offsetWidth;
      c.style.width = '0px';
    }
    c.timer = setInterval(function(){ddSlide_right(c,1)},DDTIMER);
  
}

function ddSlide_right(c,d){
  var currw = c.offsetWidth;
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxw - currw) / DDSPEED));
  }else{
    dist = (Math.round(currw / DDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;
  }
  c.style.width = currw + (dist * d) + 'px';
  c.style.opacity = currw / c.maxw;
  c.style.filter = 'alpha(opacity=' + (currw * 100 / c.maxw) + ')';
  if((currw < 2 && d != 1) || (currw > (c.maxw - 2) && d == 1)){
    clearInterval(c.timer);
  }
}



function playIt(URL, stitle)
		{
			var isSelection = URL;
			var embedStr = '<OBJECT ID="MediaPlayer" WIDTH="320" HEIGHT="240" CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"' + 
				'STANDBY="Loading Windows Media Player components..." TYPE="application/x-oleobject" >' +
				'<PARAM NAME="FileName" VALUE="mms://www.powerpod.co.uk/powerpod_videos/' + isSelection + '">' +
				'<PARAM name="ShowControls" VALUE="true">' +
				'<param name="ShowStatusBar" value="false">' +
				'<PARAM name="ShowDisplay" VALUE="false">' +
				'<PARAM name="autostart" VALUE="true">' +
				'<EMBED TYPE="application/x-mplayer2" SRC="mms://www.powerpod.co.uk/powerpod_videos/' + isSelection + '" NAME="MediaPlayer1"   id="MediaPlayer1"' +
				'	WIDTH="320" HEIGHT="240" ShowControls="1" ShowStatusBar="0" ShowDisplay="0" autostart="1"> </EMBED>' +
			'</OBJECT>'
							
			document.getElementById('PlayerDiv').innerHTML = embedStr;
						document.getElementById('playerTitle').innerHTML = stitle;
		}

		function playVideo(vidFile, stitle)
		{
			
			playIt(vidFile, stitle);
			
			if (document.embeds) 	{
				if (document.embeds.length > 0)	
				{
					
					
					
				}
				else
				{
					
					
				}
					
			}
			else  {
			}
		}
		
		
		
		function closeWindow()
			{
				window.opener='X'; 
				window.open('','_parent',''); 
				window.close();
			}
