/*
 * Common Java script code
 */

 var timerId;

/* Set an image source to specified source */
function setPictureUp( strImageName, strImageRef ) {

	var imgId = document.getElementById( strImageName );
	imgId.src = strImageRef; /* "http:" . strImageRef; */
	window.status = 'looking at ' + strImageName + ' - ' + strImageRef;

}

/* Reload the current page with new parameters */
function ReLoadMe( strParameters ) {

	var strNewPage = document.location.pathname + '?' + strParameters;

// alert ('Re Loading ' + strNewPage );
//	document.URL = strNewPage;
	window.location.replace( strNewPage );
}

function CentreTheLogo()
{
	var MC = document.getElementById("MenuCol");
	var ML = document.getElementById("MainLogo");
	var PH = document.getElementById("PageHeader");
	var MP = document.getElementById("MainPagePart");
	var MP1 = document.getElementById("MainPagePart1");

//	alert ( MP.id + " - MP top =" + MP.offsetTop + " MP left =" + MP.offsetLeft);

	ML.style.left=MP.offsetLeft - ML.width/2;
	ML.style.top=MP.offsetTop - ML.height/2;

	document.getElementById("Posie").innerHTML = "left=" + ML.style.left + ", top=" + ML.style.top;

//	alert ( "Set top to " + ML.style.top );
}


function menuOverHere(linkname ) {

 var indexNo =0;

// for ( indexNo=0; indexNo<document.all.length; indexNo++ ) {
// 	if ( document.all(indexNo).className == "ClubShow" ) {
// 		document.all(indexNo).className="ClubNoShow";
// 	}
//
// 	if ( document.all(indexNo).className == "KMainMenuActive" ) {
// 		document.all(indexNo).className="KMainMenu";
// 	}

// for ( indexNo=0; indexNo<document.childNodes.length; indexNo++ ) {
// 	if ( document.childNodes[indexNo].className == "ClubShow" ) {
// 		document.childNodes[indexNo].className="ClubNoShow";
// 	}
//
// 	else if ( document.childNodes[indexNo].className == "KKMenuActive" ) {
// 		document.childNodes[indexNo].className="KKMenu";
// 	}
//
//
// }
   document.getElementById("link_" + linkname).className="KKMenuActive";
   window.status = linkname;
   return true;
}

function menuOutHere(linkname) {


   document.getElementById("link_" + linkname).className="KKMenu";
   window.status = " ";
   return true;
}



function cluboverhere(clubno) {

 var indexNo =0;
 var clubShow = document.getElementsByTagName( "P");
 var activeClubLink = document.getElementsByTagName( "A");

// window.alert( "clubshow = " + clubShow.length);

 for ( indexNo=0; indexNo<clubShow.length; indexNo++ ) {
 	if (clubShow[indexNo].className == "ClubShow" ) {
	 	clubShow[indexNo].className = "ClubNoShow";
	}
 }

// for ( indexNo=0; indexNo<activeClubLink.length; indexNo++ ) {
// 	if( activeClubLink[indexNo].className == "KKmenu" ) {
//	 	activeClubLink[indexNo].className = "KNormalClubLink";
//	}
// }

   document.getElementById("clubdetails_" + clubno).className="ClubShow";
//   document.getElementById("clublink_" + clubno).className="KKMenu";
   document.status = "Click on name to visit club";
   return true;
}


function mainMenuOver(menuNo) {
 var indexNo =0;
 var clubShow = document.getElementsByTagName( "DIV");
 var newMenu = document.getElementById("mainMenu_" + menuNo);

 for ( indexNo=0; indexNo<clubShow.length; indexNo++ ) {
        if (clubShow[indexNo].className == "MainMenuShow" ) {
                clubShow[indexNo].className = "MainMenuNoShow";
        }
 }

  if( menuNo != 0 && newMenu != null )
      document.getElementById("mainMenu_" + menuNo).className="MainMenuShow";

   document.status = "Select a menu";
   return true;
}



var imgPVids = new Array();
var noPStartFrom=0;
var noPVideos = 5;
var txtPDesc = new Array();
var noPID = new Array();

var imgAVids = new Array();
var noAStartFrom=0;
var noAVideos = 5;
var txtADesc = new Array();
var noAID = new Array();

