﻿jQuery.fn.switchClass = function(class1,class2) { 
    if (this.hasClass(class1)) { 
        this.removeClass(class1).addClass(class2); 
    } else { 
        this.removeClass(class2).addClass(class1); 
    } 
}; 


$(document).ready(function(){
    //var max_height = 250;
    //for(i=1;i<4;i++)
    //{
    //    var h = $('.tab_'+i).height();
    //    if(h > max_height)
    //        max_height = h;
    //}
    
    var h = $('.tab_1').height();
    if(h > 250)
        $('#tab_box_main').height(h);
    
    $(".bottom_menu_sep:last").css("background","none");
    
    get_hash();
});

function change_tabs(tab, page)
{
    for(i=1;i<7;i++)
    {
        $('#tab_'+i).parent().removeClass('active_tab');
        $('.tab_'+i).addClass('hidden_tab');
    }
    $('#tab_'+tab).parent().addClass('active_tab');
    $('.tab_'+tab).removeClass('hidden_tab');
    
    if(tab == 1 && page == 'success')
        window.location.hash = "#micma";
    if(tab == 2 && page == 'success')
        window.location.hash = "#software-development";
    if(tab == 3 && page == 'success')
        window.location.hash = "#data-migrations";
        
    if(tab == 1 && page == 'faq')
        window.location.hash = "#micma";
    if(tab == 2 && page == 'faq')
        window.location.hash = "#transition-to-micma";
    if(tab == 3 && page == 'faq')
        window.location.hash = "#working-with-margasoft";
    
    if(tab == 1 && page == 'news')
        window.location.hash = "#2010";
    if(tab == 2 && page == 'news')
        window.location.hash = "#2009";
    if(tab == 3 && page == 'news')
        window.location.hash = "#2008";
    if (tab == 4 && page == 'news')
        window.location.hash = "#2007";
    if (tab == 5 && page == 'news')
        window.location.hash = "#2006";
    if (tab == 6 && page == 'news')
        window.location.hash = "#2005";
    
    var h = $('.tab_'+tab).height(); 

    if(h > 280)
        $('#tab_box_main').stop(true, false).animate({height: h});
    else
        $('#tab_box_main').stop(true, false).animate({height: 280});
        
    if(h > 305)
        $('#faq_tab_box_main').stop(true, false).animate({height: h});
    else
        $('#faq_tab_box_main').stop(true, false).animate({height: 305});
}

function get_hash()
{
    var hash = window.location.hash;
    
    if(hash == "#micma")
    {
        change_tabs(1, 'success');
        change_tabs(1, 'faq');
    }
    if(hash == "#software-development")
    {
        change_tabs(2, 'success');
    }
    if(hash == "#data-migrations")  
    {
        change_tabs(3, 'success');
    }
    if(hash == "#transition-to-micma")
    {
        change_tabs(2, 'faq');
    }
    if(hash == "#working-with-margasoft")  
    {
        change_tabs(3, 'faq');
    }
    if(hash == "#2010")  
    {
        change_tabs(1, 'news');
    }
    if(hash == "#2009")
    {
        change_tabs(2, 'news');
    }
    if(hash == "#2008")  
    {
        change_tabs(3, 'news');
    }
    if (hash == "#2007") {
        change_tabs(4, 'news');
    }
    if (hash == "#2006") {
        change_tabs(5, 'news');
    }
    if (hash == "#2005") {
        change_tabs(6, 'news');
    }

    if(hash == "#software-development")  
    {
        change_horizontal_tabs(1, 3);
    }
    if(hash == "#data-conversion-and-migration")  
    {
        change_horizontal_tabs(2, 3);
    }
    if(hash == "#software-transition-support")  
    {
        change_horizontal_tabs(3, 3);
    }
    
   // setTimeout("get_hash()", 500);
}

function change_horizontal_tabs(tab, num)
{
    for(i=1;i<num+1;i++)
    {
        $('#horizontal_tab_'+i).removeClass('horizontal_active_tab');
        $('.horizontal_tab_'+i).addClass('horizontal_hidden_tab');
    }
    
    if(num == 3)
    {
        if(tab == 1)
            window.location.hash = "#software-development";
        if(tab == 2)
            window.location.hash = "#data-conversion-and-migration";
        if(tab == 3)
            window.location.hash = "#software-transition-support";
    }
      
    $('#horizontal_tab_'+tab).addClass('horizontal_active_tab');
    $('.horizontal_tab_'+tab).removeClass('horizontal_hidden_tab');
}

