//default sizes of window
var MINWIDTH = 960;
var MAXWIDTH = 1280;
var MINHEIGHT = 550;
var MAXHEIGHT = 670;
var MARGINTOPOFFSET = -30;
var MARGINLEFTOFFSET = -20;
var topAlign=285;
var leftAlign=480;
var FOOTERHEIGHT = 20;
//might need to change this
var TOPPADDING=20;
var LEFTPADDING=20;
var flashLeft = 0;
var flashTop = 0;
var leftPosition = 0;
var topPosition = 0; 
var flash = true;
var maxWidthLeftOffset = 0; // the difference between the real width and the MAXWIDTH
var windowHeight = 0; // the full height of the browser window
var windowWidth = 0; // the full width of the browser window


function getScreenSize(){
 if (self.innerHeight) {    // all except Explorer
        width = self.innerWidth;
        height = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        width = document.documentElement.clientWidth;
        height = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        width = document.body.clientWidth;
        height = document.body.clientHeight;
    }
    windowHeight = height;
    windowWidth = width;
    
    if (width <= MINWIDTH){
        marginLeft = LEFTPADDING + MARGINLEFTOFFSET;
        leftAlign = width/2;
        width = MINWIDTH;
    }else{
        if (width >= MAXWIDTH){
            maxWidthLeftOffset = (width-MAXWIDTH)/2;
            width = MAXWIDTH;
        }
        marginLeft = ((width-MINWIDTH)/2)+LEFTPADDING + MARGINLEFTOFFSET;
        leftAlign = width/2;
    }
    if (height <= MINHEIGHT ){
        marginTop = TOPPADDING + MARGINTOPOFFSET;
        topAlign = height/2;
        height = MINHEIGHT;
        footerTop = height-topAlign;
        breadcrumbTop = 0;
    }else{
        if (height >= MAXHEIGHT){
            height = MAXHEIGHT;
            breadcrumbTop = 0;
        }
        marginTop = ((height-MINHEIGHT)/2)+TOPPADDING + MARGINTOPOFFSET;
        topAlign = height/2;
        footerTop = height-topAlign-FOOTERHEIGHT;
    }     
    
}
function showScreenSize(){
    
    getScreenSize();
	    
    //fix, shrink width by 1 pixel
    if (window.XMLHttpRequest) {
        width = width - 1;
    }         

    var elemFrame = $('#frame');
    elemFrame.css({ width:width, height:height, left:-leftAlign, top:-topAlign}); 
   
	var elemHtmlContent = $('#htmlcontent');
	elemHtmlContent.css({ width:width, height:height}); 
	
	var elemBg = $('#watch-background');
	if (elemBg.length > 0){
		elemBg.css({ width:width, height:height}); 
	}
	
    var elemFooter = $('#footer');
	elemFooter.css({width:width, left:-leftAlign, top:footerTop});
    
    var elemContent = $('#content');
	elemContent.css({marginTop:marginTop, marginLeft:marginLeft});

	
	if (window.ActiveXObject){
		var elemWatch = $('img.watch-image-basel');
		elemWatch.css({top:-marginTop});
	}
	
    var elemBreadcrumb = $('#breadcrumb-links');
	elemBreadcrumb.css({left:marginLeft}); 
}

/* DOM */
// Safari DOM workaround by Johnnie Blevins
// http://www.blevins.cx/javascripting/DOMParsing.html
if (!String.prototype.toDocumentFragment) {
    String.prototype.toDocumentFragment = function toDocumentFragment(context) {
        var aRange=document.createRange();
        context= context || document.getElementsByTagName("body")[0];
        aRange.selectNodeContents(context);
        return aRange.createContextualFragment(this);
    }
}

function killFlickerOnResize(){
    var boddyArray = [];
    bodyArray = document.getElementsByTagName('body');
    bodyArray[0].style.visibility='visible';
}

try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}


