jQuery(document).ready(function(){
	jQuery('.bullet').mousedown(function(){
		jQuery('.bullet').removeClass('activeBullet');
		jQuery(this).addClass('activeBullet');
	});
});

function confirm(message, callback) {
	jQuery('#confirm').modal({
		close:false,
		position: ["20%",],
		overlayId:'confirmModalOverlay',
		containerId:'confirmModalContainer', 
		onShow: function (dialog) {
			//hide our flash object because it peeks through
			if(jQuery('#webtour_anim')){
				jQuery('#webtour_anim').css('visibility', 'hidden');
			}
			dialog.data.find('.message').append(message);

			// if the user clicks "yes"
			dialog.data.find('.yes').click(function () {
				// call the callback
				if (jQuery.isFunction(callback)) {
					callback.apply();
				}
				// close the dialog
				jQuery.modal.close();
			});
		},
		onClose: function(){
			//show our flash object that we hid
			if(jQuery('#webtour_anim')){
				jQuery('#webtour_anim').css('visibility', 'visible');
			}
			jQuery.modal.close();
		}		
	});
}

//Bind the modal panel link.	
jQuery('.confirm').live('click', function (e) {
	e.preventDefault();

	var me = jQuery(this);
	if(jQuery('#confirmIsFeatured').val() == 'true'){
		var requestInfoUrl = jQuery('#confirmRequestInfoUrl').val();
		var schoolName = jQuery('#confirmSchoolName').val();
		confirm("Did you know that you can <br/> <a href=\"" + requestInfoUrl + "\" title=\"Request Info\">contact " + schoolName + "</a><br/>through USAEducationGuides.com?<br/><img src=\"../images/white_dot.gif\" height=\"20px\" width=\"100%\"/><a href=\"" + requestInfoUrl + "\" title=\"Request Info\"><img src=\"../images/requestInfo3.gif\" alt=\"Request Info\" style=\"border: none;\"/></a>", function () {
			var newWindow = window.open(me.attr('href'), '_blank');
			newWindow.focus();
		});	
	}else{
		var area = jQuery('#confirmArea').val();
		confirm("Did you know that you can <br/><a class=\"masterinfozaplink_" + area + "\" href=\"/request/index.jsp?productAreaID=7&productTypeID=1&infozapType=masterInfozap&area=" + area + "\" style=\"font-weight: bold;\">contact colleges and universities</a><br/>through USAEducationGuides.com?", function () {
			var newWindow = window.open(me.attr('href'), '_blank');
			newWindow.focus();
		});		
	}
});


////////////// jQuery Search Form Submit ////////////////////
// this really goes with the footer - operates on the Google CSE Searchbox
jQuery(document).ready(function(){

	// appending area refinement based on the users area setting
	jQuery("#cse-search-box").submit(function() {
		// have to put :last since MasterInfoZap form has the same value and it seems to populate differently
		// then the input that I really need. This could potentially break in the future if another 'area' input 
		// is added after the cse area input.
		var area = jQuery(":input[name='area']:last");
	 	var q = jQuery("input[name='q']");
	 
     	if (area.val() == "asia") {
      		// refinement Asian
      		q.val(q.val() + " more:asian");
     	} else if (area.val() == "europe") {
	      	// refinement European
      		q.val(q.val() + " more:european");		
    	} else if (area.val() == "la") {
	      	// refinement Latin American
      		q.val(q.val() + " more:latin_american");
     	} else if (area.val() == "row") {
	      	// refinement Other Regions
      		q.val(q.val() + " more:other_region");
    	}
     	// allow form to submit
      	return true;
	});
});
