/* Copyright (c) 2007 Affno (Pvt) Ltd, . All rights reserved.

 This software is the confidential and proprietary information of        
 Affno  ("Confidential Information").  You shall not disclose such 
 Confidential Information and shall use it only in accordance with
 the terms of the license agreement you entered into with Affno.

Module Name		: MOBWEB1
File Name		: menu.js
Description		: Mobitel hover menu and other goodies
Created By		: Bjorn de Lima
Created Date	: 12-April-2007 (hover menu originally for ODLWEB1)
Modified By		: 
Modified Date	: Er..start of the project :(
Version			: 1.00.000
Modified By		: bjorn
Modified Date	: 18/09/2007
Version			: 1.10.000 (Added mobitel sidemenu)
Modified By		: bjorn
Modified Date	: 11/12/2008
Version			: 2.00.000 (3rd level navigation)

*/

onerror = handle;

function handle(){
	 return true;
	}

var currentMenu1 = null;
var currentMenu2 = null;
var currentMenu3 = null;
var menuHideTimer = null;
var showTime = 600; // ms

function attachMenuEvents(){
	$$(".ddmenu").addEvent('mouseover', function(){
	
	if (this.hasClass('level0')	){
		if (currentMenu1!=null){
			$$("#"+currentMenu1).setStyle('display','none');
			}
	if (currentMenu2!=null){
			$$("#"+currentMenu2).setStyle('display','none');
			}
	if (currentMenu3!=null){
			$$("#"+currentMenu3).setStyle('display','none');
			}	
			
	currentMenu1 = this.getProperty('title');
	}
		
		
	if (this.hasClass('level1')	){
		if (currentMenu2!=null){
			$$("#"+currentMenu2).setStyle('display','none');
			}
			
		if (currentMenu3!=null){
			$$("#"+currentMenu3).setStyle('display','none');
			}	
				
	currentMenu2 = this.getProperty('title');
	}
	
	
	if (this.hasClass('level2')	){
		if (currentMenu3!=null){
			$$("#"+currentMenu3).setStyle('display','none');
			}
				
	currentMenu3 = this.getProperty('title');
	}

		pos = getPos(this);
		
		str = this.getProperty('title');
		$$("#"+str).setStyles({
				display :'block',
				position : 'absolute',
				top : pos[1]-12,
				left : pos[0]
//				opacity : 1
				});
		
		//var inv = new Fx.Style(str , 'opacity').set(0);
		
		var fx = new Fx.Styles(str, {duration:600,transition: Fx.Transitions.linear} ); 
		fx.start({
			 //'opacity' : [0.9],
			 'left' : [parseInt(pos[0]+20)+'px',parseInt(pos[0]+3)+'px']
			 //'padding-bottom' : [10,0]
			 });
		
		
		$$("body").addEvent('click',function(){
											 
				//var fx1 = new Fx.Styles(currentMenu1, {duration:300,transition: Fx.Transitions.linear} ); 
//				fx1.start({
//					 'opacity' : [0],
//					 'top' : [parseInt(pos[1]+90)+'px']
//					 });//				
//				var fx2 = new Fx.Styles(currentMenu2, {duration:200,transition: Fx.Transitions.linear} ); 
//				fx2.start({
//					 'opacity' : [0],
//					 'top' : [parseInt(pos[1]+90)+'px']
//					 });//				
//				var fx3 = new Fx.Styles(currentMenu3, {duration:100,transition: Fx.Transitions.linear} ); 
//				fx3.start({
//					 'opacity' : [0],
//					 'top' : [parseInt(pos[1]+90)+'px']
//					 });

			$$("#"+currentMenu1).setStyle('display','none');
			$$("#"+currentMenu2).setStyle('display','none');
			$$("#"+currentMenu3).setStyle('display','none');
				
				});
		});
}

function getPos(obj){
	ar = findPos(obj);
	if (obj.hasClass('level0')){
	ar[1] = ar[1]+21;
	ar[0] = ar[0]-10;
	}
	else{
	ar[1] = ar[1];
	ar[0] = ar[0]+140;
	}
	return ar;
	}

function showMenu2(str,obj){	
if (str!=currentMenu){
	//$E('.selectMenu').style.visibility = 'none';
	hideMenu();
	resetTimer();
	var off = 10;
	var pos = Array();
	pos = findPos(obj);
	obj2 = document.getElementById(str);
	obj2.style.display = "block";
		var inv = new Fx.Style(str, 'opacity').set(0); 
		
	var fx = new Fx.Styles(str,{duration:600,transition: Fx.Transitions.linear} ); 
	fx.start({
			 'opacity' : [0.9],
			 'top' : [parseInt(pos[1]+off+20)+'px',parseInt(pos[1]+off)+'px']
			 //'padding-bottom' : [10,0]
			 });
	
	
	obj2.style.left = parseInt(pos[0]-15)+"px";
	obj2.style.top = parseInt(pos[1]+off)+"px";
	currentMenu = str;
	}
	else{
		resetTimer();
		}
}


function showIt(obj){
	obj.style.display = 'block';
	}
	
function hideMenu1(){
	if (currentMenu1!=null){
	currentMenu1.setStyle('display','none');
	//currentMenu="";
	}
}

