$(document).ready(function () {
	// MIke ajax for comments

				$.ajaxSetup({
							   
							   global: false,
							   type: "POST"				
				 });
				 
				 $('#commentSubmit').click(function() {	
				                    var data = '';
									var comment = $('textarea[name=comment]');  
									var screen_name = $('input[name=screen_name]');  
									var pid = $('input[name=pid]'); 
									var page_type = $('input[name=page_type]'); 
								var data = 'comment=' + encodeURIComponent(comment.val()) +  '&screen_name=' + encodeURIComponent(screen_name.val()) +  '&pid=' + encodeURIComponent(pid.val()) +  '&page_type=' + encodeURIComponent(page_type.val()) ;	
									$.ajax({	
url: "/save_comments.php",			
											  data: data, 
											  success: function(data) {
														    $('#new_comment').html(data);
												  }
									});
									
				});
	
	
// "to top" button
	 $('a[href=#page-top]').click(function () {
        $.scrollTo(0, 'slow');
        return false;
    });
// do tabbed pages (template 6)
	 $('.tabbed-content').each(function () {
		 	 $('#tp-6-tab-1').css('display', 'block');
			 $('#tp-6-tab-2').css('display', 'none');
			 $('#tp-6-tab-3').css('display', 'none');
    });	
		$('#tab-link-2 a').click(function () {
			 $(this).addClass("active-tab");
			 $('#tp-6-tabs-bottom').removeClass('tp-6-tabs-l tp-6-tabs-r');
			 $("#tp-6-tabs-bottom").addClass("tp-6-tabs-m");
			 $('#tab-link-1 a').removeClass("active-tab");
			 $('#tab-link-3 a').removeClass("active-tab");
			 $('#tp-6-tab-1').css('display', 'none');
			 $('#tp-6-tab-2').fadeIn('fast', function () {
            // Animation complete
        });
			 $('#tp-6-tab-3').css('display', 'none');
    });	
		$('#tab-link-3 a').click(function () {
			 $(this).addClass("active-tab");
			 $('#tp-6-tabs-bottom').removeClass('tp-6-tabs-l tp-6-tabs-m');
			 $("#tp-6-tabs-bottom").addClass("tp-6-tabs-r");
			 $('#tab-link-1 a').removeClass("active-tab");
			 $('#tab-link-2 a').removeClass("active-tab");
			 $('#tp-6-tab-1').css('display', 'none');
			 $('#tp-6-tab-2').css('display', 'none');
			 $('#tp-6-tab-3').fadeIn('fast', function () {
            // Animation complete
        });
    });	
		$('#tab-link-1 a').click(function () {
			 $(this).addClass("active-tab");
			 $('#tp-6-tabs-bottom').removeClass('tp-6-tabs-m tp-6-tabs-r');
			 $("#tp-6-tabs-bottom").addClass("tp-6-tabs-l");
			 $('#tab-link-2 a').removeClass("active-tab");
			 $('#tab-link-3 a').removeClass("active-tab");
			 $('#tp-6-tab-1').fadeIn('fast', function () {
            // Animation complete
        });
			 $('#tp-6-tab-2').css('display', 'none');
			 $('#tp-6-tab-3').css('display', 'none');
			 $('#tp-6-tab-1').fadeIn('slow', function () {
            // Animation complete
        });
				$('#tp-6-tab-2').fadeOut('slow', function () {
            // Animation complete
        });
				$('#tp-6-tab-3').fadeOut('slow', function () {
            // Animation complete
        });
    });	
// do horizontal rules
	 $('#block-2 hr').each(function () {
        $(this).wrap('<div class="js-hr" />');
		 $(this).css('visibility', 'hidden');
		 $(this).css('margin-bottom', '0px');
    });	
// turn titles to fadein captions
    $('img').each(function () {
        if ($(this).attr('title')) {
            var figTitle = $(this).attr('title');
            $(this).data('title', $(this).attr('title'));
            $(this).removeAttr('title');
						// subtrct padding*2
            var figWidth = $(this).attr('width') - 10;
            $(this).wrap('<div class="caption-wrap" />');
            $('<span class="img-caption" style="width:' + figWidth + 'px"> ' + figTitle + '</span>').insertAfter($(this));
            $(this).next("span").hide();
        }
    });
    $('.caption-wrap').hover(function () {
        $(this).children('.img-caption').fadeIn('slow', function () {
            // Animation complete
        });
    }, function () {
        $(this).children('.img-caption').fadeOut('fast', function () {
            // Animation complete
        });
    });
});
// CYCLE
$(document).ready(function () {
    $('.slideshow').cycle({
        fx: 'scrollHorz',
        speed: 900,
        timeout: 15000,
        next: '.next',
        prev: '.prev'
    });
    // --------------------------------------------------------
/* Superfish
/**********************/
/*
	http://users.tpg.com.au/j_birch/plugins/superfish/
*/
    $("ul.sf-menu").supersubs({
        minWidth: 12,
        // minimum width of sub-menus in em units 
        maxWidth: 27,
        // maximum width of sub-menus in em units 
        extraWidth: 1 // extra width can ensure lines don't sometimes turn over 
        // due to slight rounding differences and font-family 
    }).superfish({
        animation: {
            height: 'show'
        },
        // slide-down effect without fade-in 
        delay: 200 // 0.2 second delay on mouseout 
    }).find('ul').bgIframe({
        opacity: false
    });
    // --------------------------------------------------------
/* Text resize (requires cookies)
/**********************/
/*
	http://trevordavis.net/blog/simple-jquery-text-accessibility-tools-block/
	http://plugins.jquery.com/node/1387
	MODIFIED BY WAVE for HCT
*/
    // --------------------------------------------------------
    $(".resizer").click(function () {
        var ourText = $('body');
        var currFontSize = ourText.css('fontSize');
        var finalNum = parseFloat(currFontSize, 10);
        var stringEnding = currFontSize.slice(-2);
        if (this.id == 'largeText') {
            finalNum *= 1.2;
        } else if (this.id == 'smallText') {
            finalNum /= 1.2;
        } else if (this.id == 'resetText') {
            finalNum = 13;
        }
        ourText.animate({
            fontSize: finalNum + stringEnding
        }, 200);
        $.cookie('TEXT_SIZE', finalNum, {
            path: '/',
            expires: 10000
        });
    });
});
