// JavaScript Document

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_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_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];}
}

function init(pageid){
	document.observe("dom:loaded", function() {
	initMenubars();
	MM_preloadImages('images/btn_AboutUs_f2.jpg','images/btn_AppointmentsAndEmergencies_f2.jpg','images/btn_FeesAndCarePlan_f2.jpg','images/btn_LatestNewsAndOffers_f2.jpg','images/btn_ContactUs_f2.jpg','images/btn_TreatmentsAvailable_f2.jpg','images/btn_store_f2.jpg')
	switch(pageid) {
		case 'default':
			initTabs()
			initBlender()
			$('specialofferwinter').observe('click',function(){window.location='/latestnews.asp'})
			break;
		case 'meetthedentists':
			initHorzTabs()
			break;
		case 'contactus':
			new Validation('frmEnquiry');
			break;
		case 'careplans':
			initTooltip()
			break;
	}
	})
}

function initTabs(){
	imgTab1=new Image; imgTab1.src='/images/bg_tab1.png';
	imgTab2=new Image; imgTab2.src='/images/bg_tab2_active.png';
	imgTab3=new Image; imgTab3.src='/images/bg_tab3_active.png';
	imgTab4=new Image; imgTab4.src='/images/bg_tab4_active.png';
	$$('.tab').each(function(e){
									  e.observe('click',function(){setPanel(e.identify().substr(3));})
									  })
		$('tabset')._panel=1
}

function initHorzTabs(){
	$$('.horztab').each(function(e){
									  e.observe('click',function(){setHorzPanel(e.identify().substr(7));})
									  })
		$('tabs')._panel=2
}


function setPanel(iPanel) {
	if ($('tabset')._panel==iPanel){return}
	$('tab'+$('tabset')._panel).removeClassName('active')
	$('tab'+iPanel).addClassName('active')
	new Effect.Appear($('tabbody'+iPanel),{duration: 0.2})
	new Effect.Fade($('tabbody'+$('tabset')._panel),{duration: 0.2})
	$('tabset')._panel=iPanel
}

function setHorzPanel(iPanel) {
	if ($('tabs')._panel==iPanel){return}
	$('horztab'+$('tabs')._panel).removeClassName('active')
	$('horztab'+iPanel).addClassName('active')
	$$('.dentistphoto').each(function(e){e.hide()})
	new Effect.Appear($('photo'+iPanel),{duration: 0.5})
	new Effect.BlindDown($('horztabbody'+iPanel),{duration: 0.2})
	new Effect.BlindUp($('horztabbody'+$('tabs')._panel),{duration: 0.2})
	$('tabs')._panel=iPanel
}

function initBlender() {
	var images = [
				  "images/fp_photo1.jpg",
				  "images/fp_photo2.jpg",
				  "images/fp_photo3.jpg",
				  "images/fp_photo4.jpg"
				  ];
	new Blender("photoholder", images, {  
		fadeDuration: 2.5,  
		displayDuration: 5.0
	});  
}
var RollIt = {
    timeout : null,
    showPopup : function(e){
        clearTimeout(this.timeout);
        if($(e).style.display == 'none'){
				$$('div.mainsubmenu').each(function(el){el.hide()})
			   e.show()
        }
    },
    hidePopup : function(e){
        if($(e).style.display == 'none'){
            clearTimeout(this.timeout);
        }else{
            this.timeout = setTimeout(function(){e.hide()},200);
        }
    }    
}
function initMenubars(){
	imgMenubarBullet=new Image; imgMenubarBullet.src='/images/bullet_submenu.gif';
	$$('#menubar a.hassubmenu').each(function(el){
								   el.observe('mouseover',function(event){RollIt.showPopup($(Event.element(event).readAttribute('rel')))})
								   el.observe('mouseout',function(event){RollIt.hidePopup($(Event.element(event).readAttribute('rel')))})
								   el.observe('click',function(event){$$('div.mainsubmenu').each(function(el){el.hide()})})
								   })
	$$('div.mainsubmenu').each(function(el){
								   el.observe('mouseover',function(event){RollIt.showPopup(this)})
								   el.observe('mouseout',function(event){RollIt.hidePopup(this)})
								   el.observe('click',function(event){$$('div.mainsubmenu').each(function(el){el.hide()})})
								   })
}

function setMenubar(menuopt){
	if (parseInt(menuopt)>=1 && parseInt(menuopt)<=6) {
		$('btn'+menuopt).src = $('btn'+menuopt).src.replace(".jpg","_f3.jpg")
	}
}
function initTooltip(){
	$('emergencycovertrigger').observe('mouseover',function(event){RollIt.showPopup($('emergencycovertip'))})
	$('emergencycovertrigger').observe('mouseout',function(event){RollIt.hidePopup($('emergencycovertip'))})
	$('emergencycovertip').observe('mouseover',function(event){RollIt.showPopup($('emergencycovertip'))})
	$('emergencycovertip').observe('mouseout',function(event){RollIt.hidePopup($('emergencycovertip'))})
}