jQuery(function($)
{
  if ($('div#flashContent').length == 1)
  {
  	toggleDetails();
  }
  
  gaTracking();
});

function toggleDetails()
{
	var benefits = $('#flashContent dl');
	var term = $('#flashContent dt'); //array of all definition titles
	var desc = $('#flashContent dd'); //array of all definition descriptions
	var origDetail = $('#flashContent #content_1_dd'); //array of all definition titles

	term.hover(
	function() {
	    origDetail.removeClass('visible');
	    $(this).next().addClass('visible');

	},
	function() {
	$(this).next().removeClass('visible');
	origDetail.addClass('visible');	    


	});
}

var f9Utility = (function() {
    function ie6CorrectPng(img) {
        var imgName = img.src.toUpperCase();
        if (((_utility.checkForPngClassName && img.className.indexOf(_utility.fixPngClassName) > -1) || !_utility.checkForPngClassName) && imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
            var imgID = (img.id) ? "id='" + img.id + "' " : "";
            var imgClass = (img.className) ? "class='" + img.className + "' " : "";
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
            var imgStyle = "display:inline-block;" + img.style.cssText;
            if (img.align == "left") imgStyle = "float:left;" + imgStyle;
            if (img.align == "right") imgStyle = "float:right;" + imgStyle;
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
		    + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
		    + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		    + "(src=\'" + img.src + "\');\"></span>";
            img.outerHTML = strNewHTML;
            return true;
        }
        return false;
    }
    function ie6FixAllPngs() {
        for (var i = 0; i < document.images.length; i++) {
            var img = document.images[i];
            if (ie6CorrectPng(img)) {
                i = i - 1;
            }
        }
    }
    function _utility() { }
    _utility.fixPngClassName = "f9PNG";
    _utility.checkForPngClassName = true;
    _utility.browser = (function() {
        function b() { }
        b.name = window.navigator.userAgent.toLowerCase();
        b.version = (b.name.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [0, '0'])[1];
        b.isIE = function() { return /msie/.test(b.name); }
        b.isIE6 = function() { return (b.isIE() && parseInt(b.version) < 7); }
        return b;
    })();
    _utility.addWindowEvent = function(eventName, func) {
        if (window.attachEvent) {
            window.attachEvent("on" + eventName, func);
        } else {
            window.addEventListener(eventName, func, false);
        }
    }
    _utility.fixPngs = function() {
        if (_utility.browser.isIE6()) {
            ie6FixAllPngs();
        }
    }
    _utility.enterPressed = function(e, fnToExecute) {
        var key;
        if (window.event) key = window.event.keyCode;
        else key = e.which;
        if (key == 13) eval(fnToExecute)();
    }
    _utility.getStyle = function(el, style) {
        if (!document.getElementById)
            return;
        var value = el.style[style];
        if (!value) {
            if (el.currentStyle)
                value = el.currentStyle[style];
            else if (document.defaultView)
                value = document.defaultView.getComputedStyle(el, "").getPropertyValue(style);
        }
        return value;
    }
    _utility.getCenterX = function(divWidth) {
        var x = 0;
        if (_utility.browser.isIE()) {
            x = (document.documentElement.clientWidth - divWidth) / 2;
        } else {
            x = (window.innerWidth - divWidth) / 2;
        }
        if (!_utility.browser.isIE()) x -= 10;
        if (x < 0) x = 0;
        return x;
    }
    return _utility;
})();
function toggleDiv(divID, showDiv, center) {
    var obj = document.getElementById(divID);
    if (showDiv) {
        if (center) obj.style.left = f9Utility.getCenterX(parseInt(f9Utility.getStyle(obj, "width")));
        obj.style.display = "block";
    } else {
        obj.style.display = "none";
    }
}

//*********************
// TRACKING FUNCTIONS
//*********************
function googleTrack(tag) {
	tag = "/earthquake/" + tag;
	pageTracker._trackPageview(tag);
}

function gaTracking()
{	 
	 $('#logo_chase').click(function()
	 {
	 	googleTrack('chase_logo');
		openExtLink(this.href);
		return false;
	 });
	 
	 $('#card').click(function()
	 {
	 	googleTrack('banner/apply_cardart');
		openExtLink(this.href);
		return false;
	 });
	 
	 $('#btn_apply_top').click(function()
	 {
	 	googleTrack('banner/apply_button');
		openExtLink(this.href);
		return false;
	 });
	 
	 $('#btn_apply_btm').click(function()
	 {
	 	googleTrack('apply_bottom');
		openExtLink(this.href);
		return false;
	 });

	 $('#pricingTerms,#pricingTermsFoot').click(function()
	 {
	 	googleTrack('footer/pricing');
		openExtLink(this.href);
		return false;
	 });
	 
	 $('#privacy').click(function()
	 {
	 	googleTrack('footer/privacy');
		openExtLink(this.href);
		return false;
	 });
	 
	 $('#creditTools').click(function()
	 {
	 	googleTrack('footer/credit_tools');
		openExtLink(this.href);
		return false;
	 });
	 
	 $('#termsCond').click(function()
	 {
	 	googleTrack('footer/terms');
		openExtLink(this.href);
		return false;
	 });
	 
	 //hover example
/*
	 $('.cta').hover(function()
	 {	 	
		googleTrack('#');
	 },
	 function()
	 {
	 	
	 });
*/
}
function pageWidth() {return window.innerWidth != null? window.innerWidth: document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.body != null? document.body.clientHeight:null;}
function openExtLink(url)
{
	var nH = pageHeight() - 200;
	var nW = pageWidth() - 200;	
	wExtLink=window.open(url,'externalLink','width=' + nW + ',height=' + nH + ',location=1,toolbar=1,menubar=1,directories=1,status=1,resizable=1,scrollbars=1');
	wExtLink.focus();
}