/* * JavaScript specific to Marvin.com site * */
var marvin = new marvinScripts();
	            
function marvinScripts() {
	
	/* swfobject */
	this.playMovie = function(target, videoURL, autoPlay, loop, color, width, height, playerURL, playerVersion) {

		/*
			Other browsers still see/respond to the div's onclick event.
			Guessing if the flash itself were set 'transparent', IE would do the same
		*/
		document.getElementById(target).onclick = "";
		
		document.getElementById(target).style.backgroundImage="none";
		if (color!=null) {
			document.getElementById(target).style.backgroundColor=color;
		};
		
		if (!playerURL) {
			playerURL = "flash/VideoViewer583.swf";
		};
		if (!playerVersion) {
			playerVersion = "6";
		};
		var so= new SWFObject(playerURL, target + "-movie", width, height, playerVersion);
		so.addParam("flashvars", "videoURL=" + videoURL + "&videoAutoPlay=" + autoPlay + "&videoLoop=" + loop);
		so.addParam("wmode", "transparent");
		so.addParam("menu", "true");
		so.addParam("play", "true");
		so.addParam("viewastext", "VIEWASTEXT");
		so.addParam("allowscriptaccess", "sameDomain");
		so.write(target);

	};
	this.loadFlash = function(target, swfURL, color, width, height) {

		document.getElementById(target).style.backgroundImage="none";
		if (color!=null) {
			document.getElementById(target).style.backgroundColor=color;
		};

		var so= new SWFObject(swfURL, null, width, height, playerVersion);
		so.addParam("wmode", "transparent");
		so.write(target);

	};
	/*-- swfobject */

	this.movie = new Object();
	this.movie.play = this.playMovie;
	this.movie.addTitle = function(target, title) {
		if (target.length==0 || title.length==0) {
			return;
		};
		var e = document.getElementById(target);
		if (!e) {
			return;
		};		
		
		e.innerHTML = title;
	};
	this.movie.addYouTube = function(target, url) {
		if (target.length==0) {
			return;
		};
		
		var e = document.getElementById(target);
		if (!e) {
			return;
		};		
		e.innerHTML = "";
		
		if (url.length==0) {
			return;
		};
		
		var c = document.createElement("div");
		
		var l = document.createElement("label");
		l.innerHTML = 'You Tube: '
		c.appendChild(l);
		
		var a = document.createElement("a");
		a.setAttribute("href", url);
		a.setAttribute("target", "_blank");
		a.innerHTML = url;
		c.appendChild(a);
		
		var b = document.createElement("br");
		c.appendChild(b);
		
		l = document.createElement("label");
		l.innerHTML = 'Embed Code: '
		c.appendChild(l);
		
		var t = document.createElement("textarea");
		t.setAttribute("rows",4);
		t.setAttribute("cols",55);
		t.value  = "<object width=\"560\" height=\"340\">";
		t.value += "<param name=\"movie\" value=\""+url+"\"></param>";
		t.value += "<param name=\"allowFullScreen\" value=\"true\"></param>";
		t.value += "<param name=\"allowscriptaccess\" value=\"always\"></param>";
		t.value += "<embed src=\""+url+"\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"560\" height=\"340\"></embed>";
		t.value += "</object>";
		c.appendChild(t);
		
		e.appendChild(c);
			
	};
	
};

//hover effect - swap the src of two images contained in an anchor tag
//see - marvinPhotoLeft_Hover.ascx, marvinPhotoLeft_Hover_CE.ascx
function swapImage(anchor) {
	var img = anchor.getElementsByTagName("img");
	//don't bother to try swapping if there are more or less than two images - somethings obviously horribly wrong
	if (img.length == 2) {
		var tmp=img[0].src;
		img[0].src=img[1].src;
		img[1].src=tmp;
	}
}
	
function openCasemasterFlash() {
	window.open('/flash/casemaster/index.html','popup','width=750,height=550');
	}

function openWarrantyRegistration() {
	window.location = 'http://warranty.marvin.com';
	}
	
	
/* * * * * * Left Side Navigation * * * * * */

function navMouseAction(pageName, action) {
 //var d = document.getElementById("javascriptdebug");
 //d.innerHTML = pageName + ':' + action;
 // 2006 version
 try {
  homePageFlash(pageName, action);
 } 
 catch (e) {
 };
};

/* * * * * * Popup Windows * * * * * */
	
