var selected = false;
var firstNku = true;
var firstMla = true;
var currentPlayer = "";


var siteStatus = 'start';
//var siteScene = 'begin';

var thisImage = 1;

var antTxt = '<b>Antman</b><br/><br/>We use pictures and words to change what people do';
var _antTime;
var _antChar = 0;
var _antTypeKey = 0;

var char = 0;
var caption = 'Speaking on behalf of the club, I think the book is excellent and every Jersey surfer will be proud of it. I also think it will have an international appeal as well. Well done to you guys for putting it together. My bit was easy especially when it was glassy and overhead at Trestles. My shout at the bar on Saturday. Woof.<br/>Dave Ferguson<br/>President of the JSC';
var standby;
var _typeKey = 0;
var _timeOut;

var eImg = "";
var pImg = "";
var captionTxt = "";
var currentSelect = "";
var _mouseOut = "";
var _mouseIn = "";

var flashMovie = null;
var flashDivMovies = new Array("#15","#21","#24","#41","#27","#46");
var flashMovies = new Array(null,null,null,null,null,null);
var flash_key = " ";
var flashPreviewPlay = false;
var flashMainPlay = false;
var flashLoaded = false;
var theKey;

var timerMovie;
var bigFlashMovies = new Array(null,null);
var _tick_01 = 0;
var _tick_02 = 0;
var _tick_03 = 0;
var _tickStr_03 = " ";
var _tick_04 = 0;
var _tickStr_04 = " ";
//var iFrames = 0;
//var iSeconds = 0;
var _masterTick = 0;
var bigFilmTxt = " ";
var bigFilmCaption_1 = " ";
var bigFilmCaption_2 = " ";
var timerOn = false;
var initTimer = false;
var currentTimeLimit = 0;
var gridLock = true;

var offSetX = 2;
var offSetY = 0;
var heightOffSet = 0;
var widthOffSet = 0;
var browserName = 'default';
//array check
//var a_Select_array = new Array("one","one","one","one","one","one","one","one");
var FIRSTTIME = "OFF";

$(document).ready(function() {

	checkPlatform();
	//initSkipReplay();
	
	initPhp(_ID);
	//setMenu(0);
	setScreen(0);
	//makeGrid();
	/*cookie time*/
	
	//var testArr = new Array(1,2,3,1,2,3,1,2,2,0,2,0);
	
	//$.cookie("antmanSelect2", testArr);
	
	//deBug("COOKIE: "+Request.Cookies.Get("myarray").Value);
	
	//deBug( $.cookie("antmanSelect2") );
	/**********/
	
	
	//flash video - needs re-factoing!!!
	
	if(platform != 'iPad'){
		startFlash();
		
		/*try just using startFlash??*/
		//playFlash(5,27,'in',false);//just big movies--init

		//playFlash(4,46,'in',false);
		
		//playFlash(4,46,'out');
		loadBigVideo("video_1","images/nku_blank.jpg","films/timesplice.flv");
		loadBigVideo("video_2","images/mla_blank.jpg","films/reading.flv");
	}else{
		//alert('hello '+platform);
		$("#mainPortfolio").css( { "left":"0px","top":"0px"} );
		$("#imageLayer").css( { "left":"0px","top":"0px"} );	
		iPadIcons();
		//loadiPadBigVideo("video_1","iphone/films/nku.m4v");
	}
	preloader();
	//$("#videoLayer").html("<div id='video_1'></div><div id='video_2'></div>");

	//doMovie("#mlafilm","films/reading.flv","_mlafilm","images/antweb-mla-r1c1.jpg");
	//initActions();
	//setMenu(0);
	//alert('debugger');
	//alert('??')
	

 });//end doc ready
 
