// imctv.js - 
// (c) 2008 Mikrotec Web Design
// 6/30/2008



window.onload = initAll;

jQuery.noConflict();

// Variables for the Movie Box
var movieArray = new Array( "images/footer/movieBig1.jpg", "images/footer/movieBig2.jpg", "images/footer/movieBig3.jpg", "images/footer/movieBig4.jpg" );
var movieTitlesArray = new Array( "Kick Ass", "Date Night", "The Back-up Plan", "Death at a Funeral" );
var movieTrailersArray = new Array( "http://www.youtube.com/watch?v=_oy4IFvH2Tc", 
								    "http://www.youtube.com/watch?v=aspBKFz2dBI", 
								    "http://www.youtube.com/watch?v=WAyzwSZ2o48", 
								    "http://www.youtube.com/watch?v=RidTIIvXRM8" );
var movieIndex = new Array( 0, 1, 2 );
var autoRotateFlag = true;

function initAll() {

	// Pop Button Hover Animation.
	jQuery('.popButton').hover(
		function() {
			jQuery(this).animate({height: '75px', width: '75px', marginTop: '-12px', marginLeft: '7px', marginRight: '-5px'}, 'fast');
		},
		function() {
			jQuery(this).animate({height: '50px', width: '50px',marginTop: '0px', marginLeft: '20px', marginRight: '0px'}, 'fast');
	});
	
	// Set-Up Movie Functions
	initMovies();
	
	// Set-Up Splash Buttons.
	
	jQuery('#swapButton01').click( function() {
	   splashFadeOut();		
		setTimeout( "swapSplash(1)", 500);		
		splashFadeIn();		
		return false;
	});
	
	jQuery('#swapButton02').click( function() {
	   splashFadeOut();		
		setTimeout( "swapSplash(2)", 500);		
		splashFadeIn();		
		return false;
	});
	
	jQuery('#swapButton03').click( function() {
	   splashFadeOut();		
		setTimeout( "swapSplash(3)", 500);		
		splashFadeIn();		
		return false;
	});
	
	jQuery('#swapButton04').click( function() {
	   splashFadeOut();		
		setTimeout( "swapSplash(4)", 500);		
		splashFadeIn();		
		return false;
	});
	
}





// ----- Splash Screen Functions -----

function splashFadeOut() {
	jQuery('#splashBackground').animate({opacity: '0.0'}, 'slow');
	jQuery('#splashRightBar').animate({opacity: '0.0'}, 'slow');
}

function splashFadeIn() {
	jQuery('#splashBackground').animate({opacity: '1'}, 'slow');
	jQuery('#splashRightBar').animate({opacity: '1'}, 'slow');
}

function swapSplash( swapIndex ) {
	
	if ( swapIndex == 1 ) {
		jQuery('#splashBackground').get(0).innerHTML  = jQuery('#splashSwapBackground01').get(0).innerHTML;
		jQuery('#splashRightBar').get(0).innerHTML  = jQuery('#splashSwapRightBar01').get(0).innerHTML;
	}
	
	if ( swapIndex == 2 ) {
		jQuery('#splashBackground').get(0).innerHTML  = jQuery('#splashSwapBackground02').get(0).innerHTML;
		jQuery('#splashRightBar').get(0).innerHTML  = jQuery('#splashSwapRightBar02').get(0).innerHTML;
	}
	
	if ( swapIndex == 3 ) {
		jQuery('#splashBackground').get(0).innerHTML  = jQuery('#splashSwapBackground03').get(0).innerHTML;
		jQuery('#splashRightBar').get(0).innerHTML  = jQuery('#splashSwapRightBar03').get(0).innerHTML;
	}
	
	if ( swapIndex == 4 ) {
		jQuery('#splashBackground').get(0).innerHTML  = jQuery('#splashSwapBackground04').get(0).innerHTML;
		jQuery('#splashRightBar').get(0).innerHTML  = jQuery('#splashSwapRightBar04').get(0).innerHTML;
	}
	
}







// ----- Movie Box Functions -------------

function initMovies() {
		
	jQuery('#bigPoster').get(0).src = movieArray[movieIndex[0]];
	jQuery('#movieTrailerLink').get(0).innerHTML = movieTitlesArray[movieIndex[0]];
	jQuery('#movieTrailerLink').get(0).href = movieTrailersArray[movieIndex[0]];
	
	jQuery('#smallPoster01').get(0).src = movieArray[movieIndex[1]];
	jQuery('#smallPoster01').fadeTo( 1, .6 );
	
	jQuery('#smallPoster02').get(0).src = movieArray[movieIndex[2]];
	jQuery('#smallPoster02').fadeTo( 1, .15 );	
	
	jQuery('#movieNext').click( function() {
		rotateNext();
		setTimeout( "resetAutoRotate()", 8000 );
		autoRotateFlag = false;		
		return false;
	});
	
	autoRotateFlag = false;
	autoRotate();
	setTimeout( "resetAutoRotate()", 30 );
	
	return true;
	
}

function rotateNext() { 
	var maxIndex = movieArray.length;
	
	movieIndex[0] = previousIndex( movieIndex[0], maxIndex );
	movieIndex[1] = previousIndex( movieIndex[1], maxIndex );
	movieIndex[2] = previousIndex( movieIndex[2], maxIndex );

	jQuery('#bigPoster').css({marginTop: '50px', marginLeft: '120px', width: '75px', height: '113px', opacity: '.6' });
	jQuery('#smallPoster01').css({opacity: '0.15' });	
	jQuery('#smallPoster02').css({opacity: '0' });	
	
	jQuery('#bigPoster').get(0).src = movieArray[movieIndex[0]];
	jQuery('#movieTrailerLink').css({opacity: '0'});
	jQuery('#movieTrailerLink').get(0).innerHTML = movieTitlesArray[movieIndex[0]];
	jQuery('#movieTrailerLink').get(0).href = movieTrailersArray[movieIndex[0]];
	
	jQuery('#smallPoster01').get(0).src = movieArray[movieIndex[1]];
	jQuery('#smallPoster02').get(0).src = movieArray[movieIndex[2]];
	
	jQuery('#bigPoster').animate({marginTop: '15px', marginLeft: '20px', height: '150px', width: '100px', opacity: '1' }, 'fast');
	jQuery('#smallPoster01').animate({opacity: '.6' }, 'fast');	
	jQuery('#smallPoster02').animate({opacity: '.15' }, 'fast');	
	jQuery('#movieTrailerLink').animate({opacity: '1'}, 'normal');
	
	return false;

}

function autoRotate() {
	if ( autoRotateFlag == true ) {
		rotateNext();		
	}
	setTimeout( "autoRotate()", 8000 );
}

function resetAutoRotate() {
	autoRotateFlag = true;	
}


function nextIndex( oldIndex, maxIndex ) {

	newIndex = oldIndex + 1;

	if ( newIndex == maxIndex ) {
		newIndex = 0;
	}
	
	return newIndex;
	
}

function previousIndex( oldIndex, maxIndex ) {

	newIndex = oldIndex + 1;

	if ( newIndex == maxIndex ) {
		newIndex = 0;
	}
	
	return newIndex;
	
}