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

	//setTimeout(function() { $("#snow_leopard_banner").slideDown(); }, 1000);
	
	// Open all external links in a new window.  They're determined by the http in the a href tag
	$("a[href^='http://']").click(function() {
		window.open(this.href);
		return false;
	});
		
	/* ------------------------------------------------------------------------------------- */

	/* Fade In Content */
	$("div.fade_content").hide();
	$("div.fade_content").fadeIn();
	
	/* ------------------------------------------------------------------------------------- */
	/* Software Submenu Functions */
	$("#menu_software").mouseover(function() {
		$("#software_submenu").slideDown("fast"),
		$(this).addClass("main_menu_selected");
	});
	$("#menu_software").mouseleave(function() {
		$("#menu_software").removeClass("main_menu_selected");
		$("#software_submenu").blur(function() {
			$("#software_submenu").slideUp("fast");
		});
	});
	$("#software_submenu").mouseleave(function() {
		$("#software_submenu").slideUp("fast");
	});
	
	/* Software Submenu Functions */
	$("#menu_events").mouseover(function() {
		$("#events_submenu").slideDown("fast"),
		$(this).addClass("main_menu_selected");
	});
	$("#menu_events").mouseleave(function() {
		$("#menu_events").removeClass("main_menu_selected");
		$("#events_submenu").blur(function() {
			$("#events_submenu").slideUp("fast");
		});
	});
	$("#events_submenu").mouseleave(function() {
		$("#events_submenu").slideUp("fast");
	});
	
	/* ------------------------------------------------------------------------------------- */
	
	$(".screen_image").bind("mouseover mouseout",function() {
		$(".ss_mag_glass").toggle();
	});
	
	/* ------------------------------------------------------------------------------------- */
	
	// Toggles a div with an up or down arrow.  To use, change the two vars to the 
	// class names with the arrow as the background
	
	$("div[name='toggle_header']").click(function() {
		var to_show = "toggle_header_show";
		var to_hide = "toggle_header_hide";
	
		if ($(this).hasClass(to_hide)) {
			//$("div[name='toggle_header']").addClass("toggle_header_hide");
			$(this).removeClass(to_hide);
			$(this).addClass(to_show);
		}
		else {
			$(this).removeClass(to_show);
			$(this).addClass(to_hide);
		}
	});
	
	/* ------------------------------------------------------------------------------------- */
	
	$("ul.toggle_list li").click(function() {
		var to_show = "toggle_list_show";
		var to_hide = "toggle_list";

		if ($(this).hasClass(to_hide)) {
			$(this).removeClass(to_hide);
			$(this).addClass(to_show);
		}
		else {
			$(this).removeClass(to_show);
			$(this).addClass(to_hide);
		}
	});
	
	/* ------------------------------------------------------------------------------------- */
	// Toggle On/Off Images marked in a div class swap_img. Used in the homepage header books
	
	$("div.swap_img img").hover(
		function() {
			this.src = this.src.replace("_off","_on");
		},
		function() {
			this.src = this.src.replace("_on","_off");
		}
	);
	
	/* ------------------------------------------------------------------------------------- */
	/* JCarousel Functions */
	
	$(function() {	
		$("div.carousel").jCarouselLite({
			btnNext: ".carousel_next",
			btnPrev: ".carousel_prev",
			scroll: 1,
	        speed: 600,
      		easing: null,
        	vertical: false,
        	circular: false,
        	visible: 1,
        	start:0,
        	beforeStart: null,
        	afterEnd: changeScrollNumber
		});	
	});
	
	$(function() {	
		$("div.carousel_iphone").jCarouselLite({
			btnNext: ".carousel_iphone_next",
			btnPrev: ".carousel_iphone_prev",
			scroll: 1,
	        speed: 200,
      		easing: null,
        	vertical: false,
        	circular: true,
        	visible: 1,
        	start:0,
        	beforeStart: null,
        	afterEnd: changeIphoneScrollNumber
		});	
	});

	/* ------------------------------------------------------------------------------------- */
	/* Hide the iPhone Carousel div here because JCarousel won't show if 
		display:none style is used 		on the div.  Bug in JCarousel */
	$("#iphone_screenshots_div").hide();
	
	$("#aqua_connect_nav li a").click(function() {
		$(".abilities_menu li a").each(function() {
			$(this).removeClass("ability_menu_selected");
		});
		$(this).addClass("ability_menu_selected");
	});

});

/* ------------------------------------------------------------------------------------- */
/* Custom jquery scripts */


/* Generic Div Slide function passing the div id as the parameter */
function DivSlide(thediv) {
	$('#'+thediv+'').slideToggle("normal");
}

function ToggleBios(toggle)
{
	$(".bio").each(function() {
		$(this).slideUp("normal");
	});
	$("#"+toggle+"").slideDown("normal");
}

/* Events Google Map toggle between Apple events and trade shows */
function ToggleEvents(event)
{
	var iframe_src = "http://www.macpractice.com/macpractice2/events_map.php";
	
	if (event != "all") {
		$("#events_list li").hide();
		$("#events_list ."+event+"").show();
	}
	else {
		$("#events_list li").show();
	}
	$("#event_map_iframe").attr("src",iframe_src+"?event="+event);
}

/* Function for the left side divs that slide up and down: ie Contact, Events, News divs */
function ToggleBoxes(thediv)
{
	/*
	var this_div = "#"+thediv+"";
	
	$("div[name='toggle_box']").slideUp("normal");
	
	if ($(this_div).is(":hidden")) {
		$(this_div).slideDown("normal");
	}
	*/
	$("#"+thediv+"").slideToggle();
}

/* These functions change the scroll number in the JCarousel slides.  It updates a span id  with the 
	index of the image being show.  This function is called from the JCarousel function afterEnd setting */
function changeScrollNumber(o)
{
	num = $(o).attr('class');
	$("#screenshot_num").text(num);
}
function changeIphoneScrollNumber(o)
{
	num = $(o).attr('class');
	$("#iphone_screenshot_num").text(num);
}
