// Detect Mobile Phones
var mobile = ((navigator.platform.indexOf("iPhone") != -1) || (navigator.platform.indexOf("iPod") != -1) || (navigator.userAgent.indexOf("iPad") != -1) || (navigator.userAgent.indexOf("Android") != -1));

if (mobile){
	$('head').append('<link rel="stylesheet" href="Style/style-mobile.css" type="text/css" />');
	$("#alt-flash").show(); 
	base.$container.find("li").swipe({
		threshold: { x: 30, y: base.$container.find("li").height() },
		swipeUp: function(e) { base.scroll( +1 ); },
		swipeDown: function(e) { base.scroll( -1 ); },
		click: function(sender) { 
				if ($(sender).find("a:first").length > 0) location = $(sender).find("a:first").attr("href"); 
			}
	});
}

	function openMainModal() {
		$(".modal_body").show();
		$("#modal_bg").show();
	}

	function openContactModal() {
		$(".modal_contact").show();
		$("#modal_bg").show();
		//showEmailBox();
		
	}

	function closeMainModal() {
		if ($(".modal_body").is(":visible")){
			$(".modal_body").hide();
			$(".modal_section").hide();
		} 
		else
			$(".modal_contact").hide();
			
		$("#modal_bg").hide();
		$("#video").show();
		
		flash.flashObject.modalCloseComplete();
	}
	
	function aboutModal() {
		showContent("about");
		trackEvent("about");
	}
	
	function educatorsModal() {
		showContent("educators");
		trackEvent("educators");
	}
	
	function mediaModal() {
		showContent("media");
		trackEvent("media");
	}
	
	function priceModal() {
		showContent("price");
		trackEvent("giftPriceIndex");
	}
	
	function contactModal() {
		openContactModal();
	}

	function showContent(target, tab) {
		if (target.indexOf(".") < 0) target = "." + target;
		
		var content = $(".modal_body").find(target);

		if (tab == null) {
			var index = $(content).find(".modal_nav a.current").parent().index();
			
			current_tab = $(content).find(".modal_section_body").eq(index);
		} else {
			current_tab = $(content).find(".modal_section_body" + "." + tab);
			
			var index = $(current_tab).index(".modal_body " + target + " .modal_section_body");
			
			$(content).find(".modal_nav a.current").removeClass("current");
			$(content).find(".modal_nav a").eq(index).addClass("current");
		}
		
		//$("#video").hide();
				
		var path = $(current_tab).attr("class");
		path = $.trim(path.replace("modal_section_body", ""));
				
		location.hash = target.substring(1) + "/" + path;

		openMainModal();

		$(content).show();
		$(current_tab).show();
	}

//swipe
var swipeOptions =
{
	//swipeStatus:swipeStatus,
	swipeUp:slideDown,
	swipeDown:slideUp,
	threshold:50
}

//Swipe handlers.
//The only arg passed is the original touch event object			
	
	
function slideUp(sender, event){
	var content = $(sender).find(".scroll-content")
	
	var top = eval(content.css("margin-top").replace("px", "")) + 100;
	var visible = content.parent().height();
	var total = content.height();
	
	if (top > 0)
		top = 0;
	
	$(content).stop().animate({ "margin-top": top }, 500);
	$(content).parents(".scroll-pane").find(".scroll-bar").find("a").stop().animate({ bottom: (100 - Math.round((top / (visible - total)) * 100)) + "%" }, 500);
}
	
function slideDown(sender, event){
	var content = $(sender).find(".scroll-content")
	
	var top = eval(content.css("margin-top").replace("px", "")) - 100;
	var visible = content.parent().height();
	var total = content.height();
	
	if (top < visible - total)
		top = visible - total;
	
	$(content).stop().animate({ "margin-top": top }, 500);
	$(content).parents(".scroll-pane").find(".scroll-bar").find("a").stop().animate({ bottom: (100 - Math.round((top / (visible - total)) * 100)) + "%" }, 500);
}

// deeplinking
var loaderDone = function () {
	setTimeout(function() {	
		if (location.hash != null) {
			var path = location.hash.toString().substring(1).split('/');
				
			if (path.length == 2){
				showContent(path[0], path[1]);
				flash.flashObject.modalOpen();
			}
		}
	}, 1000);
}

