/*NOTES ---------------------------------

misc javascript

UPDATE INFO ------------------------

Revision number: 2.0.0
Last updated: 12.03.2010
Last update made by: Michael Andrew (michael@hazardmedia.co.nz)

*/

// This will hold our timer
var myTimer = {};
var flickerCount = 0;
var lightOn = false;


//note that this method must be set up at runtime and cannot occur after the document has finished loading or the callback will not works
//callback function for #pull-me-btn swf
function flashClickHandler(){
	//alert('recieved flash event');
	
	initTimer();
}

function initTimer(){
	//alert('running init');
	if(!lightOn){
		lightOn = true;
		startTimer(500);	
	}else{
		window.location = index.html
		//lightOn = false;
		//switchToNormalMode();
	}
	
}

function startTimer(timerInterval){

	// Set the timer for .25 seconds
	myTimer = $.timer(timerInterval,onTimerEvent,function(){});

};



function initLabFlash(){
	flickerCount = 0;
		$("#cv-box-alt").flashembed( { 
		src: '_assets/_swf/cv-button-alt.swf', 
		version: [10,0,0,0],
		width: 171,
		height: 261,
		wmode: 'transparent' 	
	});
	$("#lab-intro-block .screenshotsBlank").flashembed( { 
		src: '_assets/_swf/test-tubes-alt.swf', 
		version: [10,0,0,0],
		width: 455,
		height: 371,
		wmode: 'transparent' 	
	});
}

function onTimerEvent(){
	
	switchToAltMode();
	cancelTimer();
	initLabFlash();
	
	/*switch(flickerCount){
		case 0:
			switchToAltMode();
			startTimer(10);
			flickerCount++;
			break;
		case 1:
			switchToNormalMode();
			startTimer(10);
			flickerCount++;
			break;
		case 2:
			switchToAltMode();
			startTimer(10);
			flickerCount++;
			break;
		case 3:
			switchToNormalMode();
			startTimer(1000);
			flickerCount++;
			break;
		case 4:
			switchToAltMode();
			startTimer(10);
			flickerCount++;
			break;
		case 5:
			switchToNormalMode();
			startTimer(500);
			flickerCount++;
			break;
		case 6:
			switchToAltMode();
			cancelTimer();
			initLabFlash();
			break;
	}*/
		
}

// If #cancel is clicked cancel the timer
function cancelTimer(){

	$.clearTimer(myTimer);
	
};



function switchToAltMode(){
	$('#nav a').removeClass('selected');
	$('#nav a.labs').addClass('selected');
	$('.contentItem').hide();
	$('.contentItemAlt').show();	
	$('body').addClass('bodyAlt');
	$('#header').removeClass('headerNormal');
	$('#header').addClass('headerAlt');
	$('#logo').hide();
	$('#logoAlt').show();
	$('#nav').removeClass('navNormal');
	$('#nav').addClass('navAlt');
	//$('#pull-me-btn-alt').show();
	//$('#cv-box-icon').removeClass('cv-box-icon-normal');
	//$('#cv-box-icon').addClass('cv-box-icon-alt');
	$('#cv-box-icon').hide();
	$('#cv-box-alt').show();
	$('#contentContainer').removeClass('contentContainerNormal');
	$('#contentContainer').addClass('contentContainerAlt');
	$('#download-cv').removeClass('download-cv-normal');
	$('#download-cv').addClass('download-cv-alt');
	$('#main-intro').hide(); //commented out because it breaks things on IE
	$('#lab-intro').show();
	$('#glow-alt').show();
	$('#starbust-alt').show();
	
	$('#monitor').removeClass('monitor-normal');
	$('#monitor').addClass('monitor-alt');
	$('#logo-watermark').removeClass('logo-watermark-normal');
	$('#logo-watermark').addClass('logo-watermark-alt');
	$('#home .next').hide();
	$('.nextAlt').show();
	
	$('#home').show();
	$('#core-skills').css('visibility','hidden');
	Cufon.refresh();
	$('#main-intro h1').css('visibility','hidden');
	$('#main-intro h2').css('visibility','hidden');
	$('#main-intro h3').css('visibility','hidden');
	

}

