
/*/// <summary>

///*********************************************************************************************************

/// MAIN MODULE:              chemmy alcott web site client module

/// SUB MODULE :              script

/// AUTHOR:                   Chandika Jayawardena.

/// CREATED:                  29-Auguest-2007

/// DESCRIPTION:              This contained all the common client functionality of the client module.

/// MODIFICATION HISTORY:     1.0     25-September-2007      Initial Version

/// COPYRIGHT:                Copyright accura-tech.com. All Rights Reserved

/// ********************************************************************************************************

/// </summary>

*/


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  setActiveMenuImage();
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
   setActiveMenuImage();
}

function showSubMenu(){
	document.getElementById("sub_menu").style.visibility = 'visible';
}

function hideSubMenu(){
	document.getElementById("sub_menu").style.visibility ='hidden';
}

////////////////////////////////////// Load active page menu image /////////////////////////////////////////

var PAGES = new Array("profile","racing","team","gallery","sponsor","news","contact","disclaimer");
var MENUID = new Array("mnu_profile","mnu_racing","mnu_team","mnu_gallery","mnu_sponsor","mnu_news","mnu_contact");
var ACTIVEMENUIMAGES = new Array("mnu_profileac.gif","mnu_racingac.gif","mnu_teamac.gif","mnu_galleryac.gif","mnu_sponsorac.gif","mnu_newsac.gif","mnu_contactac.gif");

var ACTIVECATEGORY ="";	//Active page ctegory (Constant)

function setActiveMenuImage(obj,url)
{
	for(var n=0;n<=PAGES.length;n++)
	{
		if(ACTIVECATEGORY==PAGES[n])
		{
			if(obj.id==MENUID[n])
			{
				document.images[MENUID[n]].src="images/"+ACTIVEMENUIMAGES[n];
			}else
			{
				obj.src="images/"+url;
			}
		}
	}
}

function showDiv()
{
	document.getElementById("splash_text").style.visibility ='visible';
}

///////////////The team record entity class////////////////////////////////
function teamRecordEntity (title1,title2,content)
{
	this.title1 = title1;
	this.title2 = title2;
	this.content = content;
}

////////////The team page content array////////////////////////////////////

var teamRecords =  new Array();

teamRecords[1] = new teamRecordEntity(); 
teamRecords[1].title1 = "MARK TILSTON";
teamRecords[1].title2 = "HEAD COACH";
teamRecords[1].content = "<p>Mark became Chemmy's Head Coach in April 2008. Previously Mark was Head Coach for Great Britain's Alpine Ski Team.</p><p><!--img src=\"images/mark_tilston.jpg\" /--></p>";

teamRecords[2] = new teamRecordEntity(); 
teamRecords[2].title1 = "JAMES VICKERS";
teamRecords[2].title2 = "ASSISTANT SKI COACH<br />AND PHYSIO";
teamRecords[2].content = "<p>James Vickers joined the team in 2009 and works with Mark on the mountain. He also helps with Chemmy's physical training in the gym and provides physio support.</p>";

teamRecords[3] = new teamRecordEntity(); 
teamRecords[3].title1 = "DUSAN KAPS";
teamRecords[3].title2 = "SKI TECHNICIAN";
teamRecords[3].content = "<p>Dusan began working with Chemmy in 2008 and prepares and waxes the skis.</p><p><!--img src=\"images/herbi_frankhauser.jpg\" /--></p>";

teamRecords[4] = new teamRecordEntity(); 
teamRecords[4].title1 = "JOANNE ELPHINSTON";
teamRecords[4].title2 = "PERFORMANCE MOVEMENT";
teamRecords[4].content = "<p>Joanne has been working with Chemmy since March 2007.  To generate maximum speed when racing a skier must be smooth and fluid - pure power alone is not enough.  Joanne ensures Chemmy's power is transmitted to the snow with the finesse of a ballet dancer.</p>";

