$(document).ready(function(){

    $('.viewdetails').hide();

	//loadcontent('#leftinc', '../includes/leftinc.html');
	
	var openmenuid = $('#submenulinkon');
	var opensubmenuid = $('#subsubmenulinkon');
	
	/*  NAME            CLASS               ONCLICK
	    parent      - .submenulink          submenulinkon
	    parentdiv   - .subsubmenu
	    subparent   - .subsubmenulink_sub   subsubmenulinkon
	    subparentdiv- .subsubsubmenu
	    child       - .subsubsubmenulink
	    
	*/
	
	// when page loads - 1. hide the Parent Div
	//                   2. if we click on a parent[who has subparents/href = empty] - toggle its class to "submenulinkon"
	//                   3. Get the immediately following siblings(.next) of parent and Display or hide (.SlideToggle)
	$('#leftnav').find('.subsubmenu').hide().end().find('.submenulink[href="empty"]').click(function() {
		$(this).toggleClass("submenulinkon");
		$(this).next().slideToggle();
		
		openmenuid = $(this);
	});
	
	//when the page loads - 1. hide the sub-parentdiv
	//                      2. if we click on a sub-parent[who has children/href = empty] - toggle its class to subsubmenulinkon
	//                      3. Get the immediately following siblings(.next) of subparent and Display or hide (.SlideToggle) 
	$('#leftnav').find('.subsubsubmenu').hide().end().find('.subsubmenulink_sub[href="empty"]').click(function() {
		$(this).toggleClass("subsubmenulinkon");
		$(this).next().slideToggle();
		
	});
	
	$('#leftnav').find('#submenulinkon').toggleClass("submenulinkon").end().next().slideToggle();
	$('#leftnav').find('#subsubmenulinkon').toggleClass("subsubmenulinkon").end().next().slideToggle();
	$('#leftnav').find('#subsubsubmenulinkon').toggleClass("subsubsubmenulinkon");

    
   // $('#leftnav').find('.subsubmenulink_sub').parent().show();      //show all subparents
  //  $('#leftnav').find('.subsubsubmenulink').parent().show();       //show all child items
    
    //  when a subparent has been clicked (.subsubmenulinkon) and we navigate to its own page - keep it and its' parent showing
    $('#leftnav').find('.subsubmenulinkon').parent().show();  
     
    //when a child has been clicked (.subsubsubmenulinkon) and we navigate to its own page - keep it, its' subparent and its' parent showing  
    $('#leftnav').find('.subsubsubmenulinkon').parents().show();   
    
    // SUB MENUS
	
	var openmenuid = $('#submenulinkon');
	var opensubmenuid = $('#subsubmenulinkon');
	
	$('#leftnav').find('.subsubmenu').find('.submenulink').click(function() {
		$(this).toggleClass("submenulinkon");
		$(this).next().slideToggle();
		if (openmenuid != null)
		{
			openmenuid.toggleClass("submenulinkon");
			openmenuid.next().slideToggle();
		}
		openmenuid = $(this);
	});
	
	$('#leftnav').find('.subsubsubmenu').find('.subsubmenulink_sub').click(function() {
		$(this).toggleClass("subsubmenulinkon");
		$(this).next().slideToggle();
		if (opensubmenuid != null)
		{
			opensubmenuid.toggleClass("subsubmenulinkon");
			opensubmenuid.next().slideToggle();
		}
		opensubmenuid = $(this);
	});
	
	$('#leftnav').find('#submenulinkon').toggleClass("submenulinkon").next().show();
	$('#leftnav').find('#subsubmenulinkon').toggleClass("subsubmenulinkon").next().show();
	$('#leftnav').find('#subsubsubmenulinkon').toggleClass("subsubsubmenulinkon");
	
// VIEW DETAILS
	
	$('.viewdetails').hide();
	
// MEGA MENU FUNCTIONS	
	$('.knowledgebase_mm').hide();
	
	$('#knowledgebaselink').hover(function() {
		$(".knowledgebase_mm").animate({ opacity: 'show' }, 'fast');
	},function(){
		$(".knowledgebase_mm").hide();
	});
	
	$('.knowledgebase_mm').hover(function() {
		$('.knowledgebase_mm').show();
	},function(){
		$(".knowledgebase_mm").hide();
	});
	
	$('.ourservices_mm').hide();
	
	$('#ourserviceslink').hover(function() {
		$(".ourservices_mm").animate({ opacity: 'show' }, 'fast');
	},function(){
		$(".ourservices_mm").hide();
	});
	
	$('.ourservices_mm').hover(function() {
		$('.ourservices_mm').show();
	},function(){
		$(".ourservices_mm").hide();
	});
	
	$('.offices_mm').hide();
	
	$('#officeslink').hover(function() {
		$(".offices_mm").animate({ opacity: 'show' }, 'fast');
	},function(){
		$(".offices_mm").hide();
	});
	
	$('.offices_mm').hover(function() {
		$('.offices_mm').show();
	},function(){
		$(".offices_mm").hide();
	});
	
	$('.order_mm').hide();
	
	$('#orderlink').hover(function() {
		$(".order_mm").animate({ opacity: 'show' }, 'fast');
	},function(){
		$(".order_mm").hide();
	});
	
	$('.order_mm').hover(function() {
		$('.order_mm').show();
	},function(){
		$(".order_mm").hide();
	});
	
	$('.group_mm').hide();
	
	$('#grouplink').hover(function() {
		$(".group_mm").animate({ opacity: 'show' }, 'fast');
	},function(){
		$(".group_mm").hide();
	});
	
	$('.group_mm').hover(function() {
		$('.group_mm').show();
	},function(){
		$(".group_mm").hide();
	});
	
	$('.partners_mm').hide();
	
	$('#partnerslink').hover(function() {
		$(".partners_mm").animate({ opacity: 'show' }, 'fast');
	},function(){
		$(".partners_mm").hide();
	});
	
	$('.partners_mm').hover(function() {
		$('.partners_mm').show();
	},function(){
		$(".partners_mm").hide();
	});
	
	$('.fees_mm').hide();
	
	$('#feeslink').hover(function() {
		$(".fees_mm").animate({ opacity: 'show' }, 'fast');
	},function(){
		$(".fees_mm").hide();
	});
	
	$('.fees_mm').hover(function() {
		$('.fees_mm').show();
	},function(){
		$(".fees_mm").hide();
	});
	
	$('.news_mm').hide();
	
	$('#newslink').hover(function() {
		$(".news_mm").animate({ opacity: 'show' }, 'fast');
	},function(){
		$(".news_mm").hide();
	});
	
	$('.news_mm').hover(function() {
		$('.news_mm').show();
	},function(){
		$(".news_mm").hide();
	});
	
	$('.contact_mm').hide();
	
	$('#contactlink').hover(function() {
		$(".contact_mm").animate({ opacity: 'show' }, 'fast');
	},function(){
		$(".contact_mm").hide();
	});
	
	$('.contact_mm').hover(function() {
		$('.contact_mm').show();
	},function(){
		$(".contact_mm").hide();
	});    
	
	
	//
	// MEGA MENU FUNCTIONS	
	$('.knowledgebase_mm_error').hide();
	
	$('#knowledgebaselink_error').hover(function() {
		$(".knowledgebase_mm_error").animate({ opacity: 'show' }, 'fast');
	},function(){
		$(".knowledgebase_mm_error").hide();
	});
	
	$('.knowledgebase_mm_error').hover(function() {
		$('.knowledgebase_mm_error').show();
	},function(){
		$(".knowledgebase_mm_error").hide();
	});
	
	$('.ourservices_mm_error').hide();
	
	$('#ourserviceslink_error').hover(function() {
		$(".ourservices_mm_error").animate({ opacity: 'show' }, 'fast');
	},function(){
		$(".ourservices_mm_error").hide();
	});
	
	$('.ourservices_mm_error').hover(function() {
		$('.ourservices_mm_error').show();
	},function(){
		$(".ourservices_mm_error").hide();
	});
	
	$('.offices_mm_error').hide();
	
	$('#officeslink_error').hover(function() {
		$(".offices_mm_error").animate({ opacity: 'show' }, 'fast');
	},function(){
		$(".offices_mm_error").hide();
	});
	
	$('.offices_mm_error').hover(function() {
		$('.offices_mm_error').show();
	},function(){
		$(".offices_mm_error").hide();
	});
	
	$('.order_mm_error').hide();
	
	$('#orderlink_error').hover(function() {
		$(".order_mm_error").animate({ opacity: 'show' }, 'fast');
	},function(){
		$(".order_mm_error").hide();
	});
	
	$('.order_mm_error').hover(function() {
		$('.order_mm_error').show();
	},function(){
		$(".order_mm_error").hide();
	});
	
	$('.group_mm_error').hide();
	
	$('#grouplink_error').hover(function() {
		$(".group_mm_error").animate({ opacity: 'show' }, 'fast');
	},function(){
		$(".group_mm_error").hide();
	});
	
	$('.group_mm_error').hover(function() {
		$('.group_mm_error').show();
	},function(){
		$(".group_mm_error").hide();
	});
	
	$('.partners_mm_error').hide();
	
	$('#partnerslink_error').hover(function() {
		$(".partners_mm_error").animate({ opacity: 'show' }, 'fast');
	},function(){
		$(".partners_mm_error").hide();
	});
	
	$('.partners_mm_error').hover(function() {
		$('.partners_mm_error').show();
	},function(){
		$(".partners_mm_error").hide();
	});
	
	$('.fees_mm_error').hide();
	
	$('#feeslink_error').hover(function() {
		$(".fees_mm_error").animate({ opacity: 'show' }, 'fast');
	},function(){
		$(".fees_mm_error").hide();
	});
	
	$('.fees_mm_error').hover(function() {
		$('.fees_mm_error').show();
	},function(){
		$(".fees_mm_error").hide();
	});
	
	$('.news_mm_error').hide();
	
	$('#newslink_error').hover(function() {
		$(".news_mm_error").animate({ opacity: 'show' }, 'fast');
	},function(){
		$(".news_mm_error").hide();
	});
	
	$('.news_mm_error').hover(function() {
		$('.news_mm_error').show();
	},function(){
		$(".news_mm_error").hide();
	});
	
	$('.contact_mm_error').hide();
	
	$('#contactlink_error').hover(function() {
		$(".contact_mm_error").animate({ opacity: 'show' }, 'fast');
	},function(){
		$(".contact_mm_error").hide();
	});
	
	$('.contact_mm_error').hover(function() {
		$('.contact_mm_error').show();
	},function(){
		$(".contact_mm_error").hide();
	});    
	//
    
});