function switchToNormalMode(){
	$('#nav a').removeClass('selected');
	$('#nav a.home').addClass('selected');
	$('.contentItem').show();
	$('.contentItemAlt').hide();
	$('body').removeClass('bodyAlt');
	$('#header').addClass('headerNormal');
	$('#header').removeClass('headerAlt');
	$('#logo').show();
	$('#logoAlt').hide();
	$('#nav').addClass('navNormal');
	$('#nav').removeClass('navAlt');
	$('#pull-me-btn-normal').show();
	//$('#pull-me-btn-alt').hide();
	//$('#cv-box-icon').addClass('cv-box-icon-normal');
	//$('#cv-box-icon').removeClass('cv-box-icon-alt');
	$('#cv-box-icon').show();
	$('#cv-box-alt').hide();
	$('#contentContainer').addClass('contentContainerNormal');
	$('#contentContainer').removeClass('contentContainerAlt');
	$('#download-cv').addClass('download-cv-normal');
	$('#download-cv').removeClass('download-cv-alt');
	$('#main-intro').show();
	$('#lab-intro').hide();
	$('#glow-alt').hide();
	$('#starbust-alt').hide();
	
	$('#monitor').addClass('monitor-normal');
	$('#monitor').removeClass('monitor-alt');
	$('#logo-watermark').addClass('logo-watermark-normal');
	$('#logo-watermark').removeClass('logo-watermark-alt');
	$('#home .next').show();
	$('.nextAlt').hide();
	
	$('#core-skills').css('visibility','visible');
	Cufon.refresh();
	$('#main-intro h1').css('visibility','visible');
	$('#main-intro h2').css('visibility','visible');
	$('#main-intro h3').css('visibility','visible');
	//$('#main-intro').show();
}

Cufon.replace('h1', {
	fontfamily: 'Franchise',
	hover: true
});
Cufon.replace('h2', {
	fontfamily: 'Franchise',
	hover: true
});
Cufon.replace('h3', {
	fontfamily: 'Franchise',
	hover: true
});
Cufon.replace('#nav a', {
	fontfamily: 'Franchise',
	hover: true
});
Cufon.replace('.skill-box', {
	fontfamily: 'Franchise',
	hover: true
});