/******************/
/* Page Tracking */
/******************/
function pageTrack(xiti_section, xiti_page, spotlight_section, spotlight_page) {
    if (((xiti_section) && (xiti_page)) &&
        ((xiti_section!=null) && (xiti_page!=null)) &&
        ((xiti_section!="null") && (xiti_page!="null")) &&
        ((xiti_section!=undefined) && (xiti_page!=undefined)) &&
        ((xiti_section!="undefined") && (xiti_page!="undefined")) &&
        ((xiti_section!="") && (xiti_page!=""))) {
        xitiFlashEvent(xiti_section, xiti_page);
    }
    if (((spotlight_section) && (spotlight_page)) && 
        ((spotlight_section!=null) && (spotlight_page!=null)) &&
        ((spotlight_section!="null") && (spotlight_page!="null")) &&
        ((spotlight_section!=undefined) && (spotlight_page!=undefined)) &&    
        ((spotlight_section!="undefined") && (spotlight_page!="undefined")) &&
        ((spotlight_section!="") && (spotlight_page!=""))) {
        spotlightEvent(spotlight_section, spotlight_page);
    }
}
/* XiTi */
function XitiConstants(){
	this._initialized = false;
	this.init = function(){
		this.channels = {
		    "1":"The Collection",
		    "2":"World of Rolex",
		    "3":"Inside Rolex",
		    "4":"Home",
		    "5":"Official Dealers"
		};
		this.level2 = {
		    "4":"Footer Navigation",
		    "5":"Extraordinary Watches",
		    "6":"Rolex Gallery",
		    "7":"Fearless Luxury",
		    "8":"Sports and Culture",
		    "9":"Journey of Innovation",
		    "10":"The Rolex Channel",
		    "11":"Rolex Company",
		    "12":"Sales and Service",
		    "13":"Rolex Institute",
		    "14":"Rolex Nav Box",
		    "15":"Yacht-MasterII",
		    "16":"BaselWorld",
		    "17":"BloggerLanding",
		    "18":"Wimbledon",
		    "19":"Global Downloads",
		    "20":"BaselWorld 2008",
		    "21":"Home",
		    "22":"Spirit of Luxury",
		    "23":"Cellini Gallery",
		    "115":"Film Yachtmaster"
		};
		this.level2ChannelsMap = {
		    "1":"1",
		    "2":"2",
		    "3":"3",
		    "5":"1",
		    "15":"1",
		    "6":"1",
		    "8":"2",
		    "13":"2",
		    "11":"2",
		    "12":"5",
		    "16":"1",
		    "20":"1",
		    "21":"4",
		    "22":"2",
		    "23":"1"
	
		};
		this.languages = {
		    "1":"en",
		    "2":"ja",
		    "3":"es",
		    "4":"fr",
		    "5":"zh-Hans",
		    "6":"zh-Hant",
		    "7":"ko",
		    "8":"pt-br",
		    "9":"de",
		    "10":"it",
		    "11":"ru"
		};
		this.version = {
		    "1":"html",
		    "2":"flash",
		    "F":"flash",
		    "M":"flash",
		    "slow":"flash"
		}
		this._initialized = true;
	}
	this._initHashes = function(){
		if (!this._initialized){
		    this.init();
		}
	}
	this.getChannel = function(xitiSectionId){
		this._initHashes();
		if (xitiSectionId > 100){
		    xitiSectionId -= 100;
		}
		return this.channels[this.level2ChannelsMap[xitiSectionId]];
	}
	this.getProp1 = function(xitiSectionId){
		this._initHashes();
		if (xitiSectionId > 100){
			xitiSectionId -= 100;
		}    
		return this.level2[xitiSectionId];
	}
	this.getLanguage = function(xitiLanguageId){
		this._initHashes();
		try{
			if (newlang){
				//ko & zh-Hant hack
				return this.languages[newlang];
			}
		}catch(e){}
		return this.languages[xitiLanguageId];
	}
	this.getVersion = function(xitiVersionId){
		this._initHashes();
		return this.version[xitiVersionId];
	}
	this.getCampaign = function(){
		if (s.getQueryParam('cmpid')){
		    var cmp = s.getQueryParam('cmpid');
		    cmpParts = cmp.split('#');
		    return cmpParts[0];
		}
		return null;
	}
	this.getWatchNameSpec = function(xitiSectionId, page){
		//check if user is in gallery
		var watchNameSpec = ["", ""];
		if (this.getProp1(xitiSectionId) == 'Rolex Gallery'){
		    //obtain watch name & spec no from xiti page name
		    var pageNameParts = page.split('::');
		    if (pageNameParts.length == 2){
			watchNameSpec[0] = pageNameParts[1]
			watchNameSpec[1] = "";
		    }
		    else if (pageNameParts.length == 3){
			var watchParts = pageNameParts[1].split('_');
			watchNameSpec[0] = watchParts[0];
			watchNameSpec[1] = pageNameParts[2];
		    }
		}
		return watchNameSpec;
	}
	this.getWatchFeature = function(xitiSectionId, page){
		//check if user is in extraordinary watches
		var watchFeature = "";
		if (this.getProp1(xitiSectionId) == 'Extraordinary Watches'){
		    //obtain watch name & spec no from xiti page name
		    var pageNameParts = page.split('::');
		    if (pageNameParts.length == 3){
			watchFeature = pageNameParts[1] + ":" + pageNameParts[0] + ":" + pageNameParts[2];
		    }
		}
		return watchFeature;
	}
	this.getVideoTitle = function(type, page){
		if (type == "M"){ 
		    // only if MEDIA type
		    return page;
		}
		return "";
	}
	this.getPageName = function(type, page){
		if (type != "M" && type != "slow"){
		    return page.replace(/::/g,":");
		}
		try{
		    return s.pageName;
		}
		catch(e){
		    return "";
		}
	}
	this.getInternalCampaign = function(){
		if (s.getQueryParam('icid')){
		    return s.getQueryParam('icid');
		}
		return null;
	}
	this.getFlashVersion = function(){
		try{
		var fo = new SWFObject();
		if (fo){
		    
		    return fo.installedVer.major + "." + fo.installedVer.minor + "." + fo.installedVer.rev;
		}
		}catch(e){}
		return "";    
	}
	this.getDealerId = function(xitiSectionId, page){
		if (this.getProp1(xitiSectionId) == "Sales and Service"){
            if (page.indexOf('World') > 0){
                s.events="event1,event23";
                var pageParts = page.split('::');
                if (pageParts.length > 2){
                    return pageParts[pageParts.length - 1];
                }
                return "";
            }
        }
        return "";
	}
	this.getMapInteraction = function(xitiSectionId, page){
        if (this.getProp1(xitiSectionId) == "Sales and Service"){
            if (page == "Minimise_Map"         || 
                page == "Enlarge_Map"         ||
                page == "View_Legend"         ||
                page == "Reset_View"          ||
                page == "Click_Icon"             ||
                page.indexOf("Pan_") > -1     ||
                page.indexOf("Zoom_") > -1){
                    return page;
            }
            return "";
        }
        return "";
    }
}
function OmnitureObj() {
    this._metricsSet = false;
    this._metricsSent = false;//used for 1 time metrics
    this._total = 0;
    this._sEvents = '';
    this._sEvar19 = '';
    this.isPageHit = function(x1,x2,total,page){
        if (x1 == "N" || x1 == "S" || x1 == "T" || x1 == "play" || x1 == "forward" || x1 == "flash_disabled" || x1 == "finish"){
            if (x1 == "play" || x1 == "forward" || x1 == "finish"){
                var mediaName = page.indexOf('.com/');
                try{mediaName = page.substring(mediaName + 5);}catch(e){mediaName = page;}
                if (total > 0){
                    this._total = total;
                }
                //new in H.15, send a dedicated media hit to populate video report
                if (x1 == "play" && x2 == 0){
                        s.Media.open(mediaName ,total,"Flash Media Player");
                        s.Media.play(mediaName ,0);
                }
                 if (x1 == "forward" || x1 == "finish"){
                    if (x1 == "forward"){
                        s.Media.stop(mediaName, x2);
                    }
                    else if (x1 == "finish"){
                        s.Media.stop(mediaName ,this._total);
                    }
                    s.Media.close(mediaName );
                }
            }
            return false;
        }
        //x1 = C || x1 = slow --> page hit
        return true;
    }
    this.setSpeedMetrics = function(slowMessageShown, loadTime){
        if (slowMessageShown){
            this._sEvents = ",event14";
        }
        this._sEvar19 = loadTime;
        this._metricsSet = true;
    }
    this.populateAndGetLinkTrackVars =function(x1,page,sectionId,x5,x2,x4){
        if (x5==null){
            x5="";
        }
        var ltv = "";
        
        if (s.eVar14 != ""){
			ltv += "eVar14,events";
			s.events="event24"; //card viewed
		} else if (s.eVar23 != ""){
			ltv += "eVar23,events"; //map action
			s.events="event26";
		}    
        switch(x1){
            case "N":
                ltv += ",prop21,";
                s.prop21=this.getPageIdentifier(window.location.href) + ":" + page.replace(/::/g,">") + ":" + this.getPageIdentifier(x5);
                if (xitiConst.getProp1(sectionId) == "Sales and Service"){
                    //dealer locator
                    if (page.indexOf('rolexdealers.com') > 0){
                        ltv += "eVar18,events,";
                        s.eVar18=page;
                        if (x4 == "AFF"){
							s.events="event12,"; //affiliate clickthrough
						} else{
							s.events="event13,"; //dealer clickthrough
						}
                    }
                }
                
                if (page == "flash_disabled"){
                        s.events = "event15,";
                        ltv += "events,";
                }
            break;
            case "S":
                //custom exit clicks
                ltv += "prop20,";
                s.prop20 = page;
                if (xitiConst.getProp1(sectionId) == "Sales and Service"){
                    //dealer locator
                    if (page.indexOf('rolexdealers.com') > 0){
                        ltv += "eVar18,events,";
                        s.eVar18=page;
                        if (x4 == "AFF"){
							s.events="event12,"; //affiliate clickthrough
						} else{
							s.events="event13,"; //dealer clickthrough
						}
                    }
                }
            break;
            case "T":
                //track language id
                ltv += "prop15,prop25";
                var iof = page.indexOf('/files/');
                try{s.prop25 = page.substring(iof + 7);}catch(e){}
            break;
            case "play":
                ltv += "events";
                s.events = "event5";
            break;
            case "forward":
                ltv += "events,products";
                s.events = "event11";
                s.products = ";;;;event11=" + x2;
            break;
        }
        return ltv;    
    }
    this.getLinkTrackEvents = function(x1,page,sectionId){
        var lte = "";
        if (s.eVar14 != ""){
			lte += ",event24"; //dealer card viewed
		} else if (s.eVar23 != ""){
			lte += ",event26"; //map action
		}
        switch(x1){
            case "N":
                if (xitiConst.getProp1(sectionId) == "Sales and Service"){
                    //dealer locator
                    if (page.indexOf('rolexdealers.com') > 0){
                        lte += "event13,";
                    }
                    if(page == "flash_disabled"){
                        lte += "event15,";
                    }
                }
            break;    
            case "S":
                //custom exit clicks
            break;
            case "T":
            
            break;
            case "play":
                lte += "event5";
            break;
            case "forward":
                lte += "event11";
            break;
        }
        return lte;
    }
    this.getPageIdentifier = function(url){
        var minUrlTokens = 3;
        //trim everything before hash mark, if any
        if (url.indexOf('#') > -1){
            url = url.substring(url.indexOf('#') + 1, url.length);    
            minUrlTokens = 2;
        }
        
        //trim everything before language selector
        var str = "";
        if (url.toLowerCase().indexOf('javascript:void(0)') < 0){    
            var urlParts = url.split('/');
            var fileName = urlParts[urlParts.length - 1];
            var fileNameParts = fileName.split('.');
            if (urlParts.length > minUrlTokens){
                for (var i=(minUrlTokens+1);i<urlParts.length-1;i++){
                    str += urlParts[i]+"/";
                }
                str += fileNameParts[0];
            }
            else{
                str = url;
            }
        }
        return str;
    }
    this.getFlashDownloadSpeed = function(type, section){
        var s = "";
        if (type == "slow" || type=="flash_disabled"){
                return section; // <-- section variable will contain the speed
        }
        return s;
    }
}
var omniObj = new OmnitureObj();
var xitiConst = new XitiConstants();
function xt_med(type,section,page,x1,x2,x3,x4,x5,site_version,total)
{
    var watchSpecs = xitiConst.getWatchNameSpec(section, page);
    
    s.pageName = xitiConst.getPageName(type,page);
    s.server="server1";
    s.channel = xitiConst.getChannel(section);
    s.pageType="";
    s.prop1 = (section == null ? s.prop1 : xitiConst.getProp1(section));
    s.prop2= watchSpecs[0];
    s.prop3= watchSpecs[1];
    s.prop4="";
    s.prop5="";
    s.prop6="";
    s.prop7="";
    s.prop8="";
    s.prop9="";
    s.prop10= xitiConst.getVideoTitle(type, page);
    s.prop11="";
    s.prop12="";
    s.prop13="";
    s.prop14="";
    s.prop15= (x1 != "" && (s.prop15 == null || s.prop15 == "" || s.prop15 == undefined) ? xitiConst.getLanguage(x1) : s.prop15);
    s.prop16="";
    s.prop17=xitiConst.getWatchFeature(section,page);
    s.prop19= (x2 == null || type == "M" ? xitiConst.getVersion(type) : xitiConst.getVersion(x2));
    s.prop18=(s.prop19 == "flash" ? xitiConst.getFlashVersion() : ""); 
    s.prop20="";
    s.prop21="";
    s.campaign=xitiConst.getCampaign();
    s.state="";
    s.zip="";
    s.events="";
    s.products="";
    s.purchaseID="";
    s.eVar1=xitiConst.getInternalCampaign();
    s.eVar2="";
    s.eVar3="";
    s.eVar4="";
    s.eVar5="";
    s.eVar6="";
    s.eVar7="";
    s.eVar8="";
    s.eVar9= xitiConst.getVideoTitle(type, page);
    s.eVar10="";
    s.eVar11="";
    s.eVar12=s.pageName;
    s.eVar13="";
    s.eVar14= xitiConst.getDealerId(section, page);
    s.eVar15="";
    s.eVar16=s.prop2;
    s.eVar17=s.prop3;
    s.eVar18="";
    s.eVar19=""; /* OmnitureObj.getFlashDownloadSpeed(type, section); //flash only */
	s.eVar23=xitiConst.getMapInteraction(section, page);
    if (omniObj.isPageHit(x1,x2,total,page)){
        s.events = (s.events == "" ? "event1" : (s.events.indexOf("event1") < 0 ? s.events + ",event1" : s.events));
        
        if (type != "slow" && page != "Y"){
            if (omniObj._metricsSet && !omniObj._metricsSent){
                s.events += omniObj._sEvents;
                s.eVar19 = omniObj._sEvar19;
                omniObj._metricsSent = true;
            }
            void(s_code = s.t());
        }
        else{
            if (type == "slow" && page == "Y"){
                s.pageName = "flash_warning";
                s.events += ",event14";
                s.eVar12=s.pageName;
                s.eVar19= omniObj.getFlashDownloadSpeed(type,section);
                void(s_code = s.t());
            }
            else if (type == "slow" && page == "N"){            
                //set the speed metrics variable for next hit
                omniObj.setSpeedMetrics(page=="Y" ? true : false, section);
            }
            else{
                void(s_code = s.t());
            }
        }
        /* if (type == "slow" && page=="Y"){
            //user has seen the "disable flash" message
            s.events += ",event14";
        } */
       
    }
    else if (type != "slow"){
        s.linkTrackVars=omniObj.populateAndGetLinkTrackVars(x1,page,section,x5,x2,x4);
        s.linkTrackEvents=omniObj.getLinkTrackEvents(x1,page,section);
        //alert( s.linkTrackVars);
        //alert(s.linkTrackEvents);
        if (x1=="N" || x1=="play" || x1 =="forward"){
            s.tl(this,'o',page);
        } 
        else if (x1=="S"){
            s.tl(this,'e',page);
        }
        else if (x1=="T"){
            s.tl(this,'d',page);
        }
    }
    if(s_code){
        document.write(s_code);
    }
    if ((x2 != null)&&(x2!=undefined)&&(type=='C')){ 
		if ((x3=='')||(x3==null)) { 
			if (window.location.href == x2){
				setTimeout('window.location.reload();', 2000);
				
			} else{
				window.location.href = x2
			}
		} else {
			xfen = window.open(x2,'xfen',''); xfen.focus();
		}
	}
    else{
		return;
	}
}
// wait until the XiTi hit has been completed before changing window location
function redirectAfterXiti(url){
    var img_is_loaded = 0;
    var redirect = function() {
        if (img_is_loaded==0){
            document.location = url;
            img_is_loaded = 1;
        }
    }
    xt_img.onload = function(){redirect;}
    self.setTimeout(redirect, 2000)
}
function xitiDownloadClick(section, url, popup, site_version) {
    if ((popup) && (popup!="'false'")) {
        xt_med("C", section, url, "T", url, 1, null, null, site_version);
    }
    else {
        xt_med("C", section, url, "T", null, null, null, null, site_version);
        if (window.ActiveXObject){ // if this IE6 or IE 7, do not wait for the XiTi request to be completed
            document.location = url;
        } else {
            redirectAfterXiti(url);
        }        
    }
}
function xitiExitClick(section, url, popup, site_version) {
    if ((popup) && (popup!="'false'")) {
        xt_med("C", section, url, "S", (popup == "''" ? null : url), 1, null, null, site_version);
    }
    else {
        xt_med("C", section, url, "S", null, null, null, null, site_version);
        redirectAfterXiti(url);
    }
}
function xitiNavClick(section, name, site_version, url, targetUrl) {
    xt_med("C", section, name, "N", (name == 'flash_disabled' ? targetUrl : null), null, null, (targetUrl? targetUrl : url), site_version);
    // if this is HTML, redirect only after the XiTi hit has been completed
    if ((site_version=="1") && (url)){
        redirectAfterXiti(url);
    }
}
function xitiNavClick2(section, name, site_version, url, targetUrl) {
    xt_med("C", section, name, "N", url, 1, null, (targetUrl? targetUrl : url), site_version);
}
function xitiFlashEvent(section, name) {
    xt_med("F", section, name, null, null, null, null, null, "2");
}
function xitiFlashMediaEvent(section, medianame, control, seconds, total) {
    if ((control == "play") && (seconds == "0")) {
        xitiFlashEvent(section, medianame);
    }
    var mediaformat = parseInt(section) + 100;
    xt_med("M", mediaformat, medianame, control, seconds, "4", "2", "5", "2", total);
}
function xitiFlashSlowConnection(loadTime, seenSlowMessage) {
    xt_med("slow", loadTime, seenSlowMessage, "slow");
}
function setupXitiOnclicks(){
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i=0; i<anchors.length; i++) {
        var anchor = anchors[i];
        if (anchor.getAttribute("rel") != null){
        if (anchor.getAttribute("href") && (anchor.getAttribute("rel")=="link-external")) {
            anchor.onclick = function(){
                xitiExitClick(xiti_section_id, this.href, 1);
                return false;
            }
        }
        else if (anchor.getAttribute("href") && (anchor.getAttribute("rel")=="link-new-window")) {
            anchor.target = "_blank";
        }

        else if (anchor.getAttribute("href") && (anchor.getAttribute("rel")=="link-download")) {
            anchor.onclick = function(){
                xitiDownloadClick(xiti_section_id, this.href, 0);
                return false;
            }
        }

        else if (anchor.getAttribute("href") && (anchor.getAttribute("rel")=="link-download-new-window")) {
            anchor.onclick = function(){
                xitiDownloadClick(xiti_section_id, this.href, 1);
                return false;
            }
        }

        else if (anchor.getAttribute("href") && (anchor.getAttribute("rel")=="nav-logo-box")) {
            anchor.onclick = function(){
                xitiNavClick(xiti_section_id, "nav-logo-box", "1", this.href);
                return false;
            }
        }
        else if (anchor.getAttribute("href") && (anchor.getAttribute("rel")=="nav-homepage-flyout-features")) {
            anchor.onclick = function(){
                xitiNavClick(xiti_section_id, "nav-homepage-flyout-features", "1", this.href);
                return false;
            }
        }
        else if (anchor.getAttribute("href") && (anchor.getAttribute("rel")=="nav-footer-affiliates")) {
            anchor.onclick = function(){
                xitiNavClick(xiti_section_id, "Footer::Rolex_Dealers", "1", this.href);
                return false;
            }
        }
        else if (anchor.getAttribute("href") && (anchor.getAttribute("rel")=="nav-footer-download")) {
            anchor.onclick = function(){
                xitiNavClick(xiti_section_id, "Footer::Downloads", "1", this.href);
                return false;
            }
        }
        else if (anchor.getAttribute("href") && (anchor.getAttribute("rel")=="nav-footer-legal")) {
            anchor.onclick = function(){
                xitiNavClick(xiti_section_id, "Footer::Legal", "1", this.href);
                return false;
            }
        }
        else if (anchor.getAttribute("href") && (anchor.getAttribute("rel")=="nav-footer-sitemap")) {
            anchor.onclick = function(){
                xitiNavClick(xiti_section_id, "Footer::Sitemap", "1", this.href);
                return false;
            }
        }
        else if (anchor.getAttribute("href") && (anchor.getAttribute("rel")=="nav-footer-language")) {
            anchor.onclick = function(){
                xitiNavClick(xiti_section_id, "Footer::Language", "1", this.href);
                return false;
            }
        }

        else if (anchor.getAttribute("href") && (anchor.getAttribute("rel").indexOf("XiTiLE") > -1)) { 
                 anchor.onclick = function(){
                    var completeRel = this.getAttribute("rel");
                    var completeRelArray = completeRel.split(" ");
                    xitiRel = completeRelArray[0];
                    var xitiRelString = xitiRel.substring(7, xitiRel.length);
                    xitiNavClick2(xiti_section_id, xitiRelString, "1", this.href);
                    return false;
                }
            }
        
         else if (anchor.getAttribute("href") && (anchor.getAttribute("rel").indexOf("XiTi") > -1)) { 
                 anchor.onclick = function(){
                    var xitiRel = this.getAttribute("rel"); 
                    var xitiRelString = xitiRel.substring(5, xitiRel.length);
                    xitiNavClick(xiti_section_id, xitiRelString, "1", this.href);
                    return false;
                }
            }        
        }

    }
}

