// Javascript for North West Dental Arts
<!--

/*
* Description:
* An image swaper for rollover images
*
* Usage:
* swapImage('coreName');
*
* Arguments:
* The coreName of the object in the document
*
* An example of naming would be
* image: click_coreName.jpg
* rollover image: click_coreName_on.jpg
* tag in html: <img src="click_coreName.jpg" name="click_coreName" id="click_coreName" />
*
* returns - nothing
*/
function swapNavImage() {
  var i,j=0,x,a=swapNavImage.arguments; 
  document.sr=new Array; 
  if ((x=findObj("click_"+a[0]))!=null){
   	document.sr[j++]=x;
	document.currentNavRolled=a[0];
	if(!x.oSrc) 
		x.oSrc=x.src;
	x.src="images/before_afters/click_"+a[0]+"_on.jpg";
  }
}

/*
* Description:
* An image swaper for rollover images
*
* Usage:
* swapImage('coreName');
*
* Arguments:
* The coreName of the object in the document
*
* An example of naming would be
* image: click_coreName.jpg
* rollover image: click_coreName_on.jpg
* tag in html: <img src="click_coreName.jpg" name="click_coreName" id="click_coreName" />
*
* returns - nothing
*/
function swapBottomImage() {
  var i,j=0,x,a=swapBottomImage.arguments; 
  document.sr=new Array; 
  if ((x=findObj("bottom_"+a[2]))!=null){
   	document.sr[j++]=x;
	document.currentBottomRolled=a[2];
	if(!x.oSrc) 
		x.oSrc=x.src;
	current = document.currentSet;
	x.src="images/before_afters/"+a[0]+"_bottom_p_"+current+"_i_"+a[1]+"_on.jpg";
  }
}

/* 
* Description:
* Restores the rollover image
* (if it is not the current image being displayed)
* The current rolled over image is 
* previously defined by swapImage()
*
* Usage:
* swapImgRestore()
*
* return - nothing
*/
function navImgRestore() { 
  var i,x,a=document.sr,c=document.currentSet,r=document.currentNavRolled;
  if(r!=c)
  	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
  		x.src=x.oSrc;
}

function bottomImgRestore() { 
  var i,x,a=document.sr,c=document.currentbefore,d=document.currentafter,r=document.currentBottomRolled;
  if(r!=c&&r!=d)
  	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++)
  		x.src=x.oSrc;
}

/*
* Description:
* A set swaper for the rollover image sets
* Displays the first images (...full_coreName_one.jpg)
* in the main before and after panels and swaps the
* bottom navigation images to the current set
* 
* Usage:
* swapBigPics('coreName');
*
* Arguments:
* The coreName of the object in the document
*
* An example of naming would be
* first before full image: before_full_coreName_one.jpg
* second before full image: before_full_coreName_two.jpg
* third before full image: before_full_coreName_three.jpg
* after full images: after_full_coreName_<one|two|three>.jpg
* bottom thumbnails: <before|after>_bottom_p_coreName_i_<one|two|three>.jpg
* bottom thumbnail rollovers: <before|after>_bottom_p_coreName_i_<one|two|three>_on.jpg
*
* return - nothing
*/
function swapSet() { //An set swaper for the image sets
  var x1,x2,x3,x4,x5,x6,a=swapSet.arguments;
  if ((x1=findObj('bottom_one'))!=null && (x2=findObj('bottom_two'))!=null && (x3=findObj('bottom_three'))!=null && (x4=findObj('bottom_four'))!=null && (x5=findObj('bottom_five'))!=null && (x6=findObj('bottom_six'))!=null){
  	if(!x1.oSrc) 
		x1.oSrc=x1.src;
  	if(!x2.oSrc) 
		x2.oSrc=x2.src;
  	if(!x3.oSrc) 
		x3.oSrc=x3.src;
	if(!x4.oSrc) 
		x4.oSrc=x4.src;
	if(!x5.oSrc) 
		x5.oSrc=x5.src;	
	if(!x6.oSrc) 
		x6.oSrc=x6.src;
	x1.src="images/before_afters/before_bottom_p_"+a[0]+"_i_one.jpg";
	x2.src="images/before_afters/before_bottom_p_"+a[0]+"_i_two.jpg";
	x3.src="images/before_afters/before_bottom_p_"+a[0]+"_i_three.jpg";
	x4.src="images/before_afters/after_bottom_p_"+a[0]+"_i_one.jpg";
	x5.src="images/before_afters/after_bottom_p_"+a[0]+"_i_two.jpg";
	x6.src="images/before_afters/after_bottom_p_"+a[0]+"_i_three.jpg";
	z=document.currentSet;
	if((m=findObj("click_"+z))!=null){
		if(!m.oSrc)
			m.oSrc=m.src
		m.src=m.oSrc;
	}
	document.currentSet=a[0];
	swapBigIndividuals("before", "one", "one");
	swapBigIndividuals("after", "one", "four");
  }
}