function makeGrid(_STATUS){
	
	//selector
	var _id = 0;
	var pKeyArr = new Array(2,4,6);//image[pKeyArr[0]]--0,1,2 - for referencing
	var randomNum;
	
	//image
	if(_STATUS == "FIRST-TIME"){
			//CREATE NEW GRID
			
			//choose random 0,1,2 - need to know if 2 elements
			//8
			
			//deBug("chooseRandom: "+chooseRandom(2));
			
			//deBug('makeGrid(): '+image[_id][pKeyArr[_id]]+' image array length: '+image.length+"\nimage[2].length: "+image[2].length);
			
			$.each(image, function(_index, value) {
		       //console.log(this);
		       //return (this != "three"); // will stop running after "three"
		       
			       if(image[_index].length == 8){
						randomNum = chooseRandom(3) ;
					}else if(image[_index].length == 6){
						randomNum = chooseRandom(2) ;
					}else if(image[_index].length == 4){
						randomNum = 0 ;
					}
				
				//update selector??
				selector[_index] = randomNum;
				
				
				
				//deBug("image[]length: "+image[_index].length+"randomNum: "+randomNum);
				
		       $("#"+_index).html("<img src="+image[_index][pKeyArr[randomNum]]+">");
		   		});
		   		//set-up cookie
		   		
		   		$.cookie("antmanSelect", selector);
   			}else{
   			
	   			var backSelector = $.cookie("antmanSelect");
	   			var indexSelector = backSelector.split(',');
	   			
	   			//deBug("indexSelector.length: "+indexSelector.length+"indexSelector: "+indexSelector);
	   			deBug("indexSelector.length: "+indexSelector.length+" indexSelector: "+indexSelector);
	   			//selector = $.cookie("antmanSelect");
	   			
	   			//if video has been touched
	   			//stop it!!
				
	   			deBug("indexSelector[46]"+indexSelector[46]);
	   			
				$.each(image, function(_index, value) {
					//deBug('selector:BACK: '+image[_index][pKeyArr[indexSelector[_index]]]+'selector[_index]'+indexSelector[_index]+'_index: '+_index);
					deBug("Identify video and drop-out..."+_index+" name: "+image[_index][pKeyArr[indexSelector[_index]]]);
					if(image[_index][pKeyArr[indexSelector[_index]]] == "VIDEO"){
						deBug("Identify video and drop-out..."+_index+"indexSelector: "+indexSelector[_index]);
						}
					
						$("#"+_index).html("<img src="+image[_index][pKeyArr[indexSelector[_index]]]+">");
							});
			
			   		}
	//deBug("selector: "+selector);
	//$("#"+_id).html("<img src="+image[_id][pKeyArr[_id]]+">");
	
	
	}
//on leaving page - update cookie
//on returning to page - if the cookie is there -
//use that to set selector

function upDateCookie(){

	$.cookie("antmanSelect", selector);
	//deBug("COOKIE: "+Request.Cookies.Get("myarray").Value);
	deBug("COOKIE CUT: "+selector);

	//deBug( $.cookie("antmanSelect") );

}

function chooseRandom(_topLimit){
	
	var rand = Math.floor(Math.random()*_topLimit)
	
	return rand;
}
 
function deBug(msg){
		if(window.console && 'undefined'!=typeof(console.log)){
				console.log(msg);		
			}
	}

function setScreen(_menuKey){

	$("#menu").css( { visibility:"visible" } );
	
	$("#list li a").each(function () {
			//alert($(this).attr('title'));
			if ($(this).attr('title') == _menuKey) {	
			$(this).css( { color:"#000000" } );
			} 
				
		  });


}


function initSkipReplay(){
	//alert('skip Init()');
	$('a.skipSkip').mousedown(function() {
		
		$('#sideTxt').html(' ');
		//mouseSwipe???
		
		//$('#sideTxt').css({"font-family":"arial","font-size":"10px"});
		//$("#menu").css( { visibility:"visible" } );
		initActions();
		
	});
		
	}


