
/*
//Login modal popup
$j("#dialog-form").dialog({
	autoOpen: false,
	height: 300,
	width: 350,
	modal: true,
	buttons: {
		"Create an account": function() {
			//var bValid = true;
			//allFields.removeClass("ui-state-error");

			//bValid = bValid && checkLength( name, "username", 3, 16 );
			//bValid = bValid && checkLength( email, "email", 6, 80 );
			//bValid = bValid && checkLength( password, "password", 5, 16 );

			//bValid = bValid && checkRegexp( name, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter." );
			// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
			//bValid = bValid && checkRegexp( email, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i, "eg. ui@jquery.com" );
			//bValid = bValid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" );

			//if (bValid) {
				/*$( "#users tbody" ).append( "<tr>" +
					"<td>" + name.val() + "</td>" + 
					"<td>" + email.val() + "</td>" + 
					"<td>" + password.val() + "</td>" +
				"</tr>" ); 
				$j(this).dialog("close");
			//}
		},
		Cancel: function() {
			$j(this).dialog("close");
		}
	},
	close: function() {
		allFields.val("").removeClass("ui-state-error");
	}
});

//Login modal popup
$j("#create-user").button().click(function() {
	$j("#dialog-form").dialog("open");
});
*/

//Checks for the last subcolumn div and apply a "no_border" class
function lastSubcolumn(){
	$j('#purchasing_options .subcolumns:first-child').addClass('no_border');
}