function popupImage(title,headline,imgSrc,imgHeight,imgWidth) {
	popup(title,headline,'popup.aspx','?imgSrc=' + imgSrc,'',imgWidth+50,imgHeight+20,'','');
}

/* photoGalleryPopup is also used by residential case studies */
function photoGalleryPopup(ID,Gallery,Action) {
	if (!Gallery) {Gallery=''}
	if (!Action) {Action=''}
	newWindow = window.open('photoPopup.aspx?ID=' + ID + '&Gallery=' + Gallery + '&action=' + Action,'caseStudy','top=45,left=80,width=775,height=540,menubar=yes,scrollbars=no',false);
}
	
function popup_AboutLaminatedGlass() {
	popup('About Laminated Glass','About Laminated Glass','','?page=popup_About_Laminated_Glass','',320,515,'','')
	}
	
function popup_StoolAndApron() {
	popup('What is a Stool and Apron?','What is a Stool and Apron?','','?page=popup_Stool_and_Apron','',210,515,'','')
	}
	
function popup_AboutUltrex() {
	popup('About Ultrex','About Ultrex','','?page=popup_About_Ultrex','',180,515,'','')
	}
	
function popup_AboutDirectGlazeAndInSashConstruction() {
	popup('About Direct Glaze and In-Sash Construction','About Direct Glaze and In-Sash Construction','','?page=popup_About_Direct_Glaze_and_InSash_Construction','',515,515,'','')
	}
	
function popup_AboutASTMZones() {
	popup('About ASTM Zones','About ASTM Zones','','?page=popup_About_ASTM_Zones','',380,515,'','')
	}
	
function popup_AboutFlurospar() {
	popup('About Marvin products and Flurospar','About Marvin products and Flurospar','','?page=popup_About_Flurospar','',360,515,'','')
	}
	
function popup_AboutPVD() {
	popup('About PVD','About PVD','','?page=popup_About_PVD','',320,515,'','')
	}
	
function popup_AboutEnergyPanels() {
	popup('Energy Panels','Energy Panels','','?page=popup_Energy_Panels','',320,515,'','')
	}

function popup_AboutCombinationPanels() {
	popup('Storm and Screen Combination Panels','Storm and Screen Combination','','?page=popup_Storm_Screen_Combination','',320,515,'','')
	}
	
function popup_AboutEnergyStar() {
	popup('About ENERGY STAR','About ENERGY STAR','','?page=popup_AboutEnergyStar','',160,515,'','')
	}
	
	
	
/* * * * * * Generic Adobe Macromedia Functions * * * * * */ 

function MM_swapImgRestore() { //v3.0
  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 MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_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 MM_findObj(n, d) { //v4.01
  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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}



////////////////////////////////////////////////////////////////////

/* Obsolete */

function obsolete_popup(title,headline,page,querystring,content,height,width,action,bScrollbars) {
  // Use shared version now
	querystringParams = 'title=' + title + '&headline=' + headline
	if (querystring == '') {
		querystring = '?' + querystringParams
		} else {
		if (querystring.substring(0, 1) != '?') {
		  querystring = '?' + querystring;
		  };
		querystring = querystring + '&' + querystringParams
		}
	var URL = page + querystring
	var scrollbars = 'no'
	if (bScrollbars) {scrollbars='yes'}
	if (action != '') {
		if (querystring == '') {
			URL += '?action=' + action
		}
		else {
			URL += '&action=' + action
		}
	}
	if ((window.navigator.userAgent.indexOf('Opera') < 0) && (popupWindow != null)) { popupWindow.close() }
	popupTitle = title;
	popupHeadline = headline;
	popupContent = content;
	// popupWindow = window.open(URL,'popup','top=45,left=80,width=' + width + ',height=' + (height+30) + ',menubar=yes,scrollbars='+scrollbars,false);
	popupWindow = window.open(URL,'popup','');
	//popupWindow = null;
}

/* * * * * * Left Side Navigation * * * * * */

function obsolete_leftnavOver(rowNumber){
	eval(rowNumber +"arrow").src="images/leftnav_doublearrow.gif";
	eval("nav" +rowNumber).style.backgroundColor='#DFDCD8';
	eval("nav" +rowNumber).style.cursor='hand';
	}

function Obsolete_leftnavOut(rowNumber){
	eval(rowNumber +"arrow").src="images/leftnav_arrow.gif";
	eval("nav" +rowNumber).style.backgroundColor='';
}