teamRecords[5] = new teamRecordEntity(); 
teamRecords[5].title1 = "DR ADAM CAREY";
teamRecords[5].title2 = "NUTRITION";
teamRecords[5].content = "<p>Adam has been working with Chemmy since March 2007.  In order for Chemmy to perform at the top level and to complete the many hours of hard physical training, she must be eating the right fuel.<br /><br />Adam's work goes far beyond purely diet, covering amongst other things hydration, sleep efficiency and blood composition.  However, a healthy balanced diet is critical to Chemmy's performance.</p><a class='subtitles' href='http://www.corperformance.co.uk' target='_blank' title='corperformance.co.uk'>Corperformance</a>";

teamRecords[6] = new teamRecordEntity(); 
teamRecords[6].title1 = "DAVE ALRED MBE Phd";
teamRecords[6].title2 = "SPORTS PSYCHOLOGIST";
teamRecords[6].content = "<p>Dave joined Team Chemmy in November 2007.  His role is to help perfect Chemmy's mental preparation, skills acquisition and performance under pressure.  The aim is to try and ensure Chemmy performs at, or very near, her potential, whatever the interference.  Dave is highly regarded by athletes, coaches and the media as the best in the world at his craft.</p><p><!--img src=\"images/simon_timson.jpg\" /--></p>";

teamRecords[7] = new teamRecordEntity(); 
teamRecords[7].title1 = "SARAH ALLEN";
teamRecords[7].title2 = "PERSONAL ASSISTANT ";
teamRecords[7].content = "<p>Sarah's responsibility is to ensure that every element of Chemmy's day to day life, both personal and sporting, runs as smoothly as possible.</p><p><!--img src=\"images/sarah_horner.jpg\" /--></p>";

teamRecords[8] = new teamRecordEntity(); 
teamRecords[8].title1 = "MATTHEW STOCKFORD ";
teamRecords[8].title2 = "MANAGER";
teamRecords[8].content = "<p>A former World Champion Paralympic skier, Matthew started working with Chemmy in 2006 to give her a coaching team comparable to the best skiing nations.</p><p><!--img src=\"images/matthew_stockford.jpg\" /--></p>";


////////////////////////This is used for retrive team data from the content array////////////////////////////
function getInformation(id)
{
	for(var i = 1; i < teamRecords.length; i++)
	{
		if(i==id)
		{
			var objid1= "team_menu" + id;
			var objid2= "team_menu_" + id;	
			document.getElementById(objid1).style.borderTop = "1px solid #ff0000";
			document.getElementById(objid2).style.color = "#ff0000";
		}
		else
		{
			var objid1= "team_menu" + i;
			var objid2= "team_menu_" + i;	
			document.getElementById(objid1).style.borderTop = "1px solid #ffffff";
			document.getElementById(objid2).style.color = "#ffffff";
			//document.getElementById(objid1).style.Top ="0px";
		}
	}
	
	document.getElementById("content_title1").innerHTML = teamRecords[id].title1;
	document.getElementById("content_title2").innerHTML = teamRecords[id].title2;
	document.getElementById("content_text").innerHTML = teamRecords[id].content;
}

////////////////////////This is used for retrive message data from the content array////////////////////////////
function msgEntity(title,mdate,description)
{
	this.title  = title;
	this.mdate  = mdate;
	this.description = description;
}

function getMsgInformation(id)
{
	var len = MSG_CONTENT.length;
	for(var i=0;i<len;i++)
	{
		if(i==id)
		{
			var objid1= "msg_" + id;
			document.getElementById(objid1).innerHTML ="";
			document.getElementById(objid1).innerHTML = "<u>"+MSG_CONTENT[id].title+"</u>";
			document.getElementById(objid1).style.color = "#ff0000";
			
			document.getElementById("chemmy_msg").innerHTML = "";
			document.getElementById("chemmy_msg_date").innerHTML = "";
			document.getElementById("chemmy_msg_date").innerHTML = "<p>"+MSG_CONTENT[id].mdate+"<br /><strong>"+MSG_CONTENT[id].title+"</strong></p>";
			document.getElementById("chemmy_msg").innerHTML = MSG_CONTENT[id].description;
		}
		else
		{
			var objid1= "msg_" + i;
			document.getElementById(objid1).innerHTML ="";
			document.getElementById(objid1).innerHTML = MSG_CONTENT[i].title;
			document.getElementById(objid1).style.color = "#ffffff";
		}
	}
}