$j(document).ready(function(){

		/* Google analytics Downloads & printables tracking */
		$j('.printablesDownloadClass').click(function(){
			_gaq.push(['_trackPageview'],$j(this).attr('href'));
		});
		/* -- end google tracking code */

		//global flag to keep track if the tab has already been set
		isTabShown = 0;
	
		// Clear Search text on Focus 
	  $j('#search_box').focus(function(){
	    $j(this).val('');
	  })
		
		// Dialog Box for try it now
		$j("#dialog").dialog({
			autoOpen: false,
			height: 400,
			width: 595,
			modal: true
		})

		// Test to see if an option has been selected
		if ($j('body').hasClass('ecomm')) {
			
			// Dialog Box for try it now
			$j("#dialog_button").click(function() {
				$j("#dialog").dialog("option", "position", ['center','center']);
				$j("#dialog").dialog("option", "resizable", false);
				$j("#dialog").dialog({ title: 'Try it now' });
				$j("#dialog").dialog("open");
				
				return false;
			});
			
			$j('select').change(function(){
				$j(this, 'option').attr('value', function(i, val){
					var thisVal = val
					if (val === "") {
						$j(this).css({
							'color': '#999'
						})
					}
					else {
						$j(this).css({
							'color': '#000'
						})
					}
				});
			});
					
		}

		//Superfish Primary Nav
		if ($j('ul.sf-menu').length > 0) {
    
		// initialise plugins
	    $j("ul.sf-menu").supersubs({
	        minWidth: 12,
	        maxWidth: 27,
	        extraWidth: 1,
	        speed: 0
	    }).superfish({
	        speed: 0,
	        delay: 0
	    });
    
	}

		$j("#accordion" ).accordion({autoHeight: false});
		$j("a.button").button();
		$j(".button").button();
		//$j('input[type="submit"]').button();
	
	//Homepage Banner	
	if ($j('body').hasClass('homepage')) {
		$j("#teaser").tabs({
			fx: {
				opacity: "toggle"
			}
		}).tabs("rotate", 5000);
		
		$j( ".tabs" ).accessibleTabs({fx:"show",fxspeed: '', syncheights: true, tabbody:'.tab-content'});
		
	}
	
	//Applies jQuery UI tabs
	if ($j('body').hasClass('dashboard') || $j('body').hasClass('ecomm') || $j('body').hasClass('tabs')) {
		
		/* make sure this is one of the templates that includes  accessbiel tabs package, not all do */
		if ($j.fn.accessibleTabs != undefined) {
			jQueryTabs = $j(".jquery_tabs").accessibleTabs({
				fx: "show",
				fxspeed: '',
				syncheights: false,
				tabbody: '.tab-content'
			});
		}
	}

	//Checks for the last subcolumn div and apply a "no_border" class
	if ($j('body').hasClass('ecomm item detail')) {
		lastSubcolumn()
	}
	
	//If a user clicks on the course title in the Program Library they will expand the description
	$j(".title").click(function(){
		var programParent = $j(this).parent().parent().parent();
		if ($j(this).siblings('.description').is(":hidden")) {
			$j(this).siblings('.description').slideDown(300);
		}
		$j(programParent).css({'background-color':'#E3EAF2'});
		$j(programParent).addClass('hovered');
	});
	$j(".close").click(function(){
		var closeParent = $j(this).parent().parent().parent();
		$j(closeParent).siblings('.c80l').children('.subcl').children('.description').slideUp(200);
		$j(closeParent).parent().css({'background-color':'#FFF'});
		$j(closeParent).parent().removeClass('hovered');
	});		
	
	// Sidebar
	
	$j('.arrowToggle').click(function() {
	
			if ($j(this, 'h4').hasClass('arrow_down')) {
				$j(this, 'h4').removeClass('arrow_down')
				$j(this, 'h4').addClass('arrow_right')
			}	
			else {
				$j(this, 'h4').addClass('arrow_down')
			}
					
		});
	
	
	
	  
/*	if ($j('.colCollapse').length > 0) {
	
		$j('.colCollapse').click(function() {
	
			if ($j(this, 'h4').hasClass('arrow_down')) {
				$j(this, 'h4').removeClass('arrow_down')
				$j(this, 'h4').addClass('arrow_right')
			}	
			else {
				$j(this, 'h4').addClass('arrow_down')
			}
					
		});
	
	} */
	
	if($j('div').hasClass('disabled')) {
		$j('#clips_toggle').height(30)
	}
	
	if ($j('.programModuleTab').length > 0) {
		$j('.programModuleTab').click(function(e){
			//grab module id
			//moduleId = e.currentTarget.childNodes[1].id;
			//DRC (02/22/11) - use jquery to get first child rather than one above as it did not work in IE8
			moduleId = $j(this).children(':first').attr('id');
			moduleId = moduleId.replace(/module_/,'');
			
			//hide all mod component divs
	    $j('.modulesList').hide();
			//show only our target mod component div
			
			//added the inline-block css ro bottom of box breaks
			$j('#components_' + moduleId).show().css("display","inline-block");
			
			//set all mod divs to not selected
			$j('#modulesNav').find('.modNavItem').attr('class', 'modNavItem modOne');
			//select our target nav div
			$j('#module_' + moduleId).attr('class', 'modNavItem modOne active');
			
			//hide all printables
			$j('#modDownloads').find('.modListInnerWrap').find('.modPrintables').hide();
			//show only our target mod component div
			$j('#printables_module_' + moduleId).show();
			
	    return false;
		});
	
	}
	
	
	
	if ($j('body').hasClass('people')) {
		  
		$j('.contact_bubble').tipTip({maxWidth: "100%", edgeOffset: 0, keepAlive : true});
		
		if($j('.items').length <= 10){
			$j(".browse").css({'visibility':'hidden'})
		}
		else {
			$j(".browse").css({'visibility':'visible'})
		}
		
		
				
		function collapseThumb() {
			$j('.this_person').animate({width:'54'},300)
		}
	
		// select .scrollable and make it scrollable. use circular and navigator plugins
		$j(".scrollable").scrollable({ circular: true, mousewheel: false, speed: 	600, onSeek: collapseThumb })
		
		
			
		$j('.this_person .thumb_bg').click(function(){
		
			$j('.this_person').animate({
				width: '54'
			}, 300)
			
			$j('.thumb_bg').removeClass('active')
	
			var nextButtonPos = $j('.next').offset().left
			var whereAmI = $j(this).offset().left
			var toBeAdded = nextButtonPos - whereAmI
			
			$j('.browse').css({'visibility':'visible'})
						
			if ((toBeAdded === 231) || (toBeAdded === 177) || (toBeAdded === 123) || (toBeAdded === 69)) {
				$j('.people.items').animate({
					left: -980
				}, 300)
			}
			
			$j(this).parent().animate({
				width: '275'
			}, 300)
			
			$j(this).addClass('active')
			
			$j(this).parent().find('.this_person_info').css({
				'display': 'block'
			})
			
		})
	}
	
 if ($j('body').hasClass('item_detail')) { 
    $j('.contact_bubble').tipTip({maxWidth: "100%", edgeOffset: 0, keepAlive : true}); 
	}
	
	// My Cart bubble - Show Bubble
	$j('#account .cart_icon').mouseover(function(){
		$j('#cart_bubble').css({'display':'block'})
	});
	$j('#my_cart_wrapper').mouseover(function(){
		$j('#cart_bubble').css({'display':'block'})
	});
	// My Cart bubble - Hide Bubble
	$j('#my_cart_wrapper').mouseout(function(){
		$j('#cart_bubble').css({'display':'none'})
	});
	
	//disable purchase button(s) on click so user cannot submit more than one order
	$j('a#place_order').bind('click', function(){
		//capture desired href
		var target = $j(this).attr('href');
		//functionally kill the link
		$j("a#place_order").removeAttr("href").css("cursor","pointer");
		//alter the button visually to make this clear 
		$j("a#place_order").parent().parent().addClass('disabled');
		//if this is first click (ie there is a target) send the user along as normal
		if((typeof target != 'undefined') && (target.length > 0)){
			window.location.href = target;
		}
		return false;
	});
	

});// End document.ready

$j(window).load(function(){
		if ($j('body').hasClass('tabs')) {
			$j('.jquery_tabs').css({
				'visibility':'visible'
			})
			$j('#innerContentBtm').css({
					'visibility':'visible'
			})
		}
});



$j(window).resize(function () {
     
}); 
		

//cart total form, for updating quantities in cart 
function submitCartForm(action){
		//update the cart
		if(action == 'update'){
			$j('#checkout').submit();	
		}else{
			//Continue action, go to home
			$j(location).attr('href','/');
		}
		 return false;
	}
	
//remove items from cart
function removeCartItem(item){
		var removeItemUrl = '/?e=RemoveFromCart&item=' + item;    
		window.location = removeItemUrl;
		return false;
	}


(function ($) {
	//Do your jquery stuff
	$(function(){
		//Document Ready
		$(":input").prompt();
		$().clearPrompts();
	});
	
})(jQuery);

