$(function() {
//    $('#header-nav').find('a').click( function(){
//       e.preventDefault();
//       if($(this).hasClass('has-sub-nav')){
//            $('#header-sub-nav').animate({height:59, opacity:1}, 200),
//            $('#header-sub-nav ul li').css({visibility:'visible'}).animate({opacity:1});
//            $('#content').animate({backgroundPosition:'0 -140'}, 250, 'easeInOutExpo');
//       } else {
//            $('#header-sub-nav').animate({height:0, opacity:0}, 200),
//            $('#header-sub-nav ul li').animate({opacity:0}).css({visibility:'hidden'});
//            $('#content').animate({backgroundPosition:'0 0'}, 250, 'easeInOutExpo');
//       }
//    });
    
    $('a[rel=external]').live('click', function() {
        $(this).attr('target', '_blank');
    });
    
    $('#search-visual-content').find('.search').live('click', function(){
        $('#search-items').find('article').animate({opacity:0},350,'easeInOutExpo');
        $('#search-items').empty();
        $('#no-results-template').tmpl().appendTo('#search-items').css({opacity:0}).animate({opacity:1});
        $('.searched-word').text($('#search-visual-content').find('input').val().toString());
        $('#search-items').css({'min-height':600});
    });
    
    
    $('#eight-things .paginator').find('ul').append('<li class="slider">1</li>');
    
    var startMargin = parseInt($('.paginator').find('li.slider').css('margin-left'));
    $('#eight-things .paginator').find('li slider').css({marginLeft:startMargin});
    
    $('#eight-things .paginator').find('li a').click(function(e){
        e.preventDefault();
        
        $('.paginator').find('.active').removeClass('active');
        $(this).parent().addClass('active');
        
        var slider = $('.paginator').find('li.slider');
        slider.text($(this).text());
        slider.stop().animate({marginLeft:(startMargin + ((parseInt($(this).parent().index())) * 56 ))}, 500, 'easeInOutExpo');
    });
    
    $('#eight-things .paginator').find('a.next').click(function(e){
        e.preventDefault();
        var currentActive = $('.paginator').find('li.active');
        if (currentActive.index() >= 7) {
            
        } else {
            $('li.active').next().find('a').trigger('click');
//            $.getScript('http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js');
        }
    });
    
    $('#eight-things .paginator').find('a.prev').click(function(e){
        e.preventDefault();
        var currentActive = $('.paginator').find('li.active');
        if (currentActive.index() == 0) {
            
        } else {
            $('li.active').prev().find('a').trigger('click');
//            $.getScript('http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js');
        }
    });
    
    
    var faqFirstText = $('#faq').find('li:first-child').text();
    $('#faq').find('ul').prepend('<li class="slider"><span class=text></span></li>');
    $('#faq .slider').find('.text').text(faqFirstText);
    
    
    $('#faq').find('li a').click(function(e){
        e.preventDefault();
        var slider = $('#faq').find('li.slider');
        slider.find('.text').text($(this).text());
        slider.stop().animate({marginTop:(-3 + (parseInt($(this).parent().index() -1) * 40))}, 500, 'easeInOutExpo');
        //load content matching index() number
    });
    
    var sideNavFirstText = $('.sidenavigation').find('li:first-child').text();
    $('.sidenavigation').find('ul').prepend('<li class="slider"><span class=text></span></li>');
    $('.sidenavigation .slider').find('.text').text(sideNavFirstText);
    
    $('.sidenavigation').find('li a').live('click', function(){
        $('.sidenavigation').find('li.active').removeClass('active');

            $(this).parent().addClass('active');
        
        var slider = $('.sidenavigation').find('li.slider');
        slider.find('.text').text($(this).text());
        slider.stop().animate({marginTop:(-3 + (parseInt($(this).parent().index() -1) * 40))}, 500, 'easeInOutExpo', function(){
            
        });
    });
    
    var sideNavLargeFirstText = $('.sidenavigation-large').find('li:first-child a').text();
    var sideNavLargeFirstNumber = $('.sidenavigation-large').find('li:first-child .number').text();
    $('.sidenavigation-large').find('ul').prepend('<li class="slider"><span class="number"></span><span class=text></span></li>');
    $('.sidenavigation-large .slider').find('.text').text(sideNavLargeFirstText);
    $('.sidenavigation-large .slider').find('.number').text(sideNavLargeFirstNumber);
    
    
    $('.sidenavigation-large').find('li a').click(function(e){
        e.preventDefault();
        var slider = $('.sidenavigation-large').find('li.slider');
        slider.find('.text').text($(this).text());
        slider.find('.number').text($(this).parent().find('.number').text());
        slider.stop().animate({marginTop:(-8 + (parseInt($(this).parent().index() -1) * 59))}, 500, 'easeInOutExpo');
        //load content matching index() number
    });
    
    
    $('#appointment').find('input').focus(function(){
        $(this).parent().css({background:'#eef2cc'});
    }).blur(function(){
        $(this).parent().css({background:'#ededed'});
    });

    $('#appointment').find('select').focus(function(){
        $(this).parent().css({background:'#eef2cc'});
        $(this).prev().css({borderColor:'#acbc00'});
    }).blur(function(){
        $(this).parent().css({background:'#ededed'});
        $(this).prev().css({borderColor:'#ccc'});
    });
    $('article.first').live('click', function(e){
       e.preventDefault();
       window.location = $(this).find('a').attr('href');
    });
    $('article.second').live('click', function(e){
       e.preventDefault();
       window.location = $(this).find('a').attr('href');
    });
    $('article.third').live('click', function(e){
       e.preventDefault();
       window.location = $(this).find('a').attr('href');
    });
    
    
    Array.prototype.max = function() {
        var max = this[0],
        len = this.length;
        for (var i = 1; i < len; i++) if (this[i] > max) max = this[i];
        return max;
    }
    
    var heights = [],
    profiles = $('.profile-info');
    profiles.each(function () {
        heights.push($(this).height());
    });
    var maxHeight = heights.max();
    profiles.height(maxHeight);
    
    
    
    var featureHeights = [],
    features = $('#key-features ul li');
    features.each(function(){
        featureHeights.push($(this).height());
    });
    var maxFeatureHeight = featureHeights.max();
    features.height(maxFeatureHeight);
    
   
    var articleHeights = [],
    articles = $('#current-openings').find('article');
    articles.each(function () {
        articleHeights.push($(this).height());
    });
    var maxArticleHeight = articleHeights.max();
    articles.height(maxArticleHeight);
    
    
    
    
    
   
    
    //Dit regelt alles betreft tabbladen op de pagina. 
    //Breedte tabs, aantal tabs, tussenruimte tabs 
    //en eventuele residu die toegekend wordt aan last-child breedte.
    var tabs = $('#tabs'),
    borderThickness = 2,
    tabsTotalWidth = tabs.parent().width(),
    tabsNumber = tabs.find('li').length,
    tabsSpacing = ((tabsNumber - 1) * borderThickness), 
    tabsMaxWidth = Math.floor((tabsTotalWidth - tabsSpacing) / tabsNumber),
    residu = tabsTotalWidth - ((tabsMaxWidth * tabsNumber) + tabsSpacing);
    tabs.find('li').width(tabsMaxWidth);
    tabs.find('li:last-child').width(tabsMaxWidth + residu);
    
    if(tabsNumber === 1){
        tabs.find('li').css({width:(tabsTotalWidth / 2) - borderThickness});
    }
    
    //Wanneer er veel tabs verschijnen moet de fontsize ook meeschalen.
    var currentFontSize = parseInt($('#tabs li a').css('fontSize'));
    if(tabsNumber > 6) {
        tabs.find('a').css({fontSize:Math.floor(currentFontSize * 0.75)});
    } else {
        tabs.find('a').css({fontSize:currentFontSize});
    }
    if(tabsNumber > 9){
        tabs.find('a').css({fontSize:Math.floor(currentFontSize * 0.6)});
    } else {
        tabs.find('a').css({fontSize:currentFontSize});
    }

    $('#tabs ul li').find('a').live('click', function(e){
       e.preventDefault();
       $('#tabs').find('li').removeClass('active');
       $(this).parent().addClass('active');
    });
    
    //Tijdelijke clone items om de 'show more' te showen.
    $('#news').find('.show-more').live('click', function(e){
       e.preventDefault();
       $('#news').find('article').clone().css({opacity:0}).appendTo('#news-items').animate({opacity:1},600,'easeInOutExpo');
    });
    
    $('#search-results').find('.show-more').live('click', function(e){
       e.preventDefault();
       $('#search-results').find('article').clone().css({opacity:0}).appendTo('#search-items').animate({opacity:1},600,'easeInOutExpo');
    });
    
    
    
//    $('#components ul li').live('hover',
//        function(){
//            $(this).find('a').animate({opacity:1}, 150);
//        },
//        function(){
//            $(this).find('a').animate({opacity:0}, 150);
//    });




//    $('#news-filter').find('label').click(function(){
//        $(this).parent().find('.checked').removeClass('checked');
//        $(this).prev().addClass('checked');
//    });
    $('input[type=radio]').click( function() {
       $('.radio-wrapper').removeClass('checked');
       $(this).parent().addClass('checked');
//       $(this).attr('checked', 'checked');
    });
    $('#components ul li').live('mouseenter', function(){
            $(this).find('a').animate({opacity:1}, 150);
    });
    $('#components ul li').live('mouseleave', function(){
            $(this).find('a').animate({opacity:0}, 150);
    });
   
    $('#components ul li').live('click', function(){
        $(this).find('a').trigger('click');
    });
    $('#components ul li a').live('click', function(e){
        e.preventDefault();
        var textHeight = $(this).parent().find('p').innerHeight();
        if($(this).hasClass('open')){
            $(this).parent().animate({height:(textHeight + 40)}, 300);
            $(this).parent().find('img').animate({opacity:1},250);
            $(this).parent().find('p').animate({height:textHeight},250);
            $(this).removeClass('open');
            $(this).addClass('close');
        } else {
            $(this).parent().animate({height:88}, 300);
            $(this).parent().find('img').animate({opacity:0},250);
            $(this).removeClass('close');
            $(this).addClass('open');
        }
        return false;
    });

    
    $('#about-visual-show-more.read-more').live('click', function(e){
        e.preventDefault();
        $(this).hide();
        $('#more-about').css({display:'block'}).animate({paddingTop:30, paddingBottom:30, opacity:1},250,'easeInOutExpo');
    });
    
    $('#more-about-close').live('click', function(e){
        e.preventDefault();
        $('#more-about').animate({opacity:0},250,'easeInOutExpo',function(){
            $(this).css({display:'none'});
            $('#about-visual-show-more.read-more').css({display:'block'});
        });
    });
    
    $('#security-visual-show-more').live('click', function(e){
        e.preventDefault();
        $(this).hide();
        $('#more-about-inspector').css({display:'block'}).animate({paddingTop:30, paddingBottom:30, opacity:1},250,'easeInOutExpo');
    });
    
    $('#more-security-close').live('click', function(e){
        e.preventDefault();
        $('#more-about-inspector').animate({opacity:0},250,'easeInOutExpo',function(){
            $(this).css({display:'none'});
            $('#security-visual-show-more').css({display:'block'});
        });
    });
    
    $('#workbench-visual-show-more').live('click', function(e){
        e.preventDefault();
        $(this).hide();
        $('#more-about-workbench').css({display:'block'}).animate({paddingTop:30, paddingBottom:30, opacity:1},250,'easeInOutExpo');
    });
    
    $('#more-workbench-close').live('click', function(e){
        e.preventDefault();
        $('#more-about-workbench').animate({opacity:0},250,'easeInOutExpo',function(){
            $(this).css({display:'none'});
            $('#workbench-visual-show-more').css({display:'block'});
        });
    });
    
    
    $('.inspectorfi-keyfeatures').live('click',function(e){
        e.preventDefault();
        $('.switch-content').empty();
        $('#inspectorfi-keyfeatures').tmpl().appendTo('.switch-content');
        resetFeatureHeights();
    });
    $('.inspectorfi-hardware').live('click',function(e){
        e.preventDefault();
        $('.switch-content').empty();
        $('#inspectorfi-hardware').tmpl().appendTo('.switch-content');
    });
    $('.inspectorfi-software').live('click',function(e){
        e.preventDefault();
        $('.switch-content').empty();
        $('#inspectorfi-software').tmpl().appendTo('.switch-content');
    });
    
    $('.inspectorsca-keyfeatures').live('click',function(e){
        e.preventDefault();
        $('.switch-content').empty();
        $('#inspectorsca-keyfeatures').tmpl().appendTo('.switch-content');
        resetFeatureHeights();
    });
    $('.inspectorsca-hardware').live('click',function(e){
        e.preventDefault();
        $('.switch-content').empty();
        $('#inspectorsca-hardware').tmpl().appendTo('.switch-content');
    });
    $('.inspectorsca-software').live('click',function(e){
        e.preventDefault();
        $('.switch-content').empty();
        $('#inspectorsca-software').tmpl().appendTo('.switch-content');
    });
    
    $('.jcworkbench-suites').live('click',function(e){
        e.preventDefault();
        $('.switch-content').empty();
        $('#jcworkbench-suites').tmpl().appendTo('.switch-content');
        resetFeatureHeights();
    });
    $('.jcworkbench-package').live('click',function(e){
        e.preventDefault();
        $('.switch-content').empty();
        $('#jcworkbench-package').tmpl().appendTo('.switch-content');
    });
    
    
    $('.security-analyst').live('click',function(e){
        var openings = $('#openings').find('.column-67');
        openings.empty();
        $('#security-analyst').tmpl().appendTo(openings);
    });
    $('.internships').live('click',function(e){
        var openings = $('#openings').find('.column-67');
        openings.empty();
        $('#internships').tmpl().appendTo(openings);
    });
    $('.security-analyst-riscure-north-america').live('click',function(e){
        var openings = $('#openings').find('.column-67');
        openings.empty();
        $('#security-analyst-riscure-north-america').tmpl().appendTo(openings);
    });
    
    
    $('.smart-cards').live('click',function(e){
         var markets = $('#markets').find('.column-67');
        markets.empty();
        $('#smart-cards').tmpl().appendTo(markets);
    });
    $('.mobile-payment').live('click',function(e){
         var markets = $('#markets').find('.column-67');
        markets.empty();
        $('#mobile-payment').tmpl().appendTo(markets);
    });
    $('.pay-tv').live('click',function(e){
         var markets = $('#markets').find('.column-67');
        markets.empty();
        $('#pay-tv').tmpl().appendTo(markets);
    });
    $('.smart-metering').live('click',function(e){
         var markets = $('#markets').find('.column-67');
        markets.empty();
        $('#smart-metering').tmpl().appendTo(markets);
    });

    $('.smartcards-rfid').live('click',function(e){
        e.preventDefault();
        $('#templates').empty();
        $('#smartcards-rfid-template').tmpl().appendTo('#templates');
        resetClassFeatureHeights();
    });
    $('.system-chip-tech').live('click',function(e){
        e.preventDefault();
        $('#templates').empty();
        $('#system-chip-tech-template').tmpl().appendTo('#templates');
        resetClassFeatureHeights();
    });
    $('.devices').live('click',function(e){
        e.preventDefault();
        $('#templates').empty();
        $('#test-devices-template').tmpl().appendTo('#templates');
        resetClassFeatureHeights();
    });
    
    
    $('.smart-card-protocol-testing').live('click',function(e){
        var techniques = $('#techniques').find('.column-67');
        techniques.empty();
        $('#smart-card-protocol-testing').tmpl().appendTo(techniques);
    });
    $('.java-card-security-testing').live('click',function(e){
        var techniques = $('#techniques').find('.column-67');
        techniques.empty();
        $('#java-card-security-testing').tmpl().appendTo(techniques);
    });
    $('.firmware-reverse-engineering').live('click',function(e){
        var techniques = $('#techniques').find('.column-67');
        techniques.empty();
        $('#firmware-reverse-engineering').tmpl().appendTo(techniques);
    });
    $('.jtag-seria-usb-interface-testing').live('click',function(e){
        var techniques = $('#techniques').find('.column-67');
        techniques.empty();
        $('#jtag-seria-usb-interface-testing').tmpl().appendTo(techniques);
    });
    $('.side-channel-analysis').live('click',function(e){
        var techniques = $('#techniques').find('.column-67');
        techniques.empty();
        $('#side-channel-analysis').tmpl().appendTo(techniques);
    });
    $('.fault-injection-testing').live('click',function(e){
        var techniques = $('#techniques').find('.column-67');
        techniques.empty();
        $('#fault-injection-testing').tmpl().appendTo(techniques);
    });
    $('.source-code-review').live('click',function(e){
        var techniques = $('#techniques').find('.column-67');
        techniques.empty();
        $('#source-code-review').tmpl().appendTo(techniques);
    });
    
    
    $('.understand-the-requirements').live('click',function(e){
        var methodology = $('#methodology').find('.column-60');
        methodology.empty();
        $('#understand-the-requirements').tmpl().appendTo(methodology);
    });
    $('.identify-the-assets').live('click',function(e){
        var methodology = $('#methodology').find('.column-60');
        methodology.empty();
        $('#identify-the-assets').tmpl().appendTo(methodology);
    });
    $('.understand-the-design').live('click',function(e){
        var methodology = $('#methodology').find('.column-60');
        methodology.empty();
        $('#understand-the-design').tmpl().appendTo(methodology);
    });
    $('.threat-analysis').live('click',function(e){
        var methodology = $('#methodology').find('.column-60');
        methodology.empty();
        $('#threat-analysis').tmpl().appendTo(methodology);
    });
    $('.select-tests').live('click',function(e){
        var methodology = $('#methodology').find('.column-60');
        methodology.empty();
        $('#select-tests').tmpl().appendTo(methodology);
    });
    $('.implement-and-execute-tests').live('click',function(e){
        var methodology = $('#methodology').find('.column-60');
        methodology.empty();
        $('#implement-and-execute-tests').tmpl().appendTo(methodology);
    });
    $('.impact-analysis').live('click',function(e){
        var methodology = $('#methodology').find('.column-60');
        methodology.empty();
        $('#impact-analysis').tmpl().appendTo(methodology);
    });
    
    
    $('.faq-general').live('click', function(){
        var support = $('#faq').find('.column-67');
        support.empty();
        $('#faq-general').tmpl().appendTo(support);
    });
    $('.faq-specifications').live('click', function(){
        var support = $('#faq').find('.column-67');
        support.empty();
        $('#faq-specifications').tmpl().appendTo(support);
    });
    $('.faq-software').live('click', function(){
        var support = $('#faq').find('.column-67');
        support.empty();
        $('#faq-software').tmpl().appendTo(support);
    });
    $('.faq-side-channel-analysis').live('click', function(){
        var support = $('#faq').find('.column-67');
        support.empty();
        $('#faq-side-channel-analysis').tmpl().appendTo(support);
    });
    $('.faq-fault-injection').live('click', function(){
        var support = $('#faq').find('.column-67');
        support.empty();
        $('#faq-fault-injection').tmpl().appendTo(support);
    });
    $('.faq-development').live('click', function(){
        var support = $('#faq').find('.column-67');
        support.empty();
        $('#faq-development').tmpl().appendTo(support);
    });
    
    
    $('#sitemap .sitemap').live('click',function(e){
        e.preventDefault();
        $('#sitemap .column-67').empty();
        $('#sitemap-template').tmpl().appendTo('#sitemap .column-67').animate({opacity:1},500,'easeInOutExpo');
    });
    $('#sitemap .disclaimer').live('click',function(e){
        e.preventDefault();
        $('#sitemap .column-67').empty();
        $('#disclaimer-template').tmpl().appendTo('#sitemap .column-67').animate({opacity:1},500,'easeInOutExpo');
    });
    $('#sitemap .privacy-policy').live('click',function(e){
        e.preventDefault();
        $('#sitemap .column-67').empty();
        $('#privacy-policy-template').tmpl().appendTo('#sitemap .column-67').animate({opacity:1},500,'easeInOutExpo');
    });
    $('#sitemap .terms').live('click',function(e){
        e.preventDefault();
        $('#sitemap .column-67').empty();
        $('#terms-template').tmpl().appendTo('#sitemap .column-67').animate({opacity:1},500,'easeInOutExpo');
    });
    
    
    
    
    
    $('#courses article').click(function(e){
        e.preventDefault();
        var sectionLeft = $(this).find('.left').height(),
        sectionRight = $(this).find('.right').height();
        if ($(this).height() > 268 ){
            $(this).stop().animate({height:268}, 300, 'easeInOutExpo');
            $(this).find('.text').css({display:'none'});
            $(this).find('.read-more').text('Read more');
            $(this).find('.read-more').removeClass('read-less');
            $(this).find('.text').stop().animate({opacity:0}, 300, 'easeInOutExpo');
        } else {
            $(this).data('height', ($(this).find('.text').height()));
            $(this).find('.text').css({display:'block'});
            $(this).stop().animate({height:($(this).data('height') + $(this).find('.intro').height() + 100)}, 300, 'easeInOutExpo');
            $(this).find('.read-more').text('Read less');
            $(this).find('.read-more').addClass('read-less');
            $(this).find('.text').stop().animate({opacity:1}, 300, 'easeInOutExpo');
        }
        return false;
            
//        var textHeight = $(this).parent().find('p').innerHeight();
//        if($(this).hasClass('open')){
//            $(this).parent().animate({height:(textHeight + 40)}, 300);
//            $(this).parent().find('img').animate({opacity:1},250);
//            $(this).parent().find('p').animate({height:textHeight},250);
//            $(this).removeClass('open');
//            $(this).addClass('close');
//        }
//        else{
//            $(this).parent().animate({height:88}, 300);
//            $(this).parent().find('img').animate({opacity:0},250);
//            $(this).removeClass('close');
//            $(this).addClass('open');
//        }
//        return false;
    });
    $(document).keydown(function(e) {
        var code = (e.keyCode ? e.keyCode : e.which);
        switch (code) {
            case 27: //esc
                if (!$('#search').height() == 0){
                    $('.search-button-close').trigger('click');
                    $('.search-close').trigger('click');
                }
                break;
        };
    });
    $('a.search-button').live('click', function(e){
        e.preventDefault();
        
        $('#search').animate({height:67, paddingTop:33}, 250, 'easeInOutExpo');
        $('#searchbar').css({display:'block', visibility:'visible'}).animate({opacity:1}, 500, 'easeInOutExpo');
        $('.search-close').css({display:'inline-block'}, 150, 'easeInOutExpo');
        $('.search-close').animate({opacity:1}, 150, 'easeInOutExpo');
        $(this).addClass('search-button-close');
        $(this).removeClass('search-button');
        $(this).stop().animate({opacity:0}, 250, 'easeInOutExpo',function(){
            $(this).css({visibility:'hidden'});
        });
        closeSecToolsFast();
        
        
    });
    $('.search-button-close').live('click', function(){
        $('#search').animate({height:0, paddingTop:0}, 250, 'easeInOutExpo', function(){
            $('#searchbar input').val('Type here what you are looking for..');
        });
        $('.search-close').animate({opacity:0}, 150, 'easeInOutExpo'), function(){
            $('.search-close').css({display:'none', visibility:'hidden'});
        };
        $('#searchbar').animate({opacity:0, height:0}, 150, 'easeInOutExpo'), function(){
            $('#searchbar').css({display:'none', visibility:'hidden'});
        };
        
        $(this).addClass('search-button');
        $(this).removeClass('search-button-close');
        $('.search-button').css({visibility:'visible'});
        $('.search-button').stop().animate({opacity:1}, 250, 'easeInOutExpo');
    });
    $('.search-close').live('click', function(){
        $(this).animate({opacity:0}).css({display:'none'});
        $('#search').animate({height:0, paddingTop:0}, 250, 'easeInOutExpo', function(){
            $('#searchbar input').val('Type here what you are looking for..');
        });
        $('.search-close').animate({opacity:0}, 150, 'easeInOutExpo'), function(){
            $('.search-close').css({display:'none', visibility:'hidden'});
        };
        $('#searchbar').animate({opacity:0, height:0}, 150, 'easeInOutExpo'), function(){
            $('#searchbar').css({display:'none', visibility:'hidden'});
        };
        $('.search-button-close').addClass('search-button');
        $('.search-button-close').removeClass('search-button-close');
        $('.search-button').css({visibility:'visible'});
        $('.search-button').stop().animate({opacity:1}, 250, 'easeInOutExpo');
    });
    $('#search-results article').live('click', function(){
        window.location = $(this).find('a').attr('href');
    });
    $('.faq-link').click(function(e) {        
        e.preventDefault();        
        $(this).toggleClass('faq-link-open');        
        var parentHeight = $(this).parent().height(),        
        linkHeight = $(this).next('h1').innerHeight() + 24,        
        answerHeight = $(this).next().next('p').innerHeight() + 24; 
        $(this).parent().animate({height:((parentHeight > (linkHeight + answerHeight)) ? parentHeight - (answerHeight + 16) : linkHeight + answerHeight + 16)}, 200);        
        $(this).next().next('p').animate({opacity:((parentHeight > (linkHeight + answerHeight)) ? 0 : 1)}, 200);    
    });
    $('a.show-more').click( function(e){
       e.preventDefault();
    });
    //Input box clear value on focus
    $('input[type=text]').focus( function(){
        $(this).val('');
    });
    
    $('#popup-overlay').live('click', function(e){
       e.preventDefault();
       popupClose();
    });
    
    $('.popup-close').live('click', function(e){
       e.preventDefault();
       popupClose();
    });
    
    $('a[rel=popup-quote]').live('click', function(e){
       e.preventDefault();
       renderPopup($(this).data('tmpl'));
       scrollTop();
    });
    
    $('a[rel=popup-form]').live('click', function(e){
       e.preventDefault();
       renderPopup($(this).data('tmpl'));
       scrollTop();
    });
    
    $('.appointment-button').live('click', function(e){
        e.preventDefault();
        popupClose();
    });
    
    function renderPopup(innerTemplate, data) {
        var innerTemplate = $('#' + innerTemplate.toString()),
        data = data || {};
        $('#popup-template').tmpl().appendTo('body');
        if (innerTemplate) {
            innerTemplate.tmpl(data).appendTo('#popup-inner-template');
        }
        $('#popup-overlay').height($(document).height());
        $('#popup-overlay').animate({opacity:.7},500, 'easeInOutExpo');
        $('#popup').animate({opacity:1},500, 'easeInOutExpo');
        centerPopup();
    }
    
    function popupClose(){
       $('#popup-overlay').animate({opacity:0}, 500, 'easeInOutExpo', function(){
            $(this).remove();
       });
       $('#popup').animate({opacity:0}, 500, 'easeInOutExpo', function(){
            $(this).remove();
       });
    }
    
    function centerPopup() {
        var popup = $('#popup'), 
        popupHeight = popup.innerHeight(),
        popupMargin = Math.ceil((popupHeight / 2) * -1);
        popup.css({marginTop:popupMargin});
    }
    
    function scrollTop() {
        $('body').scrollTop(0);
        
        //Internet Explorer Scroll Top
        $('html').scrollTop(0);
    }
    
    var overlayHeight = ($(document).height() - 80),
    overlay = $('#overlay'),
    securityTools = $('#security-tools'),
    SecurityToolsIndex = $('#security-tools li').length,
    securityToolsHeight = (SecurityToolsIndex * 80);
    $('.security-tools').click(function(e){
       e.preventDefault();
       openSecTools();
    });
    $('#overlay').click(function(e){
       e.preventDefault();
       closeSecTools();
    });
    
    $('#security-tools').find('a').click(function(e){
       e.preventDefault();
       var link = $(this).attr('href');
       securityTools.animate({height:0}, 500, 'easeInOutExpo');
       overlay.animate({opacity:0}, 500, 'easeInOutExpo', function(){
           overlay.css({height:0, marginTop:80});
           window.location = link
       }); 
    });
    
   $('.security-tools').click(function(e){
        e.preventDefault();
        if($('#security-tools').height() > 0){
            closeSecTools();
            $('#header-nav').find('.semi-active').removeClass('semi-active');
        } else {
            openSecTools();
            $('#header-nav').find('.active').addClass('semi-active');
            $('.security-tools').parent().addClass('active');
        }
    });
    
    
    function openSecTools(){
//       $('.security-tools').parent().addClass('active');
       overlay.css({height:overlayHeight, marginTop:80});
       securityTools.animate({height:securityToolsHeight}, 500, 'easeInOutExpo');
       overlay.animate({opacity:.6}, 500, 'easeInOutExpo');

        $('.search-close').animate({opacity:0}).css({display:'none'});
        $('#search').animate({height:0, paddingTop:0}, 250, 'easeInOutExpo', function(){
            $('#searchbar input').val('Type here what you are looking for..');
        });
        $('.search-close').animate({opacity:0}, 150, 'easeInOutExpo'), function(){
            $('.search-close').css({display:'none', visibility:'hidden'});
        };
        $('#searchbar').animate({opacity:0, height:0}, 150, 'easeInOutExpo'), function(){
            $('#searchbar').css({display:'none', visibility:'hidden'});
        };
        $('.search-button-close').addClass('search-button');
        $('.search-button-close').removeClass('search-button-close');
        $('.search-button').css({visibility:'visible'});
        $('.search-button').stop().animate({opacity:1}, 250, 'easeInOutExpo');
        
    };
    
    function closeSecTools(){
       $('.security-tools').parent().removeClass('active');
       securityTools.stop().animate({height:0}, 300, 'easeInOutExpo');
       overlay.stop().animate({opacity:0}, 300, 'easeInOutExpo', function(){
           overlay.css({height:0, marginTop:80});
       }); 
       $('#header-nav').find('.semi-active').removeClass('semi-active');
    };
    
    function closeSecToolsFast(){
       $('.security-tools').parent().removeClass('active');
       securityTools.stop().animate({height:0}, 150, 'easeInOutExpo');
       overlay.stop().animate({opacity:0}, 150, 'easeInOutExpo', function(){
           overlay.css({height:0, marginTop:80});
       }); 
       $('#header-nav').find('.semi-active').removeClass('semi-active');
    };
    
    function resetFeatureHeights() {
        Array.prototype.max = function() {
            var max = this[0],
            len = this.length;
            for (var i = 1; i < len; i++) if (this[i] > max) max = this[i];
            return max;
        }
    
        var heights = [],
        profiles = $('.profile-info');
        profiles.each(function () {
            heights.push($(this).height());
        });
        var maxHeight = heights.max();
        profiles.height(maxHeight);

        var featureHeights = [],
        features = $('#key-features ul li');
        features.each(function(){
            featureHeights.push($(this).height());
        });
        var maxFeatureHeight = featureHeights.max();
        features.height(maxFeatureHeight); 
    }
    
    function resetClassFeatureHeights() {
        Array.prototype.max = function() {
            var max = this[0],
            len = this.length;
            for (var i = 1; i < len; i++) if (this[i] > max) max = this[i];
            return max;
        }

//        var heights = [],
//        profiles = $('.key-features ul li');
//        profiles.each(function () {
//            heights.push($(this).height());
//        });
//        var maxHeight = heights.max();
//        profiles.height(maxHeight);

        var featureHeights = [],
        features = $('.key-features ul li');
        features.each(function(){
            featureHeights.push($(this).height());
        });
        var maxFeatureHeight = featureHeights.max();
        features.height(maxFeatureHeight); 
    }
    
});

