/**
 * Contains the basic functionality needed for Atari.com
 * It should be used for helper methods and for instantiation of global objects
 * across the site, such as Flash embedding, main navigation, etc.
 * 
 * @author Kevin Sweeney (Fi)
 * @author David Lindkvist (Fi)
 * @author Karl Stanton (Fi)
 * @author Filip Michalowski (Fi)
 * @version 1.0
 * 
 */

var AtariGlobal = {};

var config = {};
var localized_strings = {

  // String required by all pages with the main navigation
  menu_label_FindGames: 'Find Games'
};

// General Methods _____________________________________________________________

/**
 * Iniatilizes any global behaviors required throughout the site
 */
AtariGlobal.init = function () {
	
	$('body').removeClass('noJS');
	
	AtariGlobal.setupExternalLinks();
	
	AtariGlobal.setupSelects();
	
	AtariGlobal.setupSearchInput();
	
	AtariGlobal.setupInputFields();

};

/**
 * Initialize external links
 */
AtariGlobal.setupExternalLinks = function () {	
	$("a[rel='external']").attr("target","_blank");
};

/**
 * Sets up the dynamic styling of all select elements
 */
AtariGlobal.setupSelects = function () {

  if(ie6 == false) {
    // Setup all the dynamic drop downs
    $('select').dropdown({
      open: function () {
        //console.info()
      },
      change: function () {
        //console.info(this.selectedIndex);
      }
    });
  }

};

/**
 * Sets up the interactivity of the search input boxes
 * @uses localized_strings
 */
AtariGlobal.setupSearchInput = function () {

	// Setup Search Input
	$('input.searchField').val(localized_strings.menu_label_FindGames).focus(function () {
		var this_el = $(this);
		if (this_el.val() === localized_strings.menu_label_FindGames) {
			this_el.val('');
		}
		this_el.parent().addClass('active');
	}).blur(function () {
		var this_el = $(this);
		if (this_el.val() === '') {
			this_el.val(localized_strings.menu_label_FindGames);
		}
		this_el.parent().removeClass('active');
	});
	
};

/**
 * Styles all the input fields
 */
AtariGlobal.setupInputFields = function () {	
	// create text input fields with custom background
	var wrapperLeftPadding = 5;
	var wrapperLeft, wrapperRight, elementWidth;
	var setupInputFields = function(el){	
		elementWidth = ( $(el).css('width') != 'intrinsic' && $(el).css('width') != 'auto' ) ? $(el).css('width').split('px').join('') : $(el).width();
		wrapperLeft = $('<div class="inputWrapperLeft"></div>').width( elementWidth - wrapperLeftPadding );	
		wrapperRight = $('<div class="inputWrapperRight"></div>');
		$(el).wrap(wrapperLeft).wrap(wrapperRight).css({
			width: '100%',
			visibility: 'visible'
		});
	};	
	// shopping cart forms
	$('body.shopping .wrapper form input[type="text"]').each(function(){
		setupInputFields(this);
	});	
	$('body.shopping .wrapper form input[type="password"]').each(function(){
		setupInputFields(this);
	});
	
};

/**
 * Launch Atari !
 */
AtariGlobal.init();


/** 
* Custom JS for Atl
*/

$(document).ready(function(){
  // Adjusts dynamically inserted link colors on ThankYou page as per client style.
  $("td#dr_WebLoyaltyCode a").css({"color":"#cc3333","font":"normal 9pt arial,sans-serif"}).hover(function(){
    $(this).css("text-decoration","none");
  }, function() {
    $(this).css("text-decoration","underline");
  });

  // Reveals Customer Service Header on relevant pages.
  if (location.href.indexOf("10107") != -1 || location.href.indexOf("10340") != -1 || location.href.indexOf("10341") != -1 || location.href.indexOf("10342") != -1 || location.href.indexOf("10343") != -1 || location.href.indexOf("10344") != -1  || location.href.indexOf("10342") != -1 || location.href.indexOf("10345") != -1 || location.href.indexOf("10346") != -1 || (thisCustomerService)){
    $("h2#dr_custServHeader").css("display","block");
  }

// Centers accept and decline buttons on templated EULA page
$("td:has(input[src*='decline.png']), td:has(input[src*='accept.png'])").css("text-align","center");
});


      // Fireclick Web Analytics - COPYRIGHT 1999-2006 - Please do not modify this code
function handle(){return true;}
window.onerror=handle;
var fc_host='www.atari.com';
document.write('<scr'+'ipt '
+'src="'+((location.protocol=='http:')?'http:':'https:')
+'//a248.e.akamai.net/f/248/5462/3h/hints.netflame.cc/service/sc'+'ript/'+fc_host+'"></scr'+'ipt>');
function fcce(){if (typeof(fcnf)!="undefined") fcnf();}
var fcfn=window.onload;
function fcco(){window.setTimeout("fcce();", 100);fcfn();}
window.onload= null==fcfn ? fcce:fcco;


// COPYRIGHT 1997-2004 WEBSIDESTORY,INC. ALL RIGHTS RESERVED. U.S.PATENT No.6,393,479B1 & 6,766,370. INFO:http://websidestory.com/privacy
var _hbEC=0,_hbE=new Array;function _hbEvent(a,b){b=_hbE[_hbEC++]=new Object();b._N=a;b._C=0;return b;}
var hbx=_hbEvent("pv");hbx.vpc="HBX0103u";hbx.gn="ehg-atariinc.hitbox.com";

