$(document).ready(function(){
        /*
         * homepage slideshow
         */
	if( $("#homeSlide").length > 0 ) {
		$("#homeSlide").easySlider({
			auto: true,
			pause: 6000,
			continuous: true
		});
	}

        /*
         * interior slideshow
         */
	if( $("#interiorSlide").length > 0 ) {
		$("#interiorSlide").easySlider({
			auto: true,
			pause: 4000,
			continuous: true
		});
	}

        /*
         * main slider opener slideshow
         */
        if( $("#slider_gallery").length > 0 ) {
            $('#slider_gallery').easySlider({
                    continuous: true
            });
        }
        /*
         * homepage process content
         */
		$("#middle .icon_container a").click(function() {
			var processName = $(this).data("icon");
			var $allIcons = $("#middle .icon_container a");
			var $allProcessText = $("#middle .middle_open");
			var $processText = $("#middle ."+processName+"_text");

			if( $processText.is(":hidden") ) {
				$("html,body").animate({scrollTop: $("#middle").offset().top}, "slow");

				$allIcons.removeClass("active");
				$(this).addClass("active");
				$allProcessText.css("z-index", "50");
				$allProcessText.not("#middle ."+processName+"_text").fadeOut();

				$processText.css("z-index", "100").slideDown("slow", function() {
					// $allProcessText.not("#middle ."+processName+"_text").hide();
				})
			} else {
				$(this).removeClass("active");

				$processText.slideUp()
			}
		});
	
	/** icon hover effects - homepage columns **/
	$(".home_column_title .icon").hover(function() { //On hover...
		var thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'
		//Set a background image(thumbOver) on the <a> tag - Set position to bottom
		$(this).find('a.title_icon').css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});

		//Animate the image to 0 opacity (fade it out)
		$(this).find("span").stop().fadeTo('normal', 0 , function() {
			$(this).hide() //Hide the image after fade
		});
	} , function() { //on hover out...
		//Fade the image to full opacity 
		$(this).find("span").stop().fadeTo('normal', 1).show();
	});

        /***** main headline slide open on gallery template ****/
        $('#main_headline .expand_list').click(function(){
            if( $("#main_headline .main_headline_open").is(":hidden") ){
                
                $("#main_headline .main_headline_open").slideDown('slow', function(){
                    $("#main_headline .main_headline_open2").hide();
                });
            }
            else{
                $("#main_headline .main_headline_open").slideUp('slow');
            }
        });
        $('#main_headline .expand_gallery').click(function(){
            if( $("#main_headline .main_headline_open2").is(":hidden") ){
                
                $("#main_headline .main_headline_open2").slideDown('slow',function(){
                    $("#main_headline .main_headline_open").hide();
                });
            }
            else{
                $("#main_headline .main_headline_open2").slideUp('slow');
            }
        });

        
        /** icon hover effects - rss on blog **/
	$("#sidebar ul.list .icon").hover(function() { //On hover...
		var thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'
		//Set a background image(thumbOver) on the <a> tag - Set position to bottom
		$(this).find('a.rss').css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});

		//Animate the image to 0 opacity (fade it out)
		$(this).find("span").stop().fadeTo('normal', 0 , function() {
			$(this).hide() //Hide the image after fade
		});
	} , function() { //on hover out...
		//Fade the image to full opacity
		$(this).find("span").stop().fadeTo('normal', 1).show();
	});

        /*** process/blades template ****/
        lastBlock = $("#first");
        maxWidth = 709;
        minWidth = 53;

        $("#process_content #main_content_box .content").hover( function(){
               $(this).children('.title').addClass('active');
        },
        function(){
            if( $(this).width() != '709' )
               $(this).children('.title').removeClass('active');
        });
        
        $("#process_content #main_content_box .content").click(
          function(){

              $('.title').removeClass('active');
              $(this).children('.title').addClass('active');

              $(lastBlock).animate({
                width: minWidth+"px"
              }, {
                queue:false,
                duration: 500
              });

              $(this).animate({
                width: maxWidth+"px"
              }, {
                queue:false,
                duration: 500
              });
           
           
            lastBlock = this;
          }
        );


        /*** footer social icons && blog social icons **/
	$("ul.social_list li").hover(function() { //On hover...

		var thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'

		//Set a background image(thumbOver) on the <a> tag - Set position to bottom
		$(this).find("a.social_icon").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});

		//Animate the image to 0 opacity (fade it out)
		$(this).find("span").stop().fadeTo('normal', 0 , function() {
			$(this).hide() //Hide the image after fade
		});
	} , function() { //on hover out...
		//Fade the image to full opacity
		$(this).find("span").stop().fadeTo('normal', 1).show();

	});
 
});

$(".comment_guidelines_toggle").live("click", function() {
	if( $("#comment_guidelines").css("display") == "none" ) {
		$("#comment_guidelines").fadeIn();
	} else {
		$("#comment_guidelines").fadeOut();
	}
});

// Fix FOUT for font replacement (http://paulirish.com/2009/fighting-the-font-face-fout/)
(function(){
	// if firefox 3.5+, hide content till load (or 3 seconds) to prevent FOUT
	var d = document, e = d.documentElement, s = d.createElement('style');
	if(e.style.MozTransform === '') { // gecko 1.9.1 inference
		s.textContent = 'body{visibility:hidden}';
		e.firstChild.appendChild(s);
		var f = function(){s.parentNode && s.parentNode.removeChild(s);};
		addEventListener('load',f,false);
		setTimeout(f,3000);
	}
})();