function setupSitemapOnclicks() {
    var sitemapLinks = $('#sitemap a');
    if(sitemapLinks){
        for (i=0; i < sitemapLinks.length; i++){
            sitemapLinks[i].onclick =  function() {xitiNavClick(xiti_section_id, "nav-sitemap", "1", this.href); return false;}        
        }
    }
}



/* DART Tagging Functions */
function spotlightEvent(section,page) {
    if(document.cookie.indexOf("dblClickCookie="+page) === -1){
        var spotlightImage = new Image();
        var axel = Math.random()+"";
        var a = axel * 10000000000000;
        spotlightImage.src = "http://ad\.uk.doubleclick.net/activity;src=1359693;type="+section+";cat="+page+";ord=1;num="+a+"?";
    }
}
     

/*cookie redirects*/

var expireOffset = new Date(new Date().getTime()+(180*24*60*60*1000)).toGMTString();

function goLocation(lang) {
    if(lang)
        document.location.href= '/'+lang+'/';
}
function goLangDeeplink(redirURL){
    document.location.href=redirURL;
}
function goDeeplink(redirURL) {
    document.location.href=redirURL;
}
function setCookie(me){
    document.cookie = "lang2="+me+"; expires="+expireOffset+"; path=/;";
}
function setCookieHome(me){
    document.cookie = "lang2="+me+"; expires="+expireOffset+"; path=/;";
    goLocation(me);
}


