﻿//v0.1 29 April 2010 (MRM)

// if JavaScript is enabled, hide the 'no-script' list of links, and show the ajax-driven menu
// these two lines MUST be below the elements they reference in the DOM (towards the bottom of the page)
$(".no-script").hide();
$(".sections").show();

// namespace
if (typeof HAT === "undefined" || !HAT) {
    var HAT = {};
}

HAT.Languages = {
    lang: [
		{
		    intelcode: "ara",
		    textdirection: "rtl",
		    culture: "ar_AE",
		    countryval: "GlobalGateway_UAE_Arabic",
		    countrylang: ["Algeria - Arabic", "Bahrain - Arabic", "Iraq - Arabic", "Jordan - Arabic", "Kuwait - Arabic", "Lebanon - Arabic", "Morocco - Arabic", "Mauritania - Arabic", "Oman - Arabic", "Qatar - Arabic", "Tunisia - Arabic", "United Arab Emirates - Arabic", "Yemen - Arabic"],
		    fonttype: "HAT-font2"
		},
		{
		    intelcode: "ara",
		    textdirection: "rtl",
		    culture: "ar_AR",
		    countryval: "",
		    countrylang: [],
		    fonttype: "HAT-font2"
		},
		{
		    intelcode: "ara",
		    textdirection: "rtl",
		    culture: "ar_EG",
		    countryval: "GlobalGateway_Egypt_Arabic",
		    countrylang: ["Egypt - Arabic"],
		    fonttype: "HAT-font2"
		},
		{
		    intelcode: "ara",
		    textdirection: "rtl",
		    culture: "ar_SA",
		    countryval: "GlobalGateway_SaudiArabia_Arabic",
		    countrylang: ["Saudi Arabia - Arabic", "Middle East - Arabic"],
		    fonttype: "HAT-font2"
		},
		{
		    intelcode: "eng",
		    textdirection: "ltr",
		    culture: "en_SA",
		    countryval: "GlobalGateway_SaudiArabia_English.xml",
		    countrylang: ["Saudi Arabia - English", "United Arab Emirates - English", "Egypt - English", "Middle East - English"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "aze",
		    textdirection: "ltr",
		    culture: "az_AZ",
		    countryval: "",
		    countrylang: [],
		    fonttype: "HAT-font6"
		},
		{
		    intelcode: "ces",
		    textdirection: "ltr",
		    culture: "cs_CZ",
		    countryval: "/cd/corporate/europe/emea/ces/index.htm",
		    countrylang: ["Czech Republic - Czech"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "deu",
		    textdirection: "ltr",
		    culture: "de_DE",
		    countryval: "GlobalGateway_Germany_German",
		    countrylang: ["Austria - German", "Europe - German", "Germany - German", "Liechtenstein - German", "Switzerland - German"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "eng",
		    textdirection: "ltr",
		    culture: "en_AP",
		    countryval: "GlobalGateway_APAC_English",
		    countrylang: ["Asia Pacific - English", "Hong Kong - English", "Malaysia - English", "New Zealand - English", "Pakistan - English", "Philippines - English", "Singapore - English"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "eng",
		    textdirection: "ltr",
		    culture: "en_AU",
		    countryval: "GlobalGateway_Australia_English",
		    countrylang: ["Australia - English"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "eng",
		    textdirection: "ltr",
		    culture: "en_IN",
		    countryval: "GlobalGateway_India_English",
		    countrylang: ["India - English"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "sin",
		    textdirection: "ltr",
		    culture: "en_SG",
		    countryval: "",
		    countrylang: [],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "eng",
		    textdirection: "ltr",
		    culture: "en_UK",
		    countryval: "GlobalGateway_UnitedKingdom_English",
		    countrylang: ["Africa - English", "Belgium - English", "Czech Republic - English", "Denmark - English", "Estonia - English", "Europe - English", "Finland - English", "Gambia - English", "Greece - English", "Hungary - English", "Iceland - English", "Ireland - English", "Kenya - English", "Latvia - English", "Lithuania - English", "Luxembourg - English", "Nigeria - English", "Norway - English", "Romania - English", "Rwanda - English", "Tanzania - English", "United Kingdom - English", "Zimbabwe - English"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "eng",
		    textdirection: "ltr",
		    culture: "en_US",
		    countryval: "GlobalGateway_UnitedStates_English",
		    countrylang: ["United States - English", "Canada - English"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "eng",
		    textdirection: "ltr",
		    culture: "en_ZA",
		    countryval: "GlobalGateway_SouthAfrica_English",
		    countrylang: ["South Africa - English"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "spa",
		    textdirection: "ltr",
		    culture: "es_ES",
		    countryval: "GlobalGateway_Spain_Spanish",
		    countrylang: ["Spain - Spanish"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "esla",
		    textdirection: "ltr",
		    culture: "es_LA",
		    countryval: "GlobalGateway_LatinAmerica_Spanish",
		    countrylang: ["Argentina - Spanish", "Chile - Spanish", "Colombia - Spanish", "Costa Rica - Spanish", "Latin America - Spanish", "Mexico - Spanish", "Venezuela - Spanish", "Peru - Spanish", "Bolivia - Spanish", "Uruguay - Spanish"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "espanol",
		    textdirection: "ltr",
		    culture: "es_MX",
		    countryval: "",
		    countrylang: [],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "fra",
		    textdirection: "ltr",
		    culture: "fr_FR",
		    countryval: "GlobalGateway_France_French",
		    countrylang: ["Canada - French", "France - French", "Belgium – French"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "heb",
		    textdirection: "rtl",
		    culture: "he_IL",
		    countryval: "/cd/corporate/europe/emea/heb/287256.htm",
		    countrylang: ["Israel - Hebrew"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "hun",
		    textdirection: "ltr",
		    culture: "hu_HU",
		    countryval: "/cd/corporate/europe/emea/hun/index.htm",
		    countrylang: ["Hungary - Hungarian"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "bah",
		    textdirection: "ltr",
		    culture: "id_ID",
		    countryval: "/id_ID/index.htm",
		    countrylang: ["Indonesia - Bahasa"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "ita",
		    textdirection: "ltr",
		    culture: "it_IT",
		    countryval: "GlobalGateway_Italy_Italian",
		    countrylang: ["Italy - Italian"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "jpn",
		    textdirection: "ltr",
		    culture: "ja_JP",
		    countryval: "GlobalGateway_Japan_Japanese",
		    countrylang: ["Japan - Japanese"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "kor",
		    textdirection: "ltr",
		    culture: "ko_KR",
		    countryval: "GlobalGateway_Korea_Korean",
		    countrylang: ["Korea - Korean"],
		    fonttype: "HAT-font5"
		},
		{
		    intelcode: "nla",
		    textdirection: "ltr",
		    culture: "nl_NL",
		    countryval: "GlobalGateway_Netherlands_Dutch",
		    countrylang: ["Netherlands - Dutch", "Belgium – Netherlands"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "nla",
		    textdirection: "ltr",
		    culture: "nl_NL",
		    countryval: "GlobalGateway_Belgium_Dutch",
		    countrylang: ["Belgium - Dutch"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "pol",
		    textdirection: "ltr",
		    culture: "pl_PL",
		    countryval: "GlobalGateway_Poland_Polish",
		    countrylang: ["Poland - Polish"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "portugues",
		    textdirection: "ltr",
		    culture: "pt_BR",
		    countryval: "GlobalGateway_Brazil_Portuguese",
		    countrylang: ["Brazil - Portuguese"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "rom",
		    textdirection: "ltr",
		    culture: "ro_RO",
		    countryval: "",
		    countrylang: [],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "rus",
		    textdirection: "ltr",
		    culture: "ru_RU",
		    countryval: "GlobalGateway_Russia_Russian",
		    countrylang: ["Russia - Russian"],
		    fonttype: "HAT-font4"
		},
		{
		    intelcode: "swe",
		    textdirection: "ltr",
		    culture: "sv_SE",
		    countryval: "GlobalGateway_Sweden_Swedish",
		    countrylang: ["Sweden - Swedish"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "tur",
		    textdirection: "ltr",
		    culture: "tr_TR",
		    countryval: "GlobalGateway_Turkey_Turkish",
		    countrylang: ["Turkey - Turkish"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "tha",
		    textdirection: "ltr",
		    culture: "th_TH",
		    countryval: "GlobalGateway_Thailand_Thai",
		    countrylang: ["Thailand - Thai"],
		    fonttype: "GG-Thai-font"
		},
		{
		    intelcode: "vie",
		    textdirection: "ltr",
		    culture: "vi_VN",
		    countryval: "/vi_VN/index.htm",
		    countrylang: ["Vietnam - Vietnamese"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "zho",
		    textdirection: "ltr",
		    culture: "zh_CN",
		    countryval: "GlobalGateway_China_SimplifiedChinese",
		    countrylang: ["China - Simplified Chinese"],
		    fonttype: "HAT-font3"
		},
		{
		    intelcode: "ukr",
		    textdirection: "ltr",
		    culture: "uk_UA",
		    countryval: "/cd/corporate/europe/emea/rus/ukraine/index.htm",
		    countrylang: ["Ukraine - Ukrainian"],
		    fonttype: "HAT-font1"
		},
		{
		    intelcode: "zht",
		    textdirection: "ltr",
		    culture: "zh_TW",
		    countryval: "GlobalGateway_Taiwan_TraditionalChinese",
		    countrylang: ["Taiwan - Traditional Chinese"],
		    //fonttype:"HAT-font3"
		    fonttype: "GG-Taiwan-font"
		}
	]
}

HAT.Countries = [
    {
        deeplink: 'en_US_01',
        name: 'United States - English',
        cont: '/homepage/xml/GlobalGateway_UnitedStates_English.xml'
    },
	{
	    deeplink: 'es_LA_06',
	    name: 'Argentina - Spanish',
	    localizedName: 'Argentina - Español',
	    cont: '/homepage/xml/GlobalGateway_Argentina_Spanish.xml'
	},
	{
	    deeplink: 'en_AP_00',
	    name: 'Asia Pacific - English',
	    cont: '/homepage/xml/GlobalGateway_APAC_English.xml'
	},
	{
	    deeplink: 'en_AU_01',
	    name: 'Australia - English',
	    cont: '/homepage/xml/GlobalGateway_Australia_English.xml'
	},
	{
	    deeplink: 'de_DE_01',
	    name: 'Austria - German',
	    localizedName: 'Austria - Deutsch',
	    cont: '/homepage/xml/GlobalGateway_Germany_German.xml'
	},
	{
	    deeplink: 'nl_BE_01',
	    name: 'Belgium - Dutch',
	    localizedName: 'Belgium – Nederlands',
	    cont: '/homepage/xml/GlobalGateway_Belgium_Dutch.xml'
	},
	{
	    deeplink: 'fr_BE_01',
	    name: 'Belgium – French',
	    localizedName: 'Belgium – Français',
	    cont: '/homepage/xml/GlobalGateway_Belgium_French.xml'
	},
	{
	    deeplink: 'es_LA_07',
	    name: 'Bolivia - Spanish',
	    localizedName: 'Bolivia - Español',
	    cont: '/homepage/xml/GlobalGateway_Bolivia_Spanish.xml'
	},
	{
	    deeplink: 'pt_BR_01',
	    name: 'Brazil - Portuguese',
	    localizedName: 'Brazil - Português',
	    cont: '/homepage/xml/GlobalGateway_Brazil_Portuguese.xml'
	},
	{
	    deeplink: 'en_CA_01',
	    name: 'Canada - English',
	    link: '/en_CA/index.htm'
	},
	{
	    deeplink: 'fr_CA_01',
	    name: 'Canada - French',
	    localizedName: 'Canada - Français',
	    link: '/fr_CA/index.htm'
	},
	{
	    deeplink: 'es_LA_02',
	    name: 'Chile - Spanish',
	    localizedName: 'Chile - Español',
	    cont: '/homepage/xml/GlobalGateway_Chile_Spanish.xml'
	},
	{
	    deeplink: 'zh_CN_01',
	    name: 'China - Simplified Chinese',
	    localizedName: 'China - 简体中文',
	    cont: '/homepage/xml/GlobalGateway_China_SimplifiedChinese.xml'
	},
	{
	    deeplink: 'es_LA_03',
	    name: 'Colombia - Spanish',
	    localizedName: 'Colombia - Español',
	    cont: '/homepage/xml/GlobalGateway_Colombia_Spanish.xml'
	},
	{
	    deeplink: 'es_CR_01',
	    name: 'Costa Rica - Spanish',
	    localizedName: 'Costa Rica-Español',
	    link: '/costarica/index.htm'
	},
	{
	    deeplink: 'cz_CZ_01',
	    name: 'Czech Republic - English',
	    cont: '/homepage/xml/GlobalGateway_Czech_Rep_Czech.xml'
	},
	{
	    deeplink: 'en_EG_01',
	    name: 'Egypt - English',
	    cont: '/homepage/xml/GlobalGateway_Egypt_English.xml'
	},
	{
	    deeplink: 'ar_EG_01',
	    name: 'Egypt - Arabic',
	    localizedName: 'Egypt - عربي',
	    cont: '/homepage/xml/GlobalGateway_Egypt_Arabic.xml'
	},
	{
	    deeplink: 'fr_FR_01',
	    name: 'France - French',
	    localizedName: 'France - Français',
	    cont: '/homepage/xml/GlobalGateway_France_French.xml'
	},
	{
	    deeplink: 'de_DE_03',
	    name: 'Germany - German',
	    localizedName: 'Germany - Deutsch',
	    cont: '/homepage/xml/GlobalGateway_Germany_German.xml'
	},
	{
	    deeplink: 'en_AP_01',
	    name: 'Hong Kong - English',
	    cont: '/homepage/xml/GlobalGateway_HongKong_English.xml'
	},
	{
	    deeplink: 'hu_HU_01',
	    name: 'Hungary - English',
	    cont: '/homepage/xml/GlobalGateway_Hungary_English.xml'
	},
	{
	    deeplink: 'en_IN_01',
	    name: 'India - English',
	    cont: '/homepage/xml/GlobalGateway_India_English.xml'
	},
	{
	    deeplink: 'id_ID_01',
	    name: 'Indonesia - Bahasa',
	    link: '/id_ID/index.htm'
	},
	{
	    deeplink: 'en_UK_16',
	    name: 'Ireland - English',
	    link: '/corporate/europe/emea/irl/intel/index.htm'
	},
	{
	    deeplink: 'he_IL_01',
	    name: 'Israel - Hebrew',
	    localizedName: 'Israel - עברית',
	    link: 'http://www.intel.com/cd/corporate/europe/emea/heb/287256.htm'
	},
	{
	    deeplink: 'it_IT_01',
	    name: 'Italy - Italian',
	    localizedName: 'Italy - Italiano',
	    cont: '/homepage/xml/GlobalGateway_Italy_Italian.xml'
	},
	{
	    deeplink: 'ja_JP_01',
	    name: 'Japan - Japanese',
	    localizedName: 'Japan - 日本語',
	    cont: '/homepage/xml/GlobalGateway_Japan_Japanese.xml',
	    imagelink: '#jp-link'
	},
	{
	    deeplink: 'ko_KR_01',
	    name: 'Korea - Korean',
	    localizedName: 'Korea - 한국어',
	    cont: '/homepage/xml/GlobalGateway_Korea_Korean.xml'
	},
	{
	    deeplink: 'es_LA_01',
	    name: 'Latin America - Spanish',
	    localizedName: 'Latin America - Español',
	    cont: '/homepage/xml/GlobalGateway_LatinAmerica_Spanish.xml'
	},
	{
	    deeplink: 'en_AP_03',
	    name: 'Malaysia - English',
	    link: '/en_MY/index.htm'
	},
	{
	    deeplink: 'es_LA_04',
	    name: 'Mexico - Spanish',
	    localizedName: 'Mexico - Español',
	    cont: '/homepage/xml/GlobalGateway_Mexico_Spanish.xml'
	},
	{
	    deeplink: 'en_XR_01',
	    name: 'Middle East - English',
	    cont: '/homepage/xml/GlobalGateway_MiddleEast_English.xml'
	},
	{
	    deeplink: 'ar_XR_01',
	    name: 'Middle East - Arabic',
	    localizedName: 'Middle East – عربي',
	    cont: '/homepage/xml/GlobalGateway_MiddleEast_Arabic.xml'
	},
	{
	    deeplink: 'nl_NL_01',
	    name: 'Netherlands - Dutch',
	    localizedName: 'Netherlands - Nederlands',
	    cont: '/homepage/xml/GlobalGateway_Netherlands_Dutch.xml'
	},
	{
	    deeplink: 'en_AP_04',
	    name: 'New Zealand - English',
	    cont: '/homepage/xml/GlobalGateway_NewZealand_English.xml'
	},
	{
	    deeplink: 'en_AP_05',
	    name: 'Pakistan - English',
	    cont: '/homepage/xml/GlobalGateway_Pakistan_English.xml'
	},
	{
	    deeplink: 'es_LA_08',
	    name: 'Peru - Spanish',
	    localizedName: 'Peru - Español',
	    cont: '/homepage/xml/GlobalGateway_Peru_Spanish.xml'
	},
	{
	    deeplink: 'en_AP_06',
	    name: 'Philippines - English',
	    link: '/en_PH/index.htm'
	},
	{
	    deeplink: 'pl_PL_01',
	    name: 'Poland - Polish',
	    localizedName: 'Poland - Polski',
	    cont: '/homepage/xml/GlobalGateway_Poland_Polish.xml'
	},
	{
	    deeplink: 'ru_RU_05',
	    name: 'Russia - Russian',
	    localizedName: 'Russia - Русский',
	    cont: '/homepage/xml/GlobalGateway_Russia_Russian.xml'
	},
	{
	    deeplink: 'en_SA_01',
	    name: 'Saudi Arabia - English',
	    cont: '/homepage/xml/GlobalGateway_SaudiArabia_English.xml'
	},
	{
	    deeplink: 'ar_SA_01',
	    name: 'Saudi Arabia - Arabic',
	    localizedName: 'Saudi Arabia – عربي',
	    cont: '/homepage/xml/GlobalGateway_SaudiArabia_Arabic.xml'
	},
	{
	    deeplink: 'en_AP_07',
	    name: 'Singapore - English',
	    cont: '/homepage/xml/GlobalGateway_Singapore_English.xml'
	},
	{
	    deeplink: 'en_ZA_01',
	    name: 'South Africa - English',
	    cont: '/homepage/xml/GlobalGateway_SouthAfrica_English.xml'
	},
	{
	    deeplink: 'es_ES_01',
	    name: 'Spain - Spanish',
	    localizedName: 'Spain - Español',
	    cont: '/homepage/xml/GlobalGateway_Spain_Spanish.xml'
	},
	{
	    deeplink: 'sv_SE_01',
	    name: 'Sweden - Swedish',
	    localizedName: 'Sweden - Svenska',
	    cont: '/homepage/xml/GlobalGateway_Sweden_Swedish.xml'
	},
	{
	    deeplink: 'de_DE_05',
	    name: 'Switzerland - German',
	    localizedName: 'Switzerland - Deutsch',
	    cont: '/homepage/xml/GlobalGateway_Germany_German.xml'
	},
	{
	    deeplink: 'zh_TW_01',
	    name: 'Taiwan - Traditional Chinese',
	    localizedName: 'Taiwan - 繁體中文',
	    cont: '/homepage/xml/GlobalGateway_Taiwan_TraditionalChinese.xml'
	},
	{
	    deeplink: 'th_TH_01',
	    name: 'Thailand - Thai',
	    localizedName: 'Thailand - ภาษาไทย',
	    cont: '/homepage/xml/GlobalGateway_Thailand_Thai.xml'
	},
	{
	    deeplink: 'tr_TR_01',
	    name: 'Turkey - Turkish',
	    localizedName: 'Turkey - Türkçe',
	    cont: '/homepage/xml/GlobalGateway_Turkey_Turkish.xml'
	},
	{
	    deeplink: 'ru_RU_09',
	    name: 'Ukraine - Ukrainian',
	    localizedName: 'Ukraine - Українська',
	    link: 'http://www.intel.com/cd/corporate/europe/emea/rus/ukraine/index.htm'
	},
	{
	    deeplink: 'en_AE_01',
	    name: 'United Arab Emirates - English',
	    cont: '/homepage/xml/GlobalGateway_UAE_English.xml'
	},
	{
	    deeplink: 'ar_AE_01',
	    name: 'United Arab Emirates - Arabic',
	    localizedName: 'United Arab Emirates – عربي',
	    cont: '/homepage/xml/GlobalGateway_UAE_Arabic.xml'
	},
	{
	    deeplink: 'en_UK_15',
	    name: 'United Kingdom - English',
	    cont: '/homepage/xml/GlobalGateway_UnitedKingdom_English.xml'
	},
	{
	    deeplink: 'es_LA_09',
	    name: 'Uruguay - Spanish',
	    localizedName: 'Uruguay - Español',
	    cont: '/homepage/xml/GlobalGateway_Uruguay_Spanish.xml'
	},
	{
	    deeplink: 'es_LA_05',
	    name: 'Venezuela - Spanish',
	    localizedName: 'Venezuela - Español',
	    cont: '/homepage/xml/GlobalGateway_Venezuela_Spanish.xml'
	},
	{
	    deeplink: 'vi_VN_01',
	    name: 'Vietnam - Vietnamese',
	    localizedName: 'Vietnam – Tiếng Việt',
	    link: '/vi_VN/index.htm'
	}
];

HAT.Countries.getByDeeplink = function (deeplink) {
    for (var index = 0; index < HAT.Countries.length; index++) {
        var c = HAT.Countries[index];
        if (c && c.deeplink.toLowerCase() === deeplink.toLowerCase()) {
            return c;
        }
    }
    return null;
};

HAT.Countries.getByName = function (name) {
    for (var index = 0; index < HAT.Countries.length; index++) {
        var c = HAT.Countries[index];
        if (c && c.name.toLowerCase() === name.toLowerCase()) {
            return c;
        }
    }
    return null;
};

//checking for best browser out there:
var ie6 = false;
var ie7 = false;
var heroBg = "";
var heroBgrtl = "";
var curTextDir = "";
var curTextDir = "";
var firstTime = true;
var DefaultLocale = 'en_US_01';
$(document).ready(function () {
    //just in case you are using the best browser-now we KNOW!!!							   
    if ($.browser.msie && $.browser.version.substring(0, 1) === '6') {
        ie6 = true;
    }

    if ($.browser.msie && $.browser.version.substring(0, 1) === '7') {
        ie7 = true;
    }

    //redraw dropdown for internet explore:
    if (ie6) { }


    //left side navigation		
    function navMenu() { $(this).height('auto'); }
    $(".section").hover(function () {
        if ($(this).attr("class").indexOf("work") > -1) $(this).addClass("navhover-top");
        else if ($(this).attr("class").indexOf("about") > -1) $(this).addClass("navhover-bot");
        else if ($(this).attr("class").indexOf("play") > -1) $(this).addClass("navhover");
        else if ($(this).attr("class").indexOf("support") > -1) $(this).addClass("navhover");
        //else $(this).addClass("navhover2");
        $(this).find('.contents').show();

    }, function () {
        $(this).removeClass("navhover");
        $(this).removeClass("navhover2");
        $(this).removeClass("navhover-top");
        $(this).removeClass("navhover-bot");
        $(this).find('.contents').hide();
    });
});

function addMofileParam(url) {
    if (url.indexOf('?') > -1) {
        return url + '&r=f';
    }
}

var default_country_name;
var default_country;

/*  
If there is a country code in the Query String parameter, skip this block
and load
*/
var deeplink = getLocale();
if (deeplink === null || deeplink === undefined || deeplink === '') {

    var ctry = null;
    var cVal = param("country");
    var ckVal = cookie("countrylang");

    // if there is a passed-in param use that
    if (cVal !== null && cVal !== undefined) {
        default_country_name = cVal;
    }
    // Otherwise if there is a cookie set use that
    else if (ckVal !== null && ckVal !== undefined) {
        default_country_name = ckVal;
    };

    // If no cookie, then determine geo by browser language (geocheck.js)
    if ((default_country_name === null || default_country_name === undefined) && (typeof (geocheck) !== undefined)) {
        ctry = HAT.Countries.getByDeeplink(checkGeo());
    }
    else {
        ctry = HAT.Countries.getByName(default_country_name);
    }

    var redirectUrl;
    if (ctry !== null && ctry !== undefined) {
        redirectUrl = "?" + ctry.deeplink;
    } else {
        redirectUrl = '?' + DefaultLocale;
    }

    if (hasMobileParam(location.search)) {
        redirectUrl = addMofileParam(redirectUrl);
    }
    location.href = redirectUrl;
}

/*  
Code below will execute if there is a country code found (either via the Query String, 
browser language, or cookie.)
*/

var redirect = ((param("country") === null || param("country") === undefined) &&
                (deeplink === null || deeplink === undefined)); // don't (initially) redirect if a country has been passed in
var initialTracking = false;
var omniture_page_name;

$.each(HAT.Countries, function (i, country) {
    // for convenience, set up a direct link the the appropriate item in HAT.Languages.lang
    $.each(HAT.Languages.lang, function (i, language) {
        if ($.inArray(country.name, language.countrylang) >= 0) {
            country.language = language;
            return false;
        }
    });

    // set up the default country value and an analytics tracking name
    if (deeplink === country.deeplink || default_country_name === country.name) {
        default_country = country;
        // set omniture page name, but NOT for the default (index 0, en_US) selection
        if (i && country.language) {
            omniture_page_name = country.language.countryval.replace(/_/g, ":");
        }
    }
});

function hasParameters(queryString) {
    return queryString.indexOf('?') > -1;
}

$(document).ready(function () {
    // parse the country list into a select box when loaded
    $.each(HAT.Countries, function (i, n) {
        $("<option value='" + n.name + "'>")
			.html(n.localizedName || n.name)
			.attr("selected", (n === default_country ? "selected" : ""))
			.appendTo("#country-selector");
    });

    var locale = getLocale();
    var redirectUrl;

    //check the param first
    var country = HAT.Countries.getByDeeplink(locale);

    //if no value is found, check the cookie
    if (country === null || country === undefined) {
        country = HAT.Countries.getByName(cookie("countrylang"));

        //if no value is found, check browser language
        if (country === null || country === undefined) {
            country = HAT.Countries.getByDeeplink(checkGeo());
        }

        //if no value is found still, set the default language
        if (country === null || country === undefined) {
            country = HAT.Countries.getByDeeplink(DefaultLocale);
        }

        redirectUrl = "?" + country.deeplink;

        if (hasMobileParam(location.search)) {
            redirectUrl = addMofileParam(redirectUrl);
        }

        location.href = redirectUrl;
    }

    if (country.language && country.language.textdirection === "rtl") {  // to fix a positioning bug in IE if switching to a RTL language
        $("#supportbtn_wrapper").hide();
        if (ie6) {
            $("#sot").css("left", "10px");
        }
        else if (ie7) {
            $("#sot").css("left", "95px");
        }
        else {
            $("#sot").css("left", "80px");
        }

        curTextDir = country.language.textdirection;
    }
    else {
        $("#sot").css("left", "245px");
    }

    setCookieWithCountryValue(country);

    // show the country selector, and add a change handler
    $("#country-selector").show().change(function (e) {
        firstTime = false;
        var selIndex = this.selectedIndex - 1;
        if (selIndex === -1) selIndex = 0;
        country = HAT.Countries[selIndex];
        redirectUrl = "?" + country.deeplink;

        if (hasMobileParam(location.search)) {
            redirectUrl = addMofileParam(redirectUrl);
        }

        location.href = redirectUrl;
    });

    // If a country has a redirect set up, load that page url.
    if (country.link) {
        location.href = country.link;
    }
    // Otherwise, set up the current page with country appropriate values
    else if (country.cont && country.language) {
        var headerJs = "/sites/sitewide/HAT/40recode/" + country.language.culture + "/json/gh_gateway.js";
        var footer = "/sites/sitewide/HAT/40recode/" + country.language.culture + "/" + country.language.textdirection + "_Standards_W1024_HTTP_UTF8/gf_default.inc";
        var languageClasses = "HAT-globalgateway HAT-wide " + country.language.fonttype + (country.language.textdirection === "rtl" ? " HAT-rtl" : "");
        var styleLink = "/sites/sitewide/HAT/40recode/css/" + country.language.textdirection + "_header.css";

        $("#gaat-linkstyle").attr('href', styleLink);

        /* 
        US header which contains the June 2010 search functionality is loaded by default from the page markup.
        For non-US locales, we need to load the old search markup.
        */
        if (country.deeplink !== 'en_US_01') {
            $(".gaat40-search").html('<li><form method="get" id="FORMSearchHeader" action="http://mysearch.intel.com/corporate/default.aspx"><fieldset><input type="hidden" id="culture" name="culture" value="' + country.language.culture + '" /><input type="hidden" name="category" id="category" /><input type="hidden" name="adv" id="adv" /><input type="hidden" name="value" id="value" /><label id="lbl_search" for="q">Search</label><input id="q" name="q" type="text" class="gaat40-inptsearch" /><input type="submit" value="Search" id="input-submit" class="gaat40-btnsearch" /><div id="HAT-filtermenu-container" class="gaat40-hide"></div></fieldset></form></li>' +
            '<scr' + 'ipt type="text/javascript" src="' + GAAT40.AssetPath + GAAT40.renderSettings.sitewidePath + '/js/header2.js"><\/scr' + 'ipt>');
        }

        $.get(country.cont, parseCountryXML, "xml");
        $.getJSON(headerJs, parseHeaderJSON);

        $("#footerdiv").load(footer);
        $("html").attr("dir", country.language.textdirection);

        $("#gaat40-header, #ggw").attr('class', languageClasses);

        // track change after the language updates for better user experience
        // but only after the initial page load
        if (initialTracking) {
            var omniture_page_name = country.language.countryval.replace(/_/g, ":").toLowerCase();
            waTrackAsLink("global gateway selection: " + country.name, 'o', 'wa_prop14=cim:' + omniture_page_name);
        }

        //default value for select country dropdown div

        // fix a bug in IE6 where the country selector loses track of which item is selected when changing between LTR and RTL
        $("#country-selector").find("option").filter(function () {
            if ($(this).val() === country.name) {
                $(this).attr("selected", "selected");
            }
        });

        if (ie6 && firstTime) {
            $("#optionDis").attr("selected", "selected");
        }
    }

    // show the country selector, and add a change handler
    // load the selected language if it is not the first (0th)
    // this assumes that the default language is already set up
    if ($("#country-selector").get(0).selectedIndex) {
        //$("#country-selector").trigger('change');

    } else {
        var country = HAT.Countries[0];
        $.get(country.cont, parseCountryXML, "xml");
        $("#main-c").addClass("postload");

        firstTime = true;
    }

    // make gfx a clickable link (if applicable)
    $("#sot span#gfx").click(function () {
		// 'sotlink' is set by showSOT if country.sot.href is defined						  
        var sotlink = $(this).attr("sotlink");
        if (sotlink && sotlink !== "") {
			// If this link has an iid associated with it, register the click
			var linkIID = $(this).attr("iid");
			if (linkIID && linkIID !== ""){
				// Register the IID click
				var s='s_gs()'; 
				waCustomLink(this,'','e','wa_iid=' + linkIID);				
			}
		
			// Redirect
            location.href = sotlink;
        }
    });

    redirect = true; // after the initial language is set up, re-enable redirects
    initialTracking = true;

    var previousImageLink; //previous image-map link

    function parseCountryXML(xml) {
        var $xml = $(xml);
        var optionHtml = '<option value="" id="optionDis">' + $xml.find("ctalink2").text() + '</option>';

        $('#optionDis').remove();
        $(optionHtml).attr('disabled', 'disabled').prependTo('#country-selector');

        function localize(selector, textnode, linknode) {
            $(selector).html($.trim($xml.find(textnode).text()) || "&nbsp;"); // insert a hard space even if item is empty, to preserve HTML layout
            if (linknode) { $(selector).attr('href', $xml.find(linknode).text()); }
        }

        //update main background if it is not default:
        if ($xml.find("herobackground").text().length > 1) {
            if (curTextDir === "rtl") {
                heroBg = $("#ggw").css('background-image');
            }
            else {
                heroBgrtl = $("#ggw").css('background-image');
            }

            $("#ggw").css('background-image', 'url(' + $xml.find("herobackground").text() + ')');
        }
        else {
            if (heroBg !== "" && curTextDir === "rtl") {
                $("#ggw").css('background-image', heroBgrtl);
            }
            else {
                $("#ggw").css('background-image', heroBg);
            }
        }
        //remove ctalinks if they exist:
        $("#ctalink1").remove();
        $("#ctalink2").remove();
        $("#ctalink3").remove();

        localize(".section.work h1 a", "worktitle", "worklink");
        localize(".section.play h1 a", "playtitle", "playlink");
        localize(".section.support h1 a", "supporttitle", "supportlink");
        localize(".section.about h1 a", "abouttitle", "aboutlink");
        localize(".section.work h2", "worksubtitle");
        localize(".section.play h2", "playsubtitle");
        localize(".section.support h2", "supportsubtitle");
        localize(".section.about h2", "aboutsubtitle");
        localize(".section.work .body", "workbody");
        localize(".section.play .body", "playbody");
        localize(".section.support .body", "supportbody");
        localize(".section.about .body", "aboutbody");
        $("#main-c").addClass("postload");
        //have to update this from selected in the select box

        if (firstTime) {
            if (ie6) {
                $("#optionDis").attr("selected", "selected");
            }
            else { localize('#local-text h2', "ctalink2"); }
        }

        else {
            $("#local-text h2").html($('#country-selector option:selected').text());
        }


        if (typeof (previousImageLink) !== "undefined") //check if we're changing from a geo that had an image-map link.  If so, hide it so we can't accidentally click it.
        { $(previousImageLink).css('display', 'none'); }
        //*****************************************************************//
        //************HERO UPDATES FROM COUNTRY XML*******************************// 

        var gfxBg = $xml.find("heroheadline").text();

        var gfxLink = $xml.find("heroheadlinelink").text();
        var imgWidth = $xml.find("heroheadlinewidth").text();
        var imgHeight = $xml.find("heroheadlineheight").text();

        var gfxEl = $("#sot span#gfx").css('background-image', 'url(' + gfxBg + ')');
        gfxEl.css("height", imgHeight);
        gfxEl.css("width", imgWidth);

        if (gfxLink.length > 1) {

			// Strip the IID tag out of the link (if it exists)
			var iidRegex = /(iid=([\w\+]+)&?)/i;
			var matchArray = iidRegex.exec(gfxLink);

			// Remove the IID from the link
			if (matchArray[1] !== "") {
				gfxLink = gfxLink.replace(matchArray[1], "");
				gfxLink = gfxLink.replace(/[\?|&]$/, ""); // trim off trailing ? and & chars
			}

			// Save the IID
			if (matchArray[2] !== "") {
				gfxEl.attr("iid", matchArray[2]);
			}

            gfxEl.attr("sotlink", gfxLink);
            gfxEl.css("cursor", "pointer");
		}
        //legacy???	
        if ($xml.find("heroimagemap").text().length > 1) {
            var heroimagemap = $xml.find("heroimagemap").text();
            $(heroimagemap).css('display', 'block'); //if this country has an image-map link, show it
            previousImageLink = $xml.find("heroimagemaplink").text(); //this country's image-map link is now the "previous" image-map link
        }

        if ($xml.find("heroextra").text().length > 1) {
            $("#cto-link").html("&nbsp;");
            var ctobutton = $xml.find("heroextra").text();
            $(ctobutton).appendTo("#cto-link");
        }

        if ($xml.find("heroextraright").text().length > 1) {
            $("#cto-link-right").html("&nbsp;");
            var ctobutton = $xml.find("heroextraright").text();
            $(ctobutton).appendTo("#cto-link-right");
        }
        if ($xml.find("ctalink1").text().length > 1 && $xml.find("ctalink1position").text().length > 1) {
            var ctalink1 = $xml.find("ctalink1").text();
            var ctapos1 = $xml.find("ctalink1position").text();
            //$("<div id=\"ctalink1\" style=\"+ctapos1+\">"+ctalink1+"</div>").attr("style",ctapos1).appendTo("#ggw");
        }

        if ($xml.find("ctalink2").text().length > 1 && $xml.find("ctalink2position").text().length > 1) {
            var ctalink2 = $xml.find("ctalink2").text();
            var ctapos2 = $xml.find("ctalink2position").text();
            //$("<div id=\"ctalink2\" style=\"+ctapos2+\">"+ctalink2+"</div>").appendTo("#ggw");
        }

        if ($xml.find("ctalink3").text().length > 1 && $xml.find("ctalink3position").text().length > 1) {
            var ctalink3 = $xml.find("ctalink3").text();
            var ctapos3 = $xml.find("ctalink3position").text();
            //$("<div id=\"ctalink3\" style=\"+ctapos3+\">"+ctalink3+"</div>").appendTo("#ggw");
        }
    }


    function parseHeaderJSON(json) {
        $("#lbl_search").html(json.header.search.button);
        $("#culture").val(json.header.search.culture);
        $("#input-submit")
			.attr('alt', json.header.search.button)
			.attr('title', json.header.search.button)

        GAAT40.SearchFilterLUT.head = json.header.search.filter.filterhead;

        GAAT40.SearchFilterLUT.qs = $.map(json.header.search.filter.term, function (n) {
            return { filter: n.query, term: n.value };
        });

        $("#HAT-filter-menu").remove();
        setTimeout(function () {
            $("#HAT-filter-menu").remove();
            GAAT40.FilterMenu();
        }, 50);        				

        // add overview (AKA tweenlink) support
        if (json.header.tweenlinks.link) {
            if (json.header.tweenlinks.link.length === null || json.header.tweenlinks.link.length === undefined) {
                $('.gaat40-overview li:nth-child(1)').html('');
                $('.gaat40-overview li:nth-child(2)').html('<a href="' + json.header.tweenlinks.link.href + json.header.tweenlinks.link.iid + '">' + json.header.tweenlinks.link.value + '</a>');
                $('.gaat40-overview li:nth-child(2)').addClass('gaat40-first');
            }
            else {
                $('.gaat40-overview li:nth-child(1)').html('<a href="' + json.header.tweenlinks.link[0].href + json.header.tweenlinks.link[0].iid + '">' + json.header.tweenlinks.link[0].value + '</a>');
                $('.gaat40-overview li:nth-child(2)').html('<a href="' + json.header.tweenlinks.link[1].href + json.header.tweenlinks.link[1].iid + '">' + json.header.tweenlinks.link[1].value + '</a>');
            }
            $('#gaat40-locale').removeClass('gaat40-first');
        }
        else {
            $('.gaat40-overview li:nth-child(1)').html('');
            $('.gaat40-overview li:nth-child(2)').html('');
            $('#gaat40-locale').addClass('gaat40-first');
            $('.gaat40-overview li:nth-child(2)').addClass('gaat40-first');
        }

        $('#gaat40-locale').html('<a href="' + json.header.widgets.changelocationwidget.link.href + json.header.widgets.changelocationwidget.link.iid + '">' + json.header.widgets.changelocationwidget.text[1].value + '</a>');

        $('.gaat40-overview').removeClass('header-hide').addClass('header-show');
        $('#footerdiv').removeClass('header-hide').addClass('header-show');
    }

    // this harmless snippet will add a top margin to the top-most sub-nav popup menu
    $('.section:first > .contents').addClass('contents-first');
});

function cookie(key) {
    //return parseParams(document.cookie, /; ?/)[key];
    //IE6 Cookie Fix 2/1/2009
    return decodeURIComponent(parseParams(document.cookie, /; ?/)[key]);
}

function param(key) {
    var params = parseParams(location.search.substr(1), "&");
    return params[key] ? unescape(params[key]) : null;
}

function setCookieWithCountryValue(country) {
    var nextyear = new Date();
    nextyear.setFullYear(nextyear.getFullYear() + 1);
    var cookie_value = "countrylang=" + encodeURIComponent(country.name) + "; domain=.intel.com; path=/; expires=" + nextyear.toUTCString();
    document.cookie = cookie_value;
}

function getLocale() {
    var search = location.search;
    var keyValues = search.split("&");
    if (keyValues.length > 0) {
        var value = keyValues[0].replace("?", "").replace("/", "");
        if (value === 'r=f')
            return null;
        return value;
    }
    return null;
}

// can be used for cookies or URL search strings
function parseParams(str, delimiter) {
    var x = {};
    $.each(str.split(delimiter), function (i, n) {
        var keyVal = n.split(/=/);
        if (keyVal[0] && keyVal[1]) { x[keyVal[0]] = keyVal[1]; }
    });
    return x;
}

// utility function to generate the 'no script' list of country links
function createNoscriptList() {
    var $div = $(".no-script").empty().show();
    var $list = $("<ul>").appendTo($div);
    $.each(HAT.Countries, function (i, n) {
        var value = n.link;
        if (n.cont) {
            $.ajax({ async: false, url: n.cont,
                success: function (countryXML) { value = $(countryXML).find("worklink").text(); }
            });
        }
        $list.append("<li><a href='" + value + "'>" + (n.localizedName || n.name) + "<\/a><\/li>");
        if ((i + 1) % 16 === 0) {
            if (i + 1 === HAT.Countries.length) {
                $list.css("text-align", "right");
                $div.append("<div class='clear'>");
            } else {
                $list = $("<ul>").appendTo($div);
            }
        }
    });
}