////////////////////////These aare used for show and hide the forgot password window ////////////////////////////
function showPasswordDiv()
{
	document.getElementById("forgot_password").style.visibility ='visible';
	$('#accico1').ifixpng();
}

function hidePasswordDiv()
{
	document.getElementById("forgot_password").style.visibility ='hidden';
}

////////////////////////This is used for retrive news data from the content array////////////////////////////
function newsEntity(title,description)
{
	this.title  = title;
	this.description = description;
}
	
function showNewsInfor(id)
{
	newsImage = '';
	if (NEWS_CONTENT[id].image != '')
	{
	  newsImage = '<img src="news_images/'+NEWS_CONTENT[id].image+'" alt="" style="display: block;"/>';
	}
	document.getElementById("news_detail_panel").innerHTML = "";
	document.getElementById("news_detail_panel").innerHTML = "<h1 style=\"font-size: 16px \">"+NEWS_CONTENT[id].title + "</h1><br />"+newsImage+NEWS_CONTENT[id].description;
	
	//document.getElementById(objid1).innerHTML = NEWS_CONTENT[id].title;
	document.getElementById("news_detail_panel").style.bgcolor = '#ffffff'
	
	
	var len = NEWS_CONTENT.length;
	for(var i=0;i<len;i++)
	{	//alert(objid1);
		if(i==id)
		{
			var objid1= "news_" + id;
			//document.getElementById(objid1).innerHTML ="";
			document.getElementById('news_'+i).innerHTML = "<br />"+NEWS_CONTENT[i].theDate + "<br /><u>"+NEWS_CONTENT[i].title+"</u>";
			document.getElementById('news_'+i).style.textTransform = "capitalize";
			document.getElementById('news_'+i).style.color = "#ff0000";
		}
		else
		{
			var objid1= "news_" + i;
			//document.getElementById(objid1).innerHTML ="";
			document.getElementById('news_'+i).innerHTML = "<br />"+NEWS_CONTENT[i].theDate + " <br /><u>"+NEWS_CONTENT[i].title+"</u>";
			document.getElementById('news_'+i).style.textTransform = "capitalize";
			document.getElementById('news_'+i).style.color = "#ffffff";
		}
	}
}

////////////////////////This is used for retrive image gallery images from the content array////////////////////////////
function showImageFile(id,flag)
{
	var imageholder = document.getElementById("image_place_holder");
	var imagepath ="gallery/images/";
	var len = PHOTO_GALLERY.length;
	FLAG = flag;
	for(var i=0;i<len;i++)
	{
		if(i==id)
		{
			var objid1= "photocell_" + id;
			document.getElementById(objid1).style.border = "1px solid #ff0000";
			imageholder.innerHTML = "";
			imageholder.innerHTML = "<img src='"+imagepath + PHOTO_GALLERY[id]+"' align=\"right\" />";
			document.getElementById("image_place_holder_descr").innerHTML = PHOTO_DESCR[id];
			ACTIVE_IMAGE_INDEX = parseInt(id);
			//imagePaginingController();
		}
		else
		{
			var objid1= "photocell_" + i;
			document.getElementById(objid1).style.border = "0px solid #ffffff";
		}
	}
}

