﻿var activetab = '';
var prevtab = '';
var animateSpeed = 'slow'; // Values Allowed 'slow', 'fast', any integer without quotes (200,300,400 etc)
var fadeOutSpeed = 1500; // Values Allowed 'slow', 'fast', any integer without quotes (200,300,400 etc)
var posdistance = "+=20px";
var nevdistance = "-=20px";
var OperaDistance = 20;

function toggleTabs()
{
    if(activetab=='tab1'){
          $("#tab1").animate({"left": nevdistance}, animateSpeed);
         $("#div_Enterprise").fadeIn(fadeOutSpeed);
    }
    else if(activetab=='tab2'){
	      $("#tab2").animate({"left": nevdistance}, animateSpeed);
	      $("#div_Mobile").fadeIn(fadeOutSpeed);
    }
    else if(activetab=='tab3'){
	      $("#tab3").animate({"left": nevdistance}, animateSpeed);
	      $("#div_Interactive").fadeIn(fadeOutSpeed);
    }
    else
    {}
}	

// Below function executes only for the Opera Desktop and Mobile Browsers 
// as the jQuery Animate function is not working properly
function Opera_ToggleTabs()
{
    if(activetab=='tab1'){
         var leftPostion = document.getElementById("tab1").style.left.replace('px','');
         if(leftPostion == "")
         {
            leftPostion = parseInt('0'); 
         }else
         {
            leftPostion = parseInt(leftPostion);
         }
         document.getElementById("tab1").style.left = leftPostion  - OperaDistance; 
         $("#div_Enterprise").fadeIn(fadeOutSpeed);
    }
    else if(activetab=='tab2'){
	     var leftPostion = document.getElementById("tab2").style.left.replace('px','');
         if(leftPostion == "")
         {
            leftPostion = parseInt('0'); 
         }else
         {
            leftPostion = parseInt(leftPostion);
         }
	      document.getElementById("tab2").style.left = leftPostion  - OperaDistance; 
	      $("#div_Mobile").fadeIn(fadeOutSpeed);
    }
    else if(activetab=='tab3'){
         var leftPostion = document.getElementById("tab3").style.left.replace('px','');
         if(leftPostion == "")
         {
            leftPostion = parseInt('0'); 
         }else
         {
            leftPostion = parseInt(leftPostion);
         }
	      document.getElementById("tab3").style.left = leftPostion  - OperaDistance;
	      $("#div_Interactive").fadeIn(fadeOutSpeed);
    }
    else
    {}
}

function OnHomePageReady()
{

    // Identify the Correct Tab to be animated based on the DIV id's you show in the page
	activetab = IdentifyCorrectTab();
	
	// validate the tab
	if(activetab != 'tab1' && activetab != 'tab2' && activetab != 'tab3'){
	    // If incorrect parameters then make 'tab1' as default
	    activetab = 'tab1';
	}
	
    $("#tab1").click(function(){
	      window.location.assign("index.htm");
    });
    $("#tab2").click(function(){
          window.location.assign("mobile_home.htm");
    });
    $("#tab3").click(function(){
          window.location.assign("interactive_home.htm");
    });
    
    EnableBrowserFunction();
}

function IdentifyCorrectTab()
{
    if(document.getElementById('div_Enterprise') != null){
        return 'tab1';
    }
    else if(document.getElementById('div_Mobile') != null){
        return 'tab2';
    }
    else if(document.getElementById('div_Interactive') != null){
        return 'tab3';
    }
    else
    {
        return '';
    }
}

function EnableBrowserFunction()
{
    // If the browser is Opera Desktop or Mobile
    if(BrowserDetect.browser == 'Opera'){
            Opera_ToggleTabs();
    }else
    {
      toggleTabs();
    }
}

function OnSubPageReady(animate , animationspeed)
{
    // Activate the Tab1 by default
	activetab = 'tab1';
	
	$("#tab1").click(function(){
	      window.location.assign("index.htm");
    });
    $("#tab2").click(function(){
          window.location.assign("mobile_home.htm");
    });
    $("#tab3").click(function(){
          window.location.assign("interactive_home.htm");
    });
    
    // No need the toggling for static Pages. Only enable click
    if(animate == true){
        animateSpeed = animationspeed;
        EnableBrowserFunction();
    }
}
