$(document).ready(function(){ /// the DOM-ready thing covers the first four snippets

//================== manually and automatically designated internal and external links with icons
$(function(){
$('a[href^="http://"]').addClass('external').attr('target','_blank');
$('a[href^="https://"]').addClass('external').attr('target','_blank');
$('.external').attr('target','_blank');
$('a[href$=pdf]').addClass('pdfLink').attr('target','_blank');
$('a[href$=doc]').addClass('wordLink').attr('target','_blank');
});
// ================= Last list items of simple list within the text area to add a class of lastBullet
// Engage

//$(function(){
//$("ul.simple_list li:last").addClass("lastBullet");
//});

//================= First para after H3 adds a FirstPara class
$("h3 + p").addClass("FirstPara");


//================= Simple but very nice toggle/fade with opacity
// Fade Slider Toggle plugin copyright(c) 2009, Cedric Dugas
// http://www.position-relative.net
// Licenced under the MIT Licence
jQuery.fn.fadeSliderToggle = function(settings) {
 	 settings = jQuery.extend({
		speed:500,
		easing : "easeInQuad"
	}, settings)
	caller = this
 	if($(caller).css("display") == "none"){
 		$(caller).animate({
 			opacity: 1,
 			height: 'toggle'
 		}, settings.speed, settings.easing);
	}else{
		$(caller).animate({
 			opacity: 0,
 			height: 'toggle'
 		}, settings.speed, settings.easing);
	}
}; 
// ================= MULTI-CLASS FAQ Professional with up and down arrow but problem with p tag
// http://www.webdesignerwall.com/demo/jquery/accordion2.html
	$(".FAQContainer h3").eq(3).addClass("active");
	//$(".accordion2 p").eq(3).show();
	$(".FAQContainer h3").click(function(){
		$(this).next("p").slideToggle("slow")
		.siblings("p:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h3").removeClass("active");
});
	
// ================= NICE SIMPLE FAQ MVJ adapted for DL list format
// http://www.learningjquery.com/2007/02/more-showing-more-hiding
//$(document).ready(function() {
	$('dl.faq:eq(0)> dd').hide();  
	$('dl.faq:eq(0)> dt').click(function() {
    $(this).next().slideToggle('slow');
	//$(this).next().slideToggle(800);  //make it really slow and easy!
	});
//  });

// ====================  Popupwindow plugin for jQuery by Tony Petruzzi
// homepage: http://rip747.wordpress.com
// plugin download: http://rip747.wordpress.com/2007/03/02/the-return-of-popupwindow-jquery-plugin
jQuery.fn.popupwindow = function(p)
{
	var profiles = p || {};
	return this.each(function(index){
		var settings, parameters, mysettings, b, a;
		// for overrideing the default settings
		mysettings = (jQuery(this).attr("rel") || "").split(",");
		settings = {
			height:600, // sets the height in pixels of the window.
			width:600, // sets the width in pixels of the window.
			toolbar:0, // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
			scrollbars:0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
			status:0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
			resizable:1, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
			left:0, // left position when the window appears.
			top:0, // top position when the window appears.
			center:0, // should we center the window? {1 (YES) or 0 (NO)}. overrides top and left
			createnew:1, // should we create a new window for each occurance {1 (YES) or 0 (NO)}.
			location:0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
			menubar:0 // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
		};

		// if mysettings length is 1 and not a value pair then assume it is a profile declaration
		// and see if the profile settings exists

		// if(mysettings.length == 1 && mysettings[0].split(":").length == 1)
//		{
//			a = mysettings[0];
//			// see if a profile has been defined
//			if(typeof profiles[a] != "undefined")
//			{
//				settings = jQuery.extend(settings, profiles[a]);
//			}
//		}
//		else
		{
			// overrides the settings with parameter passed in using the rel tag.
			for(var i=0; i < mysettings.length; i++)
			{
				b = mysettings[i].split(":");
				if(typeof settings[b[0]] != "undefined" && b.length == 2)
				{
					settings[b[0]] = b[1];
				}
			}
		}
		// center the window if the REL parameters aren't qualified
		if (settings.center == 1)
		{
			settings.top = (screen.height-(settings.height + 110))/2;
			settings.left = (screen.width-settings.width)/2;
		}
		
		parameters = "location=" + settings.location + ",menubar=" + settings.menubar + ",height=" + settings.height + ",width=" + settings.width + ",toolbar=" + settings.toolbar + ",scrollbars=" + settings.scrollbars  + ",status=" + settings.status + ",resizable=" + settings.resizable + ",left=" + settings.left  + ",screenX=" + settings.left + ",top=" + settings.top  + ",screenY=" + settings.top;
		
		jQuery(this).bind("click", function(){
			var name = settings.createnew ? "PopUpWindow" + index : "PopUpWindow";
			window.open(this.href, name, parameters).focus();
			return false;
		});
	});

};

//================= jQuery Scroll to Top Control SIMPLE, NO ABSOLUTELY POSITIONED GRAPHIC BUTTON BOTTOM RIGHT
//================= This also counts the paragraphs and assigns links as defined by eq(n)
//** http://www.electrictoolbox.com/jquery-scroll-top/ with add links to certain paragraphs added bits by MVJ
//** define the HTML string to insert	
	$('<div class="BacktoTopCont"><a href="#top">Top</a></div>')
//  .insertAfter('div#contentTextArea p:eq(5), div#contentTextArea p:eq(8), div#contentTextArea p:eq(11)');
//** and now add the click function
	$('a[href*=#top]').click(function(){
	$('html, body').animate({scrollTop:0}, 1500);
	return false;
});
	
//================= jQuery Striped Tables, SIMPLE, NO SORT
//** http://15daysofjquery.com/examples/zebra/ AND http://15daysofjquery.com/examples/zebra/code/demoFinal.php
//** requires: stripeMeTables.css and lines 124-128 on global.js unremed.
	//$(".stripeMe tr:even").addClass("alt");
	//$(".stripeMe tr").mouseover(function() {$(this).addClass("over");}).mouseout(function() {$(this).removeClass("over");});
	//$(".stripeMe th:first-child").addClass("FirstColumnHeader");
	//$(".stripeMe th:last-child").addClass("LastColumnHeader");
	//$(".stripeMe td:first-child").addClass("FirstColumnCell");

//================= Floaty Engage Tooltip  == only works with JQuery 1.3.2 ==
//** http://www.arcinspirations.com/
//	$('a.tooltip').hover(function(){
//		tipText = $(this).attr('title');
//		$(this).attr('title','');
//		$('body').append('<div id="tooltip">'+tipText+'</div>');
//		$('#tooltip').css({opacity:0}).animate({opacity:1});
//		$().mousemove(function(e){
//			$('#tooltip').css({left:e.pageX + 20, top:e.pageY - 35}); // defines the relative position
//		});
//	},function(){
//		$(this).attr('title', tipText);
//		$('#tooltip').remove();
//	});

//================= cross-fade images no plugin, all native JQuery
//** http://jqueryfordesigners.com/demo/fade-method1.html
    $(function () {
        // find the div.fade elements and hook the hover event
        $('div.fade').hover(function() {
            // on hovering over find the element we want to fade *up*
            var fade = $('> div', this);
            // if the element is currently being animated (to fadeOut)...
            if (fade.is(':animated')) {
                // ...stop the current animation, and fade it to 1 from current position
                fade.stop().fadeTo(2000, 1);
            } else {
                fade.fadeIn(2000);
            }
        }, function () {
            var fade = $('> div', this);
            if (fade.is(':animated')) {
                fade.stop().fadeTo(3000, 0);
            } else {
                fade.fadeOut(3000);
            }
        });
    });
}); /// the DOM ready thing thats covers all the above snippets