function hideMenu2(){
	if (currentMenu2){
	currentMenu2.setStyle('display','none');
	//currentMenu="";
	}
}

function hideMenu3(){
	if (currentMenu3){
	currentMenu3.setStyle('display','none');
	//currentMenu="";
	}
}

function startTimer1(){
	menuHideTimer1 = setTimeout("hideMenu1()", showTime );
}

function startTimer2(){
	menuHideTimer2 = setTimeout("hideMenu2()", showTime );
}

function startTimer3(){
	menuHideTimer3 = setTimeout("hideMenu3()", showTime );
}
	
function resetTimer1(){
		clearTimeout(menuHideTimer1);
	}
	
function resetTimer2(){
		clearTimeout(menuHideTimer2);
	}

function resetTimer3(){
		clearTimeout(menuHideTimer3);
	}

function getCurrentPage(url){
	if (url){
	str = url+"";
	arr = str.split('/');
	url = arr[arr.length-1];
	if (url){
	return url;
	}
	}
	else{
		return url;
		}
}

function sideMenu(){
	mainobjs = Array();
	mainobjs = "";
	cursubobj = curobj = false;
	if($('sidemenu')){
		var menuitems = $('sidemenu').getChildren();
		var url = getCurrentPage(location.href);
		j = menuitems.length
		for (i=0;i<j;i++){
		menuitems[i].setStyle('display','block');	
			if (menuitems[i].hasClass('subitem') ){
				subobj = menuitems[i];
				}
			if ( url == getCurrentPage(menuitems[i].getFirst().href) ){
				if (menuitems[i].hasClass('subsubitem')){ 
				cursubobj = menuitems[i];
				curobj = subobj;
				}
				if (menuitems[i].hasClass('subitem')){
				cursubobj = menuitems[i];
				curobj = menuitems[i];
				}
			}
		}
		
	//	alert(curobj);
		if (cursubobj){
			curobj.addClass('blue');
			cursubobj.addClass('green');
			//	curobj.setStyle('margin-top','10px');
			cursubobj.setStyle('display','block');
			
		if (curobj.getNext()){
		node = curobj.getNext();
		while (!node.hasClass('subitem')){				
				node.setStyle('display','block');
				node = node.getNext();
				}
			//node.setStyle('padding-top','10px');
			}
		}		
	}
}


// ...in the beginning there was the word
window.addEvent('domready', function(){
  init();

});


function init(){
if ($('phonie')){  phonie();  }
// drop menu
attachMenuEvents();

// phonie slideshow	
if ($('phonie')){  phonie();  }

// banners
if ($('banners')){  setBanners();  }


if ($('a1')) { 
current = Cookie.get('userSelect');
current2 = Cookie.get('userSelect2');
if (!current){
	current=0;
	current2=0;
 	}
	


$('userSelect').selectedIndex = current;
num = parseInt(current)+1;
$('a'+num).style.display ="block";
$('a'+num).selectedIndex = current2;
}
else{
	Cookie.remove('userSelect');
	Cookie.remove('userSelect2');
	}


if ($("userSelect")){
$$("#userSelect").addEvent('change', function(){
quick(this);
});
quick($('userSelect'));
}

$$(".subsubitem a").addEvent('click', function(){
if (this.href.contains('#')){ 
	$('sidemenu').getChildren().removeClass('green');
	this.getParent().addClass('green');
	
	}
});


$$(".boxclear").addEvent('focus', function(){
if ((this.value=='Mobile No') || (this.value=='Password') || (this.value=='DD') || (this.value=='YYYY') || (this.value=='First name') || (this.value=='Last name') || (this.value=='City')){ 
this.value="";
this.style.color = "#222222";
}
});

if ($('sidemenu')){
	sideMenu();
	}
	
if ($$(".fselect")){
	initFSelect();
	}
	

}
// domready event ends here


function findPos(obj) {  // http://www.quirksmode.org/js/findpos.html#
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}


function quick(obj){
arr = $$(".hideselects select");
for(i=0;i<arr.length;i++){
	arr[i].style.display="none";
	}
$('a'+parseInt(obj.selectedIndex+1)).style.display = "block";
}

function openPopup(obj){
	window.open('s','popup');
	}
	
function openPopupWindow(params){
	window.open(params);
	}	
	
function quickNavi(obj){
	for (i=0;i<obj.childNodes.length;i++){
		if(obj.childNodes[i].id){
			if(obj.childNodes[i].style.display == 'block'){
				Cookie.remove('userSelect');
				Cookie.set('userSelect',$('userSelect').selectedIndex,{path: '/'});
				Cookie.set('userSelect2',obj.childNodes[i].selectedIndex,{path: '/'});
				document.location = obj.childNodes[i].value;
				}
			}
		}	
	}
	
function flashWrite(file,width,height){
		document.write("<object type='application/x-shockwave-flash' width='"+width+"' height='"+height+"' data='"+file+"'>	<param name='movie' value='"+file+"' /><param name='quality' value='high' /><param name='wmode' value='opaque' /><embed src='"+file+"' quality='high' wmode='opaque'></embed></object>");	
	}
	