function AJumpPic( noDirection ){

        noAStartFrom += noDirection;
        if ( noAStartFrom + noAVideos >= imgAVids.length )
                noAStartFrom = imgAVids.length - noAVideos -1;
        if ( noAStartFrom <=0 ) {
                noAStartFrom = 0;
        }

        for (var i=0; i<noAVideos; i++ ){
                if (noAStartFrom+i >= imgAVids.length ) {
                        document.getElementById("APIC" + (i+1)).src = "/images/kazenlogo.gif";
                        document.getElementById("ATEXT" + (i+1)).innerHTML = "";


                } else {
                        document.getElementById("APIC" + (i+1)).src = imgAVids[noAStartFrom+i].src;
                        document.getElementById("ATEXT" + (i+1)).innerHTML = txtADesc[noAStartFrom+i];
                        document.getElementById("ALINK" + (i+1)).href="javascript:ReLoadMe('ThisAVideo="
                                                        + noAID[noAStartFrom+i] + "');";
                }
        }

        document.getElementById("txtAPos").innerHTML = (noAStartFrom+1) + " to " + (noAStartFrom+noAVideos+1)
                        + " of " + imgAVids.length;

        if ( noAStartFrom + noAVideos >= imgAVids.length-1 ) {
                document.getElementById("ARightArrow").disabled= true;
        } else {
                document.getElementById("ARightArrow").disabled = false;
        }

        if ( noAStartFrom <=0 ) {
                document.getElementById("ALeftArrow").disabled = true;
        } else {
                document.getElementById("ALeftArrow").disabled = false;
        }
        return true;
}

function PJumpPic( noDirection ){

        noPStartFrom += noDirection;
        if ( noPStartFrom + noPVideos >= imgPVids.length )
                noPStartFrom = imgPVids.length - noPVideos -1;
        if ( noPStartFrom <=0 ) {
                noPStartFrom = 0;
        }

        for (var i=0; i<noPVideos ; i++ ){
                if (noPStartFrom+i >= imgPVids.length ) {
                        document.getElementById("PPIC" + (i+1)).src = "/images/kazenlogo.gif";
                        document.getElementById("PTEXT" + (i+1)).innerHTML = "";
                } else {
                        document.getElementById("PPIC" + (i+1)).src = imgPVids[noPStartFrom+i].src;
                        document.getElementById("PTEXT" + (i+1)).innerHTML = txtPDesc[noPStartFrom+i];
                        document.getElementById("PLINK" + (i+1)).href="javascript:ReLoadMe('ThisPVideo="
                                                        + noPID[noPStartFrom+i] + "');";
                }
        }

        document.getElementById("txtPPos").innerHTML = (noPStartFrom+1) + " to " + (noPStartFrom+noPVideos+1)
                        + " of " + imgPVids.length;

        if ( noPStartFrom + noPVideos >= imgPVids.length-1 ) {
                document.getElementById("PRightArrow").disabled= true;
        } else {
                document.getElementById("PRightArrow").disabled = false;
        }

        if ( noPStartFrom <=0 ) {
                document.getElementById("PLeftArrow").disabled = true;
        } else {
                document.getElementById("PLeftArrow").disabled = false;
        }
        return true;
}



function findCoords(e) {
   var posX = 0;
   var posY = 0;

   if( !e ) { e = window.event; } if( !e ) { return [ 0,0] ; }
   if( typeof( e.pageX ) == 'number' ) {
      posX = e.pageX;
      posY = e.pageY;
   } else {


     if( typeof( e.clientX ) == 'number' ) {
       posX = e.clientX;
       posY = e.clientY;

       if( document.body
         && ( document.body.scrollTop || document.body.scrollLeft )
         && ! ( window.opera || window.debug || navigator.vendor == 'KDE' ) ) {

               posX += document.body.scrollLeft;
               posY += document.body.scrollTop;
        } else {
            if( document.documentElement
             && ( document.documentElement.scrollTop || document.documentElement.scrollLeft )
             && !( window.opera || window.debug || navigator.vendor == 'KDE' ) ) {
               posX += document.documentElement.scrollLeft;
               posY += document.documentElement.scrollTop;
            }


       }
     }

   }
   return [ posX, posY ];
}



