/* I had to comment out all of the console.log() calls because IE */

$(document).ready(function(){
	$('.control_box_content_container').hide(0);
	$('#control_lightbox').hide(0);
	
	$('.image_lightbox_button').bind('click', function(e){
		
		$('#general_lightbox').fadeIn(400);
		$('.control_box_content_container').hide(0);
		$('#contact_your_rep').hide(0);
		var img = $(this).attr('rel');
		$('#landing_large_img').html('<img src="' + img + '" />');
		$('#landing_page_lightbox_image').fadeIn(400);
		return false;
		e.preventDefault();
		
	});
	
	$('.contact_opener, #landing_pages_right_col_1').bind('click', function(){
		$('#video_window').remove();
		$('.control_box_content_container').hide();
		$('#general_lightbox').hide();
		$('#control_lightbox').fadeIn(400);
		$('#contact_your_rep').show();
	});
	
	$('#control_panel6_talk_to_rep').bind('click', function(){
		$('#control_lightbox').fadeIn(400);
		$('.control_box_content_container').hide(0);
		$('#contact_your_rep').fadeIn(200);
	});
	
	$('#control_talk_top_btn').bind('click', function(){
		$('#control_lightbox').fadeIn(400);
		$('.control_box_content_container').hide(0);
		$('#contact_your_rep').fadeIn(200);
	});
	
	$('.demo_opener').bind('click', function(){
		$('#control_lightbox').fadeIn(400);
		$('.control_box_content_container').hide(0);
		$('#contact_schedule_demo').fadeIn(200);
	});
	
	$('.lb-send-info').bind('click', function(){
		$('#control_lightbox').fadeIn(400);
		$('.control_box_content_container').hide(0);
		$('#contact_send_info').show();
	});
	
	$('#control_panel6_schedule_demo').bind('click', function(){
		$('#control_lightbox').fadeIn(400);
		$('.control_box_content_container').hide(0);
		$('#contact_schedule_demo').fadeIn(200);
	});
	
	$('#control_panel6_fba').bind('click', function(){
		$('#control_lightbox').fadeIn(400);
		$('.control_box_content_container').hide(0);
		$('#contact_fba').fadeIn(200);
	});
	
	$('#control_panel6_send_info').bind('click', function(){
		$('#control_lightbox').fadeIn(400);
		$('.control_box_content_container').hide(0);
		$('#contact_send_info').show();
	});
	
	$('#schedule_live_demo').bind('click', function(){
		$('#control_lightbox').fadeIn(400);
		$('.control_box_content_container').hide(0);
		$('#contact_schedule_demo').fadeIn(200);
	});
	$('#talking_to_rep').bind('click', function(){
		$('#control_lightbox').fadeIn(400);
		$('.control_box_content_container').hide(0);
		$('#contact_your_rep').fadeIn(200);
	});
	
	$('.testimonials_opener').bind('click', function(){
		$('#video_window').remove();
		$('.control_box_content_container').hide(0);
		$('#control_lightbox').hide(0);
		$('#general_lightbox').fadeIn(400);
		$('.general_content_container').hide(0);
		$('#testimonials').show();
	});
	
	$('#lightbox_close_btn').bind('click', function(){
		$('#control_lightbox').fadeOut(400);
	});
	
	$('#general_lightbox_close_btn').bind('click', function(){
		$('#video_window').remove();
		$('#general_lightbox').fadeOut(400);
		$('.general_content_container').fadeOut(0);
		$('#testimonials').fadeOut(0);
		$('#system_requirements_window').hide();
	});

	$('.lb-send-message').bind('click', function(){
		$('.control_box_content_container').fadeOut(0, function(){
			$('#contact_your_rep').fadeIn(0)
			});
	});
	
	$('.lb-schedule-demo').bind('click', function(){
		$('.control_box_content_container').fadeOut(0, function(){
			$('#contact_schedule_demo').fadeIn(0)
			});
	});
	
	$('.lb-fba').bind('click', function(){
		$('.control_box_content_container').fadeOut(0, function(){
			$('#contact_fba').fadeIn(0)
			});
	});
	
	//Testimonial Lightbox
	$('.testimonial_video_single').mouseenter(function(){
		$(this).addClass('hover', 400);
	});
	
	$('.testimonial_video_single').mouseleave(function(){
		$(this).removeClass('hover', 400);
	});
	
	$('#testimonial_videos_container').children('#test_vid_single').bind('click', function(){
		//$('.general_content_container').hide();
		var vid_link = $(this).children('.testimonial_video_box').attr('rel');
		var vid_title = $(this).children('.testimonial_video_box').attr('title');
		$('#testimonials').fadeOut(400);
		
		// Old
		//$('.vid_containment').append('<div id="video_window"><div id="lb_video_title">'+vid_title+'</div><embed src="'+vid_link+'" width="640px" height="374px" bgcolor="000000"></embed><div id="test_video_back">Hear how other Control users have succeeded</div></div>');
		$('.vid_containment').append('<div id="video_window"><iframe width="640" height="435" src="http://www.youtube.com/embed/'+vid_link+'?rel=0" frameborder="0" allowfullscreen></iframe><div id="test_video_back">Hear how other Control users have succeeded</div></div>');
		
		$('#test_video_back').bind('click', function(){
			
			$('#video_window').remove();
			$('#testimonials').fadeIn(400);
		});
	
	});
	
	
	//Get Control Lightbox
	$('.get_control_top_btn').bind('click', function(){
		$('#general_lightbox').fadeIn(400);
		$('.general_content_container').fadeOut(0);
		$('#get_control_window').show();
	});
	
	$('#get_control').bind('click', function(){
		$('#general_lightbox').fadeIn(400);
		$('.general_content_container').hide(0);
		$('#get_control_window').show();
	});
	
	$('#control_path2_video_container').children().bind('click', function(){
		var path2_vid_url = $(this).attr('rel');
		var vid_title = $(this).attr('title');
		$('#general_lightbox').fadeIn(400);
		$('.control_box_content_container').hide();
		$('.general_content_container').hide();
		// Old
		//$('.vid_containment').append('<div id="video_window"><div id="lb_video_title">'+vid_title+'</div><embed src="'+path2_vid_url+'" width="640px" height="435px" bgcolor="00000"></embed><div id="path_video_back">Explore More Control Features</div></div>');
		$('.vid_containment').append('<div id="video_window"><iframe width="640" height="435" src="http://www.youtube.com/embed/'+path2_vid_url+'?rel=0" frameborder="0" allowfullscreen></iframe><div id="path_video_back">Explore More Control Features</div></div>');
		
		
		$('.vid_containment').fadeIn(200);
		
		$('#path_video_back').bind('click', function(){
			$('#video_window').remove();
			$('#general_lightbox').fadeOut(100);
		});
	});
	
	$('.watch_video').bind('click', function(){
		var path2_vid_url = "Eo0mrL6APLw";
		var vid_title = $(this).attr('title');
		$('#general_lightbox').fadeIn(400);
		$('.control_box_content_container').hide();
		$('.general_content_container').hide();
		// Old
		//$('.vid_containment').append('<div id="video_window"><div id="lb_video_title">'+vid_title+'</div><embed src="'+path2_vid_url+'" width="640px" height="435px" bgcolor="00000"></embed><div id="path_video_back">Explore More Control Features</div></div>');
		$('.vid_containment').append('<div id="video_window"><iframe width="640" height="435" src="http://www.youtube.com/embed/'+path2_vid_url+'?rel=0" frameborder="0" allowfullscreen></iframe><div id="path_video_back">Contact a Cyrious Rep</div></div>');
		
		
		$('.vid_containment').fadeIn(200);
		
		$('#path_video_back').bind('click', function(){
			
			$('#control_lightbox').fadeIn(200);
			$('.control_box_content_container').hide(200);
			$('#contact_your_rep').fadeIn(200);
			
			$('#video_window').remove();
			$('#general_lightbox').fadeOut(200);
			
		});
	});
	
	//
	$('.video_button').bind('click', function(){
		var path2_vid_url = $(this).attr('rel');
		var vid_title = $(this).attr('title');
		$('#general_lightbox').fadeIn(400);
		$('.control_box_content_container').hide();
		$('.general_content_container').hide();
		// Old
		//$('.vid_containment').append('<div id="video_window"><div id="lb_video_title">'+vid_title+'</div><embed src="'+path2_vid_url+'" width="640px" height="435px" bgcolor="00000"></embed><div id="path_video_back">Explore More Control Features</div></div>');
		$('.vid_containment').append('<div id="video_window"><iframe width="640" height="435" src="http://www.youtube.com/embed/'+path2_vid_url+'?rel=0" frameborder="0" allowfullscreen></iframe><div id="path_video_back">Contact a Cyrious Rep</div></div>');
		
		
		$('.vid_containment').fadeIn(200);
		
		$('#path_video_back').bind('click', function(){
			
			$('#control_lightbox').fadeIn(200);
			$('.control_box_content_container').hide(200);
			$('#contact_your_rep').fadeIn(200);
			
			$('#video_window').remove();
			$('#general_lightbox').fadeOut(200);
			
		});
	});
	
	//Hardware Requirements
	$('.software_req_btn').click(function(){
			var next_container = '#'+($(this).next().attr('id'));
			var next_container_tracker = $('.open_requirement').attr('id');

			
			if($(next_container).hasClass('open_requirement')){
				$(next_container).animate({
						height: 'toggle'
					}, 200, function(){
						$(next_container).removeClass('open_requirement');
					});
			} else if($('.control_requirements_container').hasClass('open_requirement')) {

				$('.open_requirement').animate({
					height: 'toggle'
				}, 200, function(){
					$('.open_requirement').removeClass('open_requirement');
					$(next_container).animate({
						height: 'toggle'
					}, 200, function(){
						$(next_container).addClass('open_requirement');
					});
				});
			} else {

				$(next_container).animate({
					height: 'toggle'
				}, 200, function(){
					$(next_container).addClass('open_requirement');
				});
			};
		});
	
	$('#control_hardware_requirements').bind('click', function(){
		$('#general_lightbox').fadeIn(400);
		$('.general_control_container').hide();
		$('.general_content_container').hide();
		$('#system_requirements_window').show();
		
		$('.control_requirements_container').hide();
		
	});
	
	//Make It More Custom
	$('#control_custom_to_you').bind('click', function(){
		$('#general_lightbox').fadeIn(400);
		$('#more_custom_content').fadeIn(0);
	});
	
	//Product Screenshot Lightbox
	$('#control_works_photo_container ul li img').bind('click', function(){
		$('#general_lightbox').fadeIn(400);
		$('.general_control_container').hide();
		$('.general_content_container').hide();
		$('#product_screenshot_lightbox').show();
		
		var image_location = $(this).attr('rel');
		
		$('#product_screenshot_lightbox').html('<div id="control_product_screenshot"><img src="'+image_location+'">');
	});
	
	//FAQ Lightbox
	$('#control_faqs').bind('click', function(){
		$('#general_lightbox').fadeIn(400);
		$('.general_control_container').hide();
		$('.general_content_container').hide();
		$('#faq_lightbox').show();
		$('#faq_lightbox ul li .toggled').removeClass('toggled');
		$('#faq_lightbox ul li p').hide();
	});
	
	$('#faq_lightbox ul li h4').bind('click', function(){
		var nextp = $(this).next('p');
		
		if($(nextp).hasClass('active')){
			$(nextp).toggle(400);
			$(nextp).removeClass('active');
			$(nextp).removeClass('toggled');
		}else if($('#faq_lightbox ul li p').hasClass('toggled')){
			$('#faq_lightbox ul li .toggled').toggle(400);
			$('#faq_lightbox ul li .toggled').removeClass('active');
			$('#faq_lightbox ul li .toggled').removeClass('toggled');
			$(nextp).toggle(400);
			$(nextp).addClass('toggled');
			$(nextp).addClass('active');
		}else{
			$(nextp).toggle(400);
			$(nextp).addClass('toggled');
			$(nextp).addClass('active');
		};
	});
	
	//Online Lightbox See it in Action
	$('#online_path2_video_container').children().bind('click', function(){
		var path2_vid_url = $(this).attr('rel');
		var vid_title = $(this).attr('title');
		$('#general_lightbox').fadeIn(400);
		$('.control_box_content_container').hide();
		$('.general_content_container').hide();
		// Old
		//$('.vid_containment').append('<div id="video_window"><div id="lb_video_title">'+vid_title+'</div><embed src="'+path2_vid_url+'" width="640px" height="435px" bgcolor="00000"></embed><div id="path_video_back">Explore More Control Features</div></div>');
		$('.vid_containment').append('<div id="video_window"><iframe width="640" height="435" src="http://www.youtube.com/embed/'+path2_vid_url+'?rel=0" frameborder="0" allowfullscreen></iframe><div id="path_video_back">Explore More Online Features</div></div>');
		
		
		$('.vid_containment').fadeIn(200);
		
		$('#path_video_back').bind('click', function(){
			$('#video_window').remove();
			$('#general_lightbox').fadeOut(100);
		});
	});
	
	//Videos Lightbox
	$('#cam_flyout').bind('click', function(){
		$('#general_lightbox').fadeIn(400);
		$('.general_control_container').hide();
		$('.general_content_container').hide();
        $('#float_videos_lightbox').fadeIn(400);
	});
	
	$('#float_videos_thumb_container').children('#test_vid_single').bind('click', function(){
		//$('.general_content_container').hide();
		var vid_link = $(this).children('.testimonial_video_box').attr('rel');
        console.log("vidLink: "+vid_link)
		$('#float_videos_lightbox').fadeOut(400);
		
		//Old
		//$('.vid_containment').append('<div id="video_window"><embed src="'+vid_link+'" width="640px" height="374px" bgcolor="000000"></embed><div id="float_video_back">Contact a Cyrious Rep</div><div id="float_video_title">Save Time. Save Money. Gain Control</div></div>');
		$('.vid_containment').append('<div id="video_window"><iframe width="640" height="435" src="http://www.youtube.com/embed/'+vid_link+'?rel=0" frameborder="0" allowfullscreen></iframe><div id="float_video_back">Contact a Cyrious Rep</div></div>');
		
		$('#float_video_back').bind('click', function(){
			$('#video_window').remove();
					$('.control_box_content_container').hide();
					$('#general_lightbox').hide();
					$('#control_lightbox').fadeIn(400);
					$('#contact_your_rep').show();
		});
	
	});
});