// used by GroupIntroduction webpart
function show_rightover(id)
{
	document.getElementById(id).className = "home_right_over";
}
function hide_rightover(id)
{
	document.getElementById(id).className = "home_right_01";
}
//


function showMapPopup(id)
{
    
    if (document.getElementById(id).style.display == "none")
	{
		//opensubmenuid = id;
		document.getElementById(id).style.display="block";
		
	}
    
}

function hideMapPopup(id)
{
    
    if (document.getElementById(id).style.display == "block")
	{
		document.getElementById(id).style.display="none";
		
	}
    
}



//Currency Convertor START

// Array.insert( index, value ) - Insert value at index, without overwriting existing keys
Array.prototype.insert = function insert( i, v ) 
{
 if( i>=0 ) 
 {
  var a = this.slice(), b = a.splice( i );
  a[i] = v;
  return a.concat( b );
 }
}

//var MyArray = new Array();
//MyArray[0] = null;



function changeCurrency(id)
{
//Please Note: The Global Array: 'MyArray' is created in the default.master for FEES

    
var currencyRawValue = 0;

    if (document.getElementById('currencyDrop')!=null)
	{
	var dropdownIndex = document.getElementById('currencyDrop').selectedIndex;
    var currencyRate = document.getElementById('currencyDrop')[dropdownIndex].value; //7, 11 ??
	var currencyCode = document.getElementById('currencyDrop')[dropdownIndex].text;  // usd, gbp ??
	
	}
	if (currencyRate != "Select")
	{	
	  for(i=0;i<400;i++)
        {
                  
            if (document.getElementById('cur' + i)!=null)
	        {
	           var cellindex = i;
	            //alert (cellindex);
	            //alert (MyArray[cellindex]);
	            //MyArray[cellindex] = '350';
                if (MyArray[cellindex]!=null)
                    {
                        currencyRawValue = MyArray[cellindex]
                        //alert (MyArray[cellindex]);
                    }
                else 
                    {
                       // currencyRawValue = (document.getElementById('cur' + i).innerHTML).substr(3);
                        currencyRawValue = (document.getElementById('cur' + i).innerHTML);
                        MyArray[cellindex] = currencyRawValue;
                        //alert (MyArray[cellindex]);
                    }
               
	            var currencyCalc = currencyRawValue * currencyRate;
	            //alert(currencyCalc);
	            document.getElementById('cur' + i).innerHTML = currencyCode + " " + Math.round(currencyCalc*100)/100 ;
    		    //document.getElementById('cur' + i).innerHTML = currencyCalc;
        		
	        }
            
        }
    }
   
    
	//alert('hello');
    
}

// Currency Converter END


// Offices Display Time START

function startTime(timezone)
{

var today=new Date();
var h=timezone + today.getUTCHours();
var m=today.getUTCMinutes();
 if(h >= 24)
 {    
    h = h - 24;
 }
 if(m < 10)
 { m = "0"+m;}
 if(h < 10)
 { h = "0"+h;}
 
 
//document.getElementById('txt').innerHTML=h+":"+m";
document.write(h+":"+m);


}
// Offices Display Time END


function view_details(id)
{
	$(id).animate({ opacity: 'show' }, 'fast');
}
function hide_details(id)
{
	$(id).hide();
}

function view_details(id)
{
	$(id).animate({ opacity: 'show' }, 'fast');
}
function hide_details(id)
{
	$(id).hide();
}



function loadcontent(contentdiv, contenturl)
{
	$(""+contentdiv+"").load(contenturl);
}



function show_rightover(id)
{
	document.getElementById(id).className = "home_right_over";
}
function hide_rightover(id)
{
	document.getElementById(id).className = "home_right_01";
}

function show_rightover2(id)
{
	document.getElementById(id).className = "home_right_over";
}
function hide_rightover2(id)
{
	document.getElementById(id).className = "home_right_02";
}