function initActions(){

	$('a.mainGrid').each(function () {
			//alert($(this).attr('id'));
			if ($(this).attr('id') == 27 || $(this).attr('id') == 46) {	
				$(this).css( { cursor:"pointer" } );
			} else{
				$(this).css( { cursor:"default" } );
				}
				
		  });
	//
   $('a.mainGrid').mouseover(function() {
	  var _key = $(this).attr('id');
	  currentSelect = _key;
	  _mouseIn = _key;
	  //alert('mouse over!'); 
	  Y = eval(imageTopStart + image[_key][1]);
	  captionTxt = text[_key][1];
	  $('#sideTxt').css({"font-family":"arial","font-size":"10px"});
	  
	  if(platform == 'iPad' && (_key == 15 || _key == 21 || _key == 24 || _key == 41)){
	  		//alert("dd");
	  		$('#sideTxt').html("Flash video loop.<br/>Not supported for iOS.");
	  }else{
		
	 	//TEST IF ITS A VIDEO
		 if(image[_key][2] != "VIDEO"){	
		 						
								  drawMainImg(_key); 
							}else{
								//alert('now!');
								
									if(platform != 'iPad'){
										doVideo(_key);
									}else{
										//alert('hello '+platform);
										doiPadVideo(_key);
									}
								
								}//end else
	 		
	}
		
	});
   
   $('a.mainGrid').mousedown(function() {
   					//alert('mouseIt: '+_mouseIn);
					//alert('mouser');	
					//if(!flashPreviewPlay){
					//alert('flash_key: '+flash_key+'currentSelect: '+currentSelect);//5/27
					//alert('currentSelect: '+currentSelect);
				if(platform != 'iPad'){
					if(currentPlayer ==""){
						
						if (currentSelect ==  46){
							//alert('clickIt() '+currentSelect);
							//$("#mainPortfolio").html("<div id='video_1'></div><div id='video_2'></div>");
							$("#imageLayer").css({"opacity":"0.0" });
							jwplayer("video_1").play();
							
							$("#film_2").css({"opacity":"0.0" });
							//$("#mainPortfolio").html("<div id='video_1'></div><div id='video_2'></div>");
							$("#video_1").css({"opacity":"1.0" });
							currentPlayer = "video_1";
							
							
						}
						
						if (currentSelect ==  27){
							$("#imageLayer").css({"opacity":"0.0" });
							jwplayer("video_2").play();
							$("#film_1").css({"opacity":"0.0" });
							
							$("#video_2").css({"opacity":"1.0" });
							currentPlayer = "video_2";
							
						}
						
							timerReset();
							timerOn = true;
							//alert(text[currentSelect][0]);
							displayTime();
					}
					
					/*
										*/
					
					//opacity: 0.0;
	//filter: alpha(opacity = 0);
					
					if( flash_key== 4 || flash_key == 5){
							
							
					}
						//flashPreviewPlay = true;	
					//}
					}//end iPad splitter
			});
									
									
	
   
   $('a.mainGrid').mouseleave(function() {
   
   		//$("#film_2").css({"opacity":"0.0" });
   		//$("#film_2").html("WHY??");
   		var _key = currentSelect;
		currentPlayer = "";
		if(platform !='iPad'){
			jwplayer("video_1").stop();
			$("#video_1").css({"opacity":"0.0" });
			
			jwplayer("video_2").stop();
			$("#video_2").css({"opacity":"0.0" });
			
			$("#mainPortfolio").css( { "left":"0px","top":"0px"} );	
			//IF WANT TO CHANGE ROLLING VIDEO ICONS.........................................
			//if(flash_key != 5 && flash_key != 4){
				playFlash(flash_key,_key,'out',false);
			//}
			//$("#imageLayer").css({"opacity":"0.0" });
			
			$("#film_2").css({"opacity":"0.0" });
			$("#film_1").css({"opacity":"0.0" });
			
			}
		$("#imageLayer").css({"opacity":"0.0"});
		//$("#mainPortfolio").css( { "left":"0px","top":"0px"} );
		//$("#imageLayer").css( { "left":"0px","top":"0px"} );		
		
		_mouseOut = _key;
		clearTimeout(timerMovie);
		timerReset();
		//$("#mainPortfolio").html("");
		//alert('why?');
		//$("#mainPortfolio").css({"height":"5px","width":"5px","background-color":"transparent" });
		//$("#mainPortfolio").css({"height":"5px","width":"5px","opacity":"0.0"  });
		$('#sideTxt').html("");
		captionTxt = "";
		drawThmbImg(_key);
		upDateMap(_key);
		
		
	});
   
} //end function initActions()


function getKey(_key){
	switch(_key){
			case '15':
			//B_8
			_key = 0;
			break;
			case '21':
			_key = 1;
			break;
			case '24':
			_key = 2;
			break;
			case '41':
			_key = 3;
			break;
			case '27':
			_key = 4;
			break;
			case '46':
			_key = 5;
			break;
			}
	return _key;	


}