/* GLOBAL DOWNLOADS CONTROL */
// downloads panel
function DownloadsPanel(){
	var d = this;
	d.divs = $("#downloads > div");
	d.currentAssetLocation = '';
	
	this.init = function(){
		$("div.download-description-bg").addClass("short");
		$("div.download-links").addClass("hidden");
		
	 	d.divs.each(function(){
			$("div.download-item").mouseover(function(){
				$("div.download-description-bg",this).removeClass("short");
				$("div.download-description",this).addClass("hidden");
				$("div.download-links",this).removeClass("hidden");
				$("div.download-links",this).addClass("middle");
			}).mouseout(function(){
				$("div.download-description-bg",this).addClass("short");
				$("div.download-description",this).removeClass("hidden");
				$("div.download-links",this).removeClass("middle");
				$("div.download-links",this).addClass("hidden");
			});
		});
	
		$('#downloads-list').click(function(event) {
			var target = event.target;
			if($(target).is('a')) {
				targetUrl = target.href;
				document.cookie.match("RolexDownloads=true") ? document.jsAPI.trackDownload(null, null, targetUrl) : d.openEula(targetUrl);	
				event.preventDefault();
			}
		});
		
		$("#downloads-eula-accept").click(function(event) {
			d.closeEula();
	        if($("#downloads-eula-accept-check").attr('checked'))
	            document.cookie = "RolexDownloads=true;expires=" + expireOffset +";path=/;";
	        document.jsAPI.trackDownload(null, null, d.currentAssetLocation);
			event.preventDefault();
		});
		
		$('#eula-backlink').click(function(event) {
			d.closeEula();
			event.preventDefault();
		});
		$('#downloads-eula-decline').click(function(event) {
			d.closeEula();
			event.preventDefault();
		});
		
		$('#dl-button-close').click(function(event) {
			document.jsAPI.trackLink(s.pageName, 'Downloads>Close', s.pageName);
			//event.preventDefault();
		});
	}
	
	this.openEula = function(assetLocation) {
		$("#downloads-list").css({visibility:'hidden'});
	    $("#downloads-eula").css({visibility:'visible'});
		d.currentAssetLocation = assetLocation;
	}
	
	this.closeEula = function() {
		$("#downloads-list").css({visibility:'visible'});
	    $("#downloads-eula").css({visibility:'hidden'});
	}
}
function initDownloads(){
     if ($("#downloads")){
        var thisDownloadsPanel = new DownloadsPanel();
        thisDownloadsPanel.init();
    } 
}
 function alignElementsGlobal(){
    var BOTTOM_NAV_HEIGHT = 96;
    var WIDTH_OFFSET = 20;
    var leftPosition = 0;
    var topPosition = 0; 
    var newOffsetMaxMid = 1;
    if ($('#downloads') || $('#lang-select')) {               
        if (height >= MAXHEIGHT){
            topPosition = MAXHEIGHT - BOTTOM_NAV_HEIGHT - TOPPADDING - marginTop + newOffsetMaxMid;
        }
        else if (height <= MINHEIGHT){
            topPosition = MINHEIGHT - BOTTOM_NAV_HEIGHT - TOPPADDING - marginTop + FOOTERHEIGHT;
        }
        else{
            topPosition = height - BOTTOM_NAV_HEIGHT - TOPPADDING - marginTop + newOffsetMaxMid;
        }
        leftPosition = LEFTPADDING - marginLeft - WIDTH_OFFSET;
        if(downloadsNode = $('#downloads')){
            var downloadsHeight = downloadsNode.height();
            downloadsNode.css({left:leftPosition - 480}); 
            downloadsNode.css({top:footerTop - downloadsHeight + 1});
            //downloadsNode.css({height: 383});
            downloadsNode.css({width:width}); 
            var downloadsListNode = $('#downloads-list');
            downloadsListNode.css({left:marginLeft + LEFTPADDING}); 
            var downloadsListNode = $('#downloads-eula');
            downloadsListNode.css({left:marginLeft + LEFTPADDING}); 
            var lang = "en";
            var downloadsHeaderNode = $('#downloads-header');
			downloadsHeaderNode.css({right:marginLeft + 50});
			var downloadsHeaderNode = $('#dl-button-close');
			downloadsHeaderNode.css({left: marginLeft + 923});
        }
        if(langSelectNode = $('#lang-select')){
		var langSelectHeight = langSelectNode.height();
		langSelectNode.css({left: leftPosition - 480});
		langSelectNode.css({top: footerTop - langSelectHeight});
		langSelectNode.css({width: width});
		langSelectNode = $('#lang-select-button-close');
		langSelectNode.css({left: marginLeft + 923});
		langSelectNode = $('#lang-select-header');
		langSelectNode.css({left: marginLeft + 780});
		langSelectNode = $('#lang-select-container');
		langSelectNode.css({left: marginLeft + 180});
   }
    }
}