////////////////////////Pagining controler  of the image gallery ////////////////////////////
function imagePaginingController(flag)
{
	var activeIndex = parseInt(ACTIVE_IMAGE_INDEX);
	var previd = parseInt(activeIndex)-1;
	var nextid = parseInt(activeIndex)+1;
	var currentid = parseInt(activeIndex)+1;
	var filecontroller =currentid + " / " + PHOTO_GALLERY.length;
	var nextstyle="";
	var prevstyle ="";
	if(FLAG=='p')
	{
		nextstyle ="style=\"color:'#ff0000';\"";	
	}
	else if(FLAG == 'n')
	{
		prevstyle ="style=\"color:'#ff0000';\"";	
	}
	else
	{
		prevstyle ="style=\"color:'#ffffff';\"";
		nextstyle ="style=\"color:'#ffffff';\"";
	}
	if(((activeIndex>MIN_VAL) && (activeIndex<MAX_VAL)))
	{
		document.getElementById("pc_prev").innerHTML = "<a "+nextstyle+" href=\"javascript:showImageFile("+previd+",'p')\">&lt;Previous</a>";
		document.getElementById("pc_next").innerHTML = "<a "+prevstyle+" href=\"javascript:showImageFile("+nextid+",'n')\">Next&gt;</a>";
		document.getElementById("pc").innerHTML = filecontroller;
	}else if(activeIndex==MAX_VAL)
	{
		document.getElementById("pc_prev").innerHTML = "<a "+prevstyle+" href=\"javascript:showImageFile("+previd+",'p')\">&lt;Previous</a>";
		document.getElementById("pc_next").innerHTML = "";
		document.getElementById("pc").innerHTML = filecontroller;
	}else if(activeIndex==MIN_VAL)
	{
		document.getElementById("pc_next").innerHTML = "<a "+nextstyle+" href=\"javascript:showImageFile("+nextid+",'n')\">Next&gt;</a>";
		document.getElementById("pc_prev").innerHTML = "";
		document.getElementById("pc").innerHTML = filecontroller;
	}
}

////////////////////////This is used for retrive video gallery video from the content array////////////////////////////
function videoEntity(title,file)
{
	this.title  = title;
	this.description = file;
}

function showVideoFile(id,flag)
{
	FLAG=flag;
	var len = VIDEO_GALLERY.length;
	
	for(var i=0;i<len;i++)
	{
		var video_cell = "vcell_";
		video_cell  = video_cell +i;
		if(i==id)
		{
			var objid1= "video_" + id;
			document.getElementById(objid1).innerHTML ="";
			document.getElementById(objid1).innerHTML = "<u>"+VIDEO_GALLERY[id].title+"</u>";
			document.getElementById(objid1).style.color = "#ff0000";
			
			var videofile = HTTP_PATH + "gallery/videos/"+VIDEO_GALLERY[id].file;
			var vo = new SWFObject('swf/mediaplayer.swf','mpl','465','379','7');
			vo.addParam('allowfullscreen','true');
			vo.addParam('allowscriptaccess','true');
			vo.addVariable('file',videofile);
			vo.addVariable('autostart',true);
			vo.addVariable('height','379');
			vo.addVariable('width','465');
			vo.write('video_place_holder');
			
			ACTIVE_VIDEO_INDEX = parseInt(id);
			document.getElementById(video_cell).style.border ="1px solid #ff0000";
			videoPaginingController(flag);
		}
		else
		{
			var objid1= "video_" + i;
			document.getElementById(objid1).innerHTML ="";
			document.getElementById(objid1).innerHTML = VIDEO_GALLERY[i].title;
			document.getElementById(objid1).style.color = "#ffffff";
			document.getElementById(video_cell).style.border ="0px solid #ffffff";
		}
	}
}

