$(document).ready(function() {

  $(".currency_tab_content").hide(); //Hide all content
  $("ul.currency_tabs li:first span").addClass("active").show(); //Activate first tab
  $(".currency_tab_content:first").show(); //Show first tab content

  //On Click Event
  $("ul.currency_tabs li").click(function() {
    $("ul.currency_tabs li span").removeClass("active"); //Remove any "active" class
    $(this).find('span').addClass("active"); //Add "active" class to selected tab
    $(".currency_tab_content").hide(); //Hide all tab content

    var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
    $(activeTab).fadeIn(); //Fade in the active ID content
    return false;
  });
  
  //When page loads...
  $(".tab_content").hide(); //Hide all content
  $("ul.tabs li:first span").addClass("active").show(); //Activate first tab
  $(".tab_content:first").show(); //Show first tab content


  //On Click Event
  $("ul.tabs li").click(function() {

    $("ul.tabs li span").removeClass("active"); //Remove any "active" class
    $(this).find('span').addClass("active"); //Add "active" class to selected tab
    $(".tab_content").hide(); //Hide all tab content

    var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
    $(activeTab).fadeIn(); //Fade in the active ID content
    return false;
  });  
  
  $(".tab_content2").hide(); //Hide all content
  $("ul.tabs2 li:first span").addClass("active").show(); //Activate first tab
  $(".tab_content2:first").show(); //Show first tab content

  //On Click Event
  $("ul.tabs2 li").click(function() {
                  $("ul.tabs2 li span").removeClass("active"); //Remove any "active" class
    $(this).find('span').addClass("active"); //Add "active" class to selected tab
    $(".tab_content2").hide(); //Hide all tab content

    var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
    $(activeTab).fadeIn(); //Fade in the active ID content
    return false;
  });

   //***************************************************Nashmin_Start*************************************************//

   //*****************************To Show the active page on the left navigator**************************************//
    var querystring = location.search.replace( '?', '' ).split( '&' );
    // declare object
    var queryObj = {};
    // loop through each name-value pair and populate object
    for ( var i=0; i<querystring.length; i++ )
    {
      // get name and value
      var name = querystring[i].split('=')[0];
      var value2 = querystring[i].split('=')[1];
      // populate object
      queryObj[name] = value2;
     }

    $("#nav_left li").each(function(index) {
    var value = $(this).attr('value');

    if (queryObj[ "id" ] == value) 
    {
      $(this).addClass("selected");
      return;
    }

  });

 $("#topnav ul.topnav li").each(function(index) {
    var value = $(this).attr('value');
 	
	// make sure all the menu dividers are showing. We will then hide the ones that are adjacent to the menu item we are selecting
	$(this).find("span").removeClass("menuDividerSelected"); 
	// remove the inside background
	$("#pageBackground").removeClass("backbodyInside"); 
	
	
    // Institutional 
	
	// Array of Insto Page IDs 
    var instoArray = ["1815"];
	
     if ($.inArray(queryObj[ "id" ], instoArray) > -1)
        {    
           $(this).find("a.navinstitutional").addClass("navsel_institutional");  
           $(this).find("a").removeClass("navinstitutional"); 
		   $("#menuDividerInsto").addClass("menuDividerSelected");		   
           return;
    }
    
    // Private 
    
    // Array of Private Page IDs 
    var privateArray = ["1397","1375","1422","1423","1777","1793", "1848", "1405", "1374", "1413", "1414", "1415", "1376", "1416", "1400", "1390", "1398", "1446", "1673", "1668", "1676", "1399", "1424", "1677", "1426", "1428", "1429", "1401", "1444", "1701", "1402", "1379", "1443", "1403","1808", "1809", "1811", "1813", "1840", "1833", "1834", "1835", "1836", "1837", "1838"];
     
    if ($.inArray(queryObj[ "id" ], privateArray) > -1) 
	    {    
	       $(this).find("a.navprivate").addClass("navsel_private");  
	       $(this).find("a").removeClass("navprivate");  
		   $("#menuDividerInsto").addClass("menuDividerSelected");
		   $("#menuDividerPrivate").addClass("menuDividerSelected");
		   
		   // apply the inside background
		   $("#pageBackground").addClass("backbodyInside");
	       return;
    }
    
    // Corporate Services 
    if ((queryObj[ "id" ] == 1816)) 
    	    {    
    	       $(this).find("a.navcorporate_services").addClass("navsel_corporate_services");  
    	       $(this).find("a").removeClass("navcorporate_services");  
			   $("#menuDividerPrivate").addClass("menuDividerSelected");
			   $("#menuDividerCorp").addClass("menuDividerSelected");
    	       return;
    }
    
	// Research 
	if ((queryObj[ "id" ] == 1814)) 
		{    
		   $(this).find("a.navresearch").addClass("navsel_research");  
		   $(this).find("a").removeClass("navresearch"); 
		   $("#menuDividerCorp").addClass("menuDividerSelected");
		   $("#menuDividerResearch").addClass("menuDividerSelected");	
		   return;
	}
		
	 // About Us 
	if ((queryObj[ "id" ] == 1404)) 
		{    
		   $(this).find("a.navaboutus").addClass("navsel_aboutus");  
		   $(this).find("a").removeClass("navaboutus");  
		   $("#menuDividerResearch").addClass("menuDividerSelected");
		   return;
	}
	 
 
  });
  
  // Sub nav ribbon selected items
  $("#subNavRibbon ul li").each(function(index) {
  
	$("#subNavRibbon ul li").removeClass("subNavSelected"); 
	$("#subNavRibbon ul li").removeClass("subNavDividerSelected"); 
  
	// Stockbroking 
	var sbArr = ["1405", "1374", "1413", "1414", "1415", "1376", "1416"];
	
	if ($.inArray(queryObj[ "id" ], sbArr) > -1) 
	{
		$("#subStockBroking").addClass("subNavSelected");
		$("#dividerStockBroking").addClass("subNavDividerSelected");
	}
	
    // Corporate  Advisory
	var corpArr = ["1397","1375","1422","1423","1777"];
	
	if ($.inArray(queryObj[ "id" ], corpArr) > -1) 
	{
		$("#subCorp").addClass("subNavSelected");
		$("#dividerStockBroking").addClass("subNavDividerSelected");
		$("#dividerCorp").addClass("subNavDividerSelected");
	}
	
	// Futures 
	var fArr = ["1398", "1446", "1668", "1676", "1673", "1848"];
	
	if ($.inArray(queryObj[ "id" ], fArr) > -1) 
	{
		$("#subFutures").addClass("subNavSelected");
		$("#dividerCorp").addClass("subNavDividerSelected");
		$("#dividerFutures").addClass("subNavDividerSelected");
	}
	
	// Foreign Exchange 
	var fxArr = ["1399", "1424", "1677", "1426", "1428", "1429"];
	
	if ($.inArray(queryObj[ "id" ], fxArr) > -1) 
	{
		$("#subForEx").addClass("subNavSelected");
		$("#dividerFutures").addClass("subNavDividerSelected");
		$("#dividerForEx").addClass("subNavDividerSelected");
	}
	
	// Cash Account
	var caArr = ["1400", "1390", "1840"];
	
	if ($.inArray(queryObj[ "id" ], caArr) > -1) 
	{
		$("#subCash").addClass("subNavSelected");
		$("#dividerForEx").addClass("subNavDividerSelected");
		$("#dividerCash").addClass("subNavDividerSelected");
	}
	
	 // Fixed Income
	  var fiArr = ["1833", "1834", "1835", "1836", "1837", "1838"];
	  
	  if ($.inArray(queryObj[ "id" ], fiArr) > -1) 
	  {
		$("#subFixedIncome").addClass("subNavSelected");
		$("#dividerCash").addClass("subNavDividerSelected");
		$("#dividerFixed").addClass("subNavDividerSelected");
	  }

	
	// Lending
	var mlArr = ["1401", "1444", "1701"];
	
	if ($.inArray(queryObj[ "id" ], mlArr) > -1) 
	{
		$("#subLending").addClass("subNavSelected");
		$("#dividerFixed").addClass("subNavDividerSelected");
		$("#dividerLending").addClass("subNavDividerSelected");
	}
	
	// Superannuation
	var sArr = ["1402", "1379", "1443"];
	
	if ($.inArray(queryObj[ "id" ], sArr) > -1) 
	{
		$("#subSuper").addClass("subNavSelected");
		$("#dividerLending").addClass("subNavDividerSelected");
		$("#dividerSuper").addClass("subNavDividerSelected");
	}
	
	// Portfolio Admin
	var paArr = ["1403"];
	
	if ($.inArray(queryObj[ "id" ], paArr) > -1) 
	{
		$("#supPortfolioAdmin").addClass("subNavSelected");
		$("#dividerSuper").addClass("subNavDividerSelected");
	}
  
  });
  
  //**************************By clicking on the new item ,the previous item should lose its focus*******************
 //  $("#nav_left li").click(function()
 //   {
 //      $("#nav_left li").removeClass("selected");
  //     $(this).addClass("selected");

//     }
  // );

 //  $("#nav .stockbroking_li a").click(function()
  //  {

      // $("#nav_left li").removeClass("sel");
  //     $(this).addClass("sel1");

  //   }
  // );
 
  //******************************************Remove the empty <h2>*************************************************//

  $("#main_content h2").each(function(index) 
  {
       if($(this).text()=="")
    {
                 $(this).remove();
            }  
          });
  $("h3").each(function(index) 
  {
       if($(this).text()=="")
    {
                 $(this).remove();
            }  
          });
   
  //*************************************Remove the empty <span summary> if it is empty******************************//
          if($("#main_content .summary").text()=="")
     $("#main_content .summary").remove();
  
  //***************************************Remove the empty <span summary> if it is empty****************************//
          if($("#main_content .summary").text()=="")
     $("#main_content .summary").remove();

  //************************************************Remove the empty <p>*********************************************//     
         $("#main_content .body_text p").each(function(index) 
  {
          if($(this).text()=="")
     {
               $(this).remove();
             }  
          });
	  
		  
   //*******************Top Navigation Drop Down List the rest are at the buttom of the page************************//
    $("#nav ul.topnav li").mouseenter(function(){
     
        if ($(this).children("ul.subnav").css('display') == 'none'){
         if(navigator.appName == "Microsoft Internet Explorer")
          {
            $(this).children("ul.subnav").slideDown(200); 
          } 
         else
          {
      $(this).children("ul.subnav").slideDown(400); 
   }
       }
          
    });
    
    $("#nav ul.topnav li").mouseleave(function(){    
        if ($(this).children("ul.subnav").css('display') == 'block') {
         if(navigator.appName == "Microsoft Internet Explorer")
           {
            $(this).children("ul.subnav").slideUp(200);
           }
         else
          {
            $(this).children("ul.subnav").slideUp(100);

           }

        }
        
    });
 });

  //**************************************************ZOOM IN A+ ***************************************************//

 function increase()
 {
    bigger("#main_content *"); 
 };

 //******************************IF browser is not IE then increase the text sizes instead**************************//