function doiPadVideo(_key){
		
		//alert(_key);
		var X = eval(imageLeftStart + image[_key][0]);
		var Y = eval(imageTopStart + offSetY + image[_key][1]);
		
		//alert('iPadVideo'+image[_key][4]);
		//X = Number(X + offSetX);
		//alert('x: '+X+' y: '+Y);
		
		//switch on/off- preload video like flash
		if(_key == 46){
			$("#imageLayer").css({"opacity":"1.0"});
			//$("#imageLayer").css( { "left":"322px","top":"154px"} );
			$("#imageLayer").css( { "left":"690px","top":"334px"} );
			//$("#imageLayer").html("<img src="+image[_key][4]+">");
			$("#imageLayer").html('<video  width="274" height="178" poster="/images/antweb-nkuweb-still.jpg" controls="controls" ><source src="iphone/films/nku.m4v" /></video>');
		}
		
		if(_key == 27){
			$("#imageLayer").css({"opacity":"1.0"});
			//$("#imageLayer").css( { "left":"690px","top":"214px"} );
			$("#imageLayer").css( { "left":"414px","top":"214px"} );
			//$("#imageLayer").html("<img src="+image[_key][4]+">");
			$("#imageLayer").html('<video  width="274" height="178" poster="/images/antweb-mla-still.jpg" controls="controls" ><source src="iphone/films/eyReading.m4v" /></video>');
		}
		
		
		//$("#imageLayer").css({"opacity":"1.0" });
		//$("#video_1").css({"opacity":"1.0" });
		//$("#video_1").html('<video  width="274" height="178" controls="controls" ><source src="iphone/films/nku.m4v" /></video>');
		$('#sideTxt').html(text[_key][0]+text[_key][1]);


	}


function doVideo(_key){
	//return flashkey
	deBug('doVideo: '+_key);
	//flash_key = getkey(_key);
	flash_key = getKey(_key);
	//alert('_key: '+_key+'temp: '+temp);

	
		//alert(flash_key);
		playFlash(flash_key,_key,'in',true);

		var X = eval(imageLeftStart + image[_key][0]);
	  	var Y = eval(imageTopStart + offSetY + image[_key][1]);
		
		//big movie stuff//
		//alert(_key);
		if(_key == 46 || _key == 27 ){
				deBug('FILM: '+_key);
				//alert('key: '+_key+'text: '+text[_key][0]+text[_key][1]);
				//$("#mainPortfolio").html("<img src="+image[_key][4]+">");
				$("#imageLayer").html("<img src="+image[_key][4]+">");//clapper
				X = Number(X + offSetX);
				
				$("#imageLayer").css({"opacity":"1.0" });
				$("#imageLayer").css( { "left":""+X+"px","top":""+Y+"px"} );
				//$("#mainPortfolio").css( { left:""+X+"px",top:""+Y+"px"} );
				
				$('#sideTxt').html(text[_key][0]+text[_key][1]);
				
				upDateMap(_key);
				
				//$('#sideTxt').append();
				}
			
		//need to load it once
	
	}//end doVideo
	//5,27
	
	
function playFlash(flash_key,_key,_state,_clapper){
		//alert(flash_key+'_'+_key);
		deBug('playFlash: '+flash_key+' _key: '+_key+'_state: '+_state);
		deBug("flashMovies: "+flashMovies[flash_key]);
		if(flashMovies[flash_key]){//flashLoaded??
			//if specific movie is loaded
			//IE PROBLEM - can't send functions to objects
			//
			//can we swap it??
			/*
			if($.browser.name == 'msie'){
				deBug('flash called in browser: '+$.browser.name+'id: '+_key);
				$("#film_2").css({"left":"782px","top":"461px"});
				$("#film_2").html("<img src='images/film_Over.png' />");
				//film_Over.png
				//$("#fgGrid #row #film_2").css({"opacity":"1.0"});
				//$("#fgGrid").css({"opacity":"1.0"});
			}else{
			*/
				flashMovies[flash_key].flash(function() {
						//if(browserName != 'IE'){
							//this.StopPlay();
							
							if(_state == 'in' ){
									//this.sendTextToFlash(1);//1
									
									this.Play();
									//this.StopPlay();
									
									if(_key == 46 && _clapper){
									  $("#film_2").css({"opacity":"1.0" });
									  $("#film_2").css({"left":"782px","top":"453px"});
									  $("#film_2").html("<img src='images/film_Over.png' />");
									  }
									  
									if(_key == 27 && _clapper){
									  $("#film_1").css({"opacity":"1.0" });
									  $("#film_1").css({"left":"506px","top":"333px"});
									  $("#film_1").html("<img src='images/film_Over.png' />");
									  }
									
								}else{	
									//deBug("out: "+_key+" flash key: "+flash_key);
										//this.stopPlay();
										
										//if(_key == 27 || _key == 46 ) {
											// do owt
											//this.stopPlay();
										//}else{
										//this.Play();
											this.StopPlay();
										//}
										
																		//poss. issue with 46/27
									}			  
								

					});
			

		}else{
			//alert('loading flash key: '+flash_key);
			//seperate branch to load film first
			//alert(flash_key);
			flashMovies[flash_key] = $('#'+_key);
			flashMovies[flash_key].flash(
				{
					swf: image[_key][3],
					height: 58,
					width: 90 // default is 320
					
				});
			
			//alert('start!!');
			//playFlash(flash_key,_key);					
					
		}//end..if
		
	}
	