////////////////////////Pagining controler  of the video gallery ////////////////////////////
function videoPaginingController(flag)
{
	var activeIndex = parseInt(ACTIVE_VIDEO_INDEX);
	var previd = parseInt(activeIndex)-1;
	var nextid = parseInt(activeIndex)+1;
	var currentid = parseInt(activeIndex)+1;
	var filecontroller =currentid + " / " + VIDEO_GALLERY.length;
	var nextstyle="";
	var prevstyle ="";
	if(FLAG=='p')
	{
		nextstyle ="style=\"color:'#ff0000';\"";	
	}
	else if(FLAG == 'n')
	{
		prevstyle ="style=\"color:'#ff0000';\"";	
	}
	else
	{
		prevstyle ="style=\"color:'#ffffff';\"";
		nextstyle ="style=\"color:'#ffffff';\"";
	}
	if(((activeIndex>MIN_VAL) && (activeIndex<MAX_VAL)))
	{
		document.getElementById("pc_prev").innerHTML = "<a "+nextstyle+" href=\"javascript:showVideoFile("+previd+",'p')\">&lt;Previous</a>";
		document.getElementById("pc_next").innerHTML = "<a "+prevstyle+" href=\"javascript:showVideoFile("+nextid+",'n')\">Next&gt;</a>";
		document.getElementById("pc").innerHTML = filecontroller;
	}else if(activeIndex==MAX_VAL)
	{
		document.getElementById("pc_prev").innerHTML = "<a "+prevstyle+" href=\"javascript:showVideoFile("+previd+",'p')\">&lt;Previous</a>";
		document.getElementById("pc_next").innerHTML = "";
		document.getElementById("pc").innerHTML = filecontroller;
	}else if(activeIndex==MIN_VAL)
	{
		document.getElementById("pc_next").innerHTML = "<a "+nextstyle+" href=\"javascript:showVideoFile("+nextid+",'n')\">Next&gt;</a>";
		document.getElementById("pc_prev").innerHTML = "";
		document.getElementById("pc").innerHTML = filecontroller;
	}
}

////////////////////////This is used for get page height ////////////////////////////
function Viewport(){ this.windowX = (document.documentElement && document.documentElement.clientWidth) || window.innerWidth || self.innerWidth || document.body.clientWidth; this.windowY = (document.documentElement && document.documentElement.clientHeight) || window.innerHeight || self.innerHeight || document.body.clientHeight; this.scrollX = (document.documentElement && document.documentElement.scrollLeft) || window.pageXOffset || self.pageXOffset || document.body.scrollLeft; this.scrollY = (document.documentElement && document.documentElement.scrollTop) || window.pageYOffset || self.pageYOffset || document.body.scrollTop; this.pageX = (document.documentElement && document.documentElement.scrollWidth) ? document.documentElement.scrollWidth : (document.body.scrollWidth > document.body.offsetWidth) ? document.body.scrollWidth : document.body.offsetWidth; this.pageY = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;return this.pageY;
}


////////////////////////This is used for get page height - for safari latest version ////////////////////////////
function getPageSizeWithScroll()
{ 
    if (window.innerHeight && window.scrollMaxY) {// Firefox 
        yWithScroll = window.innerHeight + window.scrollMaxY; 
        xWithScroll = window.innerWidth + window.scrollMaxX; 
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac 
        yWithScroll = document.body.scrollHeight; 
        xWithScroll = document.body.scrollWidth; 
    } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari 
        yWithScroll = document.body.offsetHeight; 
        xWithScroll = document.body.offsetWidth; 
      } 
    arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll); 
    //alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll ); 
    return yWithScroll; 
} 

////////////////////////This is used for menu navigation - text menu version ////////////////////////////

