//******************************************
//RALPH LAUREN - ICG - JAVASCRIPT FUNCTIONS
//******************************************


//######## RLTV #############
function ralphlaurentv(mid)
{
	var options = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=yes,width=792,height=530";
	if (mid==undefined) {		
		msgWindow=window.open("http://entertainment.ralphlauren.com/rltv/default.asp?resize=yes&ab=footer_rltv","rltv1",options);
	} else {
		msgWindow=window.open("http://entertainment.ralphlauren.com/rltv/media.asp?media_id="+mid,"rltv1",options);	
	}
	msgWindow.focus();
}


//CREATE TIME LINE POPUP
function HistoryTimeLine() 
{
	var options = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=790,height=440";
	msgWindow=window.open('http://about.ralphlauren.com/history/default.asp',"TimeLine",options);
}
//################### GSI CODE ########################
function prl_preloadImages() {
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=prl_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function prl_swapImgRestore() {
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function prl_findObj(n, d) {
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=prl_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function prl_swapImage() {
var i,j=0,x,a=prl_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=prl_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function prl_navPreload(){
prl_preloadImages("nav_runway_on.gif","nav_home_on.gif","nav_girl_on.gif","nav_restaurant.gif","nav_magazine.gif")
}
var prl_bnav_xMousePos = 0;var prl_bnav_yMousePos = 0;var prl_bnav_topX = 0;var prl_bnav_topY = 0;var prl_bnav_bottomX = 0;var prl_bnav_bottomY = 0;var prl_bnav_br;
var prl_bnav_isNavDivDisplayed = false;
var prl_bnav_tempTimeoutID;
if(navigator.appName == "Netscape" && document.layers != null){prl_bnav_br="ns";}
else if(navigator.appName == "Microsoft Internet Explorer" && document.all != null){prl_bnav_br="ie";}
else{prl_bnav_br=null}
if ((document.getElementById) && (prl_bnav_br!="ie")) { prl_bnav_br="ns6";}
var prl_bnav_IsMac = (navigator.appVersion.indexOf("Macintosh") != -1)
function prl_bnavSetNav(){ 
if (prl_bnav_br == "ie"){  
objBottomNavDiv = document.getElementById("othersitesPosDIV"); 
botNavX = objBottomNavDiv.offsetLeft + 502;
botNavY = objBottomNavDiv.offsetTop - 4 - 205;  
}else{
objBottomNavLayer = document.othersites;
botNavX = objBottomNavLayer.x - 94;
botNavY = objBottomNavLayer.y - 4 - 205;
}

if (prl_bnav_br == "ie"){
document.all["othersitesImgDiv"].style.left = botNavX;
document.all["othersitesImgDiv"].style.top = botNavY;
}else if (prl_bnav_br == "ns6"){
document.getElementById("othersitesImgDiv").style.left = botNavX;
document.getElementById("othersitesImgDiv").style.top = botNavY;
}else{
document.othersitesImgDiv.left = botNavX;
document.othersitesImgDiv.top = botNavY;
}
prl_bnav_topX = botNavX + 100
prl_bnav_topY = botNavY + 20
prl_bnav_bottomX = botNavX + 454
prl_bnav_bottomY = botNavY + 414
}
function prl_bnavShowNav(){
prl_swapBottomNavImage();
if (prl_bnav_br == "ie"){
document.all["othersitesImgDiv"].style.visibility = "visible";
}else if (prl_bnav_br == "ns6"){
document.getElementById("othersitesImgDiv").style.visibility = "visible";
}else{
document.othersitesImgDiv.visibility = "show";
}
prl_bnavDisplayElements(false);
prl_bnav_isNavDivDisplayed = true;
}
function prl_bnavHideNav(){
prl_swapBottomNavImage();
if (prl_bnav_br == "ie"){
document.all["othersitesImgDiv"].style.visibility = "hidden";
}else if (prl_bnav_br == "ns6"){
document.getElementById("othersitesImgDiv").style.visibility = "hidden";
}else{
document.othersitesImgDiv.visibility = "hidden";
}
prl_bnavDisplayElements(true);
prl_bnav_isNavDivDisplayed = false;
}
function prl_bnavDisplayElements(blnDisplay){
if (prl_bnav_br !="ie" || prl_bnav_IsMac){
return;
}
objSelects = document.all.tags("SELECT");
if (objSelects.length==0){
return;
}
var objSelects;
var strVisibility;
if(blnDisplay){
strVisibility="visible";
}else{
strVisibility="hidden";
}
for (var x = 0; x < objSelects.length; x++) {
objIndivSel = objSelects[x];
selx=0; sely=0; var selp;
if(objIndivSel.offsetParent){
selp=objIndivSel
while(selp.offsetParent){
selp=selp.offsetParent;
selx+=selp.offsetLeft;
sely+=selp.offsetTop;
}
}
if (selx < prl_bnav_bottomX && sely > prl_bnav_topY-30){
objIndivSel.style.visibility=strVisibility;
}
}
}
function prl_bnavCheckNav(){
tempID = setTimeout("prl_bnavCheckMousePos()",10);
}
function prl_bnavCheckMousePos(){
if (prl_bnav_br=="ns"){
document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = prl_bnavGetMouseXY;
}else if (prl_bnav_br=="ie"){
document.onmousemove = prl_bnavGetMouseXY;
}else if (prl_bnav_br=="ns6"){
document.onmousemove = prl_bnavGetMouseXY;
}
if (prl_bnav_xMousePos < prl_bnav_topX || prl_bnav_xMousePos > prl_bnav_bottomX || prl_bnav_yMousePos < prl_bnav_topY || prl_bnav_yMousePos > prl_bnav_bottomY){
prl_bnavHideNav();
}
}
function prl_bnavGetMouseXY(e){
if (prl_bnav_br == "ie"){
tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
}else{
tempX = e.pageX
tempY = e.pageY
}
if (tempX < 0){tempX = 0}
if (tempY < 0){tempY = 0}
prl_bnav_xMousePos = tempX
prl_bnav_yMousePos = tempY
}
function prl_resizeWindow(){
if ((prl_bnav_br=="ns") || (prl_bnav_br=="ie" && prl_bnav_IsMac)){
window.location.reload();
return;
}else{
prl_bnavSetNav();
}
}
function prl_bnavOpenLink(link){
window.open(link);
prl_bnavHideNav();
}
function prl_bnavOnload(){
prl_navPreload();
prl_bnavSetNav();
prl_bnavCheckMousePos();
}
function prl_swapBottomNavImage(){
var blnOthersites = document.bnav_form.blnOthersites.value; 
if(blnOthersites == 1){
document.bnav_form.blnOthersites.value = 0;
}
else {
document.bnav_form.blnOthersites.value = 1;}
}
function prl_bnavToggle(){
if (!prl_bnav_isNavDivDisplayed){
prl_bnavShowNav();
prl_bnav_tempTimeoutID = setTimeout("prl_bnavHideNav()",8000);
}else{
prl_bnavHideNav();
clearTimeout(prl_bnav_tempTimeoutID);
}
}


//######## Open Centered Window #############
function OpenWindow(url, width, height, name) {
	var x, y = 0;
	if (screen) {
		x = (screen.availWidth - width) / 2;
		y = (screen.availHeight - height) / 2;
	}   
	if(name==undefined) {
	    name = 'new';
	}
	var options = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=" + width + ",height=" + height + ",screenX=" + x + ",screenY=" + y + ",left=" + x + ",top=" + y;
	msgWindow=window.open(url,name,options);		
}

function OpenWindowScroll(url, width, height, name) {
	var x, y = 0;
	if (screen) {
		x = (screen.availWidth - width) / 2;
		y = (screen.availHeight - height) / 2;
	} 
	if(name==undefined) {
	    name = 'new';
	}
    var options = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=0,width=" + width + ",height=" + height + ",screenX=" + x + ",screenY=" + y + ",left=" + x + ",top=" + y;
    msgWindow=window.open(url,name,options);
}

function OpenPrintView(url, width, height, name) {
	var x, y = 0;
	if (screen) {
		x = (screen.availWidth - width) / 2;
		y = (screen.availHeight - height) / 2;
	}   
	var options = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=" + width + ",height=" + height + ",screenX=" + x + ",screenY=" + y + ",left=" + x + ",top=" + y;
	msgWindow=window.open(url,name,options);	
}

//################ Flash Detection ################

function writeFlashObject(url,flashvars,width,height,bgColor,version) {
	if (version==undefined){
		version="6"
	}
	if (detectFlash(version)) {
		if (bgColor==undefined){
			bgColor="000000"
		}
		width = width.toString();
		height = height.toString();
		document.writeln('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+version+',0,0,0"')
		document.writeln(' width="' + width + '" height="' + height + '">')
		document.writeln('<param name="allowScriptAccess" value="always" />')
		document.writeln('<param name="movie" value="' + url + '" />')
		document.writeln('<param name="flashvars" value="' + flashvars + '" />')
		document.writeln('<param name="quality" value="high" />')
		document.writeln('<param name="wmode" value="transparent" />')
		document.writeln('<param name="bgcolor" value="#'+ bgColor +'" />')
		document.writeln('<embed src="' + url + '" flashvars="' + flashvars + '" quality="high" bgcolor="#'+ bgColor +'" wmode="transparent" width="' + width + '" height="' + height + '" align="middle"')
		document.writeln(' allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');
	}
	else {
		document.writeln('This page requires the Macromedia Flash player.<br><br><a href="http://www.macromedia.com/go/getflashplayer" target="_blank"><img src="http://entertainment.ralphlauren.com/magazine/graphics/get_flash_player.gif" border="0"></a><br><br>You can download the Flash player<br> from Macromedia by <a href="http://www.macromedia.com/go/getflashplayer" target="_blank"><b>clicking here</b></a>.');
	}
}

var plugflash = false;
var MM_FlashCanPlay;
var MM_contentVersion;

function detectFlash(version)
{
	if (version==undefined) {
		MM_contentVersion = 6;
	} else {
		MM_contentVersion = version;
	}
		
	var agent = navigator.userAgent.toLowerCase(); 
	var mac = agent.indexOf('mac') != -1;
	var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
	if (plugin) {
		var words = navigator.plugins["Shockwave Flash"].description.split(" ");
		for (var i = 0; i < words.length; ++i)
		{
		if (isNaN(parseInt(words[i])))
		continue;
		var MM_PluginVersion = words[i]; 
		}
		 MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
	}
	else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1)) {
		//THIS WILL FIX THE FUNCTION PROB
		runvbscript();
	}
	if (MM_FlashCanPlay) {
		plugflash = true;
	} else{
		plugflash = false;
	}
	return plugflash;
}

function runvbscript() {
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
	document.write('on error resume next \n');
	document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
	document.write('</SCR' + 'IPT\> \n');
}

//##########################
var agent = navigator.userAgent.toLowerCase(); 
var mac = agent.indexOf('mac') != -1;
var w3c = (document.getElementById) ? true : false;
var iex = (document.all) ? true : false;
var ns4 = (document.layers) ? true : false;
var supported = (w3c || iex || ns4) ? true : false;
var active = false;
var curObj, curNest;

function fixNetscape(){
	if(origWidth != window.innerWidth || origHeight != window.innerHeight){
		window.location.reload();
	}	
}
if(ns4){
	origWidth = window.innerWidth;
	origHeight = window.innerHeight;
	window.onresize = fixNetscape;
}


function mousemoved (evt){
	if(iex){
		mousex = window.event.clientX+document.body.scrollLeft;
		mousey = window.event.clientY+document.body.scrollTop;
	}
	else if(ns4){
		mousex = evt.pageX+window.pageXOffset;
		mousey = evt.pageY+window.pageYOffset;
	}
	else{
		mousex = evt.pageX;
		mousey = evt.pageY;
	}
	if(active){
		shiftTo(curObj, mousex-140, mousey-150, curNest);
	}
	return true;
}

function getStyle (objstr, nest){
	nest = (nest) ? "document."+nest+"." : "";
	return (w3c) ? document.getElementById(objstr).style : (iex) ? document.all[objstr].style : (ns4) ? eval(nest+"document."+objstr) : false;
}

function shiftTo (objstr, x, y, nest){
var x = x + 155;
var y = y + 80;
	var obj = getStyle(objstr,nest);
	if(iex){
		obj.pixelLeft = x;
		obj.pixelTop = y;
	}
	else if(ns4){
		obj.moveTo(x,y);
	}
	else if(w3c){
		obj.left=x+"px";
		obj.top=y+"px";
	}
}
function show (objstr,nest){
	curObj = objstr;
	curNest = (nest) ? nest : null;
	getStyle(objstr,nest).visibility = "visible";
	active = true;
}
function hide (){
	getStyle(curObj,curNest).visibility = "hidden";
	active = false;
}

if(supported){
	if(ns4){
		document.captureEvents(Event.MOUSEMOVE);
	}
	document.onmousemove = mousemoved;
}

function WriteInnerHTML(divId,strHtml){
 if (document.getElementById) {
       document.getElementById(divId).innerHTML = strHtml;
 } else {
     with (document.layers[divId].document) {
     open();
     write(strHtml);
     close();
     }
 }
}

function returnObjById(id) { 
    if (document.getElementById) 
        var returnVar = document.getElementById(id); 
    else if (document.all) 
        var returnVar = document.all[id]; 
    else if (document.layers) 
        var returnVar = document.layers[id]; 
    return returnVar; 
}

// cross-browser function to get an object's style object given its id
function getStyleObject(objectId) {
    if(document.getElementById && document.getElementById(objectId)) { // W3C DOM	    
	    return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) { // MSIE 4 DOM	    
	    return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) { // NN 4 DOM.. note: this won't find nested layers	    
	    return document.layers[objectId];
    } else {
	    return false;
    }
}
