$(document).ready(function() {
//metanav search
		$('.search-btn').click(function() {
			// keep a reference to the slide-toggle element
	    var slideToggle = this;
	    if ($('.search-box').is(':visible')) {
	        $('.search-box').slideUp(function() {
	            $(slideToggle).removeClass('active'); // remove class from slide-toggle
	        });
	    }
	    else {
	        $('.search-box').slideDown();
	        $(slideToggle).addClass('active'); // add class to slide-toggle
	    }
			});

   
    // Make external links validate
   $('a.external').attr('target', '_blank');

  // add styling and/or make it easier to do stuff
  $('ul').each(function() {
    $(this).find('li:last-child').addClass('last');
    $(this).find('li:first-child').addClass('first');
  });
});

/**
 * HIDE EMAIL SCRIPT
 *
 *     <script type="text/javascript">myEmail("Contact Name", "email", "domain.com");</script>
	   <script type="text/javascript">writeEmail("email", "email", "domain.com");</script>
 *
 */
function myEmail(contact, email, emailHost) {
  document.write("<a href=" + "&#109a&#105l" + "&#116&#111:" + email + "@" + emailHost+ ">" + contact+"</a>");
}

function writeEmail(contact, email, emailHost) {
  document.write("<a href=" + "&#109a&#105l" + "&#116&#111:" + email + "@" + emailHost+ ">" + contact + "@" + emailHost+"</a>");
}

/***************************************/


/* MY CUSTOM JQUERY TOGGLE v1.0 */
function toggle(){
$("ul.submenu").slideToggle("fast");
}


/* MY CUSTOM FADEIN/OUT NAVIGATION MENU (LIKE DG) */

$(document).ready(function () {	
	
	$('#nav li').hover(
		function () {
			//show its submenu
			$('ul', this).fadeIn('slow');

		}, 
		function () {
			//hide its submenu
			$('ul', this).fadeOut('slow');			
		}
	);
	
});



/***************************************/




 /* TABS */
/* Usage

<ul class="tabs">
            <li><a href="javascript:tabSwitch(1, 3, 'tab_', 'content_');" id="tab_1" class="active">Topics</a></li>
            <li><a href="javascript:tabSwitch(2, 3, 'tab_', 'content_');" id="tab_2">Archives</a></li>
            <li><a href="javascript:tabSwitch(3, 3, 'tab_', 'content_');" id="tab_3">Pages</a></li>
        </ul>

        <div id="content_1" class="content">
        	<ul>
            	<li><a href="">HTML Techniques <small>4 Posts</small></a></li>
            	<li><a href="">CSS Styling <small>32 Posts</small></a></li>
            	<li><a href="">Flash Tutorials <small>2 Posts</small></a></li>
            	<li><a href="">Web Miscellanea <small>19 Posts</small></a></li>
            	<li><a href="">Site News <small>6 Posts</small></a></li>
            	<li><a href="">Web Development <small>8 Posts</small></a></li>
			</ul>
        </div>

 */
 
function showHide(targetName) {
                if( document.getElementById ) { // NS6+
                    target = document.getElementById(targetName);
                } else if( document.all ) { // IE4+
                    target = document.all[targetName];
                }
                
                if( target ) {
                    if( target.style.display == "none" ) {
                        target.style.display = "inline";
                    } else {
                        target.style.display = "none";
                    }
                }
            }
            
function tabSwitch(active, number, tab_prefix, content_prefix) {

	for (var i=1; i < number+1; i++) {
	  document.getElementById(content_prefix+i).style.display = 'none';
	  document.getElementById(tab_prefix+i).className = '';
	}
	document.getElementById(content_prefix+active).style.display = 'block';
	document.getElementById(tab_prefix+active).className = 'active';	

}

/***************************************/

// Toggle control for top contact section
  this.toggleContact = function(e) {
    // prevent the anchor from reloading the page
    e.preventDefault();

    $('.header-contact-info').slideToggle();
    $(this).parent().toggleClass("open");
  };


/***************************************/ 




/* BASIC POP UP WINDOW */

function popUp(url, name, props) {window.open(url, name, props);}







/* PRINT PAGE SCRIPT */

var addPrintLink = {
	init:function(sTargetEl,sLinkText) {
		if (!document.getElementById || !document.createTextNode) {return;} // Check for DOM support
		if (!document.getElementById(sTargetEl)) {return;} // Check that the target element actually exists
		if (!window.print) {return;} // Check that the browser supports window.print
		var oTarget = document.getElementById(sTargetEl);
		var oLink = document.createElement('a');
		oLink.id = 'print-link'; // Give the link an id to allow styling
		oLink.href = '#'; // Make the link focusable for keyboard users
		oLink.appendChild(document.createTextNode(sLinkText));
		oLink.onclick = function() {window.print(); return false;} // Return false prevents the browser from following the link and jumping to the top of the page after printing
		oTarget.appendChild(oLink);
	},
/*
addEvent function included here for portability. Replace with your own addEvent function if you use one.
*/
/* addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html */
	addEvent:function(obj, type, fn) {
		if (obj.addEventListener)
			obj.addEventListener(type, fn, false);
		else if (obj.attachEvent) {
			obj["e"+type+fn] = fn;
			obj[type+fn] = function() {obj["e"+type+fn](window.event);}
			obj.attachEvent("on"+type, obj[type+fn]);
		}
	}
};
addPrintLink.addEvent(window, 'load', function(){addPrintLink.init('span','Print this page');});




/***************************************/



/* BACK TO TOP SCRIPT */

//back to top
	$('#back_to_top a').click(function(){
		
		$('html, body').animate({scrollTop: '0px'}, 1000);
		
		return false;
	});


/***************************************/

/*SCROLL TO TOP*/

$(document).ready(function() {
$(".returnToTop").click(function(){
          $('html, body').animate({ scrollTop: 0 }, 'slow');
})
});

/***************************************/


/*TOOL TIP POPUP */
this.tooltip = function(){	
	/* CONFIG */		
		xOffset = -10;
		yOffset = -75;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};



// starting the script on page load
$(document).ready(function(){
	tooltip();
});