var maxTxtSize = 20;
function bigger(name){
  var items = $(name).children();
  for(k=0;k<items.length;k++)
  { 
   if(jQuery(items[k]).is('table.rate'))  
     maxTxtSize=18;

   if(!($(items[k]).is('#main_content h1 span')))
   {     
      var currentFontSize =$(items[k]).css('font-size');
      var currentFontSizeNum = parseFloat(currentFontSize, 10);
      if(jQuery(items[k]).is('#Convert a span'))  
      {
            $(items[k]).css('font-size',currentFontSize );
      }
      else
      {
      if(maxTxtSize > currentFontSizeNum )
      {
        var newFontSize=currentFontSizeNum  + 2;    
        $(items[k]).css('font-size',newFontSize);
        $('#main_content .small_body_text').css('font-size',newFontSize);
        $('#main_content h3').css('font-size',newFontSize);
       }
      }
     }
   }
 };

//*************************************************ZOOM OUT A- ***************************************************//
 function decrease()
 {
   Smaller("#main_content *");
 };

//*********************IF browser is not IE then decrease the text sizes instead of zooming out*********************//
 
var minTxtSize = 14;

function Smaller(name)
{ 
 var items = $(name).children();
  for(k=0;k<items.length;k++)
  {
   if(!($(items[k]).is('#main_content h1 span')))
   {
    var currentFontSize =$(items[k]).css('font-size');
     var currentFontSizeNum = parseFloat(currentFontSize, 10);
     if(minTxtSize < currentFontSizeNum )
      {
       var newFontSize=currentFontSizeNum  - 2;    
       $(items[k]).css('font-size',newFontSize);
       $('#main_content .small_body_text').css('font-size',newFontSize);
       $('#main_content h3').css('font-size',newFontSize);
      }
    }
  }
};



  //***************************************************Nashmin_End*************************************************//



$(document).ready(function() { 
	if($('#s3slider').length>0){
   $('#s3slider').s3Slider({ 
      timeOut: 5000 
   });
   }

});
