/* Author: Rob Maurizi, RHM Interactive

*/

jQuery(document).ready(function($) {

	$('.ie7 .current-menu-ancestor .sub-menu').each(function() {
		var p = $('.current-menu-ancestor').find('a').eq(0).position();
		$(this).css('left', p.left).show();
	});

	/* IE fixes */
	$(".oldie #team .exec").filter(function(i) {
		return i % 3 == 0;
	}).css('clear','left');

	$(".oldie #price-comparisons .price-comps li").filter(function(i) {
		return i % 3 == 2;
	}).css('margin-right','0');
	
	$(".oldie .footer-links li:last").addClass('last');
	


	
	$("#carousel").append('<div class="carousel-nav carousel-back"></div><div class="carousel-nav carousel-next"></div>');
	
	$("#carousel-content").cycle({
		fx:     'scrollHorz', 
		prev:   '.carousel-back', 
		next:   '.carousel-next',
		timeout: 10000,
		// pause: 1,
		// pauseOnPagerHover: 1,
		speed: 2000
	}).removeClass('noCarousel').addClass('hasCarousel');
	
	$("#carousel-content").bind(
		"mouseover", function() {
			$("#carousel-content").cycle('pause');
		}
	);
	$("#carousel-content").bind(
		"mouseout", function() {
			$("#carousel-content").cycle('resume');
		}
	);
	
	
	
	$('.global-nav > li').hover(function() {
		$(this).addClass('hovering');
		// console.log(p.left);
		if ($(this).has('.sub-menu').length != 0) {
			$('.sub-menu').hide();
		}
		var p = $(this).find('a').eq(0).position();
		$('.ie7').find($(this)).find('.sub-menu').css('left', p.left);
		$(this).find('.sub-menu').show();
		// $(this).find('.sub-menu').css('left', p.left).show();
	}, function() {
		$(this).find('.sub-menu').hide();
		$('.global-nav .current-menu-item .sub-menu, .global-nav .current_page_parent .sub-menu').show();
		$(this).removeClass('hovering');
	});
	


	$('#screens-container').cycle({
		fx: 'fade',
		timeout: 0
	});
	
	
	$("#screen-titles a").eq(0).addClass('active');
	$("#post-captions .caption").eq(0).removeClass('visuallyhidden');
	
	$('#screen-titles a').each(function(i) {
		$(this).click(function() {
			$('#screen-titles .active').removeClass('active');
			$("#screens-container").cycle(i);
			$(this).addClass('active');
			
			$("#post-captions .caption").addClass('visuallyhidden');
			$("#post-captions .caption").eq(i).removeClass('visuallyhidden');
			
			return false;
		});
	});


	// $("#partner-schools .video-player").eq(0).removeClass('hidden-player').addClass('visible-player');

	$('.video-thumbs a').click(function() {
		
		// var h = $('.visible-player').html();
		// console.log(h);
		// $('.visible-player').empty().html(h).removeClass('visible-player').addClass('hidden-player');
		// $('.visible-player').removeClass('visible-player').addClass('hidden-player');
		// 
		// $('.visible-player iframe').attr('src', $('.visible-player iframe').attr('src'));
		// 
		// var v = $(this).attr('href');
		// $(v).removeClass('hidden-player').addClass('visible-player');

		$("#video-player").empty();
		var u = $(this).attr('href');
		var id = $(this).attr('id');
		var asset = u+" #clip-main";
		// 
		$("#video-player").load(asset, function() {
			// if ($("#video-player iframe").attr('width') == "0") {
			// 	$("#video-player iframe").attr('width', '565');
			// 	$("#video-player iframe").attr('height', '317');
			// }
		});
		return false;
	});
	
	
	$("#blog .widget_links a").click(function() {
		var w = window.open($(this).attr('href'));
		return false;
	});
	
	
	$(".video-overlay").fancybox({
		onStart: pauseCarousel,
		onClosed: resumeCarousel,
		onComplete: adjustVideo
	});
	
	
	
	
	
	
	
	
	
});


function toggleCarousel() {
	jQuery("#carousel-content").cycle('toggle');
}
function pauseCarousel() {
	jQuery("#carousel-content").unbind('mouseout');
}
function resumeCarousel() {
	jQuery("#carousel-content").bind(
		'mouseout', function() {
			jQuery("#carousel-content").cycle('resume');
		}
	);
	jQuery("#carousel-content").cycle('resume');
}


function adjustVideo() {
	
	// if ($("#clip-main iframe").attr('width') == "0") {
	// 	$("#clip-main iframe").attr('width', '565');
	// 	$("#clip-main iframe").attr('height', '317');
	// }
	
}