$(document).ready(function(){






//alert('loading flash');
	
	//load monitor
	$("#pull-me-btn-normal").flashembed( { 
  		src: '_assets/_swf/pullme.swf', 
  		version: [10,0,0,0],
		width: 206,
		height: 210,
		wmode: 'transparent' 	
  });
	//load intro text anim
	$("#intro-text").flashembed( { 
		src: '_assets/_swf/intro-flash.swf', 
		version: [10,0,0,0],
		width: 380,
		height: 172,
		wmode: 'transparent' 	
});
/*var params = {
  menu: "false",
  wmode: "transparent"
};
  swfobject.embedSWF("_assets/_swf/pullme.swf", "pull-me-btn-alt", 206, 210, "10.0.0", "", {}, params)
  */
	/*$("#pull-me-btn-alt").flashembed( { 
  		src: '_assets/_swf/pullme.swf', 
  		version: [10,0,0,0],
		width: 206,
		height: 210,
		wmode: 'transparent' 	
  });*/

	



	//load behind the mask swf
/*$("#swf_behind_the_mask").flashembed( { 
  		src: 'slideshow_behind_the_mask.swf', 
  		version: [9,0,28,0],
		width: 530,
		height: 300,
		expressInstall:'swf/playerProductInstall.swf' 
		
  });*/
	
	//load a last stand swf
	/*$("#swf_a_last_stand").flashembed( { 
  		src: 'slideshow_a_last_stand.swf', 
  		version: [9,0,28,0],
		width: 530,
		height: 300,
		expressInstall:'swf/playerProductInstall.swf' 
		
  });*/
	
	//load northgate swf
/*	$("#swf_northgate").flashembed( { 
  		src: 'slideshow_northgate.swf', 
  		version: [9,0,28,0],
		width: 530,
		height: 390,
		expressInstall:'swf/playerProductInstall.swf' 
		
  });*/
	
	
var callback = function(e, delta) {
    //console.log(e.pageX, e.pageY, delta);

    // optionally you can prevent default behavior
    e.stopPropagation();
    e.preventDefault();
	if (delta < 0){
		$.scrollTo( '+=150px', 1, { axis: 'x'} );
	}else if (delta > 0){
		$.scrollTo( '-=150px', 1, { axis: 'x'} );	
	}
};

$('body').mousewheel(callback);

/*$('#nav ul li a').click(function(e){
								 	//override default click behaviour
								 	e.stopPropagation();
    								e.preventDefault();
								 });

$('#nav ul li a').click(function(e){
								 	
								 });*/

$('.next').click(function(e){ 
								//override default click behaviour
								e.stopPropagation();
								e.preventDefault();  
								if( $(this).hasClass('disabled') ){
								}else{
									$.scrollTo( $(this).parent().nextAll('.contentItem').eq(0), 500, { axis: 'x', offset: {left: -20}, easing: 'easeInOutSine'} );
								}
});

$('.nextAlt').click(goNextAlt);
$('#alt-grafitti .hit').click(goNextAltGrafitti);

function goNextAlt(e){ 
								//override default click behaviour
								e.stopPropagation();
								e.preventDefault();  
								if( $(this).hasClass('disabled') ){
								}else{
									$.scrollTo( $(this).parent().nextAll('.contentItemAlt').eq(0), 500, { axis: 'x', offset: {left: -20}, easing: 'easeInOutSine'} );
								}
}

function goNextAltGrafitti(e){ 
								//override default click behaviour
								e.stopPropagation();
								e.preventDefault();  
								if( $(this).hasClass('disabled') ){
								}else{
									$.scrollTo( $('.contentItemAlt').eq(0), 500, { axis: 'x', offset: {left: -20}, easing: 'easeInOutSine'} );
								}
}




$('.previous').click(function(e){ 
							//override default click behaviour
							e.stopPropagation();
							e.preventDefault();  
							if( $(this).hasClass('disabled') ){
							}else if( $(this).parent().parent().parent().parent().prev().hasClass('first') ){
								$.scrollTo( '0px', 1500, { axis: 'x', easing: 'easeInOutSine'} );
							}else{
								$.scrollTo( $(this).parent().parent().parent().parent().prev(), 1500, { axis: 'x', offset: {left: -18}, easing: 'easeInOutSine'} );
							}
});


//$('#pull-me-btn-normal embed').click(initTimer);
//$('#pull-me-btn-normal').click(initTimer);
$('#nav a.labs').click(function(){if(!lightOn){$('#pull-me-btn-normal').hide(); switchToAltMode(); initLabFlash();}});


$('#page00').click(function(e){ $.scrollTo( '0px', 1500, { axis: 'x', easing: 'easeInOutSine'} ); });

$('#page01').click(function(e){	$.scrollTo( $('.contentItem:eq(1)'), 1500, { axis: 'x', offset: {left: -18}, easing: 'easeInOutSine' } ); });

$('#page02').click(function(e){	$.scrollTo( $('.contentItem:eq(2)'), 1500, { axis: 'x', offset: {left: -18}, easing: 'easeInOutSine' } ); });

$('#page03').click(function(e){	$.scrollTo( $('.contentItem:eq(3)'), 1500, { axis: 'x', offset: {left: -18}, easing: 'easeInOutSine' } ); });

$('#page04').click(function(e){	$.scrollTo( $('.contentItem:eq(4)'), 1500, { axis: 'x', offset: {left: -18}, easing: 'easeInOutSine' } ); });

$('#page05').click(function(e){	$.scrollTo( $('.contentItem:eq(5)'), 1500, { axis: 'x', offset: {left: -18}, easing: 'easeInOutSine' } ); });

$('#page06').click(function(e){	$.scrollTo( $('.contentItem:eq(6)'), 1500, { axis: 'x', offset: {left: -18}, easing: 'easeInOutSine' } ); });

$('#page07').click(function(e){	$.scrollTo( $('.contentItem:eq(7)'), 1500, { axis: 'x', offset: {left: -18}, easing: 'easeInOutSine' } ); });

$('#page08').click(function(e){	$.scrollTo( $('.contentItem:eq(8)'), 1500, { axis: 'x', offset: {left: -18}, easing: 'easeInOutSine' } ); });


$('#page09').click(function(e){	$.scrollTo( $('.contentItem:eq(9)'), 1500, { axis: 'x', offset: {left: -18}, easing: 'easeInOutSine' } ); });

$('#page10').click(function(e){	$.scrollTo( $('.contentItem:eq(10)'), 1500, { axis: 'x', offset: {left: -18}, easing: 'easeInOutSine' } ); });

$('#page11').click(function(e){	$.scrollTo( $('.contentItem:eq(11)'), 1500, { axis: 'x', offset: {left: -18}, easing: 'easeInOutSine' } ); });

$('#page12').click(function(e){	$.scrollTo( $('.contentItem:eq(12)'), 1500, { axis: 'x', offset: {left: -18}, easing: 'easeInOutSine' } ); });
	
	
});