function upDateMap(_key){
			//shunt
			var dataLength = image[_key].length;
			deBug("upDateMap("+_key+") dataLength: "+dataLength);
			//alert('dataLength: '+dataLength);
			//8/6/4
			if(dataLength == 4){
						selector[_key] = 0;
					}
			if(dataLength == 6)
					{
						if(selector[_key] == 0)
						{
						selector[_key] = 1;
						}else if(selector[_key] ==1)
						{
						selector[_key] = 0;
						}
					}
			if(dataLength == 8)
					{
						if(selector[_key] == 0)
						{
						selector[_key] = 1;
						}else if(selector[_key] ==1)
						{
						selector[_key] = 2;
						}else if(selector[_key] ==2)
						{
						selector[_key] = 0;
						}
					}
			deBug("selector[_key]: "+selector[_key]+" _key: "+_key);
			upDateCookie();
	
	}

function  drawThmbImg(_key){
			if(image[_key][2] != "VIDEO"){
				 //need another check - not working right- dtill needs to update previouse image...
				$("#"+_key ).html("<img src="+pImg+">");
			 }
	}

function  drawMainImg(_key){
		  
		  //3 images
		  if(image[_key][7]){
			  switch(selector[_key]){
				  case 0:
					pImg = image[_key][4];
					eImg = image[_key][3];
					captionTxt = text[_key][1];
				  break;
				  case 1:
					pImg = image[_key][6];
					eImg = image[_key][5];
					captionTxt = text[_key][2];
					
				  break;
				  case 2:
					pImg = image[_key][2];
					eImg = image[_key][7];
					captionTxt = text[_key][3];
				  break;
				  }
		  }
		  //2 images
		  if(!image[_key][7] && image[_key][5]){
			  switch(selector[_key]){
				  case 0:
					pImg = image[_key][4];
					eImg = image[_key][3];
					captionTxt = text[_key][1];
				  break;
				  case 1:
					pImg = image[_key][2];
					eImg = image[_key][5];
					captionTxt = text[_key][2];
					
				  break;
				  }
		  }
		  //1 image
		  if(!image[_key][5]){
					pImg = image[_key][2];
					eImg = image[_key][3];
					captionTxt = text[_key][1];
		  }
		  //alert('pImg: '+pImg+' eImg: '+eImg);
		  var X = eval(imageLeftStart + image[_key][0]);
	  	  var Y = eval(imageTopStart + image[_key][1]);
		  
		 // alert(eImg.height());
		  //alert(eImg.clientHeight);
		  var img = new Image();
			img.src = eImg;
			//alert(img.width + 'x' + img.height);
			//deBug('text: '+text[_key][0]+captionTxt);
		  //$("#mainPortfolio").html("<img height ="+(img.height+heightOffSet)+" width="+(img.width)+" src="+eImg+">");//eImg
		  // $("#mainPortfolio").html("<img  src="+eImg+">");//eImg
		  //$("#mainPortfolio").css( { left:""+(X+offSetX)+"px",top:""+(Y+offSetY)+"px"} );
		  $("#imageLayer").css({"opacity":"1.0" });
		  $("#mainPortfolio").css( { "left":"0px","top":"0px"} );
		  $("#imageLayer").html("<img  src="+eImg+">");//eImg
		  $("#imageLayer").css( { "left":""+(X+offSetX)+"px","top":""+(Y+offSetY)+"px"} );
		  deBug("X: "+X)
		 // alert($("#mainPortfolio").height());
		  //if(_key != 27)
		  	//{
		  	//if(_key == "15" ){
		  		
		  	//}else{
		  		$('#sideTxt').html(text[_key][0]+captionTxt);
		  	//	}
		  	//}
		}
function iPadIcons(){
	
				
			$("#15").html("<img src='films/B_8.jpg'>");
			$("#21").html("<img src='films/C_6.jpg'>");
			$("#24").html("<img src='films/D_1.jpg'>");
			$("#41").html("<img src='films/F_2.jpg'>");
			
			$("#27").html("<img src='films/D_4_iPad.jpg'>");
			$("#46").html("<img src='films/F_7_iPad.jpg'>");


}