//BEGIN EDITABLE SECTION
//CONFIGURATION VARIABLES
var URL = location.href.toLowerCase();
function getPID(num, iden){
	var getPIDstartPos = URL.indexOf(iden) + iden.length;
	var getPIDendPos = getPIDstartPos + num;
	var PID = URL.substring(getPIDstartPos, getPIDendPos);

	if (num == 6 && !isNaN(PID)) {
		return PID+'+Product+Detail+Page';
	}
	else if (num == 5 && !isNaN(PID)) {
		return PID+'+Category+Page';
	}
	else {
		return "Unknown+or+Interstial+Page";
	}
}

if (frontPage) {
  hbx.pn="DR+Store+Front";
   }
   else if (thisCart) {
  hbx.pn="Shopping+Cart";
   }
   else if (URL.indexOf("10034") != -1) { // must be after thisCart in script
  hbx.pn="Cross+Sell+Page";
   }
   else if (thisAuth) {
  hbx.pn="Payment+Page";
   }
   else if (thisConfirm) {
  hbx.pn="Order+Confirmation+Page";
   }
   else if (thisThanks){
  hbx.pn="Thank+You+Page";
   }
   else if (thisVerifyAddress){
  hbx.pn="Verify+Address+Page";
   }
   else if (thisInvoice) {
  hbx.pn="Invoice+Page";
   }
   else if (thisShipping) {
  hbx.pn="Shipping+Page";
   }
   else if (thisCredit) {
  hbx.pn="Buy+On+Account+page";
   }
/* 
   else if (URL.indexOf("entry17c?") != -1 && thisCategory) {
  hbx.pn=getPID(5, "pid=");
   } 
*/
   else if (URL.indexOf("entry17c?") != -1 && thisPD) {
  hbx.pn=getPID(6, "pid=");
   }
   else if (thisCategory) {
  hbx.pn=catName;
   }
   else if (thisPD) {
  hbx.pn=getPID(6, "v1=");
   }
   else if (URL.indexOf("sp=10107&pn=4&s1=2") != -1) {
  hbx.pn="Order+Status+Page";
   }
   else if (URL.indexOf("10107") != -1 || URL.indexOf("10107") != -1 || URL.indexOf("10340") != -1 || URL.indexOf("10341") != -1 || URL.indexOf("10342") != -1 || URL.indexOf("10343") != -1 || URL.indexOf("10344") != -1 || URL.indexOf("10345") != -1) {
  hbx.pn="Customer+Service+Page";
   }
   else if (thisSecurity) {
  hbx.pn="Security+Page";
   }
   else {
  hbx.pn="Unknown+or+Interstial+Page";
   }	//page name(s)
<!-- alert -->
//alert(hbx.pn);

hbx.acct="DM54073112VW38EN3";//ACCOUNT NUMBER(S)
//hbx.pn="PUT+PAGE+NAME+HERE";//PAGE NAME(S)
if (location.href.toLowerCase().indexOf("sitemaint") != -1){
   hbx.mlc="/drteststore"; //multi-level content category
   }
   else{
      hbx.mlc="/store";	//multi-level content category
}
hbx.pndef="title";//DEFAULT PAGE NAME
hbx.ctdef="full";//DEFAULT CONTENT CATEGORY

//OPTIONAL PAGE VARIABLES
//ACTION SETTINGS
hbx.fv="1";//FORM VALIDATION MINIMUM ELEMENTS OR SUBMIT FUNCTION NAME
hbx.lt="auto";//LINK TRACKING
hbx.dlf="n";//DOWNLOAD FILTER
hbx.dft="n";//DOWNLOAD FILE NAMING
hbx.elf="y";//EXIT LINK FILTER

//SEGMENTS AND FUNNELS
hbx.seg="";//VISITOR SEGMENTATION
hbx.fnl="";//FUNNELS

//CAMPAIGNS
hbx.cmp="";//CAMPAIGN ID
hbx.cmpn="";//CAMPAIGN ID IN QUERY
hbx.dcmp="";//DYNAMIC CAMPAIGN ID
hbx.dcmpn="";//DYNAMIC CAMPAIGN ID IN QUERY
hbx.dcmpe="";//DYNAMIC CAMPAIGN EXPIRATION
hbx.dcmpre="";//DYNAMIC CAMPAIGN RESPONSE EXPIRATION
hbx.hra="";//RESPONSE ATTRIBUTE
hbx.hqsr="";//RESPONSE ATTRIBUTE IN REFERRAL QUERY
hbx.hqsp="";//RESPONSE ATTRIBUTE IN QUERY
hbx.hlt="";//LEAD TRACKING
hbx.hla="";//LEAD ATTRIBUTE

if (thisThanks){
  hbx.gp="LAST";
   }
   else {
hbx.gp="";//CAMPAIGN GOAL
}

hbx.gpn="";//CAMPAIGN GOAL IN QUERY
hbx.hcn="";//CONVERSION ATTRIBUTE
hbx.hcv="";//CONVERSION VALUE
hbx.cp="null";//LEGACY CAMPAIGN
hbx.cpd="";//CAMPAIGN DOMAIN

//CUSTOM VARIABLES
hbx.ci="";//CUSTOMER ID
hbx.hc1="";//CUSTOM 1
hbx.hc2="";//CUSTOM 2
hbx.hc3="";//CUSTOM 3
hbx.hc4="";//CUSTOM 4
hbx.hrf="";//CUSTOM REFERRER
hbx.pec="";//ERROR CODES

//INSERT CUSTOM EVENTS

//END EDITABLE SECTION
