$(document).ready(
	function(){
		if ($("#introvideo").length != 0) {
			$("#introvideo").show();
			$("#introvideoClose").click(
				function() {
					$("#introvideo").hide();
					$("#introvideo").html('');
				});
			if($("#introvideo").html() != ""){
				$("html").click(
					function() {
						$("#introvideo").hide();
						$("#introvideo").html('');
					});
			}
		}
		$("#headerbg_images").innerfade({
			speed: 4000,
			timeout: 8000,
			type: 'random_start',
			containerheight: '300px'
			});
		
		$("#footercontent").load("footer.html");
		
		$("#footercontent").hide();
		
		$("#showfooter").click(
			function() {
				$("#footercontent").slideDown(500, "easeInQuint");
				$("#showfooter").hide();
				$("#hidefooter").show();
			});
			
		$("#hidefooter").click(
			function() {
				$("#footercontent").slideUp(500, "easeOutQuint");
				$("#hidefooter").hide();
				$("#showfooter").show();
			});
		
		$("a[rel='external']").addClass("external").click(
			function() {
        		window.open( $(this).attr('href') );
        		return false;
    		});
		
		$(".next, .next2, .prev, .prev2").fadeTo(1, 0.25);
  
  		$(".next, .next2, .prev, .prev2").hover(
    		function () {
    			$(this).fadeTo("fast", 1);
    		},
    		function () {
      			$(this).fadeTo("normal", 0.25);
    		});
		
		$(".catthumb img, .headthumb img").fadeTo(1, 0.5);
		
		$(".catthumb img, .headthumb img").hover(
    		function () {
    			$(this).fadeTo("fast", 1);
    		},
    		function () {
      			$(this).fadeTo("normal", 0.5);
    		});
		if($(".scrollable").length){
			$(".scrollable").scrollable({
				size: 3,
				items: ".scrollthirdscontent",
				easing: "easeInQuart"
				});
		}
		if($("div.scrollable2").length){
			$("div.scrollable2").scrollable({
				size: 8, 
				items: ".scrollheadthumbs",
				easing: "easeInQuart",
				prev: ".prev2",
				next: ".next2"
				});
		}
		$("li.headthumb").click(
			function() {
				var _biopg = $(this).children('img').attr('src').replace('thumb.jpg','.html');
				var _biourl = _biopg.replace('images/team/','bios/');
				$("#bioinsert").load(_biourl);				
			});
		
		$("#bioinsert").ajaxComplete(function () {
				$(".cert img").fadeTo(1, 0.5);
				$("#certdesc").fadeTo(1, 0);
				
				$("#certicons").hover(
					function () {
						$("#certdesc").fadeTo(250, 1);
					},
					function () {
						$("#certdesc").fadeTo(250, 0);
				});
				
				$(".cert img").hover(
					function () {
						$(this).fadeTo(250, 1);
					},
					function () {
						$(this).fadeTo(250, 0.5);
				});
				
				$("#certprogram").hover(
					function () {
						$("#certdesc").html('<p class="small">Smart Squad Certified Programmer</p>');
					},
					function () {
						$("#certdesc").html("");
				});
				
				$("#certinspect").hover(
					function () {
						$("#certdesc").html('<p class="small">Smart Squad Inspector</p>');
					},
					function () {
						$("#certdesc").html("");
				});
				
				$("#certinstall").hover(
					function () {
						$("#certdesc").html('<p class="small">Smart Squad Certified Installer</p>');
					},
					function () {
						$("#certdesc").html("");
				});
				
				$("#certalarm").hover(
					function () {
						$("#certdesc").html('<p class="small">NYS Licensed Alarm Technician</p>');
					},
					function () {
						$("#certdesc").html("");
				});
				
				$("#certsecurity").hover(
					function () {
						$("#certdesc").html('<p class="small">Smart Squad Certified Security Installer</p>');
					},
					function () {
						$("#certdesc").html("");
				});
				
				$("#certcedia").hover(
					function () {
						$("#certdesc").html('<p class="small">CEDIA Certified Installer</p>');
					},
					function () {
						$("#certdesc").html("");
				});
				
				
		});
		
		$('.gallery_unstyled').addClass('gallery'); // adds new class name to maintain degradability
		if($('ul.gallery').length) {
		$('ul.gallery').galleria({
			history   : false,
			clickNext : true,
			insert    : '#main_image',
			onImage   : function(image,caption,thumb) {
				
				// fade in the image & caption
				image.css('display','none').fadeIn(1000);
				caption.css('display','none').fadeIn(1000);
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// fade out inactive thumbnail
				_li.siblings().children('img.selected').fadeTo(500,0.3);
				
				// fade in active thumbnail
				thumb.fadeTo('fast',1).addClass('selected');
				
				// add a title for the clickable image
				image.attr('title','Next image »');
				},
			onThumb : function(thumb) { // thumbnail effects goes here
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// if thumbnail is active, fade all the way.
				var _fadeTo = _li.is('.active') ? '1' : '0.3';
				
				// fade in the thumbnail when finished loading
				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
				
				// hover effects
				thumb.hover(
					function() { thumb.fadeTo('fast',1); },
					function() { _li.not('.active').children('img').fadeTo('fast',0.3); }
					)
				}
			});
		}
		if($('#thumbnails').length){
			$('#thumbnails').autoscroll(AUTOSCROLL_Y);
		}
		
		if($('a.fancy').length){
			$('a.fancy').fancybox({
				overlayOpacity	: .75
				});
		}
	});
