/**************************************************************************************
File: 			global.js
Copyright: 		Breakthrough Design Group
Description: 	Global js file
***************************************************************************************/

/***************************************************
Dropdown Navigations in jQuery
***************************************************/

function hidemenu(menu){
	parentnav = menu.substring(menu.indexOf("#")+1,menu.indexOf('-drop'));
	if($('.'+parentnav).attr('overstate')!='on'){
		$('.'+parentnav).css({backgroundPosition: '0px 0px'});
	}
	$(menu).slideUp('slow');
}
function showmenu(parentnav){
	$('.'+parentnav).css({backgroundPosition: '0px 35px'});
	$('#'+parentnav+'-drop').slideDown('slow');
	if($('#'+parentnav+'-drop').attr("timeoutid")!=undefined){
		clearTimeout($('#'+parentnav+'-drop').attr("timeoutid"));
	}
}

$(document).ready(function () {
	/** CREATING THE NAV MENU EVENTS **/
	$('.second-nav a').mouseover(function(){
		showmenu(this.className);
	}).mouseout(function(){
		var activemenu = '#'+this.className+'-drop';
		var menutimeout = setTimeout("hidemenu('"+activemenu+"')",900);
		//Setting custom attribute "timeoutid" on the dropdown div
		$(activemenu).attr('timeoutid', menutimeout);	
		/** ADDING INLINE BG POS TO ALL NAV ELEMENTS - REQ'D BY jquery-bgpos.js **/
	}).css( {backgroundPosition: "0px 0px"});
	
	/** CREATING THE DROPDOWN MENU EVENTS **/
	$('.dropdown').mouseover(function(){
		// stopping the settimeout whose id was set in the custom attribute "timeoutid" on thd dropdown div
		clearTimeout($('#'+this.id).attr("timeoutid"));
	}).mouseout(function(){
		var activemenu = '#'+this.id;
		menutimeout = setTimeout("hidemenu('"+activemenu+"')",900);
		$(activemenu).attr('timeoutid', menutimeout);	
	});
	$(".second-nav a[overstate='on']").css({backgroundPosition: '0px 35px'});
	
	/** INSERTING THE BOTTOM BREADCRUMB **/
	var breadcrumbs = '<p>You Are Here: '+$('.breadcrumbs').html();
	$('.breadcrumbs-bottom').html(breadcrumbs);
	
	/** TOOLTIPS FOR GAGE HOME GRAPHIC **/
	if($('#gage-home-map area').length > 0){
		$('#gage-home-map area').tooltip({ 
		    track: true, 
		    delay: 0, 
		    showURL: false, 
		    showBody: " - ", 
			bodyHandler: function() {
		     	return $("<img/>").attr("src", template_url+'/images/tooltip-'+this.className+'.jpg');
		   	}
		});
	}
});			


/*** AFTER FORM SUBMISSION HANDLER **/
function afterFormSubmit(){
	$("div.wpcf7 > form").unbind('submit.form-plugin');
	$("div.wpcf7 > form").attr('action','https://www.paypal.com/cgi-bin/webscr');
	$("div.wpcf7 > form").submit();
}