var PAGES = new Array("profile","racing","team","gallery","sponsor","news","contact");
var TDID = new Array("mnu_bg_0","mnu_bg_1","mnu_bg_2","mnu_bg_3","mnu_bg_4","mnu_bg_5","mnu_bg_6");
var MENUID = new Array("mnu_profile","mnu_racing","mnu_team","mnu_gallery","mnu_sponsor","mnu_news","mnu_contact");
function menuActive(objid,flag)
{
	if(flag==1)
	{//Mouse over state
		document.getElementById(objid).style.backgroundImage="url(images/mnuover.jpg)";
	}else if(flag==2)
	{//Mouse click state
		for(var n=0;n<=PAGES.length;n++)
		{
			if(ACTIVECATEGORY==PAGES[n])
			{
				document.getElementById(TDID[n]).style.backgroundImage="url(images/mnuover.jpg)";
				document.getElementById(MENUID[n]).style.color="#ff0000";
			}
		}	
	}else if(flag==0)
	{//Mouse out state
		document.getElementById(objid).style.backgroundImage="url(images/pixel.gif)";
		for(var n=0;n<=PAGES.length;n++)
		{
			if(ACTIVECATEGORY==PAGES[n])
			{
				document.getElementById(TDID[n]).style.backgroundImage="url(images/mnuover.jpg)";
				document.getElementById(MENUID[n]).style.color="#ff0000";
			}
		}
	}
}

function changeBg(obj,flag)
{
	if(flag==1)
	{//Mouse over state
		document.getElementById(obj).style.backgroundImage="url(images/mnuover.jpg)";
	}else
	{
		document.getElementById(obj).style.backgroundImage="url(images/pixel.gif)";
	}
}

function openFile(url)
{
	window.location.href="/"+url;	
}

function racingVideo(filepath)
{
	//Create Video gallery object
	var playerurl = filepath+"/swf/flvplayer.swf";
	//var xmlrurl ="displayheight=200&backcolor=0x343434&lightcolor=0xf60007&frontcolor=0xffffff&transition*slowfade&file="+filepath+"/xml/playlist.xml&height=304&width=310&autostart=true&shuffle=false;";    //"profile/videos/gym_465.flv"
	var xmlrurl =filepath+"/xml/playlist.xml";   
	var so = new SWFObject(playerurl, "videoplayer", "304", "300", "8", "#FF0000");
	so.addParam("file",xmlrurl);
	so.addParam('allowfullscreen','true');
	so.addParam('allowscriptaccess','true');
	so.addParam("wmode", "transparent");
	so.addParam("salign", "t");
	so.addVariable('overstretch', true);
	so.addVariable('file',xmlrurl);
	so.addVariable('shuffle',false);
	so.addVariable('autostart',true);
	so.addVariable('height','304');
	so.addVariable('width','310');
	so.addVariable('displayheight','200');
	so.addVariable('backcolor','0x343434');
	so.addVariable('lightcolor','0xf60007');
	so.addVariable('frontcolor','0xffffff');
	so.write("racing_video");	
}

//video for profile page
function profileVideo(filepath)
{
	//Create Video gallery object
	var playerurl = filepath+"/swf/flvplayer.swf";
	//var xmlrurl ="displayheight=200&backcolor=0x343434&lightcolor=0xf60007&frontcolor=0xffffff&transition*slowfade&file="+filepath+"/xml/playlist.xml&height=304&width=310&autostart=true&shuffle=false;";    //"profile/videos/gym_465.flv"
	var xmlrurl =filepath+"/xml/playlist_profile.xml";   
	var so = new SWFObject(playerurl, "videoplayer", "306", "300", "8", "#FF0000");
	so.addParam("file",xmlrurl);
	so.addParam('allowfullscreen','true');
	so.addParam('allowscriptaccess','true');
	so.addParam("wmode", "transparent");
	so.addParam("salign", "t");
	so.addVariable('overstretch', true);
	so.addVariable('file',xmlrurl);
	so.addVariable('shuffle',false);
	so.addVariable('autostart',true);
	so.addVariable('height','288');
	so.addVariable('width','310');
	so.addVariable('displayheight','200');
	so.addVariable('backcolor','0x343434');
	so.addVariable('lightcolor','0xf60007');
	so.addVariable('frontcolor','0xffffff');
	so.write("profile_video");	
}