/***************************************
 
 Meetings Home Media 2.0.1 (Codename 'Autoscroll')
 by Will Peavy, will.peavy@visitorlando.com
 
***************************************/

$('#home-player')
	.css('background','#C6E9E8 url(/images/home-media/' + $('#player-menu li:first').attr('img') +')')
	.attr('link',$('#player-menu li:first').attr('link'));
	
if ($('#player-menu li:first').hasClass('image')) {
	$('#home-player, #player-overlay').addClass('playerType-Image');
}
else {
	$('#home-player, #player-overlay').addClass('playerType-Video');
	
}

var firstLink = $('#player-menu li:first').attr('link');
$('#player-overlay').attr('link',firstLink);

$('#player-menu li:first').addClass('active');
var ovrHead = $('#player-menu li:first').find('.overlay-header').text();
var ovrText = $('#player-menu li:first').find('.overlay-text').text();
/*$('#overlay-content').html('<strong>' + ovrHead + '</strong><br>' + ovrText); */
$('#overlay-content').html('<h1>' + ovrHead + '</h1><br>' + ovrText);


$(document).ready(function() {
	
	$('#player-menu, #menu-bg').show();
	$('#player-menu li:last').addClass('last');
	$('#player-menu').jcarousel();
	
	//var menuSize = $('#player-menu li').size();
	var i = 0;
	var pauseScroll = false;
	var stopScroll = false;
	var delay = false;
	var startTime = 6000;
	
	$('#player-menu li, #home-media .jcarousel-next, #home-media .jcarousel-prev, #home-player, #player-overlay, #watchVid')
	.hover(																																																	
		function () {
			pauseScroll = true;
		}, 
		function () {
			pauseScroll = false;
		}
	
	);
	
	$('#readMore').click(function() {
		window.location = firstLink;
	});
	
	var activeItem = $('#player-menu li').eq(i);
	 if (activeItem.hasClass('video')) {
		 if(activeItem.attr('itemID')==='199'){
			 $('#links').html("<a href='#' id='watchVid'>Watch Video</a>&nbsp;&nbsp;<a href='" + activeItem.attr('link') + "'>Read More</a>");
		 } else {$('#links').html("<a href='#' id='watchVid'>Watch Video</a>");} 
		 $('#home-player').colorbox({height:"494",width:"700",scrolling: false,html:"<iframe src=/customcf/home.video-frame.cfm?vid="+activeItem.attr('vid')+"></iframe>"});
								
								$('#watchVid').colorbox({height:"494",width:"700",scrolling: false,onClosed:function(){stopScroll=false;},html:"<iframe src=/customcf/home.video-frame.cfm?vid="+activeItem.attr('vid')+"></iframe>"});
								
								$('#watchVid').click( function() {
									pauseScroll = true;
								});
								
								$('#readMore').click(function() {
									
									window.location = activeItem.attr('vidlink');
								});
								
								$('#home-player').colorbox.close
								
	 } else {
		 $('#links').html("<a href='" + firstlink + "'>Read More</a>");
	 }
	
	function autoScroll() {
						
		if (stopScroll == false) {
		
			if (i < 6) { //menuSize
				
				setTimeout(function() {
					
					if (pauseScroll === false && stopScroll == false) {
					
						i++;
						var activeItem = $('#player-menu li').eq(i);
						
						$('#player-menu li').removeClass('active');
						activeItem.addClass('active');
						
						ovrHead = activeItem.find('.overlay-header').text();
						ovrText = activeItem.find('.overlay-text').text();
						$('#overlay-content').html('<h1>' + ovrHead + '</h1><br>' + ovrText);
						$('#player-overlay').show();
						
						if (activeItem.hasClass('image')) {
							$('#home-player')
								.addClass('playerType-Image').removeClass('playerType-Video')
								.css('background','#C6E9E8 url(/images/home-media/' + activeItem.attr('img') +')')
								.attr('link',activeItem.attr('link'))
								
								if($('#home-player').colorbox()) {
									$('#home-player').unbind();
								}
								
								if($('#watchVid').colorbox()) {
									$('#watchVid').unbind();
								}
								
								/*$('#readMore').click(function() {
									
									window.location = activeItem.attr('link');
								}); */
								
								$('#links').html("<a href='" + activeItem.attr('link') + "'>Read More</a>");
                                
								
							$('#player-overlay')
								.addClass('playerType-Image').removeClass('playerType-Video')
								.attr('link',activeItem.attr('link'));
							
							if ($('#home-player').attr('vid')) {
								$('#home-player, #player-overlay').removeAttr('vid')
							}

						}
						
						else if (activeItem.hasClass('video')) {
							
							if(activeItem.attr('itemID')==='199'){
			                   $('#links').html("<a href='#' id='watchVid'>Watch Video</a>&nbsp;&nbsp;<a href='" + activeItem.attr('link') + "'>Read More</a>");
		                    } else {$('#links').html("<a href='#' id='watchVid'>Watch Video</a>");} 
							
							$('#home-player')
								.addClass('playerType-Video').removeClass('playerType-Image')
								
								.css('background','#C6E9E8 url(/images/home-media/' + activeItem.attr('img') +')')
								.attr('vid',activeItem.attr('vid'));
							/*	$('#links').html("<a href='#' id='watchVid'>Watch Video</a>"); */
								
								$('#home-player').colorbox({height:"494",width:"700",scrolling: false,html:"<iframe src=/customcf/home.video-frame.cfm?vid="+activeItem.attr('vid')+"></iframe>"});
								
								$('#watchVid').colorbox({height:"494",width:"700",scrolling: false,onClosed:function(){stopScroll=false;},html:"<iframe src=/customcf/home.video-frame.cfm?vid="+activeItem.attr('vid')+"></iframe>"});
								
								$('#watchVid').click( function() {
									pauseScroll = true;
								});
								
								/*
								$('#readMore').click(function() {
									
									window.location = activeItem.attr('vidlink');
								});
								*/
								
								
							$('#player-overlay')
								.addClass('playerType-Video').removeClass('playerType-Image')
								.attr('vid',activeItem.attr('vid'));

							if ($('#home-player').attr('link')) {
								$('#home-player, #player-overlay').removeAttr('link')
							}
							
							if (activeItem.attr('pos')) {
								$('#home-player, #player-overlay').attr('pos',activeItem.attr('pos'));
							}
							else {
								$('#home-player, #player-overlay').removeAttr('pos');
							}

						}
						
						//if (i === 3 || i === 6 || i === 9 || i === 12) {
						if (i === 3) {
							$('#home-media .jcarousel-next').click();
							$('#home-media .jcarousel-next').attr('style','display:none').after('<div class="jcarousel-next jcarousel-next-horizontal jcarousel-next-disabled jcarousel-next-disabled-horizontal" style="display: block;" disabled="true"></div>');
						}
					
					}
					
				}, startTime);
				
				setTimeout(autoScroll, 8000);
				
			}
			
			else {
				
				
				i = -1;
				//var j = -1;
				
				function restart() {
					if (pauseScroll === false && stopScroll == false) {
						/*j++;
						if (j < (menuSize / 3)) {
							$('#home-media .jcarousel-prev').click();
							startTime = j * 500;
							setTimeout(restart, 500);
						}*/
						$('#home-media .jcarousel-prev').click();
						$('#home-media .jcarousel-next:eq(0)').attr('style','display:block');
						$('#home-media .jcarousel-next-disabled').remove();
						startTime =  0; //500;
					}
				}
				
				restart();
				autoScroll();
				
			}
		
		}
		
	};
	
	autoScroll();
	
	
	$('#player-menu li').click(function() {
		
		stopScroll = true;
		ovrHead = $(this).find('.overlay-header').text();
		ovrText = $(this).find('.overlay-text').text();
		
		$('#player-menu li').removeClass('active');
		$(this).addClass('active');
		$('#overlay-content').html('<h1>' + ovrHead + '</h1><br>' + ovrText);
		$('#player-overlay').show();
		
		$('#home-player')
			.css('background','#C6E9E8 url(/images/home-media/' + $(this).attr('img') +')')
			.attr('link',$(this).attr('link'));
			
	 	$('#player-overlay').attr('link',$(this).attr('link'));
		$('activeItem').attr
		
		if ($(this).hasClass('image')) {
			$('#home-player, #player-overlay').addClass('playerType-Image').removeClass('playerType-Video');
			
			if($('#home-player').colorbox()) {
				$('#home-player').unbind();
			}
			
			if($('#watchVid').colorbox()) {
				$('#watchVid').unbind();
			}
			
			$('#links').html("<a href='" + $('#home-player').attr('link') + "'>Read More</a>");
			
		/*	$('#readMore').click(function() {
				window.location = $('#home-player').attr('link');
			}); */
			
		}
		
		else {
			
		/*	$('#links').html("<a href='#' id='watchVid'>Watch Video</a>"); */
		   if($(this).attr('itemID')==199){
					
			                   $('#links').html("<a href='#' id='watchVid'>Watch Video</a>&nbsp;&nbsp;<a href='" + activeItem.attr('link') + "'>Read More</a>");
		                    } else {$('#links').html("<a href='#' id='watchVid'>Watch Video</a>");}
			
			$('#home-player, #player-overlay').addClass('playerType-Video').removeClass('playerType-Image')
			    
				.attr('vid',$(this).attr('vid'))
				
			    $('#readMore').attr('vidlink',$(this).attr('vidlink')) 	
				
				$('#watchVid').colorbox({height:"494",width:"700",scrolling: false,onClosed:function(){stopScroll=false;},html:"<iframe src=/customcf/home.video-frame.cfm?vid="+$(this).attr('vid')+"></iframe>"});
				
				$('#home-player').colorbox({height:"494",width:"700",scrolling: false, html:"<iframe src=/customcf/home.video-frame.cfm?vid="+$(this).attr('vid')+"></iframe>"});
				
				
				$('#watchVid').click( function() {
									pauseScroll = true;
								});
													
											
			
			if ($(this).attr('pos')) {
				$('#home-player, #player-overlay').attr('pos',$(this).attr('pos'));
			}
			else {
				$('#home-player, #player-overlay').removeAttr('pos');
			}
			
		}
		
		$('#home-player').html('');
		
	});
	
	$('#home-media').delegate('.playerType-Image', 'click', function(){
		
		window.location = $(this).attr('link'); 
	});
	
	
	$('#home-media').delegate('.playerType-Video', 'click', function(){
		
		stopScroll = true;
		
		/*$('#home-player') */ 
		
		/*	.html('<iframe id="video-frame" src ="/customcf/home.video-frame.cfm?vid='+$(this).attr('vid')+'" width="643" height="317" frameborder="0" scrolling="no"></iframe>'); */
		
		/*$('#player-overlay').fadeOut(750); */
		
		if ($(this).attr('pos')) {
			videoTracker($(this).attr('pos'));
		}
		
	});
	
	
	
	/*if ($.browser.webkit) {
		$('#player-menu li.last').attr('style','position:absolute; top:0; right:-55px; padding-right:95px');
	}*/
	
	$('#home-media .jcarousel-next').click(function() {
		$('#home-media .jcarousel-next').attr('style','display:none').after('<div class="jcarousel-next jcarousel-next-horizontal jcarousel-next-disabled jcarousel-next-disabled-horizontal" style="display: block;" disabled="true"></div>');
	});
	
	$('#home-media .jcarousel-prev').click(function() {
		$('#home-media .jcarousel-next').attr('style','display:block');
		$('#home-media .jcarousel-next-disabled').remove();
	});
							
	$('#home-media .jcarousel-next, #home-media .jcarousel-prev').mouseup(function() {
		stopScroll = true;
	});
	
});




