/*----------------------------
	Flash Video Embeds
 ----------------------------*/
/* banner ad */
var flashvars = {}
var params = {};
params.bgcolor = "#e9eaec";
params.allowFullScreen = "false";
params.scale = "showall";
params.loop = "true";
params.wmode = "transparent";
params.menu = 'false';
var attributes = {};

swfobject.embedSWF("../global/flash/bannerredux.swf", "flashBannerContent", "722", "81", "9", "expressInstall.swf", flashvars, params, attributes);


/* video player */
flashvars = {}
flashvars.videoPath = "aquent.flv";	
params = {};
params.allowFullScreen = "true";
params.wmode = "transparent";
params.menu = 'false';
attributes = {};
swfobject.embedSWF("../global/flash/VideoPlayer.swf", "flashVideoContent", "307", "148", "9", "expressInstall.swf", flashvars, params, attributes);

var IOS = window.IOS || {};


/*----------------------------
	Google Tracking Calls
 ----------------------------*/

IOS.googleAnalytics = {
	track: function(section,item) {
		if (typeof pageTracker != "undefined") {
			if (item) {
				pageTracker._trackPageview('/'+section+'/'+item);
			} else {
				pageTracker._trackPageview('/'+section);
			}
		}
	}
}

/*----------------------------
	Internal Flash Calls
 ----------------------------*/
IOS.handleBannerClick = function() {
	$("#flash.section").click();
}

IOS.handleVideoClick = function() {
	$("#video.section").click();
}

/*----------------------------
	Page Interactivity
 ----------------------------*/

var $sections = null;
var $a = null;

IOS.details = {
	isOpen: false,
	open: function(elm) {
		$("#wipe").addClass("show");
        $(elm).addClass("active");
        $("#"+$(elm).attr("id")+"-details").addClass("active").focus();
        if ($.browser.msie) {
            var dp = $("#"+$(elm).attr("id")+"-details").position();
            var ip = $(elm).position();
            $("#ie-shadow-details").css("left", (dp.left + 29) + "px").css("top",(dp.top + 29) + "px");
            $("#ie-shadow-item").width($(elm).width()).height($(elm).height()).css("left", (ip.left + 29) + "px").css("top",(ip.top + 29) + "px");
        }
        
		this.isOpen = true;
	},
	close: function() {
		
	},
	clear: function() {
		$sections.filter(".active").removeClass("active").find("a").focus();
        $(".details").removeClass("active");
        $("#wipe").removeClass("show");
        if ($.browser.msie) {
            $(".ie-shadow").css("top", "-9999px")
        }
		this.isOpen = false;
	}
}

IOS.how = {
	isOpen: false,
	open: function() {
        $("body").addClass("how");
		$("#howthisworks").focus();
		this.isOpen = true;
	},
	close: function() {
		$("body").removeClass("how");
		this.isOpen = false;
	}
}

$(document).ready(function() {
    $sections = $(".section");
    $a = $("#aquent a");

	// browser testing and page setup
	$("body").addClass("js-enabled"); // switch styles if JS is on
    $("a[rel=external]").attr("target","_blank"); //external links in new window
    // set up drop shadow layers for MSIE
    if ($.browser.msie) {
        $("#wrap").append('<div class="ie-shadow" id="ie-shadow-details"></div><div class="ie-shadow" id="ie-shadow-item"></div>');
    }
//	$sections.attr("tabindex","-1");
	$(".details, #howthisworks").attr("tabindex","-1");


    $sections.bind("mouseover",function(e) {
        $(this).addClass("hover");
    });
    $sections.bind("mouseout", function(e) {
        $(this).removeClass("hover");
    });
	
    $sections.bind("click", function(e) {
		// if this section isn't already open
		if (!$(this).is(".active")) {
			IOS.details.open(this);
			IOS.googleAnalytics.track($(this).attr("id"),null);
		}
		
        // let clickthrough work on social links / trigger popup
        if ($(e.target).is("#social a")) {
			window.open(e.target.href,"ios_social","resizable=1,scrollbars=auto,width=760,height=450");
            e.preventDefault();
			IOS.googleAnalytics.track($(this).attr("id"),$(e.target).attr("id"));
        } else {
            e.preventDefault();
		}
    });

    $("#wipe, .ie-shadow").bind("click", function(e) {
        e.preventDefault();
        if ($("#wipe").is(".show")) {
            IOS.details.clear();
        };
    });


	// Opening and Closing of How This Works content
    $a.bind("click", function(e) {
        e.preventDefault();
		IOS.how.open();
		IOS.googleAnalytics.track("howthisworks",null);
    });

    $("#howthisworks .close").bind("click",function(e){
        e.preventDefault();
		IOS.how.close();
    });

	// Support ESC keystroke
    $(document).bind("keydown", function(e) {
        if (e.which == 27) {  // esc
            e.preventDefault();
			IOS.details.clear();
			IOS.how.close();
        }
    });

	// Close if click on body
    $("body").bind("click", function(e) {
		if ($(e.target).is("body")) {
            e.preventDefault();
			IOS.details.clear();
			IOS.how.close();
		}
    });
	
	// Close if click on close button
	$(".content .close").bind("click",function(e){
        e.preventDefault();
		IOS.details.clear();
		IOS.how.close();
    });

	// tabbish items in details content
    $(".details dt").bind("click",function(e){
       e.preventDefault();
       $(this).addClass("active").siblings("dt").removeClass("active");
       $(this).siblings("dd").hide();
       $(this).next("dd").show();
    });

	// call us content swaps
	$("a.callus").bind("click", function(e) {
		//if (!$(this).is(".clicked")) { // let someone click the number in their browser, may work
			e.preventDefault();
		//}
		$(this).addClass("clicked");
		var phone = $(this).attr("href").split("+1-")[1];
		$(this).html("Call: "+phone);
		var section = null;
		if ($(this).closest(".details").length != 0) {
			section = $(this).closest(".details").attr("id").split("-")[0];
		} else { 
			section = "howthisworks";
		}
		IOS.googleAnalytics.track(section,"callus");
    });
	

	// additional tracking items
	$(".details a.emailus").bind("click", function(e) {
		var section = $(this).closest(".details").attr("id").split("-")[0];
		IOS.googleAnalytics.track(section,"emailus");
    });
	$(".details .actions a").bind("click", function(e) {
		var section = $(this).closest(".details").attr("id").split("-")[0];
		IOS.googleAnalytics.track(section,"action");
    });
	$("a.aquent").bind("click", function(e) {
		var section = $(this).closest(".details").attr("id").split("-")[0];
		IOS.googleAnalytics.track(section,"aquent");
    });


});