function subMenuOver (e, menuLevel, toolTip ) {

  var pos = new Array();
  var tmpLen,divList, thisDiv, thisId, displayId, ii;
  var obj = eventTrigger (e);

  canTimer( );

  pos = findCoords( e );
  displayId = 'subMenu_' + menuLevel;

  divList = document.getElementsByTagName
    && document.getElementsByTagName('div');
  if( divList ) {

    for( ii= 0; ii < divList.length; ii++ ) {
      thisDiv = divList[ii];
      thisId = thisDiv.id;
      tmpLen = thisId.length;
      if ( thisId == displayId ) {
	pos[1] = Math.round(pos[1]/30)*30 -15;
	pos[0] = (Math.round(pos[0]/100)+1)*100;
	thisDiv.style.position='absolute';
	thisDiv.setAttribute('top',pos[1]) ;
	thisDiv.style.top=pos[1] + 'px';
	thisDiv.style.display='inline';


      } else if ( thisId == 'subMenu_0' ) {

      } else if ( displayId.substring(0,tmpLen) == thisId ) {
	thisDiv.style.display='inline';

      } else if ( thisId.substring(0,8) == 'subMenu_' ) {
	thisDiv.style.display='none';
      }
    }
  }

  window.status=toolTip;
  return true;
}

function subMenuOut( ) {

  var noMillies = 1000;
  timerId = setTimeout( "destroyMenu()", noMillies );

}

function canTimer( ) {

  clearTimeout( timerId );

}

function destroyMenu( ) {

  var thisElem;
  var ii;
  var seriesName = 'subMenu_';

  var divList = document.getElementsByTagName('div');
  var iLen = seriesName.length;

  if ( divList ) {
    for ( ii = 0; ii < divList.length; ii++ ) {
      thisElem = divList.item(ii).id;
      if ( thisElem == seriesName + '0' ) {
	/* Ignore main Menu */
      } else if ( thisElem.substring(0, iLen ) == seriesName ) {
	/* divList.item(ii).className = 'menuNoShow'; */
	/*	divList.item(ii).style.display = 'none'; */
	divList.item(ii).style.display='none';
      }
    }
  }

}

function eventTrigger (e) {
    if (! e)
        e = event;
    return e.target || e.srcElement;
}

function eventOver (e, displayDiv, toolTip ) {

  var pos = new Array();
  var thisDiv;

  pos = findCoords( e );

 thisDiv = document.getElementById  && document.getElementById(displayDiv);
 if( thisDiv ) {
   pos[1]+=50; 
   thisDiv.style.position='absolute';
   thisDiv.setAttribute('top',pos[1]) ;
   thisDiv.setAttribute('left',pos[1]) ;
   thisDiv.style.left=pos[0] + 'px';
   thisDiv.style.top=pos[1] + 'px';
   thisDiv.style.display='inline';
   thisDiv.innerText = toolTip;
   thisDiv.textContent = toolTip;
 }
 window.status=toolTip;
 return true;
}

function eventOut (e, displayDiv ) {

  var thisDiv;

  thisDiv = document.getElementById  && document.getElementById(displayDiv);
  if( thisDiv ) {
    
    thisDiv.style.display='none';
  }
  window.status='';
  return true;
}


//function kazenDojoLoader() {

if ( useLocal ) {
 }


  dojo.require( "dojo.data.ItemFileReadStore" );
  dojo.require( "dijit.layout.AccordionContainer" );
  dojo.require( "dijit.layout.TabContainer" );
  dojo.require( "dijit.layout.ContentPane" );
  dojo.require( "dijit.Tooltip" );
  dojo.require( "dijit._Calendar" );
  dojo.require( "dojox.widget.FisheyeLite" );

  if ( useGallery ) {
    dojo.require( "dojox.image.Gallery" );
    dojo.require( "dojox.image.SlideShow" );
  }

  if ( useVideo ) {
    dojo.require( "dojox.flash");
    dojo.require( "dojox.av.FLVideo");
    dojo.require( "dojox.av.widget.Player");
    dojo.require( "dojox.av.widget.PlayButton");
    dojo.require( "dojox.av.widget.VolumeButton");
    dojo.require( "dojox.av.widget.ProgressSlider");
    dojo.require( "dojox.av.widget.Status");
  }

  if ( useGrid ) {
    dojo.require( "dojox.grid.Grid");
    dojo.require( "dojox.grid.DataGrid");
    dojo.require( "dijit.Tree" );
    dojo.require( "dojox.grid.Grid" );
    dojo.require( "dojox.grid.compat._data.model" );
  }

  dojo.require( "dojo.parser" );
  if ( usePageLoader ) {
    dojo.addOnLoad(kazenPageLoader);
  }

//}

//dojo.config.parseOnLoad = true;
//dojo.config.useXDomain=true;
//dojo.config.dojoBlankHtmlUrl = "./blank.html";