function startFlash(){
	
		
		//alert('startFlash()');
		
		for(var _tKey in flashDivMovies){
				
				switch(_tKey){
						case '0':
						theKey = 15;
						break;
						case '1':
						theKey = 21;
						break;
						case '2':
						theKey = 24;
						break;
						case '3':
						theKey = 41;
						break;
						case '4':
						theKey = 27;
						break;
						case '5':
						theKey = 46;
						break;
						
						}
					//alert('+tKey: '+_tKey);
				
					//alert(_tKey+' '+theKey);
						flashMovies[_tKey] = $(flashDivMovies[_tKey]);
				
						flashMovies[_tKey].flash(
							{
								swf: image[theKey][3],
								height: 58,
								width: 90 // default is 320
							});
						/*
						flashMovies[theKey].flash(function() {
						if(browserName != 'IE'){
							if(theKey == 46 || theKey == 27 ){	
									alert('+tKey: '+theKey);						  
									this.sendTextToFlash(2);//1
								
									this.Play();
									}
								}
							});
						*/
							
					}
	
	}
   

function typeIt() {	
	//alert('type it()');
	$('#zipTxt').html(zipTxt[_typeKey].substr(0, char++));
		if(char < zipTxt[_typeKey].length+1)
			{
			_timeOut = setTimeout("typeIt()", 40);
			}
		else if(_typeKey < zipTxt.length)
			{
			char = 0;
			//caption = "";
			//if(_typeKey < zipTxt.length){
			_typeKey++;
			deBug('_typeKey: '+_typeKey);	
			if(_typeKey == 1){
				//siteStatus = 'live';
				//$('#sideTxt').html(' ');
				initActions();
				
				//$("a.mainGrid").mousemove(function(e){
				//alert('mouse moved!!');
				
				//});
				//alert('end: '+_typeKey+'gridLock: '+gridLock);
				}else{
				//setTimeout("typeIt()", 8000);
			}
			//}
			}	
		//else
			//{
			
			//}
}


//sorry boz - cheating again!!

function antType() {	
	//alert('antType(): '+antTxt.length);
	//$('#sideTxt').html(antTxt);
	
	$('#sideTxt').html(antTxt.substr(0, _antChar++));
		if(_antChar  < antTxt.length+1){
			_antTime = setTimeout("antType()", 40);
		}else{
			_antChar  = 0;
			}
		//else if(_antChar < antTxt.length){
			//_antChar  = 0;
			//caption = "";
			//if(_typeKey < zipTxt.length){
				//_typeKey++;
				//setTimeout("typeIt()", 2000);
			//}
		//}	
		
}

function secs2hms(secs) {
/*
var iHours = Math.floor(secs/3600);
var iMinutes = Math.floor((secs/60) - (iHours*60));
var iSeconds = Math.floor(secs % 60);
var iFrames = (secs / 25).toFixed(2);
*/
var iHours = Math.floor(secs/3600);
var iMinutes = Math.floor((secs/60) - (iHours*60));
var iSeconds = Math.floor(secs % 60);
//var iSeconds = 0;
//var iFrames = (secs / 0.25).toFixed(0);
//var iFrames = (secs / 0.025).toFixed(2);//toPrecision
var iFrames = (iSeconds / 0.4).toPrecision(2);//toPrecision

//secs - master tick
//gobals
 //_tick_01 = 0;
//var _tick_02 = 0;
//var _tick_03 

if (_tick_04 > 24) {
//reset iFrames to 0
_tick_04 = 0;
//_tick_03 ++;

}else{
_tick_04++;
}



/*
if (iFrames % 25 == 0) { 
	iSeconds++; 
	//iFrames = 0; 
	} else{
	//iFrames = (iSeconds / 0.25).toFixed(0);
	}
*/	
//if (iSeconds == 10) { iMinutes++; iSeconds = 0; }   
//if (iMinutes == 10) { iHours++; iMinutes = 0; }

//25 frames a second
//HH:MM:SS:FF


//make it look right (view)
if(_tick_04 < 10){
	_tick_04 = "0"+_tick_04;
}
if(iSeconds < 10){
	iSeconds = "0"+iSeconds;
}
if(iMinutes < 10){
	iMinutes = "0"+iMinutes;
}

return(iHours+':'+iMinutes+':'+iSeconds+':'+_tick_04);
}


//<input type="button" value="click" onclick="alert(secs2hms(3719))">



