var ie4=document.all;
var ns6=document.getElementById&&!document.all;

intImageRotOpacity = 100;
currentImage = "main-picture1";
var imageRotateTimer;
imgArrIndex = 0;

timer = 5000;
objDropDownItem = new Object;
objDropDownItem="";
intOpacity = 100;

var headerImageArray = [];

headerImageArray.push("images/designed-by-a-gym-manager.jpg");
headerImageArray.push("images/solution-by-evolution.jpg");
headerImageArray.push("images/pay-as-you-go.jpg");
headerImageArray.push("images/club-manager-message.jpg");


if (window.addEventListener)				
	window.addEventListener("load", rotateImages, false);	
else if (document.addEventListener) 
	document.addEventListener("DOMContentLoaded", rotateImages, false);  
else
	window.attachEvent("onload", rotateImages);


///////////////////////////////////////// Start of slider


		$(function () {
			$('#slider1').anythingSlider({
				startStopped    : false, // If autoPlay is on, this can force it to start stopped
				width           : 910,  // Override the default CSS width
				toggleControls  : true, // if true, then slide in controls on hover and slider change, hide @ other times                                
				
                                delay               : 8000,
                                animationTime       : 1200,
                                buildArrows         : true,      // If true, builds the forwards and backwards buttons
                                  toggleArrows        : false,     // if true, side navigation arrows will slide out on hovering &amp; hide @ other times
                                  buildNavigation     : false,      // If true, builds a list of anchor links to link to each panel
                                  toggleControls      : true,     // if true, slide in controls (navigation + play/stop button) on hover and slide change, hide @ other times
                                  navigationFormatter : null,
                                  pauseOnHover: false,
				onSlideComplete : function(slider){
					
				}
			});				

		});

                $(function () {
			$('#slider').anythingSlider({
				startStopped    : false, // If autoPlay is on, this can force it to start stopped
				width           : 300,  // Override the default CSS width
                                height: 190,
				toggleControls  : false, // if true, then slide in controls on hover and slider change, hide @ other times

                                delay               : 6000,
                                animationTime       : 600,
                                buildArrows         : false,      // If true, builds the forwards and backwards buttons
                                  toggleArrows        : false,     // if true, side navigation arrows will slide out on hovering &amp; hide @ other times
                                  buildNavigation     : false,      // If true, builds a list of anchor links to link to each panel
                                  toggleControls      : true,     // if true, slide in controls (navigation + play/stop button) on hover and slide change, hide @ other times
                                  navigationFormatter : null,
                                  pauseOnHover: false,
				onSlideComplete : function(slider){

				}
			});

		});
/////////////////////////////////////////////////////////////


function rotateImages()
{	
	sortPng();
	
    try
	{		
		var picture2 = document.getElementById("main-picture2");
		picture2.onLoad=newImageLoaded();
	
		picture2.src=headerImageArray[imgArrIndex];
	}
	catch (e)
	{
		clearTimeout(imageRotateTimer);
		// Do nothing
	}	
}	


function newImageLoaded()
{	
	imageRotateTimer=setTimeout('fadeImage()', 5000);
	//fnFindBrowserStyle(document.getElementById("main-picture2")).zIndex = "99";
	//fnFindBrowserStyle(document.getElementById("main-picture1")).zIndex = "1";	
}


function fadeImage()
{
  
  intImageRotOpacity-=5;   
  
  changeOpacity(intImageRotOpacity, currentImage);
  
  if (intImageRotOpacity <= 0)
    fnRemovePic();    
  else
    imageRotateTimer=setTimeout('fadeImage()', 50);
}

function fnSwitchMenu(objSwitch, strMode, blnTimeout)
{
  if ((objDropDownItem!="")&&(objDropDownItem!=objSwitch))
    fnRemoveMenu();	
  
  fnFindBrowserStyle(document.getElementById(objSwitch)).display=strMode;
  if (objDropDownItem) changeOpacity(100, objDropDownItem);
  intOpacity = 100;
  
  if (blnTimeout)
    objDropDownItem="";
  else
    clearTimeout(timer);
  
  objDropDownItem = objSwitch;  
}

var DDSPEED = 3;
var DDTIMER = 15;

// main function to handle the mouse events //
function ddMenu(id,d){
  var h = document.getElementById('ddheader'+id);
  var c = document.getElementById('ddcontent'+id);
  c.style.display = "block";
  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('ddheader'+id);
  var c = document.getElementById('ddcontent'+id);
  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';
  if (!ie4)
  {
	c.style.opacity = currh / c.maxh;
	c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  }
  
  //alert(currh);
  
  if((currh <= 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    if (currh==2) c.style.display = "none";
    clearInterval(c.timer);
  }
}

function fadeMenu()
{
  
  intOpacity-=10;
  
  changeOpacity(intOpacity, objDropDownItem);
  
  if (intOpacity <= 0)
    fnRemoveMenu();    
  else
    timer=setTimeout('fadeMenu()', 50);
}

function fnRemoveMenu()
{
  fnFindBrowserStyle(document.getElementById(objDropDownItem)).display="none";
  changeOpacity(100, objDropDownItem);
  intOpacity = 100;
}



function changeOpacity(newOpacity, objObject)
{
    if (ie4)
        fnFindBrowserStyle(document.getElementById(objObject)).filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+newOpacity+")"
    else
    {
        fnFindBrowserStyle(document.getElementById(objObject)).KhtmlOpacity = (newOpacity/100);
    	fnFindBrowserStyle(document.getElementById(objObject)).MozOpacity = (newOpacity/100);
    }  
}

function fnRemovePic()
{
  clearTimeout(imageRotateTimer);
  document.getElementById("main-picture1").onLoad=newImageLoaded();
  
  fnFindBrowserStyle(document.getElementById(currentImage)).zIndex = "2";
  changeOpacity(100, currentImage);
  
  if ((imgArrIndex++) >= (headerImageArray.length-1)) imgArrIndex=0;
  
  document.getElementById(currentImage).src=headerImageArray[imgArrIndex];
  
  currentImage = (currentImage=="main-picture2") ? "main-picture1" : "main-picture2";
  fnFindBrowserStyle(document.getElementById(currentImage)).zIndex = "10";
    
  intImageRotOpacity = 100;  
}


function openBox(thisBox)
{
    $('#'+thisBox).slideToggle(600);
	
}

function sortPng()
{
 if (document.all && /MSIE (5\.5|6)/.test(navigator.userAgent) && document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule)
 {  
  document.styleSheets[0].addRule('#club-management', 'behavior: url(sitespecific/iepngfix.htc)');
  document.styleSheets[0].addRule('#footer', 'behavior: url(sitespecific/iepngfix.htc)');
 }
}

function fnFindBrowserStyle(objIdent)
{ return ((ie4||ns6) ? objIdent.style : objIdent); }
