/******************************* SWAP IT *************************************/
(function($) {
jQuery.fn.canvasSwap = function(options) {    	
    var options = jQuery.extend({}, jQuery.fn.canvasSwap.defaults, options);
    jQuery(this).hover (    
    	function () {
    		var thesrc = $(this).attr('src');
    		var name = thesrc.substring(0, thesrc.lastIndexOf('.'));
    		var extension = thesrc.substring(thesrc.lastIndexOf('.'));
    		$(this).attr('src', name + options.suffix + extension);
    	}, function () {
    		var thesrc = $(this).attr('src');
    		var name = thesrc.substring(0, thesrc.lastIndexOf('.') - options.suffix.length);
    		var extension = thesrc.substring(thesrc.lastIndexOf('.'));
    		$(this).attr('src', name + extension);
    	}
    );
};
jQuery.fn.canvasSwap.defaults = {
	suffix: '_hover'
}
})(jQuery);

/****************************** JS FUNCTIONS *******************************/

//Remove/Replace Input Text
function clearText(field){
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
	}

//Bookmark this page 
function bookmark_us(url, title){
if (window.sidebar) // firefox
    window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
    var elem = document.createElement('a');
    elem.setAttribute('href',url);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click();
}
else if(document.all)// ie
    window.external.AddFavorite(url, title);
}

/****************************** DOCUMENT READY *******************************/
jQuery(document).ready(function(){

//Class H*s 
jQuery(":header").addClass('header');

//Navigation
//jQuery('header li').hover(function(){
//	jQuery(this).find('>ul').addClass('holdit').delay(317).queue(function(next){
//		jQuery(this).removeClass('holdit');
//		next();
//		});});
		
//Image Hovers								
    jQuery('img.swapit').canvasSwap();
		
//Top Sliding Panel
  jQuery("#topslide").hide();
  jQuery("#topslidetab").click(function()
  	{ jQuery("#topslide").slideToggle(500); });

//Wrapped Blockquote
	jQuery('blockquote').wrap('<div class="blockquote">');

//Target Blanks
	jQuery('.external a, a.external').attr('target', '_blank');

//Clickable Elements
	jQuery("ul.pane-list li, ol.pane-list li, p.pane-list, div.pane-list, span.pane-list").click(function(){
    	window.location=jQuery(this).find("a").attr("href"); return false;
		});

//Accordions
	jQuery(".menu_list .menu_head").click(function(){
		jQuery(this).toggleClass('active').next(".menu_body").slideToggle(300).siblings(".menu_body").slideUp("slow");
		jQuery(this).siblings(".menu_head").removeClass('active')
		});
	
//ACMENU  UL BASED
  $(".acmenu>li>a").removeAttr("href");
  $('.acmenu ul').hide();
  $('.acmenu li a').click(
   function() {
    $(this).parent().siblings().removeClass('active').addClass('inactive');
	$(this).parent().removeClass('inactive').toggleClass('active');
	$(this).next().slideToggle('normal');
    $('.inactive ul').slideUp('normal'); 
      }
    );	
	
	
//EZ H6 Accordion
	jQuery("article h6").next('p, ul').addClass('a6-pane').hide();
    jQuery("article h6").addClass('a6-title').click(function(){
    jQuery(this).toggleClass('active').next(".a6-pane").slideToggle(300).siblings(".a6-pane").slideUp("slow");
        jQuery(this).siblings("h6").removeClass('active')
        });
	
	/*
//Slide to Main
    //ONLOAD CHECK CONDITION AND APPLY CLASS BUT NOT TO FIRST "a"
    jQuery("header nav.slidetomain li a:not(:first)").each(function(){
		//LETS CHECK EACH HREF
		checklink = this.href;
		//LETS SEE IF WE FIND AN # IN THE HREF
		check = checklink.indexOf('#');
		//IF WE DONT FIND ONE ADD THE CLASS
		if (check <= -1) { jQuery(this).addClass("top-anchor"); }
		});
		//YOURS TRULY : LEYLA BALAREZO
	jQuery("header nav.slidetomain a.top-anchor").each(function(){
		var newHref = jQuery(this).attr("href") + "#main";
		jQuery(this).attr("href",newHref);
		}); 
	*/

//Anchorlist
	jQuery("ul.anchorlist").each(function() {
		var lookfor = jQuery(this).attr("title");
		var sublinks = jQuery("header nav ul").find('a:contains(' + lookfor + ')').parent().find("ul").html();
		jQuery(this).html(sublinks);
		});

	var sublinks = jQuery("#ddm").find("li.current-menu-item").find("ul").html();
		jQuery("ul#sublinks").html(sublinks);

	var anchorlinks = jQuery("#ddm").find("li.current_page").find("ul").html();
		jQuery("ul#anchorlist").html(anchorlinks);


//First & Last
	jQuery(".firstlast, nav.firstlast ul").each(function() {
		jQuery(this).find('>*:first').addClass("first");
		jQuery(this).find('>*:last').addClass("last");
		});
	
//Tabbed Panels
//	jQuery(".tabcontent").hide(); //Hide all content
//		jQuery("ul.tabset li:first").addClass("active").show(); //Activate first tab
//		jQuery(".tabcontent:first").show(); //Show first tab content
//	jQuery("ul.tabset li").click(function() {
//		jQuery("ul.tabset li").removeClass("active"); //Remove any "active" class
//		jQuery(this).addClass("active"); //Add "active" class to selected tab
//		jQuery(".tabcontent").hide(); //Hide all tab content
//		var activeTab = jQuery(this).find("a").attr("href"); //Find the active tab
//		jQuery(activeTab).fadeIn(); //Fade in the active content
//		return false;
//		});
	/*http://www.sohtanaka.com/web-design/simple-tabs-w-css-jquery*/



//Tabbed Panels
	jQuery(".panes > div").addClass("panecontent");
	jQuery(".panecontent").hide(); //Hide all content
	//jQuery(".panecontent").animate({opacity:0},"fast" );
	//jQuery(".panecontent").animate({opacity:0},"fast" ); 
	
	var idarray = new Array();
	jQuery(".tabs a").each(function(){
	var id = jQuery(this).attr("href").substr(1,jQuery(this).attr("href").length);					
	jQuery(this).addClass(id);	
	idarray[id] = id;
	});

	var hash = document.location.hash.substr(1,document.location.hash.length);
//	if(hash != '') {
	if(idarray[hash] != undefined) {	
    	//get the index from URL hash
	    jQuery('#'+hash).show();
		jQuery(".tabs a."+hash).addClass("active").show();
		}else {
		jQuery(".tabs a:first").addClass("active").show(); //Activate first tab
		jQuery(".panecontent:first").show(); //Show first tab content
	}
	
	jQuery(".tabs a").click(function() {
		jQuery(".tabs a").removeClass("active"); //Remove any "active" class
		jQuery(this).addClass("active"); //Add "active" class to selected tab
		jQuery(".panecontent").hide(); //Hide all tab content
		//jQuery(".panecontent").animate({opacity:0},"fast" );
		//jQuery(".panecontent").animate({opacity:0},"fast" ); 
		var activeTab = jQuery(this).attr("href"); //Find the active tab
		jQuery(activeTab).show(); //Fade in the active content
		//jQuery(activeTab).animate({opacity:1},"fast" ); 
		//prevenDefault();
		//return false;
					});
	

	
//Smooth Scroll to Top
	jQuery('a[href=#top]').click(function(){ 
		jQuery('html, body').animate({scrollTop:0},817); return false;
		});
	

}); //close doc ready