function displayTime(){
	//every millisecnd call function
	//alert('position: '+jwplayer().getPosition());
	
	//$('#sideTxt').html('position: '+jwplayer().getPosition());
	_masterTick = jwplayer(currentPlayer).getPosition();
	//_tickStr_04 = jwplayer().getPosition();
	//secs2hms(_masterTick);
	
	
	//$('#sideTxt').html('position: '+jwplayer().getPosition());
	//bigFilmTxt = text[currentSelect][0];
		//						bigFilmCaption_1 = text[currentSelect][1];
		//						bigFilmCaption_2 = text[currentSelect][2];	
	if(_masterTick > 1){
		$('#sideTxt').html(text[currentSelect][0]+text[currentSelect][2]+"<FONT color='#FF0000'><b>0"+secs2hms(_masterTick)+"</b></FONT>");
	}
	//deBug('timerON: ');
	//if(_masterTick > 0.1){
	timerMovie = setTimeout("displayTime()",25);
	//}
	/*
		if(_tick_02 == currentTimeLimit){
			//_tick = 10;
			$('#sideTxt').html(bigFilmTxt+"TIMER FINISHED!!: ");
			$("#mainPortfolio").html("<img src="+image[46][4]+">");//flash movie still in cache??
		}else if(timerOn){
			//tick tree
			//_tick_01++;//to lock-out text update
			//10 seconds binary ho-ha..
			//_tick_01:_tick_02:_tick_03:_tick_04
			_tick_04++;//milliseconds(10);
			if( 25 / _tick_04 == 1){
				_tick_04 = 0;
				_tick_03++;
				}
			if(60 / _tick_03 == 1){
				_tick_03 = 0;
				_tick_02++;
				}
			if(60 / _tick_02 == 1){
				_tick_02 = 0;
				_tick_01++;
				}
			
			if(_tick_04 < 10){
				//_tick_04 = +_tick_04;
				_tickStr_04 = "0"+_tick_04;
				}else{
					_tickStr_04 = _tick_04;
					}
			if(_tick_03 < 10){
				//_tick_03 = 0+_tick_03;
				_tickStr_03 = "0"+_tick_03;
				}else{
					_tickStr_03 = _tick_03;
					}

			$('#sideTxt').html(bigFilmTxt+bigFilmCaption_2+"<FONT color='#FF0000'><b>0"+_tick_01+":0"+_tick_02+":"+_tickStr_03+":"+_tickStr_04+"</b></FONT>");

			setTimeout("display()",100);
			}
		*/
		
		}


function timerReset(){
		timerOn = false;
		_tick_01 = 0;
		_tick_02 = 0;
		_tick_03 = 0;
		_tick_04 = 0;
	
	}
	//"images/antweb-mla-r1c1.jpg"
	//_divName"video_1",_frontImage'images/antweb-nkuweb-r2c1.jpg',_src image[46][5]
function loadiPadBigVideo(_divName,_src){
		/*
		if(firstNku && _divName == "video_1"){
					//alert('here!');	
			$("#"+_divName).css({"left":"320px","top":"154px","opacity":"0.0" });
			$("#"+_divName).html('<video  width="274" height="178" controls="controls" ><source src="'+_src+'" /></video>');				
			}
		*/					
							
		//$("#imageLayer").css({"opacity":"1.0"});
		//$("#imageLayer").css( { "left":"320px","top":"154px"} );
		//$("#imageLayer").html("<img src="+image[_key][4]+">");
		

	}

function loadBigVideo(_divName,_frontImage,_src){
		//$("#mainPortfolio").css({"height":"178px","width":"274px","background-color":"#000000","color":"#ffffff","text-align":"center" });
		//$("#mainPortfolio").html("<div id='film' style='margin-top:70px'><img src='scripts/loader.gif'></div>");
		//alert('vid');
		//image[46] = new Array(92,0,"VIDEO","films/F_7.swf","films/F_7_clapper.jpg","films/timesplice.flv");
		
		
		jwplayer(_divName).setup({ 
			autostart: false,
			flashplayer: "scripts/player.swf", 
			file: _src, 
			height: 178, 
			width: 274,
			skin: 'scripts/glow.zip',
			image: _frontImage,
			controlbar: "none",
			plugins : ' ',//should work on full version!!
			events: { 
				onReady: function() { 
					if(firstNku && _divName == "video_1"){
						if($.browser.name == 'msie'){
							deBug($.browser.name);
							$("#"+_divName).css({"left":"322px","top":"161px","opacity":"0.0" });
						}else{
							$("#"+_divName).css({"left":"322px","top":"154px","opacity":"0.0" });
						}
					//$("#"+_divName).css({"left":"311px","top":"0px" });
					firstNku = false;
					}
					
					if(firstMla && _divName == "video_2"){
						if($.browser.name == 'msie'){
						deBug($.browser.name);
							$("#"+_divName).css({"left":"690px","top":"43px","opacity":"0.0" });
						}else{
							$("#"+_divName).css({"left":"690px","top":"36px","opacity":"0.0" });
						}
						//$("#"+_divName).css({"left":"679px","top":"-118px" });
						firstMla = false;
					
					}
					
					
				},
				onComplete: function() { 
					//alert("the video is finished!");
					currentPlayer = "";
					$("#imageLayer").css({"opacity":"1.0" });
					$("#"+_divName).css({"opacity":"0.0" });
					seek(0);
					clearTimeout(timerMovie);
					timerReset();
					//$("#video_1").css({"opacity":"0.0" });
					//$("#video_2").css({"opacity":"0.0" });
					//need to know currentslect?
					$('#sideTxt').html(text[currentSelect][0]+text[currentSelect][2]);
					
				} }
			});
								
			}//end doBigVideo
			