/*
* Description:
* An image swaper for the individual full
* images in the before and after panels
*
* Usage:
* swapBigIndividuals('before|after', 'imageNumber', 'navNumber');
*/
function swapBigIndividuals() {
	var m,x,y,z,a=swapBigIndividuals.arguments;
  	if ((x=findObj(a[0]+'_full'))!=null && (y=findObj('bottom_'+a[2]))!=null){
  	if(!x.oSrc) 
		x.oSrc=x.src;
	if(!y.oSrc)
		y.oSrc=y.src;
	current = document.currentSet;
	eval('z = document.current'+a[0]); //creates dynamic variables currentbefore and currentafter
	if((m=findObj("bottom_"+z))!=null){
		if(!m.oSrc)
			m.oSrc=m.src
		m.src=m.oSrc;
	}
	x.src="images/before_afters/"+a[0]+"_full_"+current+"_"+a[1]+".jpg";
	y.src="images/before_afters/"+a[0]+"_bottom_p_"+current+"_i_"+a[1]+"_on.jpg";
	
	eval('document.current'+a[0]+' = a[2]');
  }
}

/*
* Description:
* A HTML document object finder
*
* Usage: 
* findObj('objectName');
* findObj('objectName', document.child1.child2);
* 
* Arguments:
* Object name to search for
* Location in document to start looking (if null document root is used)
*
* return - first instance of objectName
*/
function 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=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) 
	x=d.getElementById(n); 
  return x;
}

function setCurrent() { //Used on load to set the default image set
	var m,z,n=setCurrent.arguments;
	swapSet(n[0]);
	z=n[0];
	if((m=findObj("click_"+z))!=null){
		if(!m.oSrc)
			m.oSrc=m.src
		m.src="images/before_afters/click_"+z+"_on.jpg";
	}
}

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];}}
}

var expDays = 30;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal (offset) {  
var endstr = document.cookie.indexOf (";", offset);  
if (endstr == -1)    
endstr = document.cookie.length;  
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {  
var arg = name + "=";  
var alen = arg.length;  
var clen = document.cookie.length;  
var i = 0;  
while (i < clen) {    
var j = i + alen;    
if (document.cookie.substring(i, j) == arg)      
return getCookieVal (j);    
i = document.cookie.indexOf(" ", i) + 1;    
if (i == 0) break;   
}  
return null;
}
function SetCookie (name, value) {  
var argv = SetCookie.arguments;  
var argc = SetCookie.arguments.length;  
var expires = (argc > 2) ? argv[2] : null;  
var path = (argc > 3) ? argv[3] : null;  
var domain = (argc > 4) ? argv[4] : null;  
var secure = (argc > 5) ? argv[5] : false;  
document.cookie = name + "=" + escape (value) + 
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
((path == null) ? "" : ("; path=" + path)) +  
((domain == null) ? "" : ("; domain=" + domain)) +    
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {  
var exp = new Date();  
exp.setTime (exp.getTime() - 1);  
var cval = GetCookie (name);  
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var visited = GetCookie('visitedFlash');
var vCount = GetCookie('vCount');
function checkCookie(){
	if (visited) {
		if(vCount < 2){
			vCount++;
			SetCookie('vCount', vCount, exp);
			introMovie_DoFSCommand("show_all", null);
		} else {
			DeleteCookie('visitedFlash');
			introMovie_DoFSCommand("show_all", null);
		}
	} else {
		SetCookie('visitedFlash', true, exp);
		SetCookie('vCount', 1, exp);
	}
}

function introMovie_DoFSCommand(command, args) { 
  if (command == "show_all") { 
	document.getElementById("centerColumn").style.background = 'url(/themes/northwest/images/nw_text.jpg) no-repeat top right #0F1040';
	document.getElementById("mainContent").style.visibility = 'visible';
	document.getElementById("flashcontainer").style.visibility = 'hidden';
  } else{
	alert("not called");
  }
}