function assignFooterNavClicks() {
	var footerLinks = $('#footer ul li a');
	footerLinks.each(function(index, footerLink) {
		var fl = $(footerLink);
		switch(fl.attr('rel')) {
			case 'nav-footer-affiliates':
				fl.click(function(event) {
					document.jsAPI.trackLink(s.pageName, 'Footer>Rolex_Dealers', 'find_dealers/locate_dealers');
				});
			break;
			case 'nav-footer-download':
				fl.click(function(event) {
					document.jsAPI.trackLink(s.pageName, 'Footer>Downloads', s.pageName);
				});
			break;
			case 'nav-footer-legal':
				fl.click(function(event) {
					document.jsAPI.trackLink(s.pageName, 'Footer>Legal', 'legal-notice');
				});
			break;
			case 'nav-footer-sitemap':
				fl.click(function(event) {
					document.jsAPI.trackLink(s.pageName, 'Footer>Sitemap', 'site-map');
				});
			break;
			case 'nav-footer-language':
				fl.click(function(event) {
					document.jsAPI.trackLink(s.pageName, 'Footer>Language', s.pageName);
				});
			break;
			default:
				//Do nothing to this link
			break;
		}
	});
}

//register
onloadHTMLHandlers[onloadHTMLHandlers.length] = 'showScreenSize();alignElementsGlobal();initDownloads();assignFooterNavClicks()';
onloadFlashHandlers[onloadFlashHandlers.length] = 'showScreenSize();';

onresizeFlashHandlers[onresizeFlashHandlers.length] = 'showScreenSize();alignElementsGlobal();'
onresizeHTMLHandlers[onresizeHTMLHandlers.length] = 'showScreenSize();alignElementsGlobal();';