function preloader(){
		//alert('preloader');
		var loaderKey = 0;
		var totalImages = 0;
		var percentage = 0;
		//work out total:
		for(var i in image)
			{
			totalImages = totalImages + image[i].length;
			
			}
		//load the cache:
		for(var i in image)
			{
				
				//image[i][5] != "films/timesplice.flv" || image[i][5] != "films/reading.flv" && 
				if(image[i][2] != "VIDEO"){
				//deBug('preloading: '+image[i][7]);
				//imgTotal = i;
				//alert('oi!'+this.height+'_k: '+i);
					$.cacheImage([
						image[i][2],
						image[i][3],
						image[i][4],
						image[i][5],
						image[i][6],
						image[i][7]
					],{
						load : function (e) { 
							//if( imgTotal == image.length){
								//$('#sideTxt').html('loaded...');
							//}
							
							//alert('Loaded'+this.width+'e:'+loaderKey); 
							loaderKey++;
							//$('#sideTxt').append('loading: '+loaderKey+'_'+totalImages);
							percentage = ((loaderKey/totalImages) * 100).toFixed(0);
							
							if(percentage > 64){
								$('#loader').html(" ");
							}else{
								$('#loader').html(' '+percentage+"%");
							}
							//alert('oi!'+this.height+'_k: '+i);
						}
						
						//error: function (e) { console.log('Error',   this, e); },
						//abort: function (e) { console.log('Aborted', this, e); }
					});
				//alert('i: '+i+'length: '+image.length);
				if(FIRSTTIME == 'ON'){
					deBug('first time');
					playFlash(4,46,'out',false);
					playFlash(5,27,'out',false);
					}
				}//end exception
			
			}// end for..in
	}


function initPhp(_data){
	//var _data = 
	//preloader();
	$('a.mainGrid').mouseenter(function() {
		var _ky = $(this).attr('id');
		pImg = image[_ky][4];
		//alert(pImg);
		});
	
	//$('#sideTxt').html("");
	if(_data != 'ON'){
		deBug('flashMovies-THAT one: '+flashMovies.length);
		//only called once!!!
		//alert('from php: '+_data);
		initSkipReplay();
		typeIt();
		makeGrid('FIRST-TIME');//make new grid
		//$("#menu").css( { visibility:"hidden" } );
		
		//playFlash(5,27,'in',false);//just big movies--kick start
		//playFlash(4,46,'in',false);
		
		//$("#skipTxt").css( { visibility:"hidden" } );
	}else{
		//when return to page
		$("#skipTxt").css( { visibility:"hidden" } );
		
		//playFlash(5,27,'out');//just big movies--stop
		
		deBug('flashMovies-this one: '+flashMovies.length);
		//if(flashMovies[4]){
		//playFlash(4,46,'out',false);
		//playFlash(4,46,'out',false);
		//playFlash(5,27,'out',false);//just big movies
	   			//playFlash(4,46,'in');
		
		/*
			deBug('flash movie loop: '+flashMovies.length);
			flashMovies[4].flash(function() {
										this.StopPlay();
											});
											*/
						//			}
		//alert(_data);
		makeGrid('COOKIE');
		
		//jwplayer("video_1").stop();
		//jwplayer("video_2").stop();
		
		initActions();
		
		}
	
	
	FIRSTTIME = _data;
	deBug('from php: '+_ID);
	}


function setMenu(indexkey){
		//var indexKey = 0;
		$("#list li a").each(function () {
			//alert($(this).attr('title'));
			if ($(this).attr('title') == indexkey) {	
				$(this).css( { color:"#000000" } );
			} 
				
		  });